From 3c2eb30a29b1847ea6402fa9023772e5576c6e4d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 10 Dec 2024 20:14:18 +0300 Subject: [PATCH] add test.reconfig_packs & fix world.get_total_time() & enable level controller --- dev/tests/example.lua | 4 ++++ res/scripts/stdlib.lua | 1 + src/TestMainloop.cpp | 6 ++++++ src/Time.hpp | 1 + src/logic/scripting/lua/libs/libcore.cpp | 4 ++-- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dev/tests/example.lua b/dev/tests/example.lua index 8baf6afb..beb9fc0e 100644 --- a/dev/tests/example.lua +++ b/dev/tests/example.lua @@ -1,4 +1,8 @@ +test.reconfig_packs({"base"}, {}) test.new_world("demo", "2019", "core:default") assert(world.get_generator() == "core:default") +coroutine.yield() +assert(world.get_total_time() > 0.0) +print(world.get_total_time()) test.close_world(true) assert(not world.is_open()) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 451f07c8..3687d6fc 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -14,6 +14,7 @@ if test then test.name = __VC_TEST_NAME test.new_world = core.new_world test.close_world = core.close_world + test.reconfig_packs = core.reconfig_packs end ------------------------------------------------ diff --git a/src/TestMainloop.cpp b/src/TestMainloop.cpp index 32f31627..ddf0ca17 100644 --- a/src/TestMainloop.cpp +++ b/src/TestMainloop.cpp @@ -5,6 +5,7 @@ #include "interfaces/Process.hpp" #include "debug/Logger.hpp" #include "world/Level.hpp" +#include "world/World.hpp" #include "engine.hpp" static debug::Logger logger("mainloop"); @@ -33,6 +34,11 @@ void TestMainloop::run() { while (process->isActive()) { time.step(1.0f / static_cast(TPS)); process->update(); + if (controller) { + float delta = time.getDelta(); + controller->getLevel()->getWorld()->updateTimers(delta); + controller->update(glm::min(delta, 0.2f), false, false); + } } logger.info() << "test finished"; } diff --git a/src/Time.hpp b/src/Time.hpp index 57fb5c22..9f914b1f 100644 --- a/src/Time.hpp +++ b/src/Time.hpp @@ -18,6 +18,7 @@ public: void step(double delta) { frame++; lastTime += delta; + this->delta = delta; } void set(double currentTime) { diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 811b8d53..90d8d958 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -115,8 +115,8 @@ static int l_reconfig_packs(lua::State* L) { remPacks.emplace_back(lua::tostring(L, -1)); lua::pop(L); } - auto engine_controller = engine->getController(); - engine_controller->reconfigPacks(controller, addPacks, remPacks); + auto engineController = engine->getController(); + engineController->reconfigPacks(controller, addPacks, remPacks); return 0; }