From 008e11b4b72460521cf346614227fe6d5cc07cbb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 19 Dec 2024 02:29:41 +0300 Subject: [PATCH] fix ServerMainloop timer --- dev/tests/example.lua | 0 src/ServerMainloop.cpp | 12 +++++++++--- src/logic/PlayerController.cpp | 4 +++- src/logic/PlayerController.hpp | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) delete mode 100644 dev/tests/example.lua diff --git a/dev/tests/example.lua b/dev/tests/example.lua deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/ServerMainloop.cpp b/src/ServerMainloop.cpp index 559196c66..1f496a515 100644 --- a/src/ServerMainloop.cpp +++ b/src/ServerMainloop.cpp @@ -40,13 +40,21 @@ void ServerMainloop::run() { double targetDelta = 1.0 / static_cast(TPS); double delta = targetDelta; auto begin = system_clock::now(); + auto startupTime = begin; while (process->isActive()) { if (engine.isQuitSignal()) { process->terminate(); logger.info() << "script has been terminated due to quit signal"; break; } - time.step(delta); + if (coreParams.testMode) { + time.step(delta); + } else { + auto now = system_clock::now(); + time.update( + duration_cast(now - startupTime).count() / 1e6); + delta = time.getDelta(); + } process->update(); if (controller) { controller->getLevel()->getWorld()->updateTimers(delta); @@ -57,8 +65,6 @@ void ServerMainloop::run() { auto end = system_clock::now(); platform::sleep(targetDelta * 1000 - duration_cast(end - begin).count() / 1000); - end = system_clock::now(); - delta = duration_cast(end - begin).count() / 1e6; begin = end; } } diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index d664be3ff..d9bc0065c 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -150,7 +150,9 @@ void CameraControl::switchCamera() { } } -void CameraControl::update(PlayerInput input, float delta, Chunks& chunks) { +void CameraControl::update( + PlayerInput input, float delta, const Chunks& chunks +) { offset = glm::vec3(0.0f, 0.0f, 0.0f); if (auto hitbox = player.getHitbox()) { diff --git a/src/logic/PlayerController.hpp b/src/logic/PlayerController.hpp index 3b75d371c..88e3a5f45 100644 --- a/src/logic/PlayerController.hpp +++ b/src/logic/PlayerController.hpp @@ -41,7 +41,7 @@ class CameraControl { public: CameraControl(Player& player, const CameraSettings& settings); void updateMouse(PlayerInput& input); - void update(PlayerInput input, float delta, Chunks& chunks); + void update(PlayerInput input, float delta, const Chunks& chunks); void refresh(); };