From 4f4f7e6afc4ed06f2a9e596e1f25abaf365645f2 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sat, 19 Jan 2019 14:05:51 +0100 Subject: [PATCH] more deltatime hacking --- Timer.cpp | 7 +++---- application.cpp | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Timer.cpp b/Timer.cpp index befad28e..7ef20f30 100644 --- a/Timer.cpp +++ b/Timer.cpp @@ -32,6 +32,8 @@ double GetTime() double GetDeltaTime() { // czas symulacji (stoi gdy pauza) + if (override_delta != -1.0f) + return override_delta; return DeltaTime; } @@ -79,10 +81,7 @@ void UpdateTimers(bool pause) else DeltaTime = 0.0; // wszystko stoi, bo czas nie płynie - if (override_delta != -1.0f) - DeltaTime = override_delta; - - fSimulationTime += DeltaTime; + fSimulationTime += GetDeltaTime(); oldCount = count; // Keep track of the time lapse and frame count diff --git a/application.cpp b/application.cpp index 046f2ea9..1daa0b58 100644 --- a/application.cpp +++ b/application.cpp @@ -174,6 +174,8 @@ eu07_application::run() { // // trivia: being client and server is possible + double frameStartTime = Timer::GetTime(); + bool nextloop = true; while (nextloop) { @@ -229,6 +231,14 @@ eu07_application::run() { double sync = generate_sync(); + // if we're the server + if (m_network && m_network->servers) + { + // send delta, sync, and commands we just executed to clients + double delta = Timer::GetDeltaTime(); + m_network->servers->push_delta(delta, sync, commands_to_exec); + } + // if we're slave if (m_network && m_network->client) { @@ -236,14 +246,10 @@ eu07_application::run() { if (sync != slave_sync) { WriteLog("net: DESYNC!", logtype::net); } - } - // if we're the server - if (m_network && m_network->servers) - { - // send delta, sync, and commands we just executed to clients - double delta = Timer::GetDeltaTime(); - m_network->servers->push_delta(delta, sync, commands_to_exec); + // set total delta for rendering code + double totalDelta = Timer::GetTime() - frameStartTime; + Timer::set_delta_override(totalDelta); } }