Skip to content

Commit

Permalink
lin_time.cpp, main.cpp: More time troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengtuggy committed May 1, 2024
1 parent 179705f commit c716715
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
31 changes: 15 additions & 16 deletions engine/src/lin_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SDL2/SDL.h>
Expand Down Expand Up @@ -171,6 +172,12 @@ void InitTime() {
VS_LOG(serious_warning, "InitTime(): freq is zero!");
}
QueryPerformanceCounter(&ttime);
if (freq.QuadPart == 0) {
dblnewtime = static_cast<double>(ttime.QuadPart);
} else {
dblnewtime = static_cast<double>(ttime.QuadPart) / static_cast<double>(freq.QuadPart);
}
lasttime = dblnewtime - .0001;

#elif defined (_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
Expand Down Expand Up @@ -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<double>(ticks.QuadPart) / static_cast<double>(freq.QuadPart);
dblnewtime = static_cast<double>(ticks.QuadPart) / static_cast<double>(freq.QuadPart);
} else {
tmpnewtime = static_cast<double>(ticks.QuadPart);
dblnewtime = static_cast<double>(ticks.QuadPart);
}
if (tmpnewtime == INFINITY) {
tmpnewtime = 0;
}
double tmpttime = 0;
double dblttime = 0;
if (freq.QuadPart > 0) {
tmpttime = static_cast<double>(ttime.QuadPart) / static_cast<double>(freq.QuadPart);
dblttime = static_cast<double>(ttime.QuadPart) / static_cast<double>(freq.QuadPart);
} else {
tmpttime = static_cast<double>(ttime.QuadPart);
dblttime = static_cast<double>(ttime.QuadPart);
}
elapsedtime = (tmpnewtime - tmpttime);
elapsedtime = (dblnewtime - lasttime);
ttime = newtime;
if (freq.QuadPart == 0) {
dblnewtime = 0.0;
} else {
dblnewtime = static_cast<double>(newtime.QuadPart) / static_cast<double>(freq.QuadPart);
}
if (first)
{
firsttime = dblnewtime;
Expand Down
1 change: 1 addition & 0 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ int main(int argc, char *argv[]) {
#endif

InitTime();
UpdateTime();

AUDInit();
AUDListenerGain(vs_options::instance().sound_gain);
Expand Down

0 comments on commit c716715

Please sign in to comment.