Query

Query — Functions to query entities.

Functions

Types and Values

Description

Functions

leecs_query_archetypes ()

LeecsIterator *
leecs_query_archetypes (LeecsWorld *world,
                        const char *name);

Creates a LeecsIterator for world to find entities with the archetype named name .

Parameters

world

LeecsWorld to query.

 

name

The name of the archetype to query.

 

Returns

New LeecsIterator.


leecs_find_one_archetype ()

LeecsEntity
leecs_find_one_archetype (LeecsWorld *world,
                          const char *name);

leecs_iterator_next ()

bool
leecs_iterator_next (LeecsIterator *iterator,
                     LeecsEntity *entity);

Finds the next LeecsEntity matching the query parameters or returns false if another LeecsEntity can't be found.

Example usage:

1
2
3
4
5
6
7
8
LeecsEntity entity;
LeecsIterator *iterator;

iterator = leecs_query_entities (world, Position, Velocity);
while (leecs_iterator_next (iterator, &entity))
  {
    ...
  }

Parameters

iterator

The LeecsIterator.

 

entity

Pointer to a variable to store the next entity in.

 

Returns

true if a LeecsEntity was found, false if not.


leecs_iterator_free ()

void
leecs_iterator_free (LeecsIterator *iterator);

Frees all memory associated with iterator . A LeecsIterator is freed automatically when it can no longer find another entity, but if you want to stop iterating before that, you must call this function.

Example usage:

1
2
3
4
5
6
7
8
9
10
while (leecs_iterator_next (iterator, &entity))
  {
    if (condition)
      {
        leecs_iterator_free (iterator);
        break;
      }

    ...
  }

Parameters

iterator

LeecsIterator to free.

 

leecs_query_entities()

#define             leecs_query_entities(world, ...)

Creates a LeecsIterator for world to find entities with at least the components included in the list.

Parameters

world

LeecsWorld to query.

 

...

List of components.

 

Returns

New LeecsIterator.


leecs_find_one_entity()

#define             leecs_find_one_entity(world, ...)

Finds the first entity in world which has at least the components included in the list.

Parameters

world

LeecsWorld to query.

 

...

List of components.

 

Returns

The first LeecsEntity.

Types and Values

LeecsIterator

typedef struct _LeecsIterator LeecsIterator;

Iterator for entities. Iterators are used when querying entities. An iterator is created when calling leecs_query_entities() or leecs_query_archetype(), and entities are accessed from the iterator using leecs_iterator_next().

When leecs_iterator_next() no longer finds another entity, the iterator is automatically freed. But if at any point you want to stop iterating over entities before arriving at the final one, you must manually call leecs_iterator_free() to free the iterator.