In a previous post of mine, I just denied the term CES (Component Entity Systems). Yes, I denied the term, not the concept. But after posting, I thought I should research some more about the topic and find some concrete example which validates the term CES.
From what I found out (thanks to GameDev, GamesFromWithin, T=Machine, Chris Granger), it’s clear to me that I didn’t really understood what CES actually is.
I am a OOP programmer from the start, so I think in terms of classes and objects. That is what stops you from accepting CES.
I knew that entity is an unique ID, so I thought like this:
This is a very simplified version of what I thought, but you got the idea, right? I thought of Entities as class.
But now I know they are pure int.
Components can be class or struct, but they must contain only data. They actually represent state.
But how about combining that id and a list of components. Maybe we should make a class that has an int and a list of components? That’s what I though, that’s what every OOP programmer thinks.
So if this is not the solution, then how can we approach this? Let’s refactor the above question. Instead of saying the word combining, if we say that, how about mapping that int and a list of components. You got it right? It’s a familiar data structure, a Map. The int and list of components will be the key value pairs.
Then again, games need logic which alters the states. And that is what systems are for. They alter the state.
But what are they, a class with list of entities and an update method? No way, it will just be a function which takes every entity that has an component which this function will update.
Let’s be a little bit more specific, if we have a renderComponent then there will be a function named renderer which will take entities with renderComponent and that renderer function will render that entity.
So that’s it, No more classes, no more inheritance, just a data structure and some functions to manipulate them.
But what are the CES good for? and where do they fall apart? umm… needs some research :D But at least I know what I am going to post next!