Entity Component System

Introduction

There is a problem with complexity. Generally speaking, complex sysems are harder to maintain and understand - you have probably worked on projects that seem like a tangled ball of string. The Entity Component System (ECS) design pattern attempts to manage complexity while maintaining scalability in programs that routinely operate on many different types of objects

Component

A component is a container for data with little to no functionality

The only requirement of a component is that it store an associative ID, which is usually implemented as an integer

Entity

An entity is a set of components that share a unique ID

An entity is largely a conceptual idea or a noun; most of the time there is no explicit implementation of an Entity

System

A system is a collection of functionality that operates on a subset of components from multiple entities

A system should only be concerned with one aspect of the game simulation. It is desirable to minimize the subset of components that any one system requires, as this allows for better pipeline optimizations. For example, a "MovementSystem" may be described as only updating the position of entities that have a velocity and a position. Given a "Position" component containing a 3 dimensional vector representing position, and a "Movement" component containing a 3 dimensional vector representing velocity, the movement system will only be concerned with entities that have both of these components. The benefit of such a scheme is that objects that do not need to move simply don't have a Movement component and thus aren't handled by the movement system, which helps with optimization and debugging.