Skip to content

Commit 69374f4

Browse files
committed
fix(ecs): shared pointer
1 parent 1bb4217 commit 69374f4

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
@@ -26,7 +26,7 @@
2626
#include "Utils.hpp"
2727

2828
namespace nfo {
29-
class Registry {
29+
class Registry : public std::enable_shared_from_this<Registry> {
3030
public:
3131
SparseArray<emscripten::val> &register_component(const Component &c)
3232
{
@@ -162,10 +162,9 @@ namespace nfo {
162162

163163
void run_systems(const emscripten::val &ctx)
164164
{
165-
emscripten::val registry = ctx["libs"].call<emscripten::val>("getComponentSystem")["registry"];
166165
std::vector<emscripten::val> systems_copy = _systems;
167166
for (emscripten::val &system : systems_copy)
168-
system(registry, ctx);
167+
system(shared_from_this(), ctx);
169168
}
170169

171170
void log(const Entity &entity) const

0 commit comments

Comments
 (0)