In ECS, entities are just an identifier which components will be attached to, usually just an integer.
Rather than just a typedef for Int, I decided to make Entity a struct to provide a bit more type safety. I’m trusting in the swift compiler to make this reasonably efficient.
EntityBuilder
Unique ids need to be assigned to each new entity. In addition, when entities are created, we’re going to need to usually add components to them. So there’s an EntityBuilder class that will create and assign ids to new entities.
Also, when entities are destroyed, we’ll want to reclaim those ids and notify anyone interested that the entities are gone.
We’ll come back to EntityBuilder to help us add components to an entity
The protocol for EntityContainer is fairly straight forward
So we end up with an entity builder that can create entities and destroy them, then notify anything interested when entities are destroyed (purely for cleaning up any resources).
Next up
Components and component containers
All posts about the development of SwiftECS can be found here
One of the main reasons I decided to include a game example while documenting the ECS development is
that I found that much of it is about the pattern that I...
Like I mentioned last time, properly designing and explaining an ECS is best if done in the context of a game.
I am actually designing a game while doing it,...