CORGI
An open source project by
FPL.
|
Components are objects that contain the logic and data pertaining to a particular system in your game. Typically, good Components are largely self-contained.
The data that a Component stores for each Entity is a struct (or sometimes a class) referred to as ComponentData.
Components are registered with an Entity Manager, and the Entity Manager is then responsible for adding Entities to each Component. Once per frame, the Entity Manager will call EntityManager::UpdateComponents()
, which calls each Component's ComponentInterface::UpdateAllEntities()
.
Before creating a Component, you need to create a struct (or class) that contains all your per-Entity data. In some cases, you may not have any per-Entity data. In that case, just make an empty struct.
All Components should implement the ComponentInterface (although it is often useful to extend from the Component abstract class).
Inside each header file that declares a Component, you need to use the FPL_ENTITY_REGISTER_COMPONENT()
macro. This is required in order to declare the necessary constants for lookups.
Note: This should be declared outside of any namespaces!
Inside each source file that defines a Component, you need to use the FPL_ENTTIY_DEFINE_COMPONENT()
macro. This handles defining the storage location for the Component for a given type and ComponentData type.
Note: This should be declared at the top of the file outside of any namespaces!
After calling the above macro, you can implement any necessary methods for your Component clsas. Namely, you will want to define ComponentInterface::UpdateAllEntities()
with the functionality to update each Entity each frame.