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 otherEntity
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 aTransform
component may containsInverse()
function.System
is the implementation holder, it processEntity
based on itsComponent
. TheSystem
may define a "requirement". TheEntity
is processed if it match the requirement, for exampleSpriteRendererSystem
only processEntity
that containsSpriteRenderer
andTransform
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 theScene
, basically, everything that need to added into theScene
must implement this. TheNode
can add anotherNode
instances as its child as well as parent. Currently, myEntity
implementNode
, meaning that allEntity
can be added intoScene
Scene
is the top most level ofNode
, it represent a root ofNode
and there can be only one activeScene
at a time. TheScene
basically implementsNode
and it hasUpdate()
andRender()
functions, this functions is called bySceneDirector
SceneDirector
is basically inherit game window, it manage the active Scene, passingRender()
andUpdate()
method to the active scene as well as updating theInput
states to theScene
.
Now, I combine both pattern as follows:
- The
Scene
has a list ofSystem
as well as list ofNode
. Depending theSystem
, theSystem
may called onRender()
function if theSystem
is Renderable, otherwise it will called onUpdate()
function- Upon
Render()
/Update()
function, theScene
will loop the entireEntity
, it also loop the entire registeredSystem
. TheSystem
will check theEntity
whether the requirement is match, if the requirement is fulfilled, theEntity
will be processed by theSystem
Now my questions:
- Can
Component
hold the logic? or it should not and stay as a bag of data? - Is it correct implement
Node
onEntity
? - Is it correct to let every instances of
Scene
has their ownSystem
? or should I make it globally by storing the list ofSystem
inSceneDirector
? - Is there any more efficient way to process the
Entity
rather than loop theEntities
and theSystems
completely? - Is my understanding correct about the ECS? Am I on the right track? or completely wrong?
Thanks in advance