Skip to content

Commit eebe454

Browse files
committed
fix(ecs): shared pointer
1 parent 52b1ec6 commit eebe454

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

packages/ecs-lib/wasm/Registry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace nfo {
2727
emscripten::register_type<ZipperInput>("Component[]");
2828
emscripten::register_type<ZipperOutput>("any[]");
2929

30-
emscripten::class_<Registry>("Registry")
31-
.constructor()
30+
emscripten::class_<nfo::Registry>("Registry")
31+
.smart_ptr_constructor("Registry", &std::make_shared<Registry>)
3232
.function("registerComponent", &Registry::register_component)
3333
.function(
3434
"getComponentsConst",

packages/ecs-lib/wasm/Registry.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace nfo {
3232
** This class provides methods to register components, manage entities,
3333
** add and remove components from entities, and run systems.
3434
*/
35-
class Registry {
35+
class Registry : public std::enable_shared_from_this<Registry> {
3636
public:
3737
/**
3838
* Register a component type in the registry.
@@ -257,10 +257,9 @@ namespace nfo {
257257
*/
258258
void run_systems(const emscripten::val &ctx)
259259
{
260-
emscripten::val registry = ctx["libs"].call<emscripten::val>("getComponentSystem")["registry"];
261260
std::vector<emscripten::val> systems_copy = _systems;
262261
for (emscripten::val &system : systems_copy)
263-
system(registry, ctx);
262+
system(shared_from_this(), ctx);
264263
}
265264

266265
/**

0 commit comments

Comments
 (0)