Flecs: Creation & Deletion
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
Creation & Deletion
C API » Core » World
Collaboration diagram for Creation & Deletion:

## Classes
struct | ecs_entities_t
| Type returned by ecs_get_entities(). More...

## Typedefs
typedef struct ecs_entities_t | ecs_entities_t
| Type returned by ecs_get_entities().

## Functions
ecs_world_t * | ecs_init (void)
| Create a new world.
ecs_world_t * | ecs_mini (void)
| Create a new world with just the core module.
ecs_world_t * | ecs_init_w_args (int argc, char *argv[])
| Create a new world with arguments.
int | ecs_fini (ecs_world_t *world)
| Delete a world.
bool | ecs_is_fini (const ecs_world_t *world)
| Returns whether the world is being deleted.
void | ecs_atfini (ecs_world_t *world, ecs_fini_action_t action, void *ctx)
| Register action to be executed when world is destroyed.
ecs_entities_t | ecs_get_entities (const ecs_world_t *world)
| Return entity identifiers in world.
ecs_flags32_t | ecs_world_get_flags (const ecs_world_t *world)
| Get flags set on the world.

## Detailed Description

## Function Documentation

## ◆ ecs_atfini()

void ecs_atfini | ( | ecs_world_t * | world,
|  | ecs_fini_action_t | action,
|  | void * | ctx )

Register action to be executed when world is destroyed.

Fini actions are typically used when a module needs to clean up before a world shuts down.

Parameters

  world | The world.
  action | The function to execute.
  ctx | Userdata to pass to the function

## ◆ ecs_fini()

int ecs_fini | ( | ecs_world_t * | world | ) |

Delete a world.

This operation deletes the world, and everything it contains.

Parameters

  world | The world to delete.

Returns
  Zero if successful, non-zero if failed.

## ◆ ecs_get_entities()

ecs_entities_t ecs_get_entities | ( | const ecs_world_t * | world | ) |

Return entity identifiers in world.

This operation returns an array with all entity ids that exist in the world. Note that the returned array will change and may get invalidated as a result of entity creation & deletion.

To iterate all alive entity ids, do:

ecs_entities_t entities = ecs_get_entities(world);
for (int i = 0; i < entities.alive_count; i ++) {
ecs_entity_t id = entities.ids[i];
}
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:361
ecs_get_entities
ecs_entities_t ecs_get_entities(const ecs_world_t *world)
Return entity identifiers in world.
ecs_entities_t
Type returned by ecs_get_entities().
Definition flecs.h:2014
ecs_entities_t::alive_count
int32_t alive_count
Number of alive entity ids.
Definition flecs.h:2017
ecs_entities_t::ids
const ecs_entity_t * ids
Array with all entity ids in the world.
Definition flecs.h:2015

To iterate not-alive ids, do:

for (int i = entities.alive_count + 1; i < entities.count; i ++) {
ecs_entity_t id = entities.ids[i];
}
ecs_entities_t::count
int32_t count
Total number of entity ids.
Definition flecs.h:2016

The returned array does not need to be freed. Mutating the returned array will return in undefined behavior (and likely crashes).

Parameters

  world | The world.

Returns
  Struct with entity id array.

## ◆ ecs_init()

ecs_world_t * ecs_init | ( | void |  | ) |

Create a new world.

This operation automatically imports modules from addons Flecs has been built with, except when the module specifies otherwise.

Returns
  A new world

## ◆ ecs_init_w_args()

ecs_world_t * ecs_init_w_args | ( | int | argc,
|  | char * | argv[] )

Create a new world with arguments.

Same as ecs_init(), but allows passing in command line arguments. Command line arguments are used to:

- automatically derive the name of the application from argv[0]

Returns
  A new world

## ◆ ecs_is_fini()

bool ecs_is_fini | ( | const ecs_world_t * | world | ) |

Returns whether the world is being deleted.

This operation can be used in callbacks like type hooks or observers to detect if they are invoked while the world is being deleted.

Parameters

  world | The world.

Returns
  True if being deleted, false if not.

## ◆ ecs_mini()

ecs_world_t * ecs_mini | ( | void |  | ) |

Create a new world with just the core module.

Same as ecs_init(), but doesn't import modules from addons. This operation is faster than ecs_init() and results in less memory utilization.

Returns
  A new tiny world

## ◆ ecs_world_get_flags()

ecs_flags32_t ecs_world_get_flags | ( | const ecs_world_t * | world | ) |

Get flags set on the world.

This operation returns the internal flags (see api_flags.h) that are set on the world.

Parameters

  world | The world.

Returns
  Flags set on the world.