-
Notifications
You must be signed in to change notification settings - Fork 67
Fix monitors going to sleep during cutscenes on systems with low display turn off timeouts #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Nice detail :) We will hold off merging these code edits for now until build pipeline and other things are setup. |
Generals/Code/Main/WinMain.cpp
Outdated
// =================== Community Fix Start ================= | ||
/** Prevents monitors from going to sleep during long periods of inactivity while the game is running */ | ||
/** ie: during cutscenes, waiting for people in a multiplayer lobby, ect. */ | ||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too broad, it would be better if ES_DISPLAY_REQUIRED is only set when the game is actually in progress (i.e. not paused, not in the main menu)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree personally.
Most people I know AFK at the main menu or while the game is paused, and the game has a high tendency to freeze when the device go to sleep in my experience, and I'm sure no one want to get back and see that their game has froze.
So unless we managed to fix the core issue, I think it's better if the game doesn't allow the device to sleep at all if it's running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix that freeze then.
6cfb51b
to
69ee6a1
Compare
Set! Implemented exactly as Igoorx requested. I'll elaborate a little on the chain is since the codebase is still new!
Gamemode Defs
Lastly I realized I should've put this in |
cf58e7b
to
74156c5
Compare
…splay turn off timers set.
74156c5
to
217f89f
Compare
I think we should give users of OLED screens a warning about the existence of this feature and the option to disable it (with clarification of the consequences) because there may be cases where there may be burn-in on the screen. |
We can add it to the patchnotes, but I don't know if making much more noise about it is really needed as this is already an improvement on the existing situation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the windows API documentation:
Applications such as [...] games do not need to call SetThreadExecutionState.
I'm not convinced on violating a recommendation by Microsoft themselves on this.
EDIT: It might be reasonable to do this when playing videos, or entering a cutscene state:
Multimedia applications, such as video players and presentation applications, must use ES_DISPLAY_REQUIRED when they display video for long periods of time without user input.
Hello fellow spessman! (Noticed aurora in your profile haha.) That advice is there because games typically have constant user input which prevent the monitor from going to sleep in the first place, however that article hasn't been updated in four years and the usage of OLED screens for monitors (which folks typically utilize ultra-low display sleep timers with to minimize the risk of burn-in) has only really become prevalent in the last two years. As such, it's becoming increasingly more common for games to set There is no overhead associated with, nor any downsides to enabling the flag while the game is in an active (meaning unpaused) match/cutscene/loading screen, which is how this has already been coded. (The flag is not active while the game is paused, while in the main menu, ect.) On the other hand, as previously mentioned, not having the flag enabled can result in the game to crash if the user's screen turns off if, for example, they don't immediately move their mouse the moment a cutscene finishes after a loading screen, which can easily happen with levels like GLA3, which has a loading screen that feeds into an almost 3 minute long cutscene. As someone who uses an OLED screen, having the flag ONLY enabled during the cutscene & not during the match immediately afterward would make this PR essentially worthless. As for the risk of someone going AFK during an active match, this flag is already coded to immediately deactivate when the defeat screen is shown - which is pretty much going to occur anyway if someone randomly goes AFK for 5+ minutes with an opponent on the map without first investing heavily into base defenses. xP |
Will let others weigh in on actual formatting in code, argument for violating API documentation is sound.
Folks who use OLED screens tend to set their display sleep timers pretty low to prevent burn-in.

On top of not only being inconvenient during cutscenes, this can also cause the game to crash outright since lots of stuff gets shifted by Windows when a display turns off.
This fix simply sets the main process to flag itself as
ES_DISPLAY_REQUIRED
(and the necessary prerequisite flags), meaning the game now tells powercfg that the screen must remain on at all times while it's running.