Skip to content

Commit

Permalink
Allow for creating owned flecs::world from custom C world
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 7, 2024
1 parent bc09b46 commit 37233f1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20110,9 +20110,9 @@ struct world {

/** Create world from C world.
*/
explicit world(world_t *w)
explicit world(world_t *w, bool owned = false)
: m_world( w )
, m_owned( false ) { }
, m_owned( owned ) { }

/** Not allowed to copy a world. May only take a reference.
*/
Expand Down
4 changes: 2 additions & 2 deletions include/flecs/addons/cpp/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ struct world {

/** Create world from C world.
*/
explicit world(world_t *w)
explicit world(world_t *w, bool owned = false)
: m_world( w )
, m_owned( false ) { }
, m_owned( owned ) { }

/** Not allowed to copy a world. May only take a reference.
*/
Expand Down
3 changes: 2 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,8 @@
"atfini",
"atfini_w_ctx",
"get_mut_T",
"get_mut_R_T"
"get_mut_R_T",
"world_mini"
]
}, {
"id": "Singleton",
Expand Down
8 changes: 8 additions & 0 deletions test/cpp_api/src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,3 +1927,11 @@ void World_get_mut_R_T(void) {
test_int(p->y, 20);
}

void World_world_mini(void) {
flecs::world world(ecs_mini(), true);

test_assert(world.lookup("flecs.system") == 0);
test_assert(world.lookup("flecs.pipeline") == 0);
test_assert(world.lookup("flecs.timer") == 0);
test_assert(world.lookup("flecs.meta") == 0);
}
7 changes: 6 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ void World_atfini(void);
void World_atfini_w_ctx(void);
void World_get_mut_T(void);
void World_get_mut_R_T(void);
void World_world_mini(void);

// Testsuite 'Singleton'
void Singleton_set_get_singleton(void);
Expand Down Expand Up @@ -5984,6 +5985,10 @@ bake_test_case World_testcases[] = {
{
"get_mut_R_T",
World_get_mut_R_T
},
{
"world_mini",
World_world_mini
}
};

Expand Down Expand Up @@ -6814,7 +6819,7 @@ static bake_test_suite suites[] = {
"World",
NULL,
NULL,
112,
113,
World_testcases
},
{
Expand Down

0 comments on commit 37233f1

Please sign in to comment.