Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/GameEngine/Include/Common/OptionPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class OptionPreferences : public UserPreferences
Real getGammaValue();
Int getTextureReduction();
void getResolution(Int *xres, Int *yres);
Bool getWindowed() const;
void setWindowed(Bool windowed);
Bool get3DShadowsEnabled();
Bool get2DShadowsEnabled();
Bool getCloudShadowsEnabled();
Expand Down
17 changes: 17 additions & 0 deletions Core/GameEngine/Source/Common/OptionPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,23 @@ void OptionPreferences::getResolution(Int *xres, Int *yres)
*yres=selectedYRes;
}

Bool OptionPreferences::getWindowed() const
{
OptionPreferences::const_iterator it = find("Windowed");
if (it == end())
return FALSE;

if (stricmp(it->second.str(), "yes") == 0) {
return TRUE;
}
return FALSE;
}

void OptionPreferences::setWindowed(Bool windowed)
{
(*this)["Windowed"] = (windowed ? "yes" : "no");
}

Real OptionPreferences::getMusicVolume()
{
OptionPreferences::const_iterator it = find("MusicVolume");
Expand Down
18 changes: 5 additions & 13 deletions Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,20 +1241,12 @@ const char * DX8Wrapper::Get_Render_Device_Name(int device_index)
bool DX8Wrapper::Set_Device_Resolution(int width,int height,int bits,int windowed, bool resize_window)
{
if (D3DDevice != nullptr) {
int w = (width == -1) ? ResolutionWidth : width;
int h = (height == -1) ? ResolutionHeight : height;
int b = (bits == -1) ? BitDepth : bits;
int win = (windowed == -1) ? IsWindowed : windowed;

if (width != -1) {
_PresentParameters.BackBufferWidth = ResolutionWidth = width;
}
if (height != -1) {
_PresentParameters.BackBufferHeight = ResolutionHeight = height;
}
if (resize_window)
{
Resize_And_Position_Window();
}
#pragma message("TODO: support changing windowed status and changing the bit depth")
WWDEBUG_SAY(("DX8Wrapper::Set_Device_Resolution is resetting the device."));
return Reset_Device();
return Set_Render_Device(CurRenderDevice, w, h, b, win, resize_window, true, true);
} else {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ constexpr const Int MAX_GLOBAL_LIGHTS = 3;
constexpr const Int SIMULATE_REPLAYS_SEQUENTIAL = -1;

//-------------------------------------------------------------------------------------------------
class CommandLineData
struct CommandLineData
{
friend class CommandLine;
friend class GlobalData;

CommandLineData()
: m_hasParsedCommandLineForStartup(false)
, m_hasParsedCommandLineForEngineInit(false)
, m_windowedCommandLineSpecified(false)
{}

Bool m_hasParsedCommandLineForStartup;
Bool m_hasParsedCommandLineForEngineInit;
Bool m_windowedCommandLineSpecified;
};

//-------------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Common/CommandLine.h"
#include "Common/CRCDebug.h"
#include "Common/LocalFileSystem.h"
#include "Common/OptionPreferences.h"
#include "Common/Recorder.h"
#include "Common/version.h"
#include "GameClient/ClientInstance.h"
Expand Down Expand Up @@ -118,6 +119,7 @@ Int parseNoLogOrCrash(char *args[], int)
Int parseWin(char *args[], int)
{
TheWritableGlobalData->m_windowed = true;
TheWritableGlobalData->m_commandLineData.m_windowedCommandLineSpecified = true;

return 1;
}
Expand Down Expand Up @@ -377,6 +379,7 @@ Int parseNoAudio(char *args[], int)
Int parseNoWin(char *args[], int)
{
TheWritableGlobalData->m_windowed = false;
TheWritableGlobalData->m_commandLineData.m_windowedCommandLineSpecified = true;

return 1;
}
Expand Down Expand Up @@ -1450,6 +1453,9 @@ void CommandLine::parseCommandLineForStartup()
return;
TheWritableGlobalData->m_commandLineData.m_hasParsedCommandLineForStartup = true;

OptionPreferences optionPref;
TheWritableGlobalData->m_windowed = optionPref.getWindowed();

parseCommandLine(paramsForStartup, ARRAY_SIZE(paramsForStartup));
}

Expand Down
11 changes: 11 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,8 @@ void GlobalData::reset()
//-------------------------------------------------------------------------------------------------
void GlobalData::parseGameDataDefinition( INI* ini )
{
Bool cmdWindowed = TheGlobalData->m_windowed;

if( TheWritableGlobalData && ini->getLoadType() != INI_LOAD_MULTIFILE)
{

Expand Down Expand Up @@ -1211,6 +1213,15 @@ void GlobalData::parseGameDataDefinition( INI* ini )
TheWritableGlobalData->m_playerInfoListFontSize = optionPref.getPlayerInfoListFontSize();
TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute();

if (TheGlobalData->m_commandLineData.m_windowedCommandLineSpecified)
{
TheWritableGlobalData->m_windowed = cmdWindowed;
}
else
{
TheWritableGlobalData->m_windowed = optionPref.getWindowed();
}

Int val=optionPref.getGammaValue();
//generate a value between 0.6 and 2.0.
if (val < 50)
Expand Down
54 changes: 54 additions & 0 deletions GeneralsMD/Code/Main/WinMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
#include "Common/GameMemory.h"
#include "Common/StackDump.h"
#include "Common/MessageStream.h"
#include "Common/OptionPreferences.h"
#include "Common/Registry.h"
#include "Common/Team.h"
#include "GameClient/ClientInstance.h"
#include "GameClient/Display.h"
#include "GameClient/InGameUI.h"
#include "GameClient/GameClient.h"
#include "GameLogic/GameLogic.h" ///< @todo for demo, remove
Expand Down Expand Up @@ -655,6 +657,58 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
break;
}
#endif
case WM_SYSKEYDOWN:
{
if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Key-repeat not filtered, causing rapid fullscreen toggling

WM_SYSKEYDOWN fires on auto-repeat when the user holds Enter while Alt is pressed. Bit 30 of lParam is 1 when the key was already held on the previous message; without checking it, every queued repeat will trigger a full D3D device reset, leaving the display in an undefined or flickering state.

Add !(lParam & (1 << 30)) to the guard to accept only the initial key-down transition:

Suggested change
if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter
if (wParam == VK_RETURN && (lParam & (1 << 29)) && !(lParam & (1 << 30))) // Alt + Enter (initial press only)
Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/Main/WinMain.cpp
Line: 662

Comment:
**Key-repeat not filtered, causing rapid fullscreen toggling**

`WM_SYSKEYDOWN` fires on auto-repeat when the user holds Enter while Alt is pressed. Bit 30 of `lParam` is 1 when the key was already held on the previous message; without checking it, every queued repeat will trigger a full D3D device reset, leaving the display in an undefined or flickering state.

Add `!(lParam & (1 << 30))` to the guard to accept only the initial key-down transition:

```suggestion
				if (wParam == VK_RETURN && (lParam & (1 << 29)) && !(lParam & (1 << 30))) // Alt + Enter (initial press only)
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the key needs to be configurable in ini - with a default value if not set

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, but what specific use case do you have in mind for this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F11 is a common alternative for fullscreen.

{
if (TheGameEngine && !TheGameEngine->getQuitting() && TheDisplay)
{
TheWritableGlobalData->m_windowed = !TheGlobalData->m_windowed;

DWORD windowStyle = WS_POPUP | WS_VISIBLE;
DWORD exStyle = 0;
Int resX = TheGlobalData->m_xResolution;
Int resY = TheGlobalData->m_yResolution;

if (TheGlobalData->m_windowed)
{
windowStyle |= WS_MINIMIZEBOX | WS_SYSMENU | WS_DLGFRAME | WS_CAPTION;
}
else
{
windowStyle |= WS_SYSMENU;
exStyle |= WS_EX_TOPMOST;
}

RECT windowRect = { 0, 0, resX, resY };
AdjustWindowRect(&windowRect, windowStyle, FALSE);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;

int x = 0, y = 0;
if (TheGlobalData->m_windowed)
{
x = max(0, (GetSystemMetrics(SM_CXSCREEN) - width) / 2);
y = max(0, (GetSystemMetrics(SM_CYSCREEN) - height) / 2);
}

TheDisplay->setDisplayMode(resX, resY, 32, TheGlobalData->m_windowed);

OptionPreferences optionPref;
optionPref.setWindowed(TheGlobalData->m_windowed);
optionPref.write();

// TheSuperHackers @info Apply styles and position after mode switch
SetWindowLong(hWnd, GWL_STYLE, windowStyle);
SetWindowLong(hWnd, GWL_EXSTYLE, exStyle);
SetWindowPos(hWnd, TheGlobalData->m_windowed ? HWND_NOTOPMOST : HWND_TOPMOST,
x, y, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
UpdateWindow(hWnd);
}
return 0;
}
break;
}
}

}
Expand Down
Loading