A small Entity Component System (ECS) as a proof of concept.
A store holds entities, components and systems. It will handle all the storage and logic for you.
EntityStore store{};
They can be anything!
An entity is a collection of components. Just define one as a type and start using it. Use AddEntity
to add an entity to the store.
using DenseObject = Entity<std::string, float>;
store.AddEntity(DenseObject{ "Ice" , .956f });
store.AddEntity(DenseObject{ "Wood", .753f });
A system is a function that will execute on each matching entity. The parameter list of the system is matched to the entities containing the correct components.
Add a system to the store with AddSystem
store.AddSystem(
[] (int i, float& f)
{
f += 0.123f * i;
}
)
By calling CallHandles
, all systems will be matched and executed when entities apply to them.
store.CallHandles();
This project is a proof of concept and I hope it helps.