Node API redesign
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:
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).
I've written the AddNode with the changes above in mind.
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.
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;
}
}