- Notifications
You must be signed in to change notification settings - Fork167
Components
Components are what allowEntities to be different from one another. They store the data associated with each entity, and grant them properties by making them visible to families (seeSystems).
Components should normally be fine grained. For example, if you want a moving sprite on the screen, consider having three components representing that: aPositionComponent, aVelocityComponent, and aSpriteComponent.
Components are code generated (seeECS Overview). They follow the following format:
component:name:TextLabelmembers: -text:'Halley::TextRenderer' -layer:int -mask:int
At top level, the YAML document should contain an entry calledcomponent
. It should have two keys inside it,name
, specifying a unique name for the component (NB: the actual class generated will haveComponent
appended to it, so in the example above it would generate a class calledTextLabelComponent
), andmembers
, which is a list containing all members in the component.
Each member is specified by a name, followed by its C++ type. Note that it's necessary to use the full namespace for Halley classes, as the components will be compiled in translation units that don't invokeusing namespace Halley;
At this time, it's not possible to specify default values, and all component members must be explicitly initialised in the generated constructor.
If any of your members uses a type that your game declares, you need to help the codegen find the appropriate header to include. You can do this by using a declaration in this format:
type:name:CurveTypeinclude:"src/config/art/curve_type.h"
Note that the name must match exactly. e.g. if your component needs astd::vector<CurveType>
, you'd need to declare a type forname: 'std::vector<CurveType>'
.