Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): a vertical sync box on the display page
Olcay Seygan66e0d6f929f8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1f6c4b68a..ef68efdb2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -3,7 +3,7 @@EA released the 2003 source for preservation. It did not compile, did not run, and nobody had touchedthe bugs inside it in twenty-two years. This build compiles, runs and plays.-**120 changes. ~580 engine source files ported. 14 automated test suites. Around 60 original bugs+**121 changes. ~580 engine source files ported. 14 automated test suites. Around 60 original bugsfound and fixed — EA's own, not port damage.**---@@ -11,6 +11,7 @@ found and fixed — EA's own, not port damage.**## The frame rate cap is gone- The picture now runs uncapped; the rules keep their own steady clock.+- Display options has a vertical sync box. Off, the picture still runs free. On, it waits for the monitor so the frame does not tear. The box takes effect when you Accept.- A slow moment costs you a dropped frame, not a slow game.- Every animation runs on a clock instead of counting frames.- Briefing and cutscene subtitles hold long enough to read again.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 9deca3fb0..5f9188734 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -448,6 +448,14 @@ TOOLTIP:BloomThreshold"How much of the screen is bright enough to glow at all. Only the brightest keeps it to muzzle flashes and lamps; most of the picture puts a haze over the whole battlefield."END+GUI:VSync+"Vertical Sync"+END++TOOLTIP:VSync+"Holds the picture to the monitor so it does not tear. Off, the picture runs as fast as the machine draws. Applied when you Accept."+END+GUI:MiddleMousePans"Middle Mouse Pans"ENDdiff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wndindex 3a0e59e12..cd494adab 100644--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd@@ -3327,6 +3327,53 @@ WINDOWIMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;END+ CHILD+ WINDOW+ WINDOWTYPE = CHECKBOX;+ SCREENRECT = UPPERLEFT: 400 328, BOTTOMRIGHT: 600 352, CREATIONRESOLUTION: 800 600;+ NAME = "OptionsMenu.wnd:CheckVSync";+ STATUS = ENABLED+IMAGE+BORDER;+ STYLE = CHECKBOX+MOUSETRACK;+ SYSTEMCALLBACK = "[None]";+ INPUTCALLBACK = "[None]";+ TOOLTIPCALLBACK = "[None]";+ DRAWCALLBACK = "[None]";+ FONT = NAME: "Arial", SIZE: 14, BOLD: 0;+ HEADERTEMPLATE = "MinorTitle";+ TOOLTIPTEXT = "TOOLTIP:VSync";+ TOOLTIPDELAY = -1;+ TEXT = "GUI:VSync";+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;+ ENDENDALLCHILDRENENDCHILDdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex b650e5eec..2f173d573 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -121,6 +121,7 @@ public:Int m_windowMode; ///< WindowModeType: fullscreen, borderless or windowed. m_windowed///< is derived from it and is what the device layer reads.Int m_msaaLevel; ///< multisampling, as an index into the levels the options menu offers+ Bool m_vsync; ///< wait for the monitor; off is the uncapped picture the frame-rate cap removal shippedBool m_fixedFunctionProbe; ///< -ffprobe: count the fixed-function combinations the frame actually usesBool m_combinerShaders; ///< -ffshader: draw with generated pixel shaders instead of the stage combinersBool m_direct3D11; ///< -dx11: render through the native Direct3D 11 backenddiff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex d9d42796d..22bf23e25 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -646,6 +646,7 @@ GlobalData::GlobalData()m_windowed = 0;m_windowMode = WINDOW_MODE_FULLSCREEN;m_msaaLevel = 0;+ m_vsync = FALSE;m_fixedFunctionProbe = FALSE;m_combinerShaders = FALSE;m_direct3D11 = FALSE;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex cb792c1a6..87339da08 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@ -53,6 +53,7 @@ OPTION_INT_ACCESSORS( m_textureFilterMode )OPTION_INT_ACCESSORS( m_anisotropyLevel )OPTION_INT_ACCESSORS( m_windowMode )OPTION_INT_ACCESSORS( m_msaaLevel )+OPTION_BOOL_ACCESSORS( m_vsync )OPTION_INT_ACCESSORS( m_healthBarMode )OPTION_INT_ACCESSORS( m_playerColorScheme )@@ -246,6 +247,13 @@ const OptionDef TheOptionCatalog[] =OPTION_ENUM, APPLY_DEVICE_RESET, 0, OPTION_MSAA_LEVEL_COUNT - 1,get_m_msaaLevel, set_m_msaaLevel },+ // Wait for the monitor. Off is what the uncapped picture shipped as: D3D9 honours the+ // presentation interval in a window, so leaving this on would pin a windowed game to the+ // refresh the way fullscreen used to be pinned. The device has to be reset; Accept does that.+ { "VSync", OPT_WND( "CheckVSync" ), "GUI:VSync",+ OPTION_BOOL, APPLY_DEVICE_RESET, 0, 1,+ get_m_vsync, set_m_vsync },+// Who wears a health bar: everyone, everyone hurt, only the selection, or nobody. Read every// frame by the drawable that is about to draw one, so changing it shows immediately.{ "HealthBars", OPT_WND( "ComboBoxHealthBars" ), "GUI:HealthBars",diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cppindex b053eddf5..f0d19d2e2 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp@@ -1119,6 +1119,7 @@ static void saveOptions( void )// which of the three the window is wearing right now, before the controls overwrite itconst Int oldWindowMode = TheGlobalData->m_windowMode;+ const Bool oldVSync = TheGlobalData->m_vsync;//-------------------------------------------------------------------------------------------------// The catalog's controls, read back into GlobalData before the pass below writes GlobalData out.@@ -1300,8 +1301,9 @@ static void saveOptions( void )//const Bool sizeChanged = ( oldDispSettings.xRes != xres || oldDispSettings.yRes != yres );const Bool modeChanged = ( oldWindowMode != TheGlobalData->m_windowMode );+ const Bool vsyncChanged = ( oldVSync != TheGlobalData->m_vsync );- if( sizeChanged || modeChanged )+ if( sizeChanged || modeChanged || vsyncChanged ){if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheGlobalData->m_windowed)){diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex 167370f49..7a74f8d74 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -769,6 +769,14 @@ Bool W3DDisplay::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt{extern Bool ApplicationIsBorderless;+ // WW3D2 cannot see GlobalData, so a vsync change has to be pushed in before the reset below+ // the way the sample count is pushed in before the device exists.+ if( TheGlobalData )+ {+ DX8Wrapper::Set_Requested_VSync( TheGlobalData->m_vsync != FALSE );+ Direct3D11_Set_VSync( TheGlobalData->m_vsync != FALSE );+ }+//// Which of the three the window is wearing, and which it is being asked for. The test cannot be// on the windowed flag alone: borderless and windowed are both windowed devices and differ only@@ -1024,6 +1032,8 @@ void W3DDisplay::init( void )// the sample count is handed to it here. msaaSamplesForLevel turns the stored index into 0, 2,// 4, 8 or 16; the device degrades an unsupported one on its own.DX8Wrapper::Set_Requested_MultiSample_Level( msaaSamplesForLevel( TheGlobalData->m_msaaLevel ) );+ DX8Wrapper::Set_Requested_VSync( TheGlobalData->m_vsync != FALSE );+ Direct3D11_Set_VSync( TheGlobalData->m_vsync != FALSE );// Same reason: WW3D2 cannot see GlobalData, so -ffprobe and -ffshader are pushed in from here.FixedFunctionProbe_Enable( TheGlobalData->m_fixedFunctionProbe != FALSE );@@ -1100,6 +1110,7 @@ void W3DDisplay::init( void )// multisampling is opt-in with "-msaa" / "-msaa N" and silently degrades to whatever the// device supports, so log what was actually grantedDEBUG_LOG(("W3DDisplay::init - multisampling: %ux\n", DX8Wrapper::Get_MultiSample_Level()));+ DEBUG_LOG(("W3DDisplay::init - vsync: %s\n", DX8Wrapper::Get_Requested_VSync() ? "on" : "off"));//Check if level was never set and default to setting most suitable for system.if (TheGameLODManager->getStaticLODLevel() == STATIC_GAME_LOD_UNKNOWN)diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cppindex 0508fb0a9..bd9db9df6 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp@@ -29,6 +29,7 @@static bool Requested = false;static bool PresentRequested = false;+static bool VSyncRequested = false;static bool Active = false;static DX11DeviceClass Device;static DX11BackendClass Backend;@@ -272,6 +273,11 @@ void Direct3D11_Present_Enable(bool enabled)PresentRequested = enabled;}+void Direct3D11_Set_VSync(bool enabled)+{+ VSyncRequested = enabled;+}+bool Direct3D11_Present_Is_Enabled(){return PresentRequested && Active;@@ -400,7 +406,7 @@ void Direct3D11_End_Scene(bool flip_frames){if (Active && flip_frames && PresentRequested) {Direct3D11_Finish_Frame();- Device.Present(0);+ Device.Present(VSyncRequested ? 1 : 0);}}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.hindex c16a014dc..f6a92e85e 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h@@ -111,6 +111,10 @@ void Direct3D11_Dump_Programs_To(const char * directory);void Direct3D11_Present_Enable(bool enabled);bool Direct3D11_Present_Is_Enabled();+// Wait for the monitor on the Direct3D 11 present. DXGI takes the interval per Present, so this+// does not need a device reset the way Direct3D 9's presentation interval does.+void Direct3D11_Set_VSync(bool enabled);+// -dx11post: the effects run over the finished frame, named in the order they run, as in "fxaa" or// "fxaa,sharpen". "off" or an empty chain draws straight into the swap chain the way the backend// always has. Returns false for a name it does not know and turns the chain off, so a misspeltdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cppindex eb0a3d8a1..2604fb43b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp@@ -344,6 +344,22 @@ void DX8Wrapper::Set_Requested_MultiSample_Level(unsigned samples)_RequestedMultiSampleLevel = samples;}+// Off is the default, matching the uncapped picture: present as soon as the frame is ready.+static bool _RequestedVSync = false;++void DX8Wrapper::Set_Requested_VSync(bool enabled)+{+ _RequestedVSync = enabled;+ _PresentParameters.PresentationInterval = enabled+ ? D3DPRESENT_INTERVAL_ONE+ : D3DPRESENT_INTERVAL_IMMEDIATE;+}++bool DX8Wrapper::Get_Requested_VSync(void)+{+ return _RequestedVSync;+}+// Non-multisampled depth/stencil for render-to-texture. A multisampled back buffer gets a// multisampled auto depth/stencil, and Direct3D requires the depth buffer to match the render// target - so the plain render target textures the screen filters and the water reflection draw@@ -1178,13 +1194,13 @@ bool DX8Wrapper::Set_Render_Device(int dev, int width, int height, int bits, int_PresentParameters.Flags=0; // We're not going to lock the backbuffer//- // D3DPRESENT_INTERVAL_DEFAULT is vsync, so fullscreen used to be pinned to the monitor's- // refresh however fast the machine could draw. The frame rate is deliberately uncapped now -- // everything that used to ride on the render rate keeps its own clock instead - so present- // as soon as the frame is ready. (Windowed presents are unaffected: this field only applies- // fullscreen, and the desktop compositor paces a windowed present regardless.)+ // D3D9 honours this in a window as well as fullscreen, unlike D3D8. Off (IMMEDIATE) is the+ // uncapped picture; on (ONE) waits for the monitor. The request is pushed in from the app+ // layer because WW3D2 cannot see GlobalData.//- _PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;+ _PresentParameters.PresentationInterval = _RequestedVSync+ ? D3DPRESENT_INTERVAL_ONE+ : D3DPRESENT_INTERVAL_IMMEDIATE;_PresentParameters.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;/*diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.hindex 43c22fcdf..29ab164b8 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.h@@ -535,6 +535,10 @@ public:// Samples per pixel to ask the next device for; 0, or 2..16. Set this before Set_Render_Device// or the device is created without multisampling.static void Set_Requested_MultiSample_Level (unsigned samples);+ // Wait for the monitor on the next device create or reset. WW3D2 cannot see GlobalData, so+ // the app layer pushes this in the same way it pushes the sample count.+ static void Set_Requested_VSync (bool enabled);+ static bool Get_Requested_VSync (void);// Samples per pixel actually in use, 0 if not multisampling.static unsigned Get_MultiSample_Level (void);// Depth/stencil to use with a non-multisampled render target; NULL if not multisampling.diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 2c3af6f43..d9b57e19b 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -9927,6 +9927,29 @@ TEST(msaa_levels_map_to_the_counts_a_device_offers)CHECK_EQ( msaaLevelForSamples( 64 ), OPTION_MSAA_LEVEL_COUNT - 1 );}+TEST(vsync_is_off_until_the_player_asks)+{+ const OptionDef *vsync = findOptionDef( "VSync" );+ CHECK( vsync != NULL );+ CHECK_EQ( (Int)vsync->kind, (Int)OPTION_BOOL );+ CHECK_EQ( (Int)vsync->apply, (Int)APPLY_DEVICE_RESET );+ CHECK( vsync->widgetName != NULL && strstr( vsync->widgetName, "CheckVSync" ) != NULL );++ GlobalData *saved = TheWritableGlobalData;+ GlobalData *scratch = NEW GlobalData;+ TheWritableGlobalData = scratch;++ CHECK_EQ( scratch->m_vsync, FALSE );++ vsync->set( 1 );+ CHECK_EQ( TheGlobalData->m_vsync, TRUE );+ vsync->set( 0 );+ CHECK_EQ( TheGlobalData->m_vsync, FALSE );++ TheWritableGlobalData = saved;+ delete scratch;+}+TEST(window_mode_derives_the_boolean_the_device_layer_reads){GlobalData *saved = TheWritableGlobalData;diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.pyindex c161e59f6..6d1ac3304 100644--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py@@ -95,6 +95,7 @@ CONTROLS = [("PageDisplay", COMBO, "ComboBoxBloom", None, 400, 240, 200, 24),("PageDisplay", LABEL, "LabelBloomThreshold", "GUI:BloomThreshold", 400, 272, 230, 24),("PageDisplay", COMBO, "ComboBoxBloomThreshold",None, 400, 296, 200, 24),+ ("PageDisplay", CHECK, "CheckVSync", "GUI:VSync", 400, 328, 200, 24),# Gameplay: a page that did not exist at all before, and is one setting. The eight build and# HUD conveniences that used to sit here are on for everybody now and left TheOptionCatalog