Skip to content

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.

feat(gameengine): options defaults is the classic game, catalog rows too

Olcay Seygan2e1396ababc9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 50a98b502..57fa80f10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ found and fixed, EA's own, not port damage.**
- A first start now opens the game EA shipped: its own textures and ground, the hard stencil shadows, the flat 2003 light, no glow, bilinear filtering, the original sound mix, health bars only on what you select or point at. The HD art stays on your disk, unmounted. Every setting this build added to the picture, the sound and the controls starts off, and each one is a box in Options.
- One click brings the other game back. Options, Graphics, untick Classic Graphics: the High preset fills in every Reforged box on the page, you can move the quality slider from there, and Accept saves it for the next start. Tick it again and the same boxes go off.
+- Defaults in Options now means this game too. It used to leave every setting this build added where you had put it, so a Reforged page stayed Reforged after the click. Now it ticks Classic Graphics and puts every row back where a first start has it, the controls and the sound included. Your language, window mode and resolution stay, and unticking the box still gives you High.
- A detail preset now means EA's detail settings. Before this, a preset in your settings file switched on team glow, water foam and 4x multisampling behind any box you could see, and not on the very first start, so the first start and the second drew different pictures. Now a Reforged setting comes on from its own line, which the menu writes when you accept.
- Smooth Motion, the blending that made units glide on a fast monitor, had no switch at all. It is a box in Options, Display, off until ticked, and a 60 Hz screen shows no difference either way.
- Already playing? Nothing in your settings file gets rewritten and every line in it still wins. A setting you never touched has no line, so it takes the new default, which for most of you means Classic on your next start. Untick Classic Graphics once and you are back. The settings can differ between players in one match: none of them reaches the game's logic.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h b/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h
index 20030c406..77723af5d 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/OptionsCatalog.h
@@ -195,6 +195,9 @@ extern Bool graphicsQualityRowIsReforged( const GraphicsQualityRow &row );
* its column reaches a row through the menu, which saves what it shows. */
extern void loadOptionsFromPreferences( UserPreferences& pref );
+/** What this row holds with no line in Options.ini, the value a first run has. The menu's Defaults. */
+extern Int optionDefaultValue( const OptionDef& def );
+
/** One log line with every row's value as it stands, for a run's log to say which setup it drew. */
extern void logOptionCatalog( void );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index 17256d715..d7a77f4c7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -913,8 +913,26 @@ Bool graphicsQualityRowIsReforged( const GraphicsQualityRow &row )
}
//-----------------------------------------------------------------------------
+// What each row held before Options.ini reached it: GlobalData's constructor and GameData.ini, the
+// values a first run plays with. Taken once per GlobalData, because GameData blocks parse again later
+// and by then a row holds the player's value.
+static Int TheOptionDefaults[ sizeof( TheOptionCatalog ) / sizeof( TheOptionCatalog[ 0 ] ) ];
+static const GlobalData *TheOptionDefaultsOwner = NULL;
+
+Int optionDefaultValue( const OptionDef& def )
+{
+ return TheOptionDefaults[ &def - TheOptionCatalog ];
+}
+
void loadOptionsFromPreferences( UserPreferences& pref )
{
+ if( TheOptionDefaultsOwner != TheGlobalData )
+ {
+ TheOptionDefaultsOwner = TheGlobalData;
+ for( Int i = 0; i < TheOptionCatalogCount; ++i )
+ TheOptionDefaults[ i ] = TheOptionCatalog[ i ].get();
+ }
+
for( Int i = 0; i < TheOptionCatalogCount; ++i )
{
const OptionDef& def = TheOptionCatalog[ i ];
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index 88741c515..0d7c84128 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -233,6 +233,7 @@ extern void DoResolutionDialog();
// the options layout has been taken down and nothing is reading a window out of it any more.
//
static Bool pendingShellRebuild = FALSE;
+static Bool defaultsPressed = FALSE;
//
static Bool ignoreSelected = FALSE;
@@ -1211,7 +1212,15 @@ static void readCatalogWidgets( OptionPreferences &out )
const OptionDef& def = TheOptionCatalog[ i ];
GameWindow *widget = findOptionWidget( def );
if( widget == NULL )
+ {
+ // no control for Defaults to have moved, and the file is all that remembers the row
+ if( defaultsPressed && def.get() != optionDefaultValue( def ) )
+ {
+ def.set( optionDefaultValue( def ) );
+ out[ AsciiString( def.iniKey ) ] = formatOptionValue( def, optionDefaultValue( def ) );
+ }
continue;
+ }
// A hidden, unfilled combo must not overwrite the player's opt-in.
if (strcmp(def.iniKey, "CloudStyle") == 0 && !HazardCloud::Supported())
@@ -2479,6 +2488,44 @@ static void showClassicGraphicsChoice( void )
updateSliderReadouts();
}
+/** The row Defaults leaves: the words and how the window sits on this monitor are the player's, for
+ * the reason setDefaults leaves the resolution. The slider's row follows the preset. */
+static Bool defaultsKeepsRow( const OptionDef& def )
+{
+ static const char *const kept[] = { "TextLanguage", "WindowMode", "FullscreenScaling", "VSync", "GraphicsQuality" };
+ for( Int i = 0; i < ARRAY_SIZE( kept ); ++i )
+ if( strcmp( def.iniKey, kept[ i ] ) == 0 )
+ return TRUE;
+
+ return FALSE;
+}
+
+/** Defaults is the Classic game, as a first run has it: the box ticked and every catalog row on its
+ * default, the preset the machine was rated for. Accept saves what moved, so a Reforged player is one
+ * untick away from High again. A control hidden or greyed here (-d3d9, a match) keeps what it shows. */
+static void showClassicDefaults( void )
+{
+ if( comboBoxDetail->winGetEnabled() )
+ {
+ GadgetCheckBoxSetChecked( classicGraphicsCheckBox(), TRUE );
+ showDetailPreset( STATIC_GAME_LOD_ULTRA - TheGameLODManager->findStaticLODLevel() );
+ }
+
+ ignoreSelected = TRUE;
+ for( Int i = 0; i < TheOptionCatalogCount; ++i )
+ {
+ const OptionDef& def = TheOptionCatalog[ i ];
+ GameWindow *control = findOptionWidget( def );
+ if( control != NULL && !defaultsKeepsRow( def ) && !control->winIsHidden() && control->winGetEnabled() )
+ setGraphicsQualityControl( control, optionDefaultValue( def ) );
+ }
+ GadgetCheckBoxSetChecked( checkCloudShadows, optionDefaultValue( *findOptionDef( "UseCloudMap" ) ) != 0 );
+ ignoreSelected = FALSE;
+
+ defaultsPressed = TRUE;
+ updateSliderReadouts();
+}
+
/** The grey line under the detail box: what the picked preset turns on, and that picking one only
* fills in the boxes until Accept. GUI:DetailNote0..4 follow the box's own order, Ultra to Custom. */
static void updateDetailNote( void )
@@ -2520,6 +2567,7 @@ static void markDetailCustom( void )
void OptionsMenuInit( WindowLayout *layout, void *userData )
{
ignoreSelected = TRUE;
+ defaultsPressed = FALSE;
if (TheGameEngine->getQuitting())
return;
OptionsLayout = layout;
@@ -3336,7 +3384,7 @@ WindowMsgHandledType OptionsMenuSystem( GameWindow *window, UnsignedInt msg,
else if (controlID == buttonDefaults )
{
setDefaults();
- updateSliderReadouts();
+ showClassicDefaults();
}
else if( control == classicGraphicsCheckBox() )
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 701ace3f7..4190d5610 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -17334,6 +17334,27 @@ TEST(no_options_file_is_the_classic_game_with_every_added_row_off)
TheWritableGlobalData = saved;
}
+/* The menu's Defaults puts a row on what it held before the file reached it, whatever the file says. */
+TEST(an_options_row_remembers_its_value_from_before_the_file)
+{
+ GlobalData *saved = TheWritableGlobalData;
+ TheWritableGlobalData = NEW GlobalData;
+
+ UserPreferences pref;
+ pref[ "TeamGlow" ] = "yes";
+ pref[ "ClassicGraphics" ] = "no";
+ loadOptionsFromPreferences( pref );
+ loadOptionsFromPreferences( pref );
+
+ CHECK_EQ( findOptionDef( "TeamGlow" )->get(), 1 );
+ CHECK_EQ( optionDefaultValue( *findOptionDef( "TeamGlow" ) ), 0 );
+ CHECK_EQ( optionDefaultValue( *findOptionDef( "ClassicGraphics" ) ), 1 );
+ CHECK_EQ( optionDefaultValue( *findOptionDef( "LegacySound" ) ), 1 );
+
+ delete TheWritableGlobalData;
+ TheWritableGlobalData = saved;
+}
+
/* While Classic Graphics is ticked the slider moves EA's rows alone, and the menu reads this to say which. */
TEST(the_quality_table_knows_the_forks_rows_from_eas)
{