I am trying to determine how to move my current implementation of nodes in a scene graph to an entity component system and am struggling to wrap my head around how the two can work together, if at all.
I think the main cause of my confusion is breaking the habit of structuring everything in an object oriented hierarchy. I'm not overly familiar with game development as a whole so breaking what I already know works to replace with something else will be a testament to my knowledge.
Currently, I have a scene controller and a scene which handle the update and render loops accordingly. Code removed for brevity.
//scene controller
- (void)update:(NSTimeInterval)duration
{
//loop though objects and integrate
}
- (void)render
{
[[self scene] render];
}
//scene
- (void)render
{
//loop through objects and render
}
This works fine with my scene nodes as is. Each node has properties for position, rotation, scale and geometry which are passed to shaders and rendered.
Now I am trying to remove all of these properties from the node and replace them with components.
Note: I realise that node
means something else in an Entity Component System so this will be refactored into something else entirely.
It is my understanding that once I have transitioned from the current implementation to an ECS my game objects will expose the same position, rotation, scale and geometry properties but via components instead.
As of such, where will these new game objects sit in the hierarchy of a scene graph? My first thoughts would be to refactor the update and render loops to include the appropriate systems, a la:
//scene controller
- (void)update:(NSTimeInterval)duration
{
//loop though objects and integrate
[[self positionSystem] update:duration];
}
- (void)render
{
[[self scene] render];
}
//scene
- (void)render
{
//loop through objects and render
[[self renderSystem] render];
}
However, it would seem odd to have the systems spread across two different objects (the scene controller and the scene). It would be possible remove the scene render loop and do this in the scene controller instead to keep everything in one place.
One final cause of confusion is how to link game objects together in the same way that my nodes are currently setup. A node can have children and a parent node which combine the parent matrices up the chain to allow me to link objects together, i.e.: a player and a sword.
From what I can gather, objects in an ECS shouldn't be linked together in this same way, or have I misunderstood the principles of an ECS? If this is the case, how would you create a scene graph from entities that aren't linked together in any way?
I'm eager to step back from my current implementation and overhaul the necessary parts but I'm not sure how to achieve a similar setup or if it is possible or even the correct way of doing things.