# Description of a simple ECS ## Requirements * seperation between static and dynamic components - dynamic components regulary change - static components normally don't change * static components can be shared between entities - when changing a static component, it will change for all components, which share it * iteration will only touch the important components * the components are statically typed ## Implementation details ### Storage * there is an array for each component type * there is a single array, which contains the indices of the static components * for each combination of components used in a system, there's an additional array - it contains the set of indices of the components - instead it may also just contain a single index to a data structure containing the component specific indices (less memory usage, additional indirection) ### Add and remove entities * when adding a new entity, all used components have to be specified * depending on the specified components, a different function will be called * the entities will only be added to the matching component combination arrays * removing entites is much more difficult - requires runtime function dispatch ### Iterating over objects * systems are just functions bound to a component combination - they take one argument for each component (or instead a single tuple of references) - they can take additional arguments - only dynamic components are mutable * when calling a system with some arguments, the additional arguemnts will be passed to every object afterwards ### Change object type * it has to be possible to remove components from or add components to a type * therefore it has to be removed from or added to some component combination arrays * this also requires runtime function dispatch ## Optional optimizations * it's possible to create multiple arrays for each dynamic component and copy them instead of changing them inplace