Skip to content

Commit

Permalink
Add ecs_world_get_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 26, 2024
1 parent dd39321 commit fe30351
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
7 changes: 7 additions & 0 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19765,6 +19765,13 @@ ecs_entities_t ecs_get_entities(
return result;
}

ecs_flags32_t ecs_world_get_flags(
const ecs_world_t *world)
{
flecs_poly_assert(world, ecs_world_t);
return world->flags;
}

/**
* @file addons/alerts.c
* @brief Alerts addon.
Expand Down
11 changes: 11 additions & 0 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5167,6 +5167,17 @@ FLECS_API
ecs_entities_t ecs_get_entities(
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.
*
* @param world The world.
* @return Flags set on the world.
*/
FLECS_API
ecs_flags32_t ecs_world_get_flags(
const ecs_world_t *world);

/** @} */

/**
Expand Down
11 changes: 11 additions & 0 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,17 @@ FLECS_API
ecs_entities_t ecs_get_entities(
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.
*
* @param world The world.
* @return Flags set on the world.
*/
FLECS_API
ecs_flags32_t ecs_world_get_flags(
const ecs_world_t *world);

/** @} */

/**
Expand Down
7 changes: 7 additions & 0 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -2220,3 +2220,10 @@ ecs_entities_t ecs_get_entities(
result.alive_count = flecs_entities_count(world);
return result;
}

ecs_flags32_t ecs_world_get_flags(
const ecs_world_t *world)
{
flecs_poly_assert(world, ecs_world_t);
return world->flags;
}
3 changes: 2 additions & 1 deletion test/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,8 @@
"set_get_binding_context_w_free",
"get_entities",
"run_post_frame",
"run_post_frame_outside_of_frame"
"run_post_frame_outside_of_frame",
"get_flags"
]
}, {
"id": "WorldInfo",
Expand Down
16 changes: 16 additions & 0 deletions test/core/src/World.c
Original file line number Diff line number Diff line change
Expand Up @@ -1738,3 +1738,19 @@ void World_run_post_frame_outside_of_frame(void) {
int ctx = 10;
ecs_run_post_frame(world, post_frame_action, &ctx);
}

void World_get_flags(void) {
ecs_world_t *world = ecs_mini();

test_assert(!(ecs_world_get_flags(world) & EcsWorldFrameInProgress));

ecs_frame_begin(world, 0);

test_assert((ecs_world_get_flags(world) & EcsWorldFrameInProgress));

ecs_frame_end(world);

test_assert(!(ecs_world_get_flags(world) & EcsWorldFrameInProgress));

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/core/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,7 @@ void World_set_get_binding_context_w_free(void);
void World_get_entities(void);
void World_run_post_frame(void);
void World_run_post_frame_outside_of_frame(void);
void World_get_flags(void);

// Testsuite 'WorldInfo'
void WorldInfo_get_tick(void);
Expand Down Expand Up @@ -9681,6 +9682,10 @@ bake_test_case World_testcases[] = {
{
"run_post_frame_outside_of_frame",
World_run_post_frame_outside_of_frame
},
{
"get_flags",
World_get_flags
}
};

Expand Down Expand Up @@ -11209,7 +11214,7 @@ static bake_test_suite suites[] = {
"World",
World_setup,
NULL,
65,
66,
World_testcases
},
{
Expand Down

0 comments on commit fe30351

Please sign in to comment.