Registry

Registry — Structure for storing metadata about entities and components.

Functions

Types and Values

Description

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.

Functions

LeecsCopyFunc ()

void *
(*LeecsCopyFunc) (const void *ptr);

Function prototype for copying data.

Parameters

ptr

Data to copy.

 

Returns

Copy of ptr .

[transfer full]


LeecsFreeFunc ()

void
(*LeecsFreeFunc) (void *ptr);

Function prototype for freeing data.

Parameters

ptr

Data to free.

 

leecs_registry_new ()

LeecsRegistry *
leecs_registry_new (void);

Creates a new empty LeecsRegistry.

Returns

New LeecsRegistry. Free with leecs_registry_free().

[transfer full]


leecs_registry_free ()

void
leecs_registry_free (LeecsRegistry *registry);

Frees all memory associated with registry .

Parameters

registry

LeecsRegistry to free.

 

leecs_registry_copy ()

LeecsRegistry *
leecs_registry_copy (const LeecsRegistry *registry);

Creates a copy of registry with a reference count of 0.

Parameters

registry

LeecsRegistry to copy.

 

Returns

Copy of registry . Free with leecs_registry_free().

[transfer full]


leecs_component_id ()

unsigned int
leecs_component_id (const LeecsRegistry *registry,
                    const char *name);

LEECS_COMPONENT_FULL()

#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().

Parameters

registry

LeecsRegistry to register component_t in.

 

component_t

The type of the component.

 

copy

LeecsCopyFunc for component_t .

 

free

LeecsFreeFunc for component_t .

 

LEECS_COMPONENT()

#define             LEECS_COMPONENT(registry, component_t)

Registers component_t to registry .

If component_t contains dynamically allocated member variables, use LEECS_COMPONENT_FULL().

Parameters

registry

LeecsRegistry to register component_t in.

 

component_t

The type of the component.

 

LEECS_TAG()

#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);

Parameters

registry

LeecsRegistry to register tag in.

 

tag

The symbol of the tag.

 

LEECS_MEMBER()

#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.

Parameters

registry

LeecsRegistry to register member in.

 

component_t

Type of the component.

 

member

Member of component_t .

 

type

LeecsType of member .

 

LEECS_ARCHETYPE()

#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);

Parameters

registry

LeecsRegistry to register the archetype in.

 

name

Name of the archetype as a string literal.

 

...

List of the components of the archetype.

 

Types and Values

LEECS_ERROR_ID

#define LEECS_ERROR_ID UINT_MAX

enum LeecsType

Enum of serializable C data types.

Members

LEECS_INT

int and its variants

 

LEECS_FLOAT

float and double

 

LEECS_BOOL

bool

 

LEECS_STRING

char *, should always be dynamically allocated

 

LeecsRegistry

typedef struct _LeecsRegistry LeecsRegistry;