fix ServerMainloop timer

This commit is contained in:
MihailRis 2024-12-19 02:29:41 +03:00
parent 8a4f1e16f3
commit 008e11b4b7
4 changed files with 13 additions and 5 deletions

View File

View File

@ -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);
@ -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;
}
}

View File

@ -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()) {

View File

@ -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();
};