A Brief Look at Entity Component System (ECS)

ECS is game programming pattern and it based on data-oriented design. Click the link for more information about data-oriented design. I don't want to use OOP on my game directly. Because OOP will make more complex game's code. 

ECS consists of Entity, Component and System obviously. According to my impressions, ECS provides more readable and reusable code and of course regular memory usage. Actually, I have no idea about Python's memory usage with ECS. I will see it.

I want to explain these concepts simply:

  • Entity: It's just an ID.
  • Component: It is just data which will be in entity
  • System: It contains entity's behaviour according to entity's component's data  
Let's visualize this pattern.

Entity Component System
Each entity has an id as in the image above. Also, these entities contains components. These components could be like velocity, position or size etc. For example, position component contain x and y coordinate values. They are just data. These components are the determining factors for the operation of the systems. For instance, We have a one system called RenderSystem. RenderSystem requires position component and size components to be in that entity and if it does then it will be rendered by RenderSystem. This is how ECS works in my own understanding. 

The next post, I will try to implement this pattern in code.

No comments:

Post a Comment