Skip to content

Commit 217f89f

Browse files
committed
Fixes monitors going to sleep during cutscenes on systems with low display turn off timers set.
1 parent 0a05454 commit 217f89f

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

Generals/Code/GameEngine/Include/GameLogic/GameLogic.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#include "GameNetwork/NetworkDefs.h"
4040
#include "Common/STLTypedefs.h"
4141
#include "GameLogic/Module/UpdateModule.h" // needed for DIRECT_UPDATEMODULE_ACCESS
42+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running - pr #281
43+
#ifdef _WIN32
44+
#include <WinBase.h>
45+
#endif
4246

4347
/*
4448
At one time, we distinguished between sleepy and nonsleepy
@@ -376,7 +380,20 @@ inline Real GameLogic::getHeight( void ) { return m_height; }
376380
inline UnsignedInt GameLogic::getFrame( void ) { return m_frame; }
377381

378382
inline Bool GameLogic::isInGame( void ) { return !(m_gameMode == GAME_NONE); }
379-
inline void GameLogic::setGameMode( Int mode ) { m_gameMode = mode; }
383+
384+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running - pr #281
385+
inline void GameLogic::setGameMode( Int mode )
386+
{
387+
m_gameMode = mode;
388+
#ifdef _WIN32
389+
if(!isInGame())
390+
SetThreadExecutionState(ES_CONTINUOUS);
391+
return;
392+
393+
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
394+
#endif
395+
}
396+
380397
inline Int GameLogic::getGameMode( void ) { return m_gameMode; }
381398
#if !defined(_PLAYTEST)
382399
inline Bool GameLogic::isInLanGame( void ) { return (m_gameMode == GAME_LAN); }

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

+13
Original file line numberDiff line numberDiff line change
@@ -3657,6 +3657,12 @@ void GameLogic::setGamePaused( Bool paused, Bool pauseMusic )
36573657

36583658
if(paused)
36593659
{
3660+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running - pr #281
3661+
#ifdef _WIN32
3662+
SetThreadExecutionState(ES_CONTINUOUS);
3663+
#endif
3664+
3665+
36603666
// remember the state of the mouse/input so we can return to the same state once we "unpause"
36613667
m_inputEnabledMemory = TheInGameUI->getInputEnabled();
36623668
m_mouseVisibleMemory = TheMouse->getVisibility();
@@ -3682,6 +3688,13 @@ void GameLogic::setGamePaused( Bool paused, Bool pauseMusic )
36823688
}
36833689
else
36843690
{
3691+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running - pr #281
3692+
#ifdef _WIN32
3693+
if(isInGame())
3694+
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
3695+
#endif
3696+
3697+
36853698
// set the mouse/input states to what they were before we paused.
36863699
TheMouse->setVisibility(m_mouseVisibleMemory);
36873700
if(m_inputEnabledMemory)

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
#include "Common/STLTypedefs.h"
4242
#include "GameLogic/Module/UpdateModule.h" // needed for DIRECT_UPDATEMODULE_ACCESS
4343

44+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running
45+
#ifdef _WIN32
46+
#include <WinBase.h>
47+
#endif
48+
4449
/*
4550
At one time, we distinguished between sleepy and nonsleepy
4651
update modules, and kept a separate list for each. however,
@@ -397,7 +402,21 @@ inline Real GameLogic::getHeight( void ) { return m_height; }
397402
inline UnsignedInt GameLogic::getFrame( void ) { return m_frame; }
398403

399404
inline Bool GameLogic::isInGame( void ) { return !(m_gameMode == GAME_NONE); }
400-
inline void GameLogic::setGameMode( Int mode ) { m_gameMode = mode; }
405+
406+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running
407+
inline void GameLogic::setGameMode( Int mode )
408+
{
409+
m_gameMode = mode;
410+
411+
#ifdef _WIN32
412+
if(!isInGame())
413+
SetThreadExecutionState(ES_CONTINUOUS);
414+
return;
415+
416+
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
417+
#endif
418+
}
419+
401420
inline Int GameLogic::getGameMode( void ) { return m_gameMode; }
402421
inline Bool GameLogic::isInLanGame( void ) { return (m_gameMode == GAME_LAN); }
403422
inline Bool GameLogic::isInSkirmishGame( void ) { return (m_gameMode == GAME_SKIRMISH); }

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

+13
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,12 @@ void GameLogic::setGamePaused( Bool paused, Bool pauseMusic )
42084208

42094209
if(paused)
42104210
{
4211+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running - pr #281
4212+
#ifdef _WIN32
4213+
SetThreadExecutionState(ES_CONTINUOUS);
4214+
#endif
4215+
4216+
42114217
// remember the state of the mouse/input so we can return to the same state once we "unpause"
42124218
m_inputEnabledMemory = TheInGameUI->getInputEnabled();
42134219
m_mouseVisibleMemory = TheMouse->getVisibility();
@@ -4239,6 +4245,13 @@ void GameLogic::setGamePaused( Bool paused, Bool pauseMusic )
42394245
}
42404246
else
42414247
{
4248+
// TheSuperHackers @bugfix @ShizCalev 04/03/2025 - Prevents monitors from going to sleep during long periods of inactivity while the game is running - pr #281
4249+
#ifdef _WIN32
4250+
if(isInGame())
4251+
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
4252+
#endif
4253+
4254+
42424255
// set the mouse/input states to what they were before we paused.
42434256
TheMouse->setVisibility(m_mouseVisibleMemory);
42444257
if(m_inputEnabledMemory)

0 commit comments

Comments
 (0)