Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node API redesign #31

Open
Fydar opened this issue Nov 25, 2021 · 2 comments
Open

Node API redesign #31

Fydar opened this issue Nov 25, 2021 · 2 comments
Assignees
Labels
📦 RPGCore.Behaviour Issue related to the RPGCore.Behaviour package New feature or request

Comments

@Fydar
Copy link
Owner

Fydar commented Nov 25, 2021

Currently RPGCore.Behaviour has been demoted to an experimental library. I'm unhappy with the flexibility of the current API and how poorly it interacts with conventional serializers.

Currently RPGCore.Behaviour can only represent node state in rigid data types that have to be classes. Allowing node state to be represented by structs will allow RPGCore.Behaviour to represent node state in an ECS infrastructure.

API Redesign

The current API for a node looks as follows:

Current API

Removing the duplicate definition of a "Socket"

Currently, a "Socket" is represented both on the template for a node and the instance. This makes serialisation complicated and requires serializers to use custom converters.

Removing the notion of a "node instance" entirely will mean I will no longer have the socket state represented inside the instance data.

Currently, the instance data is strongly associated with the node template; which makes RPGCore.Behaviour inflexible when it comes to interactions with pre-existing code architecture.

Making the instance data optional

There are also many nodes that will not require any instance data. Many logic and maths nodes (Add, Subtract, AND, e.t.c) read from their inputs and immediately provide an output. The output value can be stored on the connection rather than the node. This will reduce the amount of serialised data required to run a graph and allow for graphs that are purely computation (have no runtime information).

@Fydar Fydar added the 📦 RPGCore.Behaviour Issue related to the RPGCore.Behaviour package label Nov 25, 2021
@Fydar Fydar self-assigned this Nov 25, 2021
@Fydar Fydar added the New feature or request label Nov 25, 2021
@Fydar Fydar moved this to Todo in RPGCore Development Dec 23, 2021
@Fydar
Copy link
Owner Author

Fydar commented Dec 24, 2021

I've written the AddNode with the changes above in mind.

Proposed API

Instance data can be accessed through the GraphInstance API. Providing this as a reference from a NodeTemplate should be enough to uniquely identify instance data for a node.

@Fydar Fydar changed the title RPGCore.Behaviour redesign Node API redesign Dec 24, 2021
@Fydar
Copy link
Owner Author

Fydar commented Dec 25, 2021

Exploring the potential to return a reference to the raw data used by an output.

This would mean that I would need a separate API for OutputSocket<T>.IsConnected functionality.

public class AddNode : NodeTemplate
{
    public InputSocket<float> ValueA;
    public InputSocket<float> ValueB;
    public OutputSocket<float> Output;

    public override void OnInputChanged(GraphInstance graphInstance)
    {
        var valueA = graphInstance.GetInput(ValueA);
        var valueB = graphInstance.GetInput(ValueB);
        var output = ref graphInstance.GetOutput(Output);

        output = valueA.Value + valueB.Value;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 RPGCore.Behaviour Issue related to the RPGCore.Behaviour package New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

1 participant