I'm new in game development and I'm struggling to implement Entity Component System (ECS) properly, I have no idea whether I'm doing it right or completely wrong.
Basically, I try to implement ECS pattern with SceneGraph system, so here my current understanding:
Entity is nothing but a components bag, it has no logic but it may (or may not?) contain essential information to differentiate from the other Entity or grouping them as well, such as ID, Name, Tags, etc.
Component is a data container but contains no logic how to process the data but may contains function to manipulate the data, for example a Transform component may contains Inverse() function.
System is the implementation holder, it process Entity based on its Component. The System may define a "requirement". The Entity is processed if it match the requirement, for example SpriteRendererSystem only process Entity that contains SpriteRenderer and Transform component.
Currently, I have no idea if it's correct or completely mess. Therefore, I try to implement ECS along with SceneGraph as stated before, here my SceneGraph implementation:
Node is an object in the Scene, basically, everything that need to added into the Scene must implement this. The Node can add another Node instances as its child as well as parent. Currently, my Entity implement Node, meaning that all Entity can be added into Scene
Scene is the top most level of Node, it represent a root of Node and there can be only one active Scene at a time. The Scene basically implements Node and it has Update() and Render() functions, this functions is called by SceneDirector
SceneDirector is basically inherit game window, it manage the active Scene, passing Render() and Update() method to the active scene as well as updating the Input states to the Scene.
Now, I combine both pattern as follows:
- The
Scene has a list of System as well as list of Node. Depending the System, the System may called on Render() function if the System is Renderable, otherwise it will called on Update() function
- Upon
Render() / Update() function, the Scene will loop the entire Entity, it also loop the entire registered System. The System will check the Entity whether the requirement is match, if the requirement is fulfilled, the Entity will be processed by the System
Now my questions:
- Can
Component hold the logic? or it should not and stay as a bag of data?
- Is it correct implement
Node on Entity?
- Is it correct to let every instances of
Scene has their own System? or should I make it globally by storing the list of System in SceneDirector?
- Is there any more efficient way to process the
Entity rather than loop the Entities and the Systems completely?
- Is my understanding correct about the ECS? Am I on the right track? or completely wrong?
Thanks in advance