An Entity-Component-System library
Sometimes we may want to remove bidirectional dependencies between our code, and ECS is a good way to do this.
This design pattern offers a clean way to separate the data from the logic, and it's also a good way to improve the performance.
E - Entity
C - Component
S - System
But what really is it?
Well, as a human, we (entities) live in the world (context), and we have some properties (components). Moreover, we have things to do based on our properties (systems).
- A
Context
holds severalEntity
instances, someSystem
instances and someSingletonComponent
instances. - Each
Entity
has someComponent
instances. - Each
Component
(orSingletonComponent
) has only data properties. - Each
System
can filter lots ofEntity
instances in the sameContext
by their components and operate logics on them.
- Only
System
contains logics and none of them should reference on each other. But we allow one system depends on another by specifyingPriority
. (They should only depend on the filtered entities/components) Component
only contains data properties and no logics. (Again, no way to have dependency)Entity
only contains components. (It is really just a container)
- As a
System
can operate on a batch of entities with components, we can well utilize the cache of the MMU. - We can also easily parallelize the systems to improve the performance, in a multi-core CPU environment.
- We have priority for
System
, so you can control the order of systems. - We have frequency for
System
, so you can control the frequency of systems being executed. - We only allow asynchronous interfaces for
System
andContext
, so our ECS should not block the thread (unless you screw up). - We introduce built-in parallelism and/or concurrency for
System
, so you can easily parallelize your systems (for those who are in the same priority) and well utilize the multi-core CPU. - We have a cool guy who is maintaining this library. (Just kidding)
Just check out the EasyEcs.UnitTest
project. I have comments there.
Believe me, one day I will make a website for this and document everything.