I'm quite new to C++, but I've been trying to diversify my skillset a bit during the lockdown.
I'm attempting to write a node-based sound processing tool using SFML. I want to have a struct to contain all of my nodes' inputs and outputs. However, I obviously can't connect any type together. I'm looking to do something similar to what Blender does with its node types.
The following screen recording shows what I mean: the green output type is incompatible with other input types.
I thought that a struct NodeInOut
could be a useful solution to this problem: I'd have a type that I assign whenever I create a new Node, and in the logic for connecting Nodes together I make sure that incompatible types aren't connectable. However, I'll need to pass in a type whenever I create a new Node definition.
My idea for the Node class is that it would be structured a bit like this hastily made diagram.
Does anyone have an idea on how to do this, or how to structure it differently such that this isn't an issue?
I haven't written any code yet besides the SFML boilerplate stuff.
Yes, you can have a "type of types".
However, notice the user connects nodes at runtime. Thus this is a runtime problem, not something you can solve at compile time.
In other words, simply use runtime values that contain whatever types your nodes accept/send and compare them as needed.