diff --git a/engine/src/lin_time.cpp b/engine/src/lin_time.cpp index 76b84b85f9..c0789d4c94 100644 --- a/engine/src/lin_time.cpp +++ b/engine/src/lin_time.cpp @@ -39,7 +39,8 @@ VSRandom vsrandom(time(NULL)); static LARGE_INTEGER ttime{}; static LARGE_INTEGER newtime{}; static LARGE_INTEGER freq{}; -static double dblnewtime; +static double dblnewtime; +static double lasttime; #else #if defined (HAVE_SDL) # include @@ -171,6 +172,12 @@ void InitTime() { VS_LOG(serious_warning, "InitTime(): freq is zero!"); } QueryPerformanceCounter(&ttime); + if (freq.QuadPart == 0) { + dblnewtime = static_cast(ttime.QuadPart); + } else { + dblnewtime = static_cast(ttime.QuadPart) / static_cast(freq.QuadPart); + } + lasttime = dblnewtime - .0001; #elif defined (_POSIX_MONOTONIC_CLOCK) struct timespec ts; @@ -266,28 +273,20 @@ void UpdateTime() { #ifdef _WIN32 LARGE_INTEGER ticks; QueryPerformanceCounter(&ticks); - double tmpnewtime = 0; + lasttime = dblnewtime; if (freq.QuadPart > 0) { - tmpnewtime = static_cast(ticks.QuadPart) / static_cast(freq.QuadPart); + dblnewtime = static_cast(ticks.QuadPart) / static_cast(freq.QuadPart); } else { - tmpnewtime = static_cast(ticks.QuadPart); + dblnewtime = static_cast(ticks.QuadPart); } - if (tmpnewtime == INFINITY) { - tmpnewtime = 0; - } - double tmpttime = 0; + double dblttime = 0; if (freq.QuadPart > 0) { - tmpttime = static_cast(ttime.QuadPart) / static_cast(freq.QuadPart); + dblttime = static_cast(ttime.QuadPart) / static_cast(freq.QuadPart); } else { - tmpttime = static_cast(ttime.QuadPart); + dblttime = static_cast(ttime.QuadPart); } - elapsedtime = (tmpnewtime - tmpttime); + elapsedtime = (dblnewtime - lasttime); ttime = newtime; - if (freq.QuadPart == 0) { - dblnewtime = 0.0; - } else { - dblnewtime = static_cast(newtime.QuadPart) / static_cast(freq.QuadPart); - } if (first) { firsttime = dblnewtime; diff --git a/engine/src/main.cpp b/engine/src/main.cpp index 7473bb3e83..f98af8c88f 100644 --- a/engine/src/main.cpp +++ b/engine/src/main.cpp @@ -368,6 +368,7 @@ int main(int argc, char *argv[]) { #endif InitTime(); + UpdateTime(); AUDInit(); AUDListenerGain(vs_options::instance().sound_gain);