|
Thrive
|
Introductions to the entity / component approach can be found here:
The following gives an overview of the implementation of entities, components and systems in Thrive.
Entities and their components are managed by an EntityManager. The EntityManager identifies each entity by its unique id. You can use either EntityManager::generateNewId() or EntityManager::getNamedId() to obtain an id.
An entity can have at most one component of each type. Component types are distinguished primarily by their component id (see also Component::generateTypeId()). This component id is generated dynamically at application startup and may change between executions. To identify a component type across executions, use the component name, which should be constant between executions. To convert between component id and component name, use ComponentFactory::typeNameToId() and ComponentFactory::typeIdToName().
For convenience, there's an Entity class that wraps the API of EntityManager in an entity-centric way.
The absolute minimum a system has to implement is the System::update() function. You can also override System::init() and System::shutdown() for setup and teardown procedures.
Usually, a system operates on entities that have a specific combination of components. The EntityFilter template can filter out entities that have such a component makeup.
Game states represent a distinct state of the game with its own systems and entities. Examples for such a state are "main menu", "microbe stage" or "microbe editor".
All systems are managed by a game state. The game state provides an entity manager, initializes its systems, updates them during the game and finally, shuts them down.
Game states are indirectly created by Engine::addGameState(). A state's system list cannot be changed after creation.
Engine is for GameState what GameState is for System. It holds a list of registered game states. During startup the game states are all initialized. During runtime, the current game state is updated. When the game exits, the engine shuts each game state down.
1.8.10