diff --git a/Credits.cpp b/Credits.cpp index a2416143..3dab0450 100644 --- a/Credits.cpp +++ b/Credits.cpp @@ -417,11 +417,7 @@ void GetCreditScreenUserInput() { InputAtom Event; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { if( Event.usEvent == KEY_DOWN ) { diff --git a/Editor/messagebox.cpp b/Editor/messagebox.cpp index 89207a0c..2a2b5eaf 100644 --- a/Editor/messagebox.cpp +++ b/Editor/messagebox.cpp @@ -76,12 +76,7 @@ BOOLEAN MessageBoxHandled() { InputAtom DummyEvent; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&DummyEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &DummyEvent ) ) -#endif - { if ( DummyEvent.usEvent == KEY_DOWN ) { diff --git a/Editor/popupmenu.cpp b/Editor/popupmenu.cpp index e20ffde3..3c47575c 100644 --- a/Editor/popupmenu.cpp +++ b/Editor/popupmenu.cpp @@ -398,12 +398,7 @@ void PopupMenuHandle() } //Use keyboard input as well. -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &InputEvent ) ) -#endif - { switch(InputEvent.usEvent) { diff --git a/GameInitOptionsScreen.cpp b/GameInitOptionsScreen.cpp index 443b8d98..48922639 100644 --- a/GameInitOptionsScreen.cpp +++ b/GameInitOptionsScreen.cpp @@ -2658,11 +2658,7 @@ void GetGIOScreenUserInput() { InputAtom Event; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { if( Event.usEvent == KEY_DOWN ) { @@ -5579,11 +5575,7 @@ void GetGIOScreenUserInput() { InputAtom Event; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { if( Event.usEvent == KEY_DOWN ) { diff --git a/GameSettings.cpp b/GameSettings.cpp index 71283fd2..5f20ab38 100644 --- a/GameSettings.cpp +++ b/GameSettings.cpp @@ -38,10 +38,8 @@ #include "InterfaceItemImages.h" #endif -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - #include "KeyMap.h" - #include "Timer Control.h" -#endif +#include "KeyMap.h" +#include "Timer Control.h" #include "Text.h" #include "connect.h" @@ -243,8 +241,6 @@ BOOLEAN LoadGameSettings() gGameSettings.fOptions[TOPTION_QUIET_REPAIRING] = iniReader.ReadBoolean("JA2 Game Settings","TOPTION_QUIET_REPAIRING" , FALSE ); gGameSettings.fOptions[TOPTION_QUIET_DOCTORING] = iniReader.ReadBoolean("JA2 Game Settings","TOPTION_QUIET_DOCTORING" , FALSE ); - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER if (!is_networked) gGameSettings.fOptions[TOPTION_AUTO_FAST_FORWARD_MODE] = iniReader.ReadBoolean("JA2 Game Settings","TOPTION_AUTO_FAST_FORWARD_MODE" , FALSE ); else @@ -253,7 +249,6 @@ BOOLEAN LoadGameSettings() // The "HIGHSPEED_TIMER" property from the ja2.ini is not set, disable the option if (!IsHiSpeedClockMode()) gGameSettings.fOptions[TOPTION_AUTO_FAST_FORWARD_MODE] = FALSE; -#endif #ifdef ENABLE_ZOMBIES gGameSettings.fOptions[TOPTION_ZOMBIES] = iniReader.ReadBoolean("JA2 Game Settings","TOPTION_ZOMBIES" , FALSE ); @@ -421,10 +416,7 @@ BOOLEAN SaveGameSettings() settings << "TOPTION_QUIET_TRAINING = " << (gGameSettings.fOptions[TOPTION_QUIET_TRAINING] ? "TRUE" : "FALSE" ) << endl; settings << "TOPTION_QUIET_REPAIRING = " << (gGameSettings.fOptions[TOPTION_QUIET_REPAIRING] ? "TRUE" : "FALSE" ) << endl; settings << "TOPTION_QUIET_DOCTORING = " << (gGameSettings.fOptions[TOPTION_QUIET_DOCTORING] ? "TRUE" : "FALSE" ) << endl; - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER settings << "TOPTION_AUTO_FAST_FORWARD_MODE = " << (gGameSettings.fOptions[TOPTION_AUTO_FAST_FORWARD_MODE] ? "TRUE" : "FALSE" ) << endl; -#endif settings << "TOPTION_SHOW_LAST_ENEMY = " << (gGameSettings.fOptions[TOPTION_SHOW_LAST_ENEMY] ? "TRUE" : "FALSE" ) << endl; settings << "TOPTION_SHOW_LBE_CONTENT = " << (gGameSettings.fOptions[TOPTION_SHOW_LBE_CONTENT] ? "TRUE" : "FALSE" ) << endl; @@ -560,9 +552,8 @@ void InitGameSettings() gGameSettings.fOptions[ TOPTION_QUIET_REPAIRING ] = FALSE; gGameSettings.fOptions[ TOPTION_QUIET_DOCTORING ] = FALSE; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER gGameSettings.fOptions[ TOPTION_AUTO_FAST_FORWARD_MODE ] = FALSE; -#endif + gGameSettings.fOptions[TOPTION_SHOW_LAST_ENEMY] = FALSE; gGameSettings.fOptions[TOPTION_SHOW_LBE_CONTENT] = TRUE; @@ -1874,7 +1865,6 @@ void LoadGameExternalOptions() gGameExternalOptions.fEnableInventoryPoolQ = FALSE; #endif -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER ////////// CLOCK SETTINGS ////////// // Key to artificially alter the clock so turns run faster @@ -1885,7 +1875,6 @@ void LoadGameExternalOptions() gGameExternalOptions.iFastForwardPeriod = (FLOAT)iniReader.ReadDouble("Clock Settings","FAST_FORWARD_PERIOD", 500, 1, 10000); gGameExternalOptions.fClockSpeedPercent = (FLOAT)iniReader.ReadDouble("Clock Settings","CLOCK_SPEED_PERCENT", 150, 100, 300); gGameExternalOptions.iNotifyFrequency = iniReader.ReadInteger("Clock Settings","UPDATE_FREQUENCY", 16000, 1000, 20000); -#endif } diff --git a/GameSettings.h b/GameSettings.h index 2e4e3485..b0867d04 100644 --- a/GameSettings.h +++ b/GameSettings.h @@ -84,9 +84,7 @@ enum TOPTION_QUIET_REPAIRING, //Madd: mercs don't say gained experience quote while repairing items TOPTION_QUIET_DOCTORING, //Madd: mercs don't say gained experience quote while doctoring -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER TOPTION_AUTO_FAST_FORWARD_MODE, // automatically fast forward through AI turns -#endif #ifdef ENABLE_ZOMBIES TOPTION_ZOMBIES, // Flugente Zombies 1.0: allow zombies @@ -1109,7 +1107,6 @@ typedef struct INT32 iInitialMercArrivalLocation; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER // Keyboard shortcut (as VK) for fastforward key. See Utils/KeyMap INT32 iFastForwardKey; // Turn on fast forward whenever ui is disabled. @@ -1120,7 +1117,6 @@ typedef struct INT32 iNotifyFrequency; // Frequency that the screen is updated FLOAT fClockSpeedPercent; -#endif // Flugente: Weapon Overheating BOOLEAN fDisplayOverheatThermometer; // Should a 'thermometer' for guns and replacable barrels be displayed? diff --git a/Laptop/AimFacialIndex.cpp b/Laptop/AimFacialIndex.cpp index 26f1f03a..228cba9f 100644 --- a/Laptop/AimFacialIndex.cpp +++ b/Laptop/AimFacialIndex.cpp @@ -505,12 +505,7 @@ void HandleAimFacialIndexKeyBoardInput() InputAtom InputEvent; UINT32 i; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif - {//!HandleTextInput( &InputEvent ) && if( InputEvent.usEvent == KEY_DOWN ) { diff --git a/Laptop/AimMembers.cpp b/Laptop/AimMembers.cpp index d2d5bcad..b40e4d74 100644 --- a/Laptop/AimMembers.cpp +++ b/Laptop/AimMembers.cpp @@ -5028,12 +5028,7 @@ void HandleAimMemberKeyBoardInput() { InputAtom InputEvent; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif - {//!HandleTextInput( &InputEvent ) && if( InputEvent.usEvent == KEY_DOWN ) { diff --git a/Laptop/AimSort.cpp b/Laptop/AimSort.cpp index 3a960293..b2020504 100644 --- a/Laptop/AimSort.cpp +++ b/Laptop/AimSort.cpp @@ -1088,12 +1088,7 @@ void HandleAimSortKeyBoardInput() { InputAtom InputEvent; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif - {//!HandleTextInput( &InputEvent ) && if( InputEvent.usEvent == KEY_DOWN ) { diff --git a/Laptop/BobbyRGuns.cpp b/Laptop/BobbyRGuns.cpp index 39ca37a6..5f2fa632 100644 --- a/Laptop/BobbyRGuns.cpp +++ b/Laptop/BobbyRGuns.cpp @@ -3879,6 +3879,7 @@ void HandleBobbyRGunsKeyBoardInput() fCtrl = _KeyDown( CTRL ); fAlt = _KeyDown( ALT ); + //while (DequeueSpecificEvent(&InputEvent, KEY_DOWN |KEY_REPEAT) == TRUE) while (DequeueEvent(&InputEvent) == TRUE) { if( InputEvent.usEvent == KEY_DOWN ) @@ -4101,12 +4102,10 @@ void HandleBobbyRGunsKeyBoardInput() break; } } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER else { extern void HandleDefaultEvent(InputAtom *Event); HandleDefaultEvent(&InputEvent); } -#endif } } diff --git a/Laptop/BriefingRoom.cpp b/Laptop/BriefingRoom.cpp index f0df185d..49dc1149 100644 --- a/Laptop/BriefingRoom.cpp +++ b/Laptop/BriefingRoom.cpp @@ -426,11 +426,7 @@ void GetPlayerKeyBoardInputForBriefingRoomHomePage( void ) GetCursorPos(&MousePos); ScreenToClient(ghWindow, &MousePos); // In window coords! -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { // HOOK INTO MOUSE HOOKS /* diff --git a/Laptop/BriefingRoomM.cpp b/Laptop/BriefingRoomM.cpp index 2ac211d8..4bcaef4a 100644 --- a/Laptop/BriefingRoomM.cpp +++ b/Laptop/BriefingRoomM.cpp @@ -493,11 +493,7 @@ void GetPlayerKeyBoardInputForBriefingRoomEnterHomePage( void ) GetCursorPos(&MousePos); ScreenToClient(ghWindow, &MousePos); // In window coords! -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { // HOOK INTO MOUSE HOOKS /* diff --git a/Laptop/IMP Begin Screen.cpp b/Laptop/IMP Begin Screen.cpp index 7959ddf7..0885ddfa 100644 --- a/Laptop/IMP Begin Screen.cpp +++ b/Laptop/IMP Begin Screen.cpp @@ -458,11 +458,7 @@ void GetPlayerKeyBoardInputForIMPBeginScreen( void ) ScreenToClient(ghWindow, &MousePos); // In window coords! // handle input events -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent(&InputEvent) ) -#endif { if( !HandleTextInput( &InputEvent ) && (InputEvent.usEvent == KEY_DOWN || InputEvent.usEvent == KEY_REPEAT) ) { diff --git a/Laptop/IMP HomePage.cpp b/Laptop/IMP HomePage.cpp index 8dd8a1df..0db4b321 100644 --- a/Laptop/IMP HomePage.cpp +++ b/Laptop/IMP HomePage.cpp @@ -266,11 +266,7 @@ void GetPlayerKeyBoardInputForIMPHomePage( void ) GetCursorPos(&MousePos); ScreenToClient(ghWindow, &MousePos); // In window coords! -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if( !HandleTextInput( &InputEvent ) && (InputEvent.usEvent == KEY_DOWN || InputEvent.usEvent == KEY_REPEAT || InputEvent.usEvent == KEY_UP ) ) { diff --git a/Laptop/aim.cpp b/Laptop/aim.cpp index 43c9b352..0094b744 100644 --- a/Laptop/aim.cpp +++ b/Laptop/aim.cpp @@ -1315,12 +1315,7 @@ void HandleAimKeyBoardInput() { InputAtom InputEvent; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif - {//!HandleTextInput( &InputEvent ) && if( InputEvent.usEvent == KEY_DOWN ) { diff --git a/Laptop/florist Order Form.cpp b/Laptop/florist Order Form.cpp index c17bf093..7028a2e4 100644 --- a/Laptop/florist Order Form.cpp +++ b/Laptop/florist Order Form.cpp @@ -1257,11 +1257,7 @@ void HandleFloristOrderKeyBoardInput() { InputAtom InputEvent; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if( !HandleTextInput( &InputEvent ) && InputEvent.usEvent == KEY_DOWN ) { diff --git a/Laptop/mercs Files.cpp b/Laptop/mercs Files.cpp index 184dcaac..51e38ea8 100644 Binary files a/Laptop/mercs Files.cpp and b/Laptop/mercs Files.cpp differ diff --git a/Laptop/personnel.cpp b/Laptop/personnel.cpp index ab720757..cd76e0ba 100644 --- a/Laptop/personnel.cpp +++ b/Laptop/personnel.cpp @@ -6445,11 +6445,7 @@ void HandlePersonnelKeyboard( void ) GetCursorPos(&MousePos); ScreenToClient(ghWindow, &MousePos); // In window coords! -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if ( (InputEvent.usEvent == KEY_DOWN ) && (InputEvent.usParam >= '0' ) && ( InputEvent.usParam <= '9') ) { diff --git a/MPChatScreen.cpp b/MPChatScreen.cpp index 3f247fcb..62eca5f1 100644 --- a/MPChatScreen.cpp +++ b/MPChatScreen.cpp @@ -758,11 +758,7 @@ UINT32 MPChatScreenHandle( ) // Check for esc bool bHandled; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { bHandled = false; if(InputEvent.usEvent == KEY_DOWN ) diff --git a/MPConnectScreen.cpp b/MPConnectScreen.cpp index cafad384..1b2ca83a 100644 --- a/MPConnectScreen.cpp +++ b/MPConnectScreen.cpp @@ -418,11 +418,7 @@ void GetMPCScreenUserInput() // GetCursorPos(&MousePos); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { // check if this event is swallowed by text input, otherwise process key if( Event.usEvent == KEY_DOWN ) diff --git a/MPHostScreen.cpp b/MPHostScreen.cpp index a1883c97..17de7c7c 100644 --- a/MPHostScreen.cpp +++ b/MPHostScreen.cpp @@ -2740,11 +2740,7 @@ void GetMPHScreenUserInput() // GetCursorPos(&MousePos); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { // check if this event is swallowed by text input, otherwise process key if( !HandleTextInput( &Event ) && Event.usEvent == KEY_DOWN ) diff --git a/MPJoinScreen.cpp b/MPJoinScreen.cpp index 42ebad0d..9b2b6112 100644 --- a/MPJoinScreen.cpp +++ b/MPJoinScreen.cpp @@ -665,11 +665,7 @@ void GetMPJScreenUserInput() { InputAtom Event; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { // check if this event is swallowed by text input, otherwise process key if( !HandleTextInput( &Event ) && Event.usEvent == KEY_DOWN ) diff --git a/MPScoreScreen.cpp b/MPScoreScreen.cpp index e3ab8e7d..b3c64214 100644 --- a/MPScoreScreen.cpp +++ b/MPScoreScreen.cpp @@ -536,11 +536,7 @@ void GetMPSScreenUserInput() { InputAtom Event; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { // check if this event is swallowed by text input, otherwise process key if( !HandleTextInput( &Event ) && Event.usEvent == KEY_DOWN ) diff --git a/MainMenuScreen.cpp b/MainMenuScreen.cpp index fbc76801..1efc1750 100644 --- a/MainMenuScreen.cpp +++ b/MainMenuScreen.cpp @@ -501,11 +501,7 @@ void HandleMainMenuInput() InputAtom InputEvent; // Check for esc -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if( InputEvent.usEvent == KEY_UP ) { @@ -559,11 +555,7 @@ void HandleHelpScreenInput() InputAtom InputEvent; // Check for key -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { switch( InputEvent.usEvent ) { diff --git a/MessageBoxScreen.cpp b/MessageBoxScreen.cpp index dda3ca1d..55ba137a 100644 --- a/MessageBoxScreen.cpp +++ b/MessageBoxScreen.cpp @@ -1306,11 +1306,7 @@ UINT32 MessageBoxScreenHandle( ) // carter, need key shortcuts for clearing up message boxes // Check for esc -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if( !HandleTextInput( &InputEvent ) && InputEvent.usEvent == KEY_DOWN ) { diff --git a/Options Screen.cpp b/Options Screen.cpp index c25e921a..fcc055fd 100644 Binary files a/Options Screen.cpp and b/Options Screen.cpp differ diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index a5426dcf..1fb2af2e 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -4021,9 +4021,7 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) ShutdownNPCQuotes(); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER SetFastForwardMode(FALSE); // FF can sometimes be active if quick-load during AI turn transition -#endif //very small TODO //Bugfix = Stop the chopter sound diff --git a/Standard Gaming Platform/input.cpp b/Standard Gaming Platform/input.cpp index ca8569bd..9fdf2c89 100644 --- a/Standard Gaming Platform/input.cpp +++ b/Standard Gaming Platform/input.cpp @@ -111,9 +111,8 @@ BOOLEAN gfCurrentStringInputState; StringInput *gpCurrentStringDescriptor; // Thread -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - static CRITICAL_SECTION gcsInputQueueLock; -#endif +static CRITICAL_SECTION gcsInputQueueLock; + // Local function headers @@ -282,9 +281,7 @@ BOOLEAN InitializeInputManager(void) // ghKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) KeyboardHandler, (HINSTANCE) 0, GetCurrentThreadId()); // DbgMessage(TOPIC_INPUT, DBG_LEVEL_2, String("Set keyboard hook returned %d", ghKeyboardHook)); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER InitializeCriticalSection(&gcsInputQueueLock); -#endif ghMouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC) MouseHandler, (HINSTANCE) 0, GetCurrentThreadId()); DbgMessage(TOPIC_INPUT, DBG_LEVEL_2, String("Set mouse hook returned %d", ghMouseHook)); @@ -299,10 +296,7 @@ void ShutdownInputManager(void) // UnhookWindowsHookEx(ghKeyboardHook); UnhookWindowsHookEx(ghMouseHook); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER DeleteCriticalSection(&gcsInputQueueLock); -#endif - } void QueuePureEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) @@ -343,11 +337,7 @@ void QueuePureEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) } } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void InternalQueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) -#else - void QueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) -#endif +void InternalQueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) { UINT32 uiTimer; UINT16 usKeyState; @@ -470,45 +460,21 @@ void QueuePureEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) } } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void QueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) - { - EnterCriticalSection(&gcsInputQueueLock); - __try { - InternalQueueEvent(ubInputEvent, usParam, uiParam); - }__finally { - LeaveCriticalSection(&gcsInputQueueLock); - } + +void QueueEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) +{ + EnterCriticalSection(&gcsInputQueueLock); + __try { + InternalQueueEvent(ubInputEvent, usParam, uiParam); + }__finally { + LeaveCriticalSection(&gcsInputQueueLock); } -#endif +} -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags ) - { - EnterCriticalSection(&gcsInputQueueLock); - __try - { - // Is there an event to dequeue - if (gusQueueCount > 0) - { - memcpy( Event, &( gEventQueue[gusHeadIndex] ), sizeof( InputAtom ) ); - - // Check if it has the masks! - if ( ( Event->usEvent & uiMaskFlags ) ) - { - return( DequeueEvent( Event) ); - } - } - - return( FALSE ); - } - __finally - { - LeaveCriticalSection(&gcsInputQueueLock); - } - } -#else - BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags ) +BOOLEAN DequeueSpecificEvent(InputAtom *Event, UINT32 uiMaskFlags ) +{ + EnterCriticalSection(&gcsInputQueueLock); + __try { // Is there an event to dequeue if (gusQueueCount > 0) @@ -524,13 +490,13 @@ void QueuePureEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) return( FALSE ); } -#endif + __finally + { + LeaveCriticalSection(&gcsInputQueueLock); + } +} -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - BOOLEAN InternalDequeueEvent(InputAtom *Event) -#else - BOOLEAN DequeueEvent(InputAtom *Event) -#endif +BOOLEAN InternalDequeueEvent(InputAtom *Event) { HandleSingleClicksAndButtonRepeats( ); @@ -562,20 +528,19 @@ void QueuePureEvent(UINT16 ubInputEvent, UINT32 usParam, UINT32 uiParam) } } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - BOOLEAN DequeueEvent(InputAtom *Event) +BOOLEAN DequeueEvent(InputAtom *Event) +{ + __try { - __try - { - EnterCriticalSection(&gcsInputQueueLock); - return InternalDequeueEvent(Event); - } - __finally - { - LeaveCriticalSection(&gcsInputQueueLock); - } + EnterCriticalSection(&gcsInputQueueLock); + return InternalDequeueEvent(Event); } -#endif + __finally + { + LeaveCriticalSection(&gcsInputQueueLock); + } +} + void KeyChange(UINT32 usParam, UINT32 uiParam, UINT8 ufKeyState) { diff --git a/Standard Gaming Platform/sgp.cpp b/Standard Gaming Platform/sgp.cpp index de7967af..2c6232b3 100644 --- a/Standard Gaming Platform/sgp.cpp +++ b/Standard Gaming Platform/sgp.cpp @@ -151,13 +151,13 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandSho void ShutdownStandardGamingPlatform(void); void GetRuntimeSettings( ); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - INT32 FAR PASCAL SyncWindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LPARAM lParam); - void CreateStandardGamingPlatform(HWND hWindow); - void SafeSGPExit(void); - static bool CallGameLoop(bool wait); - static CRITICAL_SECTION gcsGameLoop; -#endif + +INT32 FAR PASCAL SyncWindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LPARAM lParam); +void CreateStandardGamingPlatform(HWND hWindow); +void SafeSGPExit(void); +static bool CallGameLoop(bool wait); +static CRITICAL_SECTION gcsGameLoop; + int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCommandLine, int sCommandShow); @@ -216,16 +216,16 @@ BOOLEAN gfIgnoreMessages=FALSE; // GLOBAL VARIBLE, SET TO DEFAULT BUT CAN BE CHANGED BY THE GAME IF INIT FILE READ UINT8 gbPixelDepth = PIXEL_DEPTH; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - INT32 FAR PASCAL SyncWindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LPARAM lParam) - { - INT32 retval; - EnterCriticalSection(&gcsGameLoop); - retval = WindowProcedure(hWindow, Message, wParam, lParam); - LeaveCriticalSection(&gcsGameLoop); - return retval; - } -#endif + +INT32 FAR PASCAL SyncWindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LPARAM lParam) +{ + INT32 retval; + EnterCriticalSection(&gcsGameLoop); + retval = WindowProcedure(hWindow, Message, wParam, lParam); + LeaveCriticalSection(&gcsGameLoop); + return retval; +} + bool s_bExportStrings = false; extern bool g_bUseXML_Strings;// = false; @@ -536,9 +536,7 @@ INT32 FAR PASCAL WindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LP case WM_CREATE: -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER CreateStandardGamingPlatform(hWindow); -#endif break; case WM_DESTROY: @@ -667,11 +665,7 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow) FontTranslationTable *pFontTable; // now required by all (even JA2) in order to call ShutdownSGP -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER atexit(SafeSGPExit); -#else - atexit(SGPExit); -#endif // First, initialize the registry keys. InitializeRegistryKeys( "Wizardry8", "Wizardry8key" ); @@ -732,9 +726,8 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow) return FALSE; } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER InitializeCriticalSection(&gcsGameLoop); -#endif + FastDebugMsg("Initializing Video Manager"); // Initialize DirectDraw (DirectX 2) @@ -761,13 +754,6 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow) return FALSE; } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER -#else - InitializeJA2Clock(); -#endif - - //InitializeJA2TimerID(); - #ifdef USE_VFS //vfs::Path exe_dir, exe_file; //os::getExecutablePath(exe_dir, exe_file); @@ -915,26 +901,25 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow) return TRUE; } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - static void TimerActivatedCallback(INT32 timer, PTR state) +static void TimerActivatedCallback(INT32 timer, PTR state) +{ + if (gfApplicationActive && gfProgramIsRunning) { - if (gfApplicationActive && gfProgramIsRunning) - { - if (CallGameLoop(false)) - YieldProcessor(); - } + if (CallGameLoop(false)) + YieldProcessor(); } +} - void CreateStandardGamingPlatform(HWND hWindow) - { - InitializeJA2Clock(); +void CreateStandardGamingPlatform(HWND hWindow) +{ + InitializeJA2Clock(); + + if (!IsHiSpeedClockMode()) + SetTimer( hWindow, 0, 1, NULL); + else + AddTimerNotifyCallback(TimerActivatedCallback, hWindow); +} - if (!IsHiSpeedClockMode()) - SetTimer( hWindow, 0, 1, NULL); - else - AddTimerNotifyCallback(TimerActivatedCallback, hWindow); - } -#endif void ShutdownStandardGamingPlatform(void) { @@ -959,9 +944,7 @@ void ShutdownStandardGamingPlatform(void) // Shut down the different components of the SGP // -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER ClearTimerNotifyCallbacks(); -#endif // TEST SoundServiceStreams(); @@ -1009,9 +992,7 @@ void ShutdownStandardGamingPlatform(void) // down the debugging layer UnRegisterDebugTopic(TOPIC_SGP, "Standard Gaming Platform"); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER DeleteCriticalSection(&gcsGameLoop); -#endif ShutdownDebugManager(); @@ -1277,12 +1258,6 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC FastDebugMsg("Running Game"); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER -#else - // 0verhaul: Use the smallest available timer to make sure all animation updates happen at the speed they're supposed to - SetTimer( ghWindow, uiTimer, 1, NULL); -#endif - // At this point the SGP is set up, which means all I/O, Memory, tools, etc... are available. All we need to do is // attend to the gaming mechanics themselves Message.wParam = 0; @@ -1356,10 +1331,6 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pC } #endif -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER -#else - KillTimer( ghWindow, uiTimer); -#endif // This is the normal exit point FastDebugMsg("Exiting Game"); @@ -1728,29 +1699,28 @@ void GetRuntimeSettings( ) s_CodePage = oProps.getStringProperty(L"Ja2 Settings", L"CODE_PAGE"); #endif // USE_CODE_PAGE -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - // get timer/clock initialization state - SetHiSpeedClockMode( oProps.getBoolProperty("Ja2 Settings", "HIGHSPEED_TIMER", false) ? TRUE : FALSE ); -#endif +// get timer/clock initialization state +SetHiSpeedClockMode( oProps.getBoolProperty("Ja2 Settings", "HIGHSPEED_TIMER", false) ? TRUE : FALSE ); + #endif } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void SafeSGPExit(void) + +void SafeSGPExit(void) +{ + // SGPExit tends to use resources that are already uninitialized so handle + __try { - // SGPExit tends to use resources that are already uninitialized so handle - __try - { - SGPExit(); - } - __except( EXCEPTION_EXECUTE_HANDLER ) - { - // The application is in exit and best effort to clean up - // has failed so just ignore and continue silently - } + SGPExit(); } -#endif + __except( EXCEPTION_EXECUTE_HANDLER ) + { + // The application is in exit and best effort to clean up + // has failed so just ignore and continue silently + } +} + void ShutdownWithErrorBox(CHAR8 *pcMessage) { @@ -1945,70 +1915,69 @@ static LONG __stdcall SGPExceptionFilter(int exceptionCount, EXCEPTION_POINTERS* return EXCEPTION_EXECUTE_HANDLER; } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - static void SGPGameLoop() +static void SGPGameLoop() +{ + try { - try - { - GameLoop(); - } - catch(sgp::Exception &ex) - { - SGP_ERROR(ex.what()); - SHOWEXCEPTION(ex); - } - catch(vfs::Exception &ex) - { - SGP_ERROR(ex.what()); - SHOWEXCEPTION(ex); - } - catch(std::exception &ex) - { - sgp::Exception nex(ex.what()); - SGP_ERROR(nex.what()); - SHOWEXCEPTION(nex); - } - catch(const char* msg) - { - sgp::Exception ex(msg); - SGP_ERROR(ex.what()); - SHOWEXCEPTION(ex); - } + GameLoop(); + } + catch(sgp::Exception &ex) + { + SGP_ERROR(ex.what()); + SHOWEXCEPTION(ex); + } + catch(vfs::Exception &ex) + { + SGP_ERROR(ex.what()); + SHOWEXCEPTION(ex); + } + catch(std::exception &ex) + { + sgp::Exception nex(ex.what()); + SGP_ERROR(nex.what()); + SHOWEXCEPTION(nex); + } + catch(const char* msg) + { + sgp::Exception ex(msg); + SGP_ERROR(ex.what()); + SHOWEXCEPTION(ex); + } +} + +static bool CallGameLoop(bool wait) +{ + static int numUnsuccessfulTries = 0; + if (wait) + { + EnterCriticalSection(&gcsGameLoop); + } + else + { + if ( !TryEnterCriticalSection(&gcsGameLoop) ) + return false; } - static bool CallGameLoop(bool wait) + __try { - static int numUnsuccessfulTries = 0; - if (wait) - { - EnterCriticalSection(&gcsGameLoop); - } - else - { - if ( !TryEnterCriticalSection(&gcsGameLoop) ) - return false; - } - __try { - __try - { - SGPGameLoop(); - numUnsuccessfulTries = 0; - } - __except( SGPExceptionFilter(++numUnsuccessfulTries, GetExceptionInformation()) ) - { - } + SGPGameLoop(); + numUnsuccessfulTries = 0; } - __finally + __except( SGPExceptionFilter(++numUnsuccessfulTries, GetExceptionInformation()) ) { - LeaveCriticalSection(&gcsGameLoop); } - - // Give it several attempts to recover from random exceptions and to display error screen - if (numUnsuccessfulTries > 5) - ShutdownWithErrorBox("Unhandled exception. Unable to recover."); - - return true; } -#endif + __finally + { + LeaveCriticalSection(&gcsGameLoop); + } + + // Give it several attempts to recover from random exceptions and to display error screen + if (numUnsuccessfulTries > 5) + ShutdownWithErrorBox("Unhandled exception. Unable to recover."); + + return true; +} + diff --git a/Strategic/AI Viewer.cpp b/Strategic/AI Viewer.cpp index fdb6cc2a..c10fc075 100644 --- a/Strategic/AI Viewer.cpp +++ b/Strategic/AI Viewer.cpp @@ -933,11 +933,7 @@ void HandleViewerInput() SECTORINFO *pSector; InputAtom Event; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while( DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP) ) -#else - while( DequeueEvent( &Event ) ) -#endif { if( !HandleTextInput( &Event ) && Event.usEvent == KEY_DOWN ) { diff --git a/Strategic/Auto Resolve.cpp b/Strategic/Auto Resolve.cpp index 2c14e3af..065d9025 100644 --- a/Strategic/Auto Resolve.cpp +++ b/Strategic/Auto Resolve.cpp @@ -3411,11 +3411,7 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Autoresolve3"); InputAtom InputEvent; BOOLEAN fResetAutoResolve = FALSE; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while( DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT) ) -#else - while( DequeueEvent( &InputEvent ) ) -#endif { if( InputEvent.usEvent == KEY_DOWN || InputEvent.usEvent == KEY_REPEAT ) { diff --git a/Strategic/Quest Debug System.cpp b/Strategic/Quest Debug System.cpp index dff6bb76..ec2ae91a 100644 --- a/Strategic/Quest Debug System.cpp +++ b/Strategic/Quest Debug System.cpp @@ -1311,11 +1311,7 @@ void GetUserInput() GetCursorPos(&MousePos); ScreenToClient(ghWindow, &MousePos); // In window coords! -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while( DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT) ) -#else - while( DequeueEvent( &Event ) ) -#endif { if( !HandleTextInput( &Event ) && Event.usEvent == KEY_DOWN ) { diff --git a/Strategic/mapscreen.cpp b/Strategic/mapscreen.cpp index ddf78bfd..ad8d0b6a 100644 --- a/Strategic/mapscreen.cpp +++ b/Strategic/mapscreen.cpp @@ -6825,35 +6825,6 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent ) while( DequeueEvent( &InputEvent ) ) { - #ifdef USE_HIGHSPEED_GAMELOOP_TIMER - #else - GetCursorPos(&MousePos); - ScreenToClient(ghWindow, &MousePos); // In window coords! - - // HOOK INTO MOUSE HOOKS - switch(InputEvent.usEvent) - { - case LEFT_BUTTON_DOWN: - MouseSystemHook(LEFT_BUTTON_DOWN, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown); - break; - case LEFT_BUTTON_UP: - MouseSystemHook(LEFT_BUTTON_UP, (INT16)MousePos.x, (INT16)MousePos.y ,_LeftButtonDown, _RightButtonDown); - break; - case RIGHT_BUTTON_DOWN: - MouseSystemHook(RIGHT_BUTTON_DOWN, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown); - break; - case RIGHT_BUTTON_UP: - MouseSystemHook(RIGHT_BUTTON_UP, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown); - break; - case RIGHT_BUTTON_REPEAT: - MouseSystemHook(RIGHT_BUTTON_REPEAT, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown); - break; - case LEFT_BUTTON_REPEAT: - MouseSystemHook(LEFT_BUTTON_REPEAT, (INT16)MousePos.x, (INT16)MousePos.y,_LeftButtonDown, _RightButtonDown); - break; - } - #endif - if( InputEvent.usEvent == KEY_DOWN ) { // if game is paused because of player, unpause with any key @@ -8293,6 +8264,7 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent ) } else { + extern void HandleDefaultEvent(InputAtom *Event); HandleDefaultEvent(&InputEvent); } } diff --git a/Tactical/Auto Bandage.cpp b/Tactical/Auto Bandage.cpp index e749eddb..63528479 100644 --- a/Tactical/Auto Bandage.cpp +++ b/Tactical/Auto Bandage.cpp @@ -279,11 +279,7 @@ BOOLEAN HandleAutoBandage( ) // Deque all game events DequeAllGameEvents( TRUE ); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if ( InputEvent.usEvent == KEY_UP ) { diff --git a/Tactical/ShopKeeper Interface.cpp b/Tactical/ShopKeeper Interface.cpp index df4b354e..cf82e8f7 100644 --- a/Tactical/ShopKeeper Interface.cpp +++ b/Tactical/ShopKeeper Interface.cpp @@ -1738,11 +1738,7 @@ void GetShopKeeperInterfaceUserInput() GetCursorPos(&MousePos); ScreenToClient(ghWindow, &MousePos); // In window coords! -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { // HOOK INTO MOUSE HOOKS /* removed warning condition C4060 (jonathanl) diff --git a/Tactical/Strategic Exit GUI.cpp b/Tactical/Strategic Exit GUI.cpp index 3506f84e..f6ff728b 100644 --- a/Tactical/Strategic Exit GUI.cpp +++ b/Tactical/Strategic Exit GUI.cpp @@ -620,11 +620,7 @@ void RenderSectorExitMenu( ) gsGlobalCursorYOffset = 0; SetCurrentCursorFromDatabase( CURSOR_NORMAL ); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while( DequeueEvent( &Event ) ) -#endif { if( Event.usEvent == KEY_DOWN ) { diff --git a/Tactical/Tactical Turns.cpp b/Tactical/Tactical Turns.cpp index 60ffb641..74554cb5 100644 --- a/Tactical/Tactical Turns.cpp +++ b/Tactical/Tactical Turns.cpp @@ -151,9 +151,7 @@ void HandleTacticalEndTurn( ) // OK, Do a number of things here.... // Every few turns...... -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER SetFastForwardMode(FALSE); // Cancel FF at end of battle -#endif // Get time elasped uiTime = GetWorldTotalSeconds( ); diff --git a/Tactical/TeamTurns.cpp b/Tactical/TeamTurns.cpp index f85abf0a..41dae0c1 100644 --- a/Tactical/TeamTurns.cpp +++ b/Tactical/TeamTurns.cpp @@ -168,9 +168,7 @@ void StartPlayerTeamTurn( BOOLEAN fDoBattleSnd, BOOLEAN fEnteringCombatMode ) // SOLDIERTYPE *pSoldier; // EV_S_BEGINTURN SBeginTurn; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER SetFastForwardMode(FALSE); -#endif // Start the turn of player charactors @@ -506,7 +504,6 @@ void BeginTeamTurn( UINT8 ubTeam ) if( !LightningEndOfTurn( ubTeam ) )return; //end rain -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER // disable for our turn and enable for other teams if ( gGameSettings.fOptions[TOPTION_AUTO_FAST_FORWARD_MODE] ) { @@ -521,7 +518,6 @@ void BeginTeamTurn( UINT8 ubTeam ) SetFastForwardMode( (ubTeam != OUR_TEAM) ); } } -#endif while( 1 ) { @@ -849,9 +845,7 @@ void StartInterrupt( void ) INT32 iSquad, iCounter; // disable ff mode -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER SetFastForwardMode(FALSE); -#endif // build string for display of who gets interrupt //while( 1 ) @@ -1454,7 +1448,6 @@ void EndInterrupt( BOOLEAN fMarkInterruptOccurred ) } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER if ( gGameSettings.fOptions[TOPTION_AUTO_FAST_FORWARD_MODE] ) { if (is_networked) @@ -1468,7 +1461,6 @@ void EndInterrupt( BOOLEAN fMarkInterruptOccurred ) SetFastForwardMode( (gTacticalStatus.ubCurrentTeam != OUR_TEAM) ); } } -#endif } diff --git a/TileEngine/overhead map.cpp b/TileEngine/overhead map.cpp index 1e6b366e..6f758ebd 100644 --- a/TileEngine/overhead map.cpp +++ b/TileEngine/overhead map.cpp @@ -713,11 +713,7 @@ void HandleOverheadUI(void) ScrollOverheadMap(); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while(DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT) == TRUE) -#else - while(DequeueEvent(&InputEvent) == TRUE) -#endif { if(InputEvent.usEvent == KEY_DOWN || InputEvent.usEvent == KEY_REPEAT) { diff --git a/Utils/MapUtility.cpp b/Utils/MapUtility.cpp index 08bbd955..5a6ced33 100644 --- a/Utils/MapUtility.cpp +++ b/Utils/MapUtility.cpp @@ -101,11 +101,7 @@ UINT32 MapUtilScreenHandle(void) INT32 cnt, iX, iY, iSubX1, iSubY1, iSubX2, iSubY2, iWindowX, iWindowY, iCount; FLOAT dX, dY, dStartX, dStartY; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while(DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP) == TRUE) -#else - while(DequeueEvent(&InputEvent) == TRUE) -#endif { if(InputEvent.usParam == ESC) { diff --git a/Utils/Timer Control.cpp b/Utils/Timer Control.cpp index 9389b102..ec91fefc 100644 --- a/Utils/Timer Control.cpp +++ b/Utils/Timer Control.cpp @@ -14,10 +14,7 @@ #include "worlddef.h" #include "renderworld.h" #include "interface control.h" - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER #include "keymap.h" -#endif #endif @@ -29,13 +26,12 @@ #include "connect.h" // Base resolution of callback timer -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - static INT32 BASETIMESLICE = 10; - const INT32 FASTFORWARDTIMESLICE = 1000; - const UINT32 FREQUENCY_CONST = 1000000; - static INT32 MIN_NOTIFY_TIME = 16000; - static INT32 UPDATETIMESLICE = 10000; -#endif +static INT32 BASETIMESLICE = 10; +const INT32 FASTFORWARDTIMESLICE = 1000; +const UINT32 FREQUENCY_CONST = 1000000; +static INT32 MIN_NOTIFY_TIME = 16000; +static INT32 UPDATETIMESLICE = 10000; + INT32 giClockTimer = -1; INT32 giTimerDiag = 0; @@ -45,21 +41,20 @@ UINT32 guiBaseJA2NoPauseClock = 0; BOOLEAN gfPauseClock = FALSE; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - BOOLEAN gfHispeedClockMode = FALSE; +BOOLEAN gfHispeedClockMode = FALSE; - const inline UINT32 TIME_US_TO_MS(UINT32 value) { return value / 1000; } - const inline UINT32 TIME_MS_TO_US(UINT32 value) { return value * 1000; } +const inline UINT32 TIME_US_TO_MS(UINT32 value) { return value / 1000; } +const inline UINT32 TIME_MS_TO_US(UINT32 value) { return value * 1000; } + +UINT32 giFastForwardPeriod = FASTFORWARDTIMESLICE; +BOOLEAN giFastForwardMode = FALSE; +INT32 giFastForwardKey = 0; +UINT32 guiTimeSlice = 0; +FLOAT gfClockSpeedPercent = 1.0; +LARGE_INTEGER gliPerfFreq = {0}; +LARGE_INTEGER gliPerfCount = {0}; +LARGE_INTEGER gliPerfCountNext = {0}; - UINT32 giFastForwardPeriod = FASTFORWARDTIMESLICE; - BOOLEAN giFastForwardMode = FALSE; - INT32 giFastForwardKey = 0; - UINT32 guiTimeSlice = 0; - FLOAT gfClockSpeedPercent = 1.0; - LARGE_INTEGER gliPerfFreq = {0}; - LARGE_INTEGER gliPerfCount = {0}; - LARGE_INTEGER gliPerfCountNext = {0}; -#endif INT32 giTimerIntervals[ NUMTIMERS ] = { @@ -105,18 +100,16 @@ CUSTOMIZABLE_TIMER_CALLBACK gpCustomizableTimerCallback = NULL; // Clock Callback event ID MMRESULT gTimerID; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - TIMECAPS gtc; +TIMECAPS gtc; - HANDLE ghClockThread; - DWORD gdwClockThreadId; - HANDLE ghClockThreadShutdown; +HANDLE ghClockThread; +DWORD gdwClockThreadId; +HANDLE ghClockThreadShutdown; - HANDLE ghNotifyThread; - DWORD gdwNotifyThreadId; - HANDLE ghNotifyThreadEvent; - HANDLE ghNotifyThreadShutdownComplete; -#endif +HANDLE ghNotifyThread; +DWORD gdwNotifyThreadId; +HANDLE ghNotifyThreadEvent; +HANDLE ghNotifyThreadShutdownComplete; // GLOBALS FOR CALLBACK UINT32 gCNT; @@ -141,496 +134,337 @@ extern INT32 giFlashContractBaseTime; extern UINT32 guiFlashCursorBaseTime; extern INT32 giPotCharPathBaseTime; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - typedef void (*TIMER_NOTIFY_CALLBACK) ( INT32 timer, PTR state ); - struct TIMER_NOTIFY_ITEM - { - TIMER_NOTIFY_CALLBACK callback; - PTR state; - }; - typedef std::list TIMER_NOTIFY_ITEM_LIST; - typedef TIMER_NOTIFY_ITEM_LIST::iterator TIMER_NOTIFY_ITEM_ITERATOR; - static TIMER_NOTIFY_ITEM_LIST glNotifyCallbacks; - static CRITICAL_SECTION gcsNotifyLock; - static bool HasTimerNotifyCallbacks( ); - static void BroadcastTimerNotify(INT32 ); - static BOOLEAN UpdateTimeCounter( INT32 &counter, INT32 &iTimeLeft ); - static BOOLEAN UpdateCounter( INT32 counter, INT32 &iTimeLeft); - static void UpdateTimer(); -#endif +typedef void (*TIMER_NOTIFY_CALLBACK) ( INT32 timer, PTR state ); +struct TIMER_NOTIFY_ITEM +{ + TIMER_NOTIFY_CALLBACK callback; + PTR state; +}; +typedef std::list TIMER_NOTIFY_ITEM_LIST; +typedef TIMER_NOTIFY_ITEM_LIST::iterator TIMER_NOTIFY_ITEM_ITERATOR; +static TIMER_NOTIFY_ITEM_LIST glNotifyCallbacks; +static CRITICAL_SECTION gcsNotifyLock; + +static bool HasTimerNotifyCallbacks( ); +static void BroadcastTimerNotify(INT32 ); +static BOOLEAN UpdateTimeCounter( INT32 &counter, INT32 &iTimeLeft ); +static BOOLEAN UpdateCounter( INT32 counter, INT32 &iTimeLeft); +static void UpdateTimer(); + UINT32 InitializeJA2TimerCallback( UINT32 uiDelay, LPTIMECALLBACK TimerProc, UINT32 uiUser ); // CALLBACKS void CALLBACK FlashItem( UINT uiID, UINT uiMsg, DWORD uiUser, DWORD uiDw1, DWORD uiDw2 ); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void CALLBACK TimeProc( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 ) + +void CALLBACK TimeProc( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 ) +{ + static BOOLEAN fInFunction = FALSE; + //SOLDIERTYPE *pSoldier; + + if ( !fInFunction ) { - static BOOLEAN fInFunction = FALSE; - //SOLDIERTYPE *pSoldier; + fInFunction = TRUE; - if ( !fInFunction ) + BOOLEAN timerDone = FALSE; + BOOLEAN tickTime = FALSE; + INT32 iTimeLeft = 0; + + // Use QPC to check if BASETIMESLICE (in ms) has passed + if (IsHiSpeedClockMode()) { - fInFunction = TRUE; - - BOOLEAN timerDone = FALSE; - BOOLEAN tickTime = FALSE; - INT32 iTimeLeft = 0; - - // Use QPC to check if BASETIMESLICE (in ms) has passed - if (IsHiSpeedClockMode()) + // Only advance time when sufficient time has passed to exceed next time + QueryPerformanceCounter(&gliPerfCount); + if (gliPerfCount.QuadPart > gliPerfCountNext.QuadPart) { - // Only advance time when sufficient time has passed to exceed next time - QueryPerformanceCounter(&gliPerfCount); - if (gliPerfCount.QuadPart > gliPerfCountNext.QuadPart) - { - INT32 iNext = IsFastForwardMode() ? giFastForwardPeriod : UPDATETIMESLICE; - gliPerfCountNext.QuadPart = gliPerfCount.QuadPart + (iNext * gliPerfFreq.QuadPart) / FREQUENCY_CONST; - iTimeLeft = iNext; - timerDone = IsFastForwardMode(); - tickTime = TRUE; - } - } - else - { - // When using millisecond timer, advance time everytime this function is called + INT32 iNext = IsFastForwardMode() ? giFastForwardPeriod : UPDATETIMESLICE; + gliPerfCountNext.QuadPart = gliPerfCount.QuadPart + (iNext * gliPerfFreq.QuadPart) / FREQUENCY_CONST; + iTimeLeft = iNext; + timerDone = IsFastForwardMode(); tickTime = TRUE; - timerDone = !IsFastForwardMode(); } - if (tickTime) - { - guiBaseJA2NoPauseClock += BASETIMESLICE; - - if ( !gfPauseClock ) - { - guiBaseJA2Clock += BASETIMESLICE; - - for ( gCNT = 0; gCNT < NUMTIMERS; gCNT++ ) - { - timerDone |= UpdateCounter( gCNT, iTimeLeft ); - } - - // Update some specialized countdown timers... - timerDone |= UpdateTimeCounter( giTimerAirRaidQuote, iTimeLeft ); - timerDone |= UpdateTimeCounter( giTimerAirRaidDiveStarted, iTimeLeft ); - timerDone |= UpdateTimeCounter( giTimerAirRaidUpdate, iTimeLeft ); - timerDone |= UpdateTimeCounter( giTimerTeamTurnUpdate, iTimeLeft ); - - if ( gpCustomizableTimerCallback ) - { - timerDone |= UpdateTimeCounter( giTimerCustomizable, iTimeLeft ); - } - - #ifndef BOUNDS_CHECKER - - // If mapscreen... - if( guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) - { - // IN Mapscreen, loop through player's team..... - for ( gCNT = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; gCNT <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; gCNT++ ) - { - gPSOLDIER = MercPtrs[ gCNT ]; - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PortraitFlashCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PanelAnimateCounter, iTimeLeft ); - } - } - else - { - // Set update flags for soldiers - //////////////////////////// - for ( gCNT = 0; gCNT < guiNumMercSlots; gCNT++ ) - { - gPSOLDIER = MercSlots[ gCNT ]; - - if ( gPSOLDIER != NULL ) - { - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.UpdateCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.DamageCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.ReloadCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.FlashSelCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.BlinkSelCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PortraitFlashCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.AICounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.FadeCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.NextTileCounter, iTimeLeft ); - timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PanelAnimateCounter, iTimeLeft ); - #ifdef JA2UB - timerDone |= UpdateTimeCounter( gPSOLDIER->GetupFromJA25StartCounter, iTimeLeft ); - #endif - } - } - } - #endif - } - } - - if (timerDone) - SetEvent(ghNotifyThreadEvent); - fInFunction = FALSE; } - } -#else - void CALLBACK TimeProc( UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2 ) - { - static BOOLEAN fInFunction = FALSE; - //SOLDIERTYPE *pSoldier; - - if ( !fInFunction ) + else + { + // When using millisecond timer, advance time everytime this function is called + tickTime = TRUE; + timerDone = !IsFastForwardMode(); + } + if (tickTime) { - fInFunction = TRUE; - guiBaseJA2NoPauseClock += BASETIMESLICE; - if ( !gfPauseClock ) { guiBaseJA2Clock += BASETIMESLICE; for ( gCNT = 0; gCNT < NUMTIMERS; gCNT++ ) { - UPDATECOUNTER( gCNT ); + timerDone |= UpdateCounter( gCNT, iTimeLeft ); } // Update some specialized countdown timers... - UPDATETIMECOUNTER( giTimerAirRaidQuote ); - UPDATETIMECOUNTER( giTimerAirRaidDiveStarted ); - UPDATETIMECOUNTER( giTimerAirRaidUpdate ); - UPDATETIMECOUNTER( giTimerTeamTurnUpdate ); + timerDone |= UpdateTimeCounter( giTimerAirRaidQuote, iTimeLeft ); + timerDone |= UpdateTimeCounter( giTimerAirRaidDiveStarted, iTimeLeft ); + timerDone |= UpdateTimeCounter( giTimerAirRaidUpdate, iTimeLeft ); + timerDone |= UpdateTimeCounter( giTimerTeamTurnUpdate, iTimeLeft ); if ( gpCustomizableTimerCallback ) { - UPDATETIMECOUNTER( giTimerCustomizable ); + timerDone |= UpdateTimeCounter( giTimerCustomizable, iTimeLeft ); } - #ifndef BOUNDS_CHECKER +#ifndef BOUNDS_CHECKER - // If mapscreen... - if( guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) - { - // IN Mapscreen, loop through player's team..... - for ( gCNT = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; gCNT <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; gCNT++ ) + // If mapscreen... + if( guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN ) { - gPSOLDIER = MercPtrs[ gCNT ]; - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.PortraitFlashCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.PanelAnimateCounter ); - } - } - else - { - // Set update flags for soldiers - //////////////////////////// - for ( gCNT = 0; gCNT < guiNumMercSlots; gCNT++ ) - { - gPSOLDIER = MercSlots[ gCNT ]; - - if ( gPSOLDIER != NULL ) + // IN Mapscreen, loop through player's team..... + for ( gCNT = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; gCNT <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; gCNT++ ) { - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.UpdateCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.DamageCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.ReloadCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.FlashSelCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.BlinkSelCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.PortraitFlashCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.AICounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.FadeCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.NextTileCounter ); - UPDATETIMECOUNTER( gPSOLDIER->timeCounters.PanelAnimateCounter ); - #ifdef JA2UB - UPDATETIMECOUNTER( gPSOLDIER->GetupFromJA25StartCounter ); - #endif + gPSOLDIER = MercPtrs[ gCNT ]; + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PortraitFlashCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PanelAnimateCounter, iTimeLeft ); } } - } - #endif - } + else + { + // Set update flags for soldiers + //////////////////////////// + for ( gCNT = 0; gCNT < guiNumMercSlots; gCNT++ ) + { + gPSOLDIER = MercSlots[ gCNT ]; - - fInFunction = FALSE; - } - } + if ( gPSOLDIER != NULL ) + { + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.UpdateCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.DamageCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.ReloadCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.FlashSelCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.BlinkSelCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PortraitFlashCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.AICounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.FadeCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.NextTileCounter, iTimeLeft ); + timerDone |= UpdateTimeCounter( gPSOLDIER->timeCounters.PanelAnimateCounter, iTimeLeft ); +#ifdef JA2UB + timerDone |= UpdateTimeCounter( gPSOLDIER->GetupFromJA25StartCounter, iTimeLeft ); #endif - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - static UINT32 MIN_TIMER(UINT32 timer, UINT32 other) - { - UINT32 value = TIME_MS_TO_US(timer); - return ( value && value < other ? value : other ); - } - - // Returns the smallest time interval for a counter currently in use - UINT32 GetNextCounterDoneTime(void) - { - QueryPerformanceCounter(&gliPerfCount); - INT32 time = (INT32)(((gliPerfCountNext.QuadPart - gliPerfCount.QuadPart) * FREQUENCY_CONST) / gliPerfFreq.QuadPart); - return (UINT32)((time > 0) ? time : 0); - } - - // Function to test if there are any outstanding timers. Used in fast forward routines - BOOLEAN IsTimerActive(void) - { - return GetNextCounterDoneTime() <= FASTFORWARDTIMESLICE ? TRUE : FALSE; - } - - DWORD WINAPI JA2ClockThread( LPVOID lpParam ) - { - __try - { - for(;;) - { - TimeProc(0, 0, 0, 0, 0); - - DWORD dwResult = WaitForSingleObject(ghClockThreadShutdown, 0); - if (dwResult == WAIT_OBJECT_0 || dwResult == WAIT_ABANDONED) - break; - YieldProcessor(); - - // Sleep for a couple of milliseconds if not in fast forward mode - if (!IsFastForwardMode()) - Sleep( TIME_US_TO_MS( GetNextCounterDoneTime() ) ); - } + } + } + } +#endif + } } - __except( EXCEPTION_EXECUTE_HANDLER ) - { - // Unhandled exception just exit - } - return 0L; - } - DWORD WINAPI JA2NotifyThread( LPVOID lpParam ) + if (timerDone) + SetEvent(ghNotifyThreadEvent); + fInFunction = FALSE; + } +} + + + +static UINT32 MIN_TIMER(UINT32 timer, UINT32 other) +{ + UINT32 value = TIME_MS_TO_US(timer); + return ( value && value < other ? value : other ); +} + +// Returns the smallest time interval for a counter currently in use +UINT32 GetNextCounterDoneTime(void) +{ + QueryPerformanceCounter(&gliPerfCount); + INT32 time = (INT32)(((gliPerfCountNext.QuadPart - gliPerfCount.QuadPart) * FREQUENCY_CONST) / gliPerfFreq.QuadPart); + return (UINT32)((time > 0) ? time : 0); +} + +// Function to test if there are any outstanding timers. Used in fast forward routines +BOOLEAN IsTimerActive(void) +{ + return GetNextCounterDoneTime() <= FASTFORWARDTIMESLICE ? TRUE : FALSE; +} + +DWORD WINAPI JA2ClockThread( LPVOID lpParam ) +{ + __try { - HANDLE waitHandles[] = {ghClockThreadShutdown, ghNotifyThreadEvent}; for(;;) { + TimeProc(0, 0, 0, 0, 0); + DWORD dwResult = WaitForSingleObject(ghClockThreadShutdown, 0); if (dwResult == WAIT_OBJECT_0 || dwResult == WAIT_ABANDONED) break; + YieldProcessor(); - DWORD waitTime = (!IsFastForwardMode()) ? max(TIME_US_TO_MS(MIN_NOTIFY_TIME), TIME_US_TO_MS( GetNextCounterDoneTime() ) ) : 0; - dwResult = WaitForMultipleObjectsEx(_countof(waitHandles), waitHandles, FALSE, waitTime, FALSE); - if (dwResult == WAIT_OBJECT_0) - break; - if (dwResult >= WAIT_ABANDONED_0 && dwResult <= (WAIT_ABANDONED_0 + _countof(waitHandles))) - break; - if ( dwResult == WAIT_FAILED || dwResult == WAIT_TIMEOUT || (dwResult-WAIT_OBJECT_0) == 1) - { - if (HasTimerNotifyCallbacks()) - { - BroadcastTimerNotify(-1); - } - } - else - { - // unexpected failure - } + // Sleep for a couple of milliseconds if not in fast forward mode + if (!IsFastForwardMode()) + Sleep( TIME_US_TO_MS( GetNextCounterDoneTime() ) ); } - SetEvent(ghNotifyThreadShutdownComplete); - return 0L; } -#endif - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - BOOLEAN InitializeJA2Clock() + __except( EXCEPTION_EXECUTE_HANDLER ) { - #ifdef CALLBACKTIMER - MMRESULT mmResult; - INT32 cnt; - - // Init timer delays - for ( cnt = 0; cnt < NUMTIMERS; cnt++ ) - { - giTimerCounters[ cnt ] = giTimerIntervals[ cnt ]; - } - - - // First get timer resolutions - mmResult = timeGetDevCaps( >c, sizeof( gtc ) ); - - if ( mmResult != TIMERR_NOERROR ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get timer properties"); - } - - if ( !QueryPerformanceFrequency(&gliPerfFreq) ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get performance frequency"); - } - if ( !QueryPerformanceCounter(&gliPerfCount) ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get performance frequency"); - } - - timeBeginPeriod(gtc.wPeriodMin); - - InitializeCriticalSection(&gcsNotifyLock); - - if (IsHiSpeedClockMode()) - { - ghClockThreadShutdown = CreateEvent(NULL, TRUE, FALSE, NULL); - ghNotifyThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - ghNotifyThreadShutdownComplete = CreateEvent(NULL, TRUE, FALSE, NULL); - ghClockThread = CreateThread( - NULL, // default security attributes - 0, // use default stack size - JA2ClockThread, // thread function - NULL, // argument to thread function - 0, // use default creation flags - &gdwClockThreadId);// returns the thread identifier - ghNotifyThread = CreateThread( - NULL, // default security attributes - 0, // use default stack size - JA2NotifyThread, // thread function - NULL, // argument to thread function - 0, // use default creation flags - &gdwNotifyThreadId);// returns the thread identifier - } - else - { - UpdateTimer(); - } - #endif - - return TRUE; + // Unhandled exception just exit } -#else - BOOLEAN InitializeJA2Clock(void) + return 0L; +} + +DWORD WINAPI JA2NotifyThread( LPVOID lpParam ) +{ + HANDLE waitHandles[] = {ghClockThreadShutdown, ghNotifyThreadEvent}; + for(;;) { + DWORD dwResult = WaitForSingleObject(ghClockThreadShutdown, 0); + if (dwResult == WAIT_OBJECT_0 || dwResult == WAIT_ABANDONED) + break; - #ifdef CALLBACKTIMER - - - MMRESULT mmResult; - TIMECAPS tc; - INT32 cnt; - - // Init timer delays - for ( cnt = 0; cnt < NUMTIMERS; cnt++ ) + DWORD waitTime = (!IsFastForwardMode()) ? max(TIME_US_TO_MS(MIN_NOTIFY_TIME), TIME_US_TO_MS( GetNextCounterDoneTime() ) ) : 0; + dwResult = WaitForMultipleObjectsEx(_countof(waitHandles), waitHandles, FALSE, waitTime, FALSE); + if (dwResult == WAIT_OBJECT_0) + break; + if (dwResult >= WAIT_ABANDONED_0 && dwResult <= (WAIT_ABANDONED_0 + _countof(waitHandles))) + break; + if ( dwResult == WAIT_FAILED || dwResult == WAIT_TIMEOUT || (dwResult-WAIT_OBJECT_0) == 1) { - giTimerCounters[ cnt ] = giTimerIntervals[ cnt ]; - } - - - // First get timer resolutions - mmResult = timeGetDevCaps( &tc, sizeof( tc ) ); - - if ( mmResult != TIMERR_NOERROR ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get timer properties"); - } - - // Set timer at lowest resolution. Could use middle of lowest/highest, we'll see how this performs first - gTimerID = timeSetEvent( BASETIMESLICE, BASETIMESLICE, TimeProc, (DWORD)0, TIME_PERIODIC ); - - if ( !gTimerID ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not create timer callback"); - } - - #endif - - return TRUE; - } -#endif - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void ShutdownJA2Clock(void) - { - if (IsHiSpeedClockMode()) - { - SetEvent(ghClockThreadShutdown); - WaitForSingleObject(ghNotifyThreadShutdownComplete, 2000); - HANDLE waitHandles[] = {ghClockThread, ghNotifyThread}; - WaitForMultipleObjects(_countof(waitHandles), waitHandles, TRUE, 1000); - CloseHandle(ghClockThreadShutdown); - CloseHandle(ghClockThread); - CloseHandle(ghNotifyThreadEvent); - CloseHandle(ghNotifyThread); - // During ungraceful shutdowns notify lock may be in use in notify thread - if (TryEnterCriticalSection(&gcsNotifyLock)) + if (HasTimerNotifyCallbacks()) { - LeaveCriticalSection(&gcsNotifyLock); - DeleteCriticalSection(&gcsNotifyLock); + BroadcastTimerNotify(-1); } } else { - // Make sure we kill the timer - #ifdef CALLBACKTIMER - timeKillEvent( gTimerID ); - #endif + // unexpected failure } + } + SetEvent(ghNotifyThreadShutdownComplete); + return 0L; +} - timeEndPeriod(gtc.wPeriodMin); + + +BOOLEAN InitializeJA2Clock() +{ +#ifdef CALLBACKTIMER + MMRESULT mmResult; + INT32 cnt; + + // Init timer delays + for ( cnt = 0; cnt < NUMTIMERS; cnt++ ) + { + giTimerCounters[ cnt ] = giTimerIntervals[ cnt ]; } -#else - void ShutdownJA2Clock(void) + + + // First get timer resolutions + mmResult = timeGetDevCaps( >c, sizeof( gtc ) ); + + if ( mmResult != TIMERR_NOERROR ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get timer properties"); + } + + if ( !QueryPerformanceFrequency(&gliPerfFreq) ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get performance frequency"); + } + if ( !QueryPerformanceCounter(&gliPerfCount) ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get performance frequency"); + } + + timeBeginPeriod(gtc.wPeriodMin); + + InitializeCriticalSection(&gcsNotifyLock); + + if (IsHiSpeedClockMode()) + { + ghClockThreadShutdown = CreateEvent(NULL, TRUE, FALSE, NULL); + ghNotifyThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + ghNotifyThreadShutdownComplete = CreateEvent(NULL, TRUE, FALSE, NULL); + ghClockThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + JA2ClockThread, // thread function + NULL, // argument to thread function + 0, // use default creation flags + &gdwClockThreadId);// returns the thread identifier + ghNotifyThread = CreateThread( + NULL, // default security attributes + 0, // use default stack size + JA2NotifyThread, // thread function + NULL, // argument to thread function + 0, // use default creation flags + &gdwNotifyThreadId);// returns the thread identifier + } + else + { + UpdateTimer(); + } +#endif + + return TRUE; +} + + +void ShutdownJA2Clock(void) +{ + if (IsHiSpeedClockMode()) + { + SetEvent(ghClockThreadShutdown); + WaitForSingleObject(ghNotifyThreadShutdownComplete, 2000); + HANDLE waitHandles[] = {ghClockThread, ghNotifyThread}; + WaitForMultipleObjects(_countof(waitHandles), waitHandles, TRUE, 1000); + CloseHandle(ghClockThreadShutdown); + CloseHandle(ghClockThread); + CloseHandle(ghNotifyThreadEvent); + CloseHandle(ghNotifyThread); + // During ungraceful shutdowns notify lock may be in use in notify thread + if (TryEnterCriticalSection(&gcsNotifyLock)) + { + LeaveCriticalSection(&gcsNotifyLock); + DeleteCriticalSection(&gcsNotifyLock); + } + } + else { // Make sure we kill the timer - #ifdef CALLBACKTIMER - +#ifdef CALLBACKTIMER timeKillEvent( gTimerID ); - - #endif - - } #endif - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - UINT32 InitializeJA2TimerCallback( UINT32 uiDelay, LPTIMECALLBACK TimerProc, UINT32 uiUser ) - { - MMRESULT mmResult; - MMRESULT TimerID; - - - // First get timer resolutions - mmResult = timeGetDevCaps( >c, sizeof( gtc ) ); - - if ( mmResult != TIMERR_NOERROR ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get timer properties"); - } - - // Set timer at lowest resolution. Could use middle of lowest/highest, we'll see how this performs first - TimerID = timeSetEvent( (UINT)uiDelay, (UINT)uiDelay, TimerProc, (DWORD)uiUser, TIME_PERIODIC ); - - if ( !TimerID ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not create timer callback"); - } - - return ( (UINT32)TimerID ); - } -#else - UINT32 InitializeJA2TimerCallback( UINT32 uiDelay, LPTIMECALLBACK TimerProc, UINT32 uiUser ) - { - MMRESULT mmResult; - TIMECAPS tc; - MMRESULT TimerID; - - - // First get timer resolutions - mmResult = timeGetDevCaps( &tc, sizeof( tc ) ); - - if ( mmResult != TIMERR_NOERROR ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get timer properties"); - } - - // Set timer at lowest resolution. Could use middle of lowest/highest, we'll see how this performs first - TimerID = timeSetEvent( (UINT)uiDelay, (UINT)uiDelay, TimerProc, (DWORD)uiUser, TIME_PERIODIC ); - - if ( !TimerID ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not create timer callback"); - } - - return ( (UINT32)TimerID ); } -#endif + timeEndPeriod(gtc.wPeriodMin); +} +UINT32 InitializeJA2TimerCallback( UINT32 uiDelay, LPTIMECALLBACK TimerProc, UINT32 uiUser ) +{ + MMRESULT mmResult; + MMRESULT TimerID; + + + // First get timer resolutions + mmResult = timeGetDevCaps( >c, sizeof( gtc ) ); + + if ( mmResult != TIMERR_NOERROR ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not get timer properties"); + } + + // Set timer at lowest resolution. Could use middle of lowest/highest, we'll see how this performs first + TimerID = timeSetEvent( (UINT)uiDelay, (UINT)uiDelay, TimerProc, (DWORD)uiUser, TIME_PERIODIC ); + + if ( !TimerID ) + { + DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not create timer callback"); + } + + return ( (UINT32)TimerID ); +} + void RemoveJA2TimerCallback( UINT32 uiTimer ) { timeKillEvent( uiTimer ); @@ -729,240 +563,238 @@ void SetTileAnimCounter( INT32 iTime ) giTimerIntervals[ ANIMATETILES ] = iTime; } +void SetFastForwardPeriod(DOUBLE value) +{ + giFastForwardPeriod = (UINT32)(value); + if (giFastForwardPeriod <= 1) + giFastForwardPeriod = 1; +} -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void SetFastForwardPeriod(DOUBLE value) +void SetFastForwardKey(INT32 key) +{ + giFastForwardKey = key; +} + +BOOLEAN IsFastForwardKeyPressed() +{ + // WANNE: In a multiplayer game it is not allowed for the "pure" client to do fast forward + // Only the server is allowed to do, because the AI is generated on the server + if (is_networked) { - giFastForwardPeriod = (UINT32)(value); - if (giFastForwardPeriod <= 1) - giFastForwardPeriod = 1; + if (!is_server) // It is not allowed when we are not the server + return false; + else if (gTacticalStatus.ubCurrentTeam != 1) // It is not allowed, when it is not the enemy turn! + return false; } - void SetFastForwardKey(INT32 key) - { - giFastForwardKey = key; - } + return giFastForwardKey && IsKeyPressed(giFastForwardKey); +} - BOOLEAN IsFastForwardKeyPressed() - { - // WANNE: In a multiplayer game it is not allowed for the "pure" client to do fast forward - // Only the server is allowed to do, because the AI is generated on the server - if (is_networked) - { - if (!is_server) // It is not allowed when we are not the server - return false; - else if (gTacticalStatus.ubCurrentTeam != 1) // It is not allowed, when it is not the enemy turn! - return false; +void SetFastForwardMode(BOOLEAN enable) +{ + giFastForwardMode = enable; + UpdateTimer(); +} + +BOOLEAN IsFastForwardMode() +{ + return giFastForwardMode || IsFastForwardKeyPressed(); +} + +LONGLONG GetJA2Microseconds() +{ + return gliPerfCount.QuadPart * FREQUENCY_CONST / gliPerfFreq.QuadPart; +} + +void AddTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ) +{ + EnterCriticalSection(&gcsNotifyLock); + BOOL addItem = TRUE; + for (TIMER_NOTIFY_ITEM_ITERATOR itr = glNotifyCallbacks.begin(); itr != glNotifyCallbacks.end(); ++itr) { + if ( callback == (*itr).callback && state == (*itr).state ){ + addItem = FALSE; + break; } - - return giFastForwardKey && IsKeyPressed(giFastForwardKey); } - - void SetFastForwardMode(BOOLEAN enable) + if (addItem) { - giFastForwardMode = enable; - UpdateTimer(); + TIMER_NOTIFY_ITEM item; + item.callback = callback; + item.state = state; + glNotifyCallbacks.push_back(item); } + LeaveCriticalSection(&gcsNotifyLock); +} - BOOLEAN IsFastForwardMode() +void RemoveTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ) +{ + EnterCriticalSection(&gcsNotifyLock); + for ( TIMER_NOTIFY_ITEM_ITERATOR itr = glNotifyCallbacks.begin(); itr != glNotifyCallbacks.end(); ) { - return giFastForwardMode || IsFastForwardKeyPressed(); + if ( callback == (*itr).callback && state == (*itr).state ) + itr = glNotifyCallbacks.erase(itr); + else + ++itr; } + LeaveCriticalSection(&gcsNotifyLock); +} - LONGLONG GetJA2Microseconds() +void ClearTimerNotifyCallbacks() +{ + // If we cannot get the lock it is likely due to exception while handling notification and we are shutting down + if ( TryEnterCriticalSection(&gcsNotifyLock) ) { - return gliPerfCount.QuadPart * FREQUENCY_CONST / gliPerfFreq.QuadPart; - } - - void AddTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ) - { - EnterCriticalSection(&gcsNotifyLock); - BOOL addItem = TRUE; - for (TIMER_NOTIFY_ITEM_ITERATOR itr = glNotifyCallbacks.begin(); itr != glNotifyCallbacks.end(); ++itr) { - if ( callback == (*itr).callback && state == (*itr).state ){ - addItem = FALSE; - break; - } - } - if (addItem) - { - TIMER_NOTIFY_ITEM item; - item.callback = callback; - item.state = state; - glNotifyCallbacks.push_back(item); - } + glNotifyCallbacks.clear(); LeaveCriticalSection(&gcsNotifyLock); } +} - void RemoveTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ) +static bool HasTimerNotifyCallbacks( ) +{ + return !glNotifyCallbacks.empty(); +} + + +// Call timer notify routine +// Separate the callback notifies with normal try/catch +// as SEH __try/__except are incompatible with C++ exceptions +static void InnerTimerNotify(INT32 timer) +{ + try + { + for (TIMER_NOTIFY_ITEM_ITERATOR itr = glNotifyCallbacks.begin(); itr != glNotifyCallbacks.end(); ++itr) + { + if ( NULL != (*itr).callback) + (*itr).callback( timer, (*itr).state ); + } + } + catch (...) {} +} +static void BroadcastTimerNotify(INT32 timer) +{ + EnterCriticalSection(&gcsNotifyLock); + __try + { + __try { InnerTimerNotify(timer); } + __except( EXCEPTION_EXECUTE_HANDLER ) + { /* Not sure. exit? */ } + } + __finally { - EnterCriticalSection(&gcsNotifyLock); - for ( TIMER_NOTIFY_ITEM_ITERATOR itr = glNotifyCallbacks.begin(); itr != glNotifyCallbacks.end(); ) - { - if ( callback == (*itr).callback && state == (*itr).state ) - itr = glNotifyCallbacks.erase(itr); - else - ++itr; - } LeaveCriticalSection(&gcsNotifyLock); } +} - void ClearTimerNotifyCallbacks() - { - // If we cannot get the lock it is likely due to exception while handling notification and we are shutting down - if ( TryEnterCriticalSection(&gcsNotifyLock) ) - { - glNotifyCallbacks.clear(); - LeaveCriticalSection(&gcsNotifyLock); - } - } - - static bool HasTimerNotifyCallbacks( ) - { - return !glNotifyCallbacks.empty(); - } - - - // Call timer notify routine - // Separate the callback notifies with normal try/catch - // as SEH __try/__except are incompatible with C++ exceptions - static void InnerTimerNotify(INT32 timer) - { - try - { - for (TIMER_NOTIFY_ITEM_ITERATOR itr = glNotifyCallbacks.begin(); itr != glNotifyCallbacks.end(); ++itr) - { - if ( NULL != (*itr).callback) - (*itr).callback( timer, (*itr).state ); - } - } - catch (...) {} - } - static void BroadcastTimerNotify(INT32 timer) - { - EnterCriticalSection(&gcsNotifyLock); - __try - { - __try { InnerTimerNotify(timer); } - __except( EXCEPTION_EXECUTE_HANDLER ) - { /* Not sure. exit? */ } - } - __finally - { - LeaveCriticalSection(&gcsNotifyLock); - } - } - - BOOLEAN UpdateTimeCounter( INT32 &counter, INT32 &iTimeLeft) - { - if (counter == 0) { - return FALSE; - } else if ( ( counter - BASETIMESLICE ) < 0 ) { - counter = 0; - return TRUE; - } else { - counter -= BASETIMESLICE; - if ( counter < iTimeLeft ) - iTimeLeft = counter; - return FALSE; - } +BOOLEAN UpdateTimeCounter( INT32 &counter, INT32 &iTimeLeft) +{ + if (counter == 0) { + return FALSE; + } else if ( ( counter - BASETIMESLICE ) < 0 ) { + counter = 0; + return TRUE; + } else { + counter -= BASETIMESLICE; + if ( counter < iTimeLeft ) + iTimeLeft = counter; return FALSE; } + return FALSE; +} - BOOLEAN UpdateCounter( INT32 counterIdx, INT32 &iTimeLeft ) - { - INT32& counter = giTimerCounters[ counterIdx ]; - return UpdateTimeCounter(counter, iTimeLeft); - } +BOOLEAN UpdateCounter( INT32 counterIdx, INT32 &iTimeLeft ) +{ + INT32& counter = giTimerCounters[ counterIdx ]; + return UpdateTimeCounter(counter, iTimeLeft); +} - BOOLEAN UpdateCounter( INT32 counterIdx ) - { - INT32 iDummy = 0; - return UpdateCounter(counterIdx, iDummy); - } +BOOLEAN UpdateCounter( INT32 counterIdx ) +{ + INT32 iDummy = 0; + return UpdateCounter(counterIdx, iDummy); +} - void ResetCounter(INT32 counterIdx) - { - giTimerCounters[ counterIdx ] = giTimerIntervals[ counterIdx ]; - } +void ResetCounter(INT32 counterIdx) +{ + giTimerCounters[ counterIdx ] = giTimerIntervals[ counterIdx ]; +} - BOOLEAN CounterDone(INT32 counterIdx) - { - return ( giTimerCounters[ counterIdx ] == 0 ) ? TRUE : FALSE; - } +BOOLEAN CounterDone(INT32 counterIdx) +{ + return ( giTimerCounters[ counterIdx ] == 0 ) ? TRUE : FALSE; +} - void ResetTimerCounter(INT32 &timer, INT32 value) - { - timer = value; - } +void ResetTimerCounter(INT32 &timer, INT32 value) +{ + timer = value; +} - BOOLEAN TimeCounterDone(INT32 timer) - { - return ( timer == 0 ) ? TRUE : FALSE; - } +BOOLEAN TimeCounterDone(INT32 timer) +{ + return ( timer == 0 ) ? TRUE : FALSE; +} - void ZeroTimeCounter(INT32& timer) - { - timer = 0; - } +void ZeroTimeCounter(INT32& timer) +{ + timer = 0; +} - BOOLEAN IsJA2TimerThread() - { - return (GetCurrentThreadId() == gdwClockThreadId); - } +BOOLEAN IsJA2TimerThread() +{ + return (GetCurrentThreadId() == gdwClockThreadId); +} - #ifndef GetJA2Clock - UINT32 GetJA2Clock() - { - return guiBaseJA2Clock; - } - #endif +#ifndef GetJA2Clock +UINT32 GetJA2Clock() +{ + return guiBaseJA2Clock; +} +#endif - #ifndef GetJA2NoPauseClock - UINT32 GetJA2NoPauseClock() - { - return guiBaseJA2NoPauseClock; - } - #endif +#ifndef GetJA2NoPauseClock +UINT32 GetJA2NoPauseClock() +{ + return guiBaseJA2NoPauseClock; +} +#endif - void SetHiSpeedClockMode(BOOLEAN enable) - { - gfHispeedClockMode = enable; - } +void SetHiSpeedClockMode(BOOLEAN enable) +{ + gfHispeedClockMode = enable; +} - BOOLEAN IsHiSpeedClockMode() - { - return gfHispeedClockMode; - } +BOOLEAN IsHiSpeedClockMode() +{ + return gfHispeedClockMode; +} - void SetNotifyFrequencyKey(INT32 value) - { - MIN_NOTIFY_TIME = value; - } +void SetNotifyFrequencyKey(INT32 value) +{ + MIN_NOTIFY_TIME = value; +} - void SetClockSpeedPercent(FLOAT value) - { - gfClockSpeedPercent = value; - UPDATETIMESLICE = (UINT32)((FLOAT)TIME_MS_TO_US(BASETIMESLICE) * 100.0f / value); - UpdateTimer(); - } +void SetClockSpeedPercent(FLOAT value) +{ + gfClockSpeedPercent = value; + UPDATETIMESLICE = (UINT32)((FLOAT)TIME_MS_TO_US(BASETIMESLICE) * 100.0f / value); + UpdateTimer(); +} - void UpdateTimer() +void UpdateTimer() +{ + // Set timer at lowest resolution. Could use middle of lowest/highest, we'll see how this performs first + if (!IsHiSpeedClockMode()) { - // Set timer at lowest resolution. Could use middle of lowest/highest, we'll see how this performs first - if (!IsHiSpeedClockMode()) + UINT uiTimeSlice = giFastForwardMode ? gtc.wPeriodMin : max(gtc.wPeriodMin, TIME_US_TO_MS(UPDATETIMESLICE)); + if (uiTimeSlice != guiTimeSlice) { - UINT uiTimeSlice = giFastForwardMode ? gtc.wPeriodMin : max(gtc.wPeriodMin, TIME_US_TO_MS(UPDATETIMESLICE)); - if (uiTimeSlice != guiTimeSlice) + guiTimeSlice = uiTimeSlice; + if (gTimerID != 0) timeKillEvent(gTimerID); + gTimerID = timeSetEvent( uiTimeSlice, uiTimeSlice, TimeProc, (DWORD)0, TIME_PERIODIC ); + if ( !gTimerID ) { - guiTimeSlice = uiTimeSlice; - if (gTimerID != 0) timeKillEvent(gTimerID); - gTimerID = timeSetEvent( uiTimeSlice, uiTimeSlice, TimeProc, (DWORD)0, TIME_PERIODIC ); - if ( !gTimerID ) - { - DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not create timer callback"); - } + DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not create timer callback"); } } } -#endif +} + diff --git a/Utils/Timer Control.h b/Utils/Timer Control.h index 64c7b63a..50636184 100644 --- a/Utils/Timer Control.h +++ b/Utils/Timer Control.h @@ -54,13 +54,6 @@ enum NUMTIMERS }; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER -#else - // Base resultion of callback timer - #define BASETIMESLICE 10 -#endif - - // TIMER INTERVALS extern INT32 giTimerIntervals[ NUMTIMERS ]; // TIMER COUNTERS @@ -78,9 +71,8 @@ void ShutdownJA2Clock( void ); #define GetJA2Clock() guiBaseJA2Clock -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - #define GetJA2NoPauseClock() guiBaseJA2NoPauseClock -#endif +#define GetJA2NoPauseClock() guiBaseJA2NoPauseClock + UINT32 GetPauseJA2Clock( ); @@ -92,89 +84,49 @@ void PauseTime( BOOLEAN fPaused ); void SetCustomizableTimerCallbackAndDelay( INT32 iDelay, CUSTOMIZABLE_TIMER_CALLBACK pCallback, BOOLEAN fReplace ); void CheckCustomizableTimer( void ); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - void SetFastForwardPeriod(DOUBLE value); - void SetFastForwardKey(INT32 key); - BOOLEAN IsFastForwardKeyPressed(); - void SetFastForwardMode(BOOLEAN enable); - BOOLEAN IsFastForwardMode(); - INT32 GetFastForwardLoopCount(); - void SetFastForwardLoopCount(INT32 value); +void SetFastForwardPeriod(DOUBLE value); +void SetFastForwardKey(INT32 key); +BOOLEAN IsFastForwardKeyPressed(); +void SetFastForwardMode(BOOLEAN enable); +BOOLEAN IsFastForwardMode(); +INT32 GetFastForwardLoopCount(); +void SetFastForwardLoopCount(INT32 value); - void SetNotifyFrequencyKey(INT32 value); - void SetClockSpeedPercent(FLOAT value); +void SetNotifyFrequencyKey(INT32 value); +void SetClockSpeedPercent(FLOAT value); - BOOLEAN IsTimerActive(); - BOOLEAN IsJA2TimerThread(); +BOOLEAN IsTimerActive(); +BOOLEAN IsJA2TimerThread(); - BOOLEAN IsHiSpeedClockMode(); - void SetHiSpeedClockMode(BOOLEAN enable); -#endif +BOOLEAN IsHiSpeedClockMode(); +void SetHiSpeedClockMode(BOOLEAN enable); //Don't modify this value extern UINT32 guiBaseJA2Clock; extern UINT32 guiBaseJA2NoPauseClock; extern CUSTOMIZABLE_TIMER_CALLBACK gpCustomizableTimerCallback; - #ifdef USE_HIGHSPEED_GAMELOOP_TIMER - typedef void (*TIMER_NOTIFY_CALLBACK) ( INT32 timer, PTR state ); - void AddTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ); - void RemoveTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ); - void ClearTimerNotifyCallbacks(); +typedef void (*TIMER_NOTIFY_CALLBACK) ( INT32 timer, PTR state ); +void AddTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ); +void RemoveTimerNotifyCallback( TIMER_NOTIFY_CALLBACK callback, PTR state ); +void ClearTimerNotifyCallbacks(); - BOOLEAN UpdateCounter(INT32 iTimer); - void ResetCounter(INT32 iTimer); - BOOLEAN CounterDone(INT32 iTimer); - void ResetTimerCounter(INT32 &timer, INT32 value); - BOOLEAN TimeCounterDone(INT32 timer); - void ZeroTimeCounter(INT32& timer); +BOOLEAN UpdateCounter(INT32 iTimer); +void ResetCounter(INT32 iTimer); +BOOLEAN CounterDone(INT32 iTimer); +void ResetTimerCounter(INT32 &timer, INT32 value); +BOOLEAN TimeCounterDone(INT32 timer); +void ZeroTimeCounter(INT32& timer); - #define UPDATECOUNTER( c ) UpdateCounter(c) - #define RESETCOUNTER( c ) ResetCounter(c) - #define COUNTERDONE( c ) CounterDone(c) - #define UPDATETIMECOUNTER( c ) UpdateTimeCounter(c) - #define RESETTIMECOUNTER( c, d ) ResetTimerCounter(c, d) - #define TIMECOUNTERDONE(c, d) TimeCounterDone(c) - #define SYNCTIMECOUNTER( ) - #define ZEROTIMECOUNTER(c) ZeroTimeCounter(c) -#else - - // MACROS - // CHeck if new counter < 0 | set to 0 | Decrement - - #ifdef CALLBACKTIMER - - #define UPDATECOUNTER( c ) ( ( giTimerCounters[ c ] - BASETIMESLICE ) < 0 ) ? ( giTimerCounters[ c ] = 0 ) : ( giTimerCounters[ c ] -= BASETIMESLICE ) - #define RESETCOUNTER( c ) ( giTimerCounters[ c ] = giTimerIntervals[ c ] ) - #define COUNTERDONE( c ) ( giTimerCounters[ c ] == 0 ) ? TRUE : FALSE - - #define UPDATETIMECOUNTER( c ) ( ( c - BASETIMESLICE ) < 0 ) ? ( c = 0 ) : ( c -= BASETIMESLICE ) - #define RESETTIMECOUNTER( c, d ) ( c = d ) - - #ifdef BOUNDS_CHECKER - #define TIMECOUNTERDONE( c, d ) ( TRUE ) - #else - #define TIMECOUNTERDONE( c, d ) ( c == 0 ) ? TRUE : FALSE - #endif - - #define SYNCTIMECOUNTER( ) - #define ZEROTIMECOUNTER( c ) ( c = 0 ) - - #else - - #define UPDATECOUNTER( c ) - #define RESETCOUNTER( c ) ( giTimerCounters[ c ] = giClockTimer ) - #define COUNTERDONE( c ) ( ( ( giClockTimer = GetJA2Clock() ) - giTimerCounters[ c ] ) > giTimerIntervals[ c ] ) ? TRUE : FALSE - - #define UPDATETIMECOUNTER( c ) - #define RESETTIMECOUNTER( c, d ) ( c = giClockTimer ) - #define TIMECOUNTERDONE( c, d ) ( giClockTimer - c > d ) ? TRUE : FALSE - #define SYNCTIMECOUNTER( ) ( giClockTimer = GetJA2Clock() ) - - #endif - -#endif +#define UPDATECOUNTER( c ) UpdateCounter(c) +#define RESETCOUNTER( c ) ResetCounter(c) +#define COUNTERDONE( c ) CounterDone(c) +#define UPDATETIMECOUNTER( c ) UpdateTimeCounter(c) +#define RESETTIMECOUNTER( c, d ) ResetTimerCounter(c, d) +#define TIMECOUNTERDONE(c, d) TimeCounterDone(c) +#define SYNCTIMECOUNTER( ) +#define ZEROTIMECOUNTER(c) ZeroTimeCounter(c) void SetTileAnimCounter( INT32 iTime ); #endif \ No newline at end of file diff --git a/Utils/Utils All.h b/Utils/Utils All.h index a5dc1640..fe283b03 100644 --- a/Utils/Utils All.h +++ b/Utils/Utils All.h @@ -103,10 +103,7 @@ #include "vobject.h" #include "overhead types.h" #include "tactical save.h" - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - #include "KeyMap.h" -#endif +#include "KeyMap.h" //#include //#include diff --git a/Utils/_ChineseText.cpp b/Utils/_ChineseText.cpp index 400ea9fe..69720af2 100644 --- a/Utils/_ChineseText.cpp +++ b/Utils/_ChineseText.cpp @@ -5111,10 +5111,7 @@ STR16 zOptionsToggleText[] = L"佣兵训练时保持沉默", // Madd: mercs don't say quotes while training L"佣兵修理时保持沉默", // Madd: mercs don't say quotes while repairing L"佣兵医疗时保持沉默", // Madd: mercs don't say quotes while doctoring - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"自动加速敌军回合", // Automatic fast forward through AI turns -#endif #ifdef ENABLE_ZOMBIES L"僵尸模式", @@ -5229,10 +5226,7 @@ STR16 zOptionsScreenHelpText[] = L"打开时,佣兵训练时不会随时汇报进程。", L"打开时,佣兵修理时不会随时汇报进程。", L"打开时,佣兵医疗时不会随时汇报进程。", - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"打开时,敌军回合将被大幅加速。", -#endif #ifdef ENABLE_ZOMBIES L"打开时,被击毙的敌人将有可能变成僵尸!杀出个黎明!", diff --git a/Utils/_DutchText.cpp b/Utils/_DutchText.cpp index 36fd32f0..3dcc7179 100644 --- a/Utils/_DutchText.cpp +++ b/Utils/_DutchText.cpp @@ -5112,10 +5112,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training // TODO.Translate L"Quiet Repairing", // Madd: mercs don't say quotes while repairing //TODO.Translate L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring //TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"Allow Zombies", // TODO.Translate #endif @@ -5229,10 +5226,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", //TODO.Translate L"When ON, mercs will not report progress during repairing.", // TODO.Translate L"When ON, mercs will not report progress during doctoring.", // TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"When ON, zombies will span. Be aware!", // allow zombies // TODO.Translate diff --git a/Utils/_EnglishText.cpp b/Utils/_EnglishText.cpp index 28c5fce1..33a5e748 100644 --- a/Utils/_EnglishText.cpp +++ b/Utils/_EnglishText.cpp @@ -5110,11 +5110,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training L"Quiet Repairing", // Madd: mercs don't say quotes while repairing L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns -#endif - #ifdef ENABLE_ZOMBIES L"Allow Zombies", // Flugente Zombies 1.0 #endif @@ -5228,10 +5224,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", L"When ON, mercs will not report progress during repairing.", L"When ON, mercs will not report progress during doctoring.", - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", -#endif #ifdef ENABLE_ZOMBIES L"When ON, zombies will spawn. Be aware!", // allow zombies diff --git a/Utils/_FrenchText.cpp b/Utils/_FrenchText.cpp index 3a66a44e..66b1b808 100644 --- a/Utils/_FrenchText.cpp +++ b/Utils/_FrenchText.cpp @@ -5102,10 +5102,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training // TODO.Translate L"Quiet Repairing", // Madd: mercs don't say quotes while repairing //TODO.Translate L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring //TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"Allow Zombies", // Flugente Zombies 1.0 #endif @@ -5219,11 +5216,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", L"When ON, mercs will not report progress during repairing.", // TODO.Translate L"When ON, mercs will not report progress during doctoring.", // TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", // TODO.Translate -#endif - #ifdef ENABLE_ZOMBIES L"When ON, zombies will span. Be aware!", // allow zombies // TODO.Translate #endif diff --git a/Utils/_GermanText.cpp b/Utils/_GermanText.cpp index 92278fd5..37924a1e 100644 --- a/Utils/_GermanText.cpp +++ b/Utils/_GermanText.cpp @@ -4958,10 +4958,7 @@ STR16 zOptionsToggleText[] = L"Stummes Trainieren", // Madd: mercs don't say quotes while training L"Stummes Reparieren", // Madd: mercs don't say quotes while repairing L"Stumme Behandlung", // Madd: mercs don't say quotes while doctoring - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Autom. schnelle Gegner-Züge", // Automatic fast forward through AI turns -#endif #ifdef ENABLE_ZOMBIES L"Zombies erlauben", // Flugente Zombies 1.0 #endif @@ -5075,10 +5072,7 @@ STR16 zOptionsScreenHelpText[] = L"Wenn diese Funktion aktiviert ist, werden die Söldner über ihren Fortschritt während des Trainings nicht mehr berichten.", L"Wenn diese Funktion aktiviert ist, werden die Söldner über ihren Reperaturfortschritt nicht mehr berichten.", L"Wenn diese Funktion aktiviert ist, werden die Söldner über den ärztlichen Fortschritt nicht mehr berichten.", - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Wenn diese Funktion aktiviert ist, werden gegnerische Züge schneller durchgeführt.", -#endif #ifdef ENABLE_ZOMBIES L"Wenn diese Funktion aktiviert ist, können Tote als Zombies wieder auferstehen. Seien Sie auf der Hut!", diff --git a/Utils/_ItalianText.cpp b/Utils/_ItalianText.cpp index 7b034a04..93f07c60 100644 --- a/Utils/_ItalianText.cpp +++ b/Utils/_ItalianText.cpp @@ -5096,10 +5096,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training // TODO.Translate L"Quiet Repairing", // Madd: mercs don't say quotes while repairing //TODO.Translate L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring //TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"Allow Zombies", // Flugente Zombies 1.0 #endif @@ -5213,10 +5210,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", L"When ON, mercs will not report progress during repairing.", // TODO.Translate L"When ON, mercs will not report progress during doctoring.", // TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"When ON, zombies will span. Be aware!", // allow zombies // TODO.Translate diff --git a/Utils/_PolishText.cpp b/Utils/_PolishText.cpp index 070e9c0a..a1bc2c68 100644 --- a/Utils/_PolishText.cpp +++ b/Utils/_PolishText.cpp @@ -5109,10 +5109,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training // TODO.Translate L"Quiet Repairing", // Madd: mercs don't say quotes while repairing //TODO.Translate L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring //TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"Allow Zombies", // Flugente Zombies 1.0 @@ -5227,10 +5224,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", L"When ON, mercs will not report progress during repairing.", // TODO.Translate L"When ON, mercs will not report progress during doctoring.", // TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"When ON, zombies will span. Be aware!", // allow zombies // TODO.Translate diff --git a/Utils/_RussianText.cpp b/Utils/_RussianText.cpp index 80f27d51..03c9d546 100644 --- a/Utils/_RussianText.cpp +++ b/Utils/_RussianText.cpp @@ -5078,10 +5078,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training // TODO.Translate L"Quiet Repairing", // Madd: mercs don't say quotes while repairing //TODO.Translate L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring //TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"Allow Zombies", // Flugente Zombies 1.0 @@ -5196,10 +5193,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", L"When ON, mercs will not report progress during repairing.", // TODO.Translate L"When ON, mercs will not report progress during doctoring.", // TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"When ON, zombies will span. Be aware!", // allow zombies // TODO.Translate diff --git a/Utils/_TaiwaneseText.cpp b/Utils/_TaiwaneseText.cpp index 18029932..4fb1dbc4 100644 --- a/Utils/_TaiwaneseText.cpp +++ b/Utils/_TaiwaneseText.cpp @@ -5113,10 +5113,7 @@ STR16 zOptionsToggleText[] = L"Quiet Training", // Madd: mercs don't say quotes while training // TODO.Translate L"Quiet Repairing", // Madd: mercs don't say quotes while repairing //TODO.Translate L"Quiet Doctoring", // Madd: mercs don't say quotes while doctoring //TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"Auto Fast Forward AI Turns", // Automatic fast forward through AI turns // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"Allow Zombies", // Flugente Zombies 1.0 @@ -5231,10 +5228,7 @@ STR16 zOptionsScreenHelpText[] = L"When ON, mercs will not report progress during training.", L"When ON, mercs will not report progress during repairing.", // TODO.Translate L"When ON, mercs will not report progress during doctoring.", // TODO.Translate - -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER L"When ON, AI turns will be much faster.", // TODO.Translate -#endif #ifdef ENABLE_ZOMBIES L"When ON, zombies will span. Be aware!", // allow zombies // TODO.Translate diff --git a/aniviewscreen.cpp b/aniviewscreen.cpp index 983956ce..55b19ef6 100644 --- a/aniviewscreen.cpp +++ b/aniviewscreen.cpp @@ -185,11 +185,7 @@ UINT32 AniEditScreenHandle(void) } -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER if (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - if (DequeueEvent(&InputEvent) == TRUE) -#endif { if ((InputEvent.usEvent == KEY_DOWN)&&(InputEvent.usParam == ESC)) { diff --git a/builddefines.h b/builddefines.h index a9655297..01f44a49 100644 --- a/builddefines.h +++ b/builddefines.h @@ -31,11 +31,6 @@ // It seems (and is confirmed), that executables compiled with this zombie option turned on, causes slowdown in tactical. //#define ENABLE_ZOMBIES // ----------------------------- - -// ----------------------------- -// WANNE: Enable this define, to build the gameloop with the highspeed timer. To use the highspeed timer, you also have to set the HIGHSPEED_TIMER = TRUE in ja2.ini -#define USE_HIGHSPEED_GAMELOOP_TIMER -// ----------------------------- // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Map Editor version - you should use the MapEditor configuration instead of messing with these defines (ChrisL) diff --git a/gameloop.cpp b/gameloop.cpp index 8adfbe4c..637f3650 100644 --- a/gameloop.cpp +++ b/gameloop.cpp @@ -148,12 +148,10 @@ BOOLEAN InitializeGame(void) InitButtonSystem(); InitCursors( ); -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER SetFastForwardPeriod(gGameExternalOptions.iFastForwardPeriod); SetFastForwardKey(gGameExternalOptions.iFastForwardKey); SetNotifyFrequencyKey(gGameExternalOptions.iNotifyFrequency); SetClockSpeedPercent(gGameExternalOptions.fClockSpeedPercent); -#endif // Init Fonts if ( !InitializeFonts( ) ) @@ -599,22 +597,20 @@ void NextLoopCheckForEnoughFreeHardDriveSpace() gubCheckForFreeSpaceOnHardDriveCount = 0; } +// Called by any game loop after all known events were handled +void HandleDefaultEvent(InputAtom *Event) +{ + const int MouseButtonEvents = LEFT_BUTTON_REPEAT|RIGHT_BUTTON_REPEAT| + LEFT_BUTTON_DOWN|LEFT_BUTTON_UP|MIDDLE_BUTTON_UP|X1_BUTTON_UP|X2_BUTTON_UP| + RIGHT_BUTTON_DOWN|RIGHT_BUTTON_UP|MIDDLE_BUTTON_DOWN|X1_BUTTON_DOWN|X2_BUTTON_DOWN| + MOUSE_WHEEL_UP|MOUSE_WHEEL_DOWN; -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER - // Called by any game loop after all known events were handled - void HandleDefaultEvent(InputAtom *Event) + if (Event != NULL && Event->usEvent & MouseButtonEvents) { - const int MouseButtonEvents = LEFT_BUTTON_REPEAT|RIGHT_BUTTON_REPEAT| - LEFT_BUTTON_DOWN|LEFT_BUTTON_UP|MIDDLE_BUTTON_UP|X1_BUTTON_UP|X2_BUTTON_UP| - RIGHT_BUTTON_DOWN|RIGHT_BUTTON_UP|MIDDLE_BUTTON_DOWN|X1_BUTTON_DOWN|X2_BUTTON_DOWN| - MOUSE_WHEEL_UP|MOUSE_WHEEL_DOWN; - - if (Event != NULL && Event->usEvent & MouseButtonEvents) - { - POINT MousePos; - GetCursorPos(&MousePos); - ScreenToClient(ghWindow, &MousePos); // In window coords! - MouseSystemHook(Event->usEvent, (UINT16)MousePos.x ,(UINT16)MousePos.y ,_LeftButtonDown, _RightButtonDown); - } + POINT MousePos; + GetCursorPos(&MousePos); + ScreenToClient(ghWindow, &MousePos); // In window coords! + MouseSystemHook(Event->usEvent, (UINT16)MousePos.x ,(UINT16)MousePos.y ,_LeftButtonDown, _RightButtonDown); } -#endif +} + diff --git a/jascreens.cpp b/jascreens.cpp index 084702ff..5639d63e 100644 --- a/jascreens.cpp +++ b/jascreens.cpp @@ -321,11 +321,7 @@ UINT32 ErrorScreenHandle(void) EndFrameBufferRender( ); // Check for esc -#ifdef USE_HIGHSPEED_GAMELOOP_TIMER while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT)) -#else - while (DequeueEvent(&InputEvent) == TRUE) -#endif { if( InputEvent.usEvent == KEY_DOWN ) {