| Top |
| void * | (*LeecsCopyFunc) () |
| void | (*LeecsFreeFunc) () |
| LeecsRegistry * | leecs_registry_new () |
| void | leecs_registry_free () |
| LeecsRegistry * | leecs_registry_copy () |
| unsigned int | leecs_component_id () |
| #define | LEECS_COMPONENT_FULL() |
| #define | LEECS_COMPONENT() |
| #define | LEECS_TAG() |
| #define | LEECS_MEMBER() |
| #define | LEECS_ARCHETYPE() |
LeecsRegistry stores metadata about which components exist, functions for copying and freeing those components, information about their serializable member variables, and named archetypes for querying entities.
A LeecsRegistry must be created in order to create a LeecsWorld to store and manage the actual game state. A single LeecsRegistry may be used by multiple LeecsWorld objects, and LeecsRegistry contains a reference counter for how many LeecsWorld objects are currently using it.
A LeecsRegistry can only be modified and freed when it is not being used by a LeecsWorld. However, a LeecsRegistry can be freely copied even if it is in use by a LeecsWorld. The copied LeecsRegistry will have a reference count of 0, so it may be modified immediately.
It is best to register everything necessary at once to a LeecsRegistry before creating a LeecsWorld, and finally make sure to free all LeecsWorld objects before freeing the LeecsRegistry.
void
leecs_registry_free (LeecsRegistry *registry);
Frees all memory associated with registry
.
LeecsRegistry *
leecs_registry_copy (const LeecsRegistry *registry);
Creates a copy of registry
with a reference count of 0.
unsigned int leecs_component_id (const LeecsRegistry *registry,const char *name);
#define LEECS_COMPONENT_FULL(registry, component_t, copy, free)
Registers component_t
to registry
with custom functions to free and copy
component_t
.
copy
and free
must be specified when component_t
includes dynamically
allocated member variables, otherwise, use LEECS_COMPONENT().
registry |
LeecsRegistry to register |
|
component_t |
The type of the component. |
|
copy |
LeecsCopyFunc for |
|
free |
LeecsFreeFunc for |
#define LEECS_COMPONENT(registry, component_t)
Registers component_t
to registry
.
If component_t
contains dynamically allocated member variables, use
LEECS_COMPONENT_FULL().
registry |
LeecsRegistry to register |
|
component_t |
The type of the component. |
#define LEECS_TAG(registry, tag)
Registers tag
to registry
. A tag is a component with no data associated
with it, and a type for it does not need to be defined.
Example usage:
1 2 3 |
LEECS_TAG (registry, TagSymbol); LEECS_TAG (registry, Playable); LEECS_TAG (registry, AnotherExample); |
#define LEECS_MEMBER(registry, component_t, member, type)
Registers member
of component_t
to registry
as a serializable member.
Non-serializable members of component_t
should not be registered at all.
registry |
LeecsRegistry to register |
|
component_t |
Type of the component. |
|
member |
Member of |
|
type |
LeecsType of |
#define LEECS_ARCHETYPE(registry, name, ...)
Registers an entity archetype to registry
. An archetype is a set of
components and it is identified by name
.
An entity is considered an instance of a particular archetype if it contains all of the components of the archetype. It may contain additional components which are not part of the archetype, but it may not be missing any components of the archetype.
Archetypes are used to query entities with leecs_query_archetypes() and
leecs_find_one_archetype().
Example usage:
1 2 3 |
LEECS_ARCHETYPE (registry, "moving", Position, Velocity); LEECS_ARCHETYPE (registry, "longer archetype", SomeComponent, AnotherOne, ThirdOne, Fourth); |
registry |
LeecsRegistry to register the archetype in. |
|
name |
Name of the archetype as a string literal. |
|
... |
List of the components of the archetype. |