Introduction to ECS
Cardinal uses the ECS (Entity-Component-System) architecture which facilitates fast and efficient updates to game state, as well as enabling painless extensibility to your games.
ECS stands as a programming paradigm specifically tailored for game development. While ECS is conceptually straightforward, gaining familiarity with the structured organization of an idiomatic ECS codebase is essential to fully harness its unique advantages.
Entities are simply a unique identifier of something in the game. Entities can be players, objects, NPCs, etc. They are the simplest unit in the ECS system. Entities are formed by the combination of one or more components.
Components are data fragments that bind to entities, offering descriptive attributes. Imagine a "Health" component for players, tracking their health status. Maintaining component generality is key – for instance, a health component can be reused for different types of entities, such as animals or destructible objects.
Systems are the heartbeat of ECS, encompassing functions that manipulate entities, allowing your game logic to come to life. Systems often operate by iteratively traversing specific components and updating their values. For instance, a "HealthRegen" system could iterate over entities with the "Health" component, progressively replenishing health values.
When used correctly, ECS unlocks a realm of organized code and seamless extensibility. Injecting new features into your game can be as straightforward as introducing a novel system that interacts with existing components. It's important to note that while ECS is a formidable tool, it isn't a universal solution. Certain game scenarios might find better suited solutions outside the ECS paradigm.