Skip to content

Commit 41fc725

Browse files
committed
feat(system): Prevent the system from sleeping or display from turning off while the game is busy in Windows OS
1 parent f789ed4 commit 41fc725

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

GeneralsMD/Code/GameEngine/Include/Common/OSDisplay.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ enum OSDisplayOtherFlags CPP_11(: UnsignedInt)
6363
// This function will return the button pressed to close the dialog.
6464
OSDisplayButtonType OSDisplayWarningBox(AsciiString p, AsciiString m, UnsignedInt buttonFlags, UnsignedInt otherFlags);
6565

66+
// TheSuperHackers @feature Tell the Operating System that the game is considered busy
67+
// and we would not like the display screen to shut off.
68+
void OSDisplaySetBusyState(Bool busy);
69+
6670
#endif /* __OSDISPLAY_H__ */

GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class GameLogic : public SubsystemInterface, public Snapshot
183183
Bool isInInternetGame( void );
184184
Bool isInShellGame( void );
185185
Bool isInMultiplayerGame( void );
186+
Bool isInInteractiveGame() const;
186187

187188
static Bool isInInteractiveGame(GameMode mode) { return mode != GAME_NONE && mode != GAME_SHELL; }
188189

@@ -420,6 +421,7 @@ inline GameMode GameLogic::getGameMode( void ) { return m_gameMode; }
420421
inline Bool GameLogic::isInLanGame( void ) { return (m_gameMode == GAME_LAN); }
421422
inline Bool GameLogic::isInSkirmishGame( void ) { return (m_gameMode == GAME_SKIRMISH); }
422423
inline Bool GameLogic::isInMultiplayerGame( void ) { return (m_gameMode == GAME_LAN) || (m_gameMode == GAME_INTERNET) ; }
424+
inline Bool GameLogic::isInInteractiveGame() const { return isInInteractiveGame(m_gameMode); }
423425
inline Bool GameLogic::isInReplayGame( void ) { return (m_gameMode == GAME_REPLAY); }
424426
inline Bool GameLogic::isInInternetGame( void ) { return (m_gameMode == GAME_INTERNET); }
425427
inline Bool GameLogic::isInShellGame( void ) { return (m_gameMode == GAME_SHELL); }

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "Common/LatchRestore.h"
4242
#include "Common/MapObject.h"
4343
#include "Common/MultiplayerSettings.h"
44+
#include "Common/OSDisplay.h"
4445
#include "Common/PerfTimer.h"
4546
#include "Common/Player.h"
4647
#include "Common/PlayerList.h"
@@ -1126,6 +1127,8 @@ void GameLogic::setGameMode( GameMode mode )
11261127
m_gameMode = mode;
11271128

11281129
TheMouse->onGameModeChanged(prev, mode);
1130+
1131+
OSDisplaySetBusyState(isInInteractiveGame() && !isGamePaused());
11291132
}
11301133

11311134
// ------------------------------------------------------------------------------------------------
@@ -4288,6 +4291,8 @@ void GameLogic::setGamePaused( Bool paused, Bool pauseMusic, Bool pauseInput )
42884291
pauseGameSound(paused);
42894292
pauseGameMusic(paused && pauseMusic);
42904293
pauseGameInput(paused && pauseInput);
4294+
4295+
OSDisplaySetBusyState(isInInteractiveGame() && !paused);
42914296
}
42924297

42934298
// ------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32OSDisplay.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,16 @@ OSDisplayButtonType OSDisplayWarningBox(AsciiString p, AsciiString m, UnsignedIn
123123

124124
return OSDBT_CANCEL;
125125
}
126+
127+
//-------------------------------------------------------------------------------------------------
128+
void OSDisplaySetBusyState(Bool busy)
129+
{
130+
if (busy)
131+
{
132+
::SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
133+
}
134+
else
135+
{
136+
::SetThreadExecutionState(ES_CONTINUOUS);
137+
}
138+
}

0 commit comments

Comments
 (0)