From 8f0db67c5fdbc1e7b8759f44b45ad64caf336cb5 Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Wed, 11 Sep 2019 01:46:14 -0400 Subject: World system now has a pointer to the current world, and worlds created in Lua are returned to Lua as pointers --- src/script.cpp | 2 +- src/world.cpp | 6 ++++-- src/world.hpp | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/script.cpp b/src/script.cpp index e3aca3e..f52391f 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -90,7 +90,7 @@ void ScriptSystem::scriptExport(void) std::function entitySpawn = [this](sol::table t){ return spawn(t);}; - std::function worldRegister = + std::function worldRegister = [this](sol::object t){ return worldSystem.addWorld(t); }; lua.new_usertype("Position", diff --git a/src/world.cpp b/src/world.cpp index 8b71316..63769a9 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -38,10 +38,12 @@ World::World(sol::object ref) * WORLD SYSTEM * ******************/ -unsigned int WorldSystem::addWorld(sol::object t) +World* WorldSystem::addWorld(sol::object t) { worlds.push_back(World(t)); - return worlds.size()-1; + if (currentWorld == nullptr) + currentWorld = &(worlds.back()); + return &(worlds.back()); } void WorldSystem::configure([[maybe_unused]]entityx::EntityManager& entities, diff --git a/src/world.hpp b/src/world.hpp index 7c66e6b..4ceca94 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -52,13 +52,14 @@ class WorldSystem : public entityx::System { private: std::vector worlds; - //World& currentWorld; + World* currentWorld; public: - WorldSystem(void) {} + WorldSystem(void): + currentWorld(nullptr) {} ~WorldSystem(void) {} - unsigned int addWorld(sol::object); + World* addWorld(sol::object); /** * Prepares the system for running. -- cgit v1.2.3