Skip to content

Commit

Permalink
fix ServerMainloop timer
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 18, 2024
1 parent 8a4f1e1 commit 008e11b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Empty file removed dev/tests/example.lua
Empty file.
12 changes: 9 additions & 3 deletions src/ServerMainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ void ServerMainloop::run() {
double targetDelta = 1.0 / static_cast<double>(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<microseconds>(now - startupTime).count() / 1e6);
delta = time.getDelta();
}
process->update();
if (controller) {
controller->getLevel()->getWorld()->updateTimers(delta);
Expand All @@ -57,8 +65,6 @@ void ServerMainloop::run() {
auto end = system_clock::now();
platform::sleep(targetDelta * 1000 -
duration_cast<microseconds>(end - begin).count() / 1000);
end = system_clock::now();
delta = duration_cast<microseconds>(end - begin).count() / 1e6;
begin = end;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/logic/PlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/logic/PlayerController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down

0 comments on commit 008e11b

Please sign in to comment.