Extending the code to support behavior changes
A few steps are left to fully support computer-controlled behavior in the instances. First, we need a copy of a node tree in every instance.
Creating a node tree copy for every instance
We cannot just copy the nodes since the original and copy would access the same node behind the shared pointer. Reusing the same nodes for multiple instances would lead to chaos, since collision events from all instances would be triggered, resulting in the same steps executed for all instances sharing the nodes.
To create a copy of the node tree for one of the instances, a custom copy constructor for the SingleInstanceBehavior
class has been created. The copy constructor sets the required callbacks, copies the links, and loops through the vector of existing nodes to create a clone of every node. For nodes that change instance behavior, the additional node action callback will be set.
Next, the callback chain to the renderer must be completed...