From f09420fce747c9c65d2f7cdd83e718cc87741c7d Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 12 Nov 2009 03:45:51 +0000 Subject: [PATCH] - Modified the event-driven ticks to use the same code for calculating the time as the polled timer so that the timer does not start running until the first time it is used. - Removed the srand() call from D_DoomMain(), because it started the game timer running prematurely, and we never call rand() anywhere. (Not to mention, even if we did use rand(), always seeding it with 0 is rather pointless.) SVN r1974 (trunk) --- docs/rh-log.txt | 7 +++++++ src/d_main.cpp | 2 -- src/win32/i_system.cpp | 47 +++++++----------------------------------- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 4444de5bc..631ecc046 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,11 @@ November 11, 2009 +- Modified the event-driven ticks to use the same code for calculating the + time as the polled timer so that the timer does not start running until the + first time it is used. +- Removed the srand() call from D_DoomMain(), because it started the game + timer running prematurely, and we never call rand() anywhere. (Not to + mention, even if we did use rand(), always seeding it with 0 is rather + pointless.) - Fixed: The framerate was not capped before starting a game. - Removed the one embedded DeHackEd lump restriction. - Fixed: nofreeaim in P_SpawnPlayerMissile() was broken. diff --git a/src/d_main.cpp b/src/d_main.cpp index 9d1f90048..d8bae9f8a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1597,8 +1597,6 @@ void D_DoomMain (void) const char *wad; DArgs *execFiles; - srand(I_MSTime()); - // Set the FPU precision to 53 significant bits. This is the default // for Visual C++, but not for GCC, so some slight math variances // might crop up if we leave it alone. diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 8db15225b..caa1e533d 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -145,7 +145,7 @@ int I_GetTimePolled (bool saveMS) } tm = timeGetTime(); - if (!basetime) + if (basetime == 0) basetime = tm; if (saveMS) @@ -186,46 +186,20 @@ void I_FreezeTimePolled (bool frozen) } -static int tics; -static DWORD ted_start, ted_next; - -int I_GetTimeEventDriven (bool saveMS) -{ - if (saveMS) - { - TicStart = ted_start; - TicNext = ted_next; - } - return tics; -} - int I_WaitForTicEvent (int prevtic) { assert(!TicFrozen); + + int tics = I_GetTimePolled(false); while (prevtic >= tics) { WaitForSingleObject(NewTicArrived, 1000/TICRATE); + tics = I_GetTimePolled(false); } return tics; } -void CALLBACK TimerTicked (UINT id, UINT msg, DWORD_PTR user, DWORD_PTR dw1, DWORD_PTR dw2) -{ - if (!TicFrozen) - { - tics++; - } - ted_start = timeGetTime (); - ted_next = ted_start + MillisecondsPerTic; - SetEvent (NewTicArrived); -} - -void I_FreezeTimeEventDriven(bool frozen) -{ - TicFrozen = frozen; -} - // Returns the fractional amount of a tic passed since the most recent tic fixed_t I_GetTimeFrac (uint32 *ms) { @@ -453,21 +427,14 @@ void I_Init (void) { delay = 1000/TICRATE; } - TimerEventID = timeSetEvent - ( - delay, - 0, - TimerTicked, - 0, - TIME_PERIODIC - ); + TimerEventID = timeSetEvent(delay, 0, (LPTIMECALLBACK)NewTicArrived, 0, TIME_PERIODIC | TIME_CALLBACK_EVENT_SET); MillisecondsPerTic = delay; } if (TimerEventID != 0) { - I_GetTime = I_GetTimeEventDriven; + I_GetTime = I_GetTimePolled; I_WaitForTic = I_WaitForTicEvent; - I_FreezeTime = I_FreezeTimeEventDriven; + I_FreezeTime = I_FreezeTimePolled; } else { // If no timer event, busy-loop with timeGetTime