To illustrate the way in which I program, I figured it would be interesting to show how I wrote the Entity-Component-System (ECS) for ETEngine. In this first part I will go over the basics of what it is and how we can work with it. In the next part I will go into the nitty gritty details of how it was implemented.
What is an Entity Component System?
Entity Component Systems are a design pattern that formalises the relationship between an Entity in a games Scene, it’s Properties (Data / Components) and the functionality that can be applied to them (Systems).
ECS follows the principles of Data Oriented Design, in which Data Structures (the Components) are defined separately from the logic (Systems). Entities are simple identifiers, with which we can find all the components which hold the data that makes up this entity, which are stored separately. Systems then modify the data in components in a way that’s agnostic to specific entities.
This design pattern is an alternative to other common aproaches game engines use for structuring scene data, like for example Scene Actors (in which all properties and functionality are members of an Actor, often implemented using lots of inheritance), or the nowadays somewhat ubiquitous Entity-Component model that both Unity and Unreal implement in their own way (Components contain both data and functionality, and entities may or may not do so too). Both of these approaches follow a more OOP based approach, and while this may seem a bit more intuitive to work with, there are several benefits to using an ECSs based architecture instead:
- The separation of concerns makes ECS very easy to modify. Components can be mixed and matched freely for each entity without needing to rewrite anything
- Components can easily be added and removed from entities at runtime, without needing to worry about breaking complex relationships. Systems will automatically start and stop affecting entities with the relevant components
- ECS based architecture is highly scalable because it uses composition instead of complex inheritance structures, which makes it easy to add new features as one doesn’t need to worry about breaking existing code or respecting strange edge cases that are distributed across a large code base
- Last but not least, using ECS can have big performance benefits, especially when handling scenes with large numbers of entities. This is because data can be structured in a way that makes iteration very cache friendly. They also enable mostly automating parallel execution, because systems can strictly define mutability and execution sequencing



Example of a feature implemented using ECS in ETEngine

One of the the features in my engines demo is a spawn system, which is used to shoot balls with rigid body physics from the camera into the scene. Here is how this system is defined:
Continue reading “E.T.Engines Archetype Based Entity-Component-System – Part 1: How to use it”