Skip to content
Flecs v4.1
entity_ranges.h
Go to the documentation of this file.
1/**
2 * @file addons/entity_ranges.h
3 * @brief Entity id range management.
4 */
5
6#ifdef FLECS_ENTITY_RANGES
7
8#ifndef FLECS_ENTITY_RANGES_H
9#define FLECS_ENTITY_RANGES_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15/**
16 * @defgroup c_addons_entity_ranges Entity Ranges
17 * @ingroup c_addons
18 * Entity id range management.
19 *
20 * @{
21 */
22
23/** Type that stores an entity id range.
24 * Returned by ecs_entity_range_new(), used with ecs_entity_range_set().
25 */
26typedef struct ecs_entity_range_t {
27 uint32_t min; /**< First id in range (inclusive). */
28 uint32_t max; /**< Last id in range (inclusive, 0 = unlimited). */
29 uint32_t cur; /**< Last issued id in range. */
30 ecs_vec_t recycled; /**< Recycled entity ids (vec<entity_t>). */
32
33/** Create a new entity range.
34 * This function creates a range that constrains new entity identifiers returned
35 * by the specified [min, max] interval. Each range maintains its own list of
36 * recycled entity ids, which ensures that recycled ids always respect the
37 * configured range. If `max` is set to 0, the range is unbounded.
38 *
39 * Entity ranges cannot be deleted once created. Use ecs_entity_range_set() to
40 * activate a range.
41 *
42 * @param world The world.
43 * @param min The first entity id in the range (inclusive).
44 * @param max The last entity id in the range (inclusive, 0 = unlimited).
45 * @return A pointer to the new range. Does not need to be freed.
46 */
47FLECS_API
49 ecs_world_t *world,
50 uint32_t min,
51 uint32_t max);
52
53/** Set the active entity range.
54 * This function activates a range created with ecs_entity_range_new().
55 * When a range is activated, new entity identifiers will fall within the
56 * specified [min, max] interval, including recycled identifiers.
57 *
58 * When the active range is out of available ids, operations that create new
59 * entity ids will assert.
60 *
61 * The operation only accepts ranges that have been created by
62 * ecs_entity_range_new().
63 *
64 * @param world The world.
65 * @param range The range to activate.
66 */
67FLECS_API
69 ecs_world_t *world,
70 const ecs_entity_range_t *range);
71
72/** Get the currently active entity id range.
73 * Returns the range set by ecs_entity_range_set(), or NULL if no range is
74 * active.
75 *
76 * @param world The world.
77 * @return The active range, or NULL.
78 */
79FLECS_API
81 const ecs_world_t *world);
82
83/** @} */
84
85#ifdef __cplusplus
86}
87#endif
88
89#endif
90
91#endif // FLECS_ENTITY_RANGES
FLECS_API void ecs_entity_range_set(ecs_world_t *world, const ecs_entity_range_t *range)
Set the active entity range.
FLECS_API const ecs_entity_range_t * ecs_entity_range_new(ecs_world_t *world, uint32_t min, uint32_t max)
Create a new entity range.
FLECS_API const ecs_entity_range_t * ecs_entity_range_get(const ecs_world_t *world)
Get the currently active entity id range.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:439
Type that stores an entity id range.
uint32_t max
Last id in range (inclusive, 0 = unlimited).
uint32_t cur
Last issued id in range.
ecs_vec_t recycled
Recycled entity ids (vec<entity_t>).
uint32_t min
First id in range (inclusive).