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.

fix(gameclient): hide the shell after a mid-match resolution change

Olcay Seygand8fe270e0e5c
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 3038cba89..d4f19d1d3 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -400,6 +400,7 @@ public:
Int m_resDrillFrame; ///< -resdrill <frame> [w] [h]: change the resolution at that logic frame, from inside a running match (0 = off)
Int m_resDrillX; ///< the width -resdrill asks for (0 = the next mode the device offers)
Int m_resDrillY; ///< the height -resdrill asks for
+ Bool m_resDrillKeep; ///< -resdrillkeep: answer the confirmation with Ok and stay on the new mode
AsciiString m_netGameHosts; ///< -netgame <ip>[,<ip>...]: the slot list of a LAN game started from the command line (empty = off)
Int m_netGameLocalSlot; ///< -netslot <n>: which of those addresses this copy of the game is
AsciiString m_lanPlayerName; ///< -lanname <name>: the name this copy takes in the LAN lobby (empty = the one in the preferences)
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowManager.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowManager.h
index 7965895b8..6670c6910 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowManager.h
@@ -256,6 +256,10 @@ public:
virtual GameWindow *winGetGrabWindow( void ); ///< who is currently 'held' by mouse
virtual void winSetLoneWindow( GameWindow *window ); ///< set the open window
+ ///< who owns the pointer and the keyboard, since a dead one of these eats every click
+ void logInputOwners( const char *tag );
+ void logInputOwnersOnChange( void ); ///< the same line, but only when one of them moves
+
virtual Bool isEnabled( GameWindow *win ); ///< is window or parents enabled
virtual Bool isHidden( GameWindow *win ); ///< is parent or parents hidden
virtual void addWindowToParent( GameWindow *window, GameWindow *parent );
@@ -335,6 +339,7 @@ public:
protected:
void processDestroyList( void ); ///< process windows waiting to be killed
+ const char *inputOwnerName( GameWindow *window ); ///< that window's name, or why it is not one
Int drawWindow( GameWindow *window ); ///< draw this window
@@ -351,6 +356,11 @@ protected:
ModalWindow *m_modalHead; // top of windows in the modal stack
GameWindow *m_grabWindow; // window that grabbed the last down event
GameWindow *m_loneWindow; // Set if we just opened a Lone Window
+ // the four that can stick, as they stood on the last line logInputOwnersOnChange wrote
+ GameWindow *m_loggedCaptor;
+ GameWindow *m_loggedLone;
+ GameWindow *m_loggedFocus;
+ GameWindow *m_loggedModal;
GameWindowList m_tabList; // we have to register a tab list to make a tab list.
const Image *m_cursorBitmap;
UnsignedInt m_captureFlags;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 1182fe3e6..d2ace85c6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -1009,8 +1009,6 @@ protected:
void drawPeaceTimer( void ); ///< the lobby's peace time, counting down in the top right corner
void drawHudOverlay( void ); ///< the small elapsed-time / fps plate (ShowHudOverlay)
- void drawIncomeRate( void ); ///< income per minute, drawn beside the money window
- void updateIncomeEstimate( Player *player ); ///< income per minute, shown beside the money
void drawProductionStrip( void ); ///< the production queue rows above the control bar
///< one run of cells - a column while playing, a player's row while watching - with its left
///< edge at 'left' and its first cell's top edge at 'bottomY'
@@ -1025,10 +1023,8 @@ protected:
Bool m_placementRangeRingUp; ///< we put a radius cursor up for a pending structure, so we owe a clear
Real m_placementRingRadius; ///< the radius that ring was built at, so it is not rebuilt every frame
- DisplayString * m_hudDisplayString; ///< the ShowHudOverlay line (fps / clock / income)
+ DisplayString * m_hudDisplayString; ///< the ShowHudOverlay line (fps / clock)
DisplayString * m_peaceTimeDisplayString; ///< the peace time countdown in the corner
- DisplayString * m_incomeDisplayString; ///< the "(+N/min)" drawn beside the money
- Int m_lastIncomeDisplayed; ///< so that string is only rebuilt when the rate changes
Int m_lastMoneyDisplayed; ///< so the money gadget is only written when the amount changes
UnsignedInt m_hudDrawCount; ///< rendered frames counted by drawHudOverlay itself
UnsignedInt m_hudLastSampleFrame; ///< m_hudDrawCount the fps sample was last refreshed on
@@ -1045,14 +1041,6 @@ protected:
// have passed since the freeze began and applies only the ones not applied yet.
UnsignedInt m_subtitleFreezeStartMs; ///< wall clock the current freeze started on, 0 = not frozen
UnsignedInt m_subtitleFreezeSteps; ///< frames already handed to the subtitle during it
- // Income is sampled from the player's cumulative earnings every INCOME_SAMPLE_SECONDS and
- // averaged over the whole ring, so a lumpy supply run reads as a rate instead of a spike.
- enum { INCOME_SAMPLES = 16, INCOME_SAMPLE_SECONDS = 2 }; ///< 16 buckets of 2s = a 30s window
- Int m_incomeSamples[ INCOME_SAMPLES ]; ///< cumulative money earned, one per bucket
- UnsignedInt m_incomeSampleCount; ///< buckets taken so far, the ring index is this mod INCOME_SAMPLES
- Int m_incomeSamplePlayer; ///< whose earnings those are, so an observer switching players restarts
- UnsignedInt m_hudLastMoneyFrame; ///< logic frame of the last sample
- Int m_hudIncomePerMin; ///< most recent income estimate, cash per minute, -1 until the window is warm
//
// The global production strip: everything the local player has coming - queued in any factory,
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 39721a084..1819c664f 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -1585,6 +1585,21 @@ Int parseResDrill(char *args[], int num)
return 1;
}
+/* -resdrillkeep answers the "keep this resolution?" box with Ok instead of Cancel.
+
+ The two answers are different code: Cancel is DeclineResolution, which puts the old mode back
+ and rebuilds the shell and the command bar a second time, while Ok keeps the new mode and
+ rebuilds nothing. A player who wanted the resolution he asked for presses Ok, so that branch
+ needs a drill of its own. */
+Int parseResDrillKeep(char *args[], int)
+{
+ if (TheWritableGlobalData)
+ {
+ TheWritableGlobalData->m_resDrillKeep = TRUE;
+ }
+ return 1;
+}
+
/* -teams <n> splits an -autoskirmish lobby into n allied teams instead of a free-for-all.
Free-for-all and 4v4 are not the same load and not the same game. Eight players each fighting
@@ -1984,6 +1999,7 @@ static CommandLineParam params[] =
{ "-groupdrill", parseGroupDrill },
{ "-uidrill", parseUIDrill },
{ "-resdrill", parseResDrill },
+ { "-resdrillkeep", parseResDrillKeep },
{ "-replay", parseReplay },
{ "-loadsave", parseLoadSave },
{ "-netgame", parseNetGame },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 4b3d8740e..45a432e09 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1502,7 +1502,7 @@ static void updateResDrill( void )
if( dismissed || timeGetTime() - appliedTimeMs < RES_DRILL_DISMISS_DELAY_MS )
return;
dismissed = TRUE;
- ResolutionDrillDismiss( FALSE );
+ ResolutionDrillDismiss( TheGlobalData->m_resDrillKeep );
return;
}
applied = TRUE;
@@ -1538,6 +1538,45 @@ static void updateResDrill( void )
ResolutionDrillApply( TheGlobalData->m_resDrillX, TheGlobalData->m_resDrillY );
}
+/** -----------------------------------------------------------------------------------------------
+ * The two switches that decide whether the game answers the player at all.
+ *
+ * A paused match runs no logic: production stops, units stand still, the camera keys do nothing.
+ * A disabled UI is the other half - WindowXlat hands every mouse and key message to the window
+ * system first and only then marks it used, so the menus go on answering clicks while nothing in
+ * the game moves. Together they are the state a player describes as "the interface works but the
+ * game does not", and neither of them shows up in any other line of the log.
+ *
+ * Written down whenever either one moves, because the player who meets this is not the person who
+ * can reproduce it on demand with a switch turned on.
+ */
+static void updateInputWatch( void )
+{
+ static Int lastInputEnabled = -1;
+ static Int lastPaused = -1;
+
+ if( TheInGameUI == NULL || TheGameLogic == NULL )
+ return;
+
+ static Int lastShellActive = -1;
+
+ const Int inputEnabled = TheInGameUI->getInputEnabled() ? 1 : 0;
+ const Int paused = TheGameLogic->isGamePaused() ? 1 : 0;
+ const Int shellActive = ( TheShell != NULL && TheShell->isShellActive() ) ? 1 : 0;
+
+ if( inputEnabled == lastInputEnabled && paused == lastPaused && shellActive == lastShellActive )
+ return;
+
+ lastInputEnabled = inputEnabled;
+ lastPaused = paused;
+ lastShellActive = shellActive;
+
+ DEBUG_LOG(("INPUTWATCH: frame %d, input enabled %d, game paused %d, shell active %d, quit menu %d, in game %d\n",
+ TheGameLogic->getFrame(), inputEnabled, paused, shellActive,
+ TheInGameUI->isQuitMenuVisible() ? 1 : 0,
+ ( TheGameLogic->isInGame() && !TheGameLogic->isInShellGame() ) ? 1 : 0));
+}
+
static void updateAutoCamera( void )
{
if( TheGlobalData->m_autoCameraSeconds <= 0 || TheTacticalView == NULL || TheTerrainLogic == NULL )
@@ -2003,6 +2042,7 @@ void GameEngine::update( void )
updateAutoCamera();
updateUIDrill();
updateResDrill();
+ updateInputWatch();
#ifdef DEBUG_LOGGING
fpsFrames++;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 6cbb0976a..7b1b1875e 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -707,6 +707,7 @@ GlobalData::GlobalData()
m_resDrillFrame = 0; // the resolution stays where it started unless -resdrill changes it mid-match
m_resDrillX = 0;
m_resDrillY = 0;
+ m_resDrillKeep = FALSE;
m_netGameHosts.clear(); // no network game from the command line
m_netGameLocalSlot = 0;
m_lanPlayerName.clear(); // the lobby name comes out of the preferences unless -lanname says otherwise
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp
index f992ac541..acd7ceedf 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp
@@ -784,7 +784,13 @@ void DeclineResolution()
// menu over a running game.
//
if( TheGameLogic->isInGame() && !TheGameLogic->isInShellGame() )
+ {
+ // A new Shell is born active, and an active shell makes WindowXlat mark every mouse and
+ // key message used before a game translator sees it. See applyPendingShellRebuild.
+ TheShell->hideShell();
+
ShowControlBar( TRUE );
+ }
else
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
}
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 fb16e61b4..b679d1dfd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -1570,7 +1570,19 @@ static void applyPendingShellRebuild( void )
// hidden, so it is put back.
//
if( TheGameLogic->isInGame() && !TheGameLogic->isInShellGame() )
+ {
+ //
+ // A Shell is born active - the constructor says so, because a shell that is being built is
+ // normally a shell somebody is about to look at. In a match nobody is, and an active shell
+ // is not a cosmetic detail: WindowXlat hands every mouse and key message to the window
+ // system and then marks it used whenever the shell is active, so nothing reaches the
+ // command translator, the selection translator or the camera. The menus went on answering
+ // clicks while production, unit orders, the camera keys and the whole keyboard did nothing.
+ //
+ TheShell->hideShell();
+
ShowControlBar( TRUE );
+ }
else
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
}
@@ -1717,6 +1729,18 @@ void ResolutionDrillApply( Int xres, Int yres )
DEBUG_LOG(("RESDRILL: the options menu came up without its resolution dropdown\n"));
return;
}
+ //
+ // Drop the list open first, by pressing the dropdown's own button. Setting the selection
+ // straight skips the one thing a player cannot skip: opening a combo box makes it the window
+ // manager's lone window, and the lone window is the one pointer processDestroyList does not
+ // clear when the window it names is destroyed.
+ //
+ GameWindow *dropDownButton = GadgetComboBoxGetDropDownButton( comboBoxResolution );
+ if( dropDownButton != NULL )
+ TheWindowManager->winSendSystemMsg( comboBoxResolution, GBM_SELECTED,
+ (WindowMsgData)dropDownButton,
+ dropDownButton->winGetWindowId() );
+
GadgetComboBoxSetSelectedPos( comboBoxResolution, modeIndex );
GameWindow *parent = TheWindowManager->winGetWindowFromId(
@@ -1733,6 +1757,7 @@ void ResolutionDrillApply( Int xres, Int yres )
QuitMenuLogPlacement( "before the mode change" );
resDrillLogMoney( "before the mode change" );
resDrillLogWindowRoots( "before the mode change" );
+ TheWindowManager->logInputOwners( "before the mode change" );
DEBUG_LOG(("RESDRILL: pressing Accept\n"));
TheWindowManager->winSendSystemMsg( parent, GBM_SELECTED, (WindowMsgData)accept, acceptID );
@@ -1763,6 +1788,7 @@ void ResolutionDrillDismiss( Bool accept )
resDrillLogMoney( "after the mode change" );
resDrillLogWindowRoots( "after the mode change" );
+ TheWindowManager->logInputOwners( "after the mode change" );
NameKeyType buttonID = TheNameKeyGenerator->nameToKey(
AsciiString( accept ? "MessageBox.wnd:ButtonOk" : "MessageBox.wnd:ButtonCancel" ) );
@@ -1780,6 +1806,7 @@ void ResolutionDrillDismiss( Bool accept )
TheDisplay->getWidth(), TheDisplay->getHeight()));
QuitMenuLogPlacement( "after the dialog" );
+ TheWindowManager->logInputOwners( "after the dialog" );
//
// Press Return the way a player does, then say whether the game came back. Input enabled 0 or
@@ -1792,6 +1819,7 @@ void ResolutionDrillDismiss( Bool accept )
TheInGameUI->getInputEnabled() ? 1 : 0, TheGameLogic->isGamePaused() ? 1 : 0));
resDrillLogWindowRoots( "after the quit menu closed" );
+ TheWindowManager->logInputOwners( "after the quit menu closed" );
}
static void showAdvancedOptions()
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
index 5c563051a..5b0cd3727 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
@@ -133,6 +133,16 @@ void destroyQuitMenu()
}
noSaveLoadQuitMenuLayout = NULL;
quitMenuLayout = NULL;
+
+ //
+ // The save/load layout is the shell's, not this file's - it is handed over by
+ // getSaveLoadMenuLayout and destroyed with the shell. Holding the pointer past that is holding
+ // a freed layout, and ToggleQuitMenu reads isHidden() off it before it does anything else: a
+ // read that says "showing" sends a Back press into freed memory and returns without opening the
+ // menu, leaving a paused game with nothing on screen to unpause it.
+ //
+ saveLoadMenuLayout = NULL;
+
isVisible = FALSE;
}
@@ -150,10 +160,26 @@ void RecreateQuitMenu( void )
destroyQuitMenu();
+ if( !wasVisible )
+ return;
+
// destroyQuitMenu clears isVisible, so this takes ToggleQuitMenu's open branch. The game is
// already paused and setGamePaused ignores a pause it is already holding.
- if( wasVisible )
- ToggleQuitMenu();
+ ToggleQuitMenu();
+
+ //
+ // ToggleQuitMenu has half a dozen ways to decline - a cinematic playing, the disconnect screen
+ // up, an options or save/load layout it thinks is still on screen - and every one of them
+ // returns without opening anything. The menu is what holds the pause, so a menu that does not
+ // come back has to hand the pause back instead; the alternative is a match that runs no logic
+ // with nothing on screen to press. Unpausing a game that is not paused is a no-op.
+ //
+ if( !isVisible )
+ {
+ DEBUG_LOG(("QUITMENU: it would not reopen after the resolution change, releasing the pause\n"));
+ TheGameLogic->setGamePaused( FALSE );
+ TheInGameUI->setQuitMenuVisible( FALSE );
+ }
}
//
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
index 5fd47bfb0..89634293e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp
@@ -194,6 +194,11 @@ GameWindowManager::GameWindowManager( void )
m_grabWindow = NULL; // window that grabbed the last down event
m_loneWindow = NULL; // Set if we just opened a combo box
+ m_loggedCaptor = NULL;
+ m_loggedLone = NULL;
+ m_loggedFocus = NULL;
+ m_loggedModal = NULL;
+
m_cursorBitmap = NULL;
m_captureFlags = 0;
@@ -244,6 +249,10 @@ void GameWindowManager::update( void )
// Process windows waiting to be destroyed
processDestroyList();
+
+ // after the destroy pass, so a pointer left holding a freed window reads as DESTROYED here
+ logInputOwnersOnChange();
+
if(TheTransitionHandler)
TheTransitionHandler->update();
} // end update
@@ -1673,6 +1682,61 @@ void GameWindowManager::winSetGrabWindow( GameWindow *window )
//-------------------------------------------------------------------------------------------------
/** Explicitly set the grab window */
+//-------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+/** Five pointers decide where a click goes before the window list is ever walked, and any one of
+ * them left holding a window that has been destroyed swallows every click and every key on the
+ * way to it. processDestroyList clears four of them; the lone window, which a combo box sets
+ * when its list drops down, is not one of the four. A "DESTROYED" here is the interface gone
+ * deaf. */
+//-------------------------------------------------------------------------------------------------
+const char *GameWindowManager::inputOwnerName( GameWindow *window )
+{
+ if( window == NULL )
+ return "none";
+ if( BitTest( window->m_status, WIN_STATUS_DESTROYED ) )
+ return "DESTROYED";
+
+ return window->winGetInstanceData()->m_decoratedNameString.str();
+}
+
+void GameWindowManager::logInputOwners( const char *tag )
+{
+ DEBUG_LOG(("WINOWNERS: %s, captor %s, grab %s, lone %s, focus %s, modal %s\n",
+ tag,
+ inputOwnerName( m_mouseCaptor ),
+ inputOwnerName( m_grabWindow ),
+ inputOwnerName( m_loneWindow ),
+ inputOwnerName( m_keyboardFocus ),
+ inputOwnerName( m_modalHead ? m_modalHead->window : NULL )));
+}
+
+//
+// Called every pass. A player who says the game stopped answering him has one of these holding a
+// window he cannot see or cannot reach, and the line that says which one has to already be in the
+// log by the time he says it - there is no asking him to reproduce it with a switch on. Only a
+// change writes a line, so a quiet game writes none.
+//
+// The grab window is printed but not compared: it is set on every button press and cleared on the
+// release, so testing it would put two lines in the log for every click anyone makes. It also
+// cannot be what is holding a game deaf, for the same reason - the release clears it.
+//
+void GameWindowManager::logInputOwnersOnChange( void )
+{
+ GameWindow *modalWindow = m_modalHead ? m_modalHead->window : NULL;
+
+ if( m_loggedCaptor == m_mouseCaptor && m_loggedLone == m_loneWindow
+ && m_loggedFocus == m_keyboardFocus && m_loggedModal == modalWindow )
+ return;
+
+ m_loggedCaptor = m_mouseCaptor;
+ m_loggedLone = m_loneWindow;
+ m_loggedFocus = m_keyboardFocus;
+ m_loggedModal = modalWindow;
+
+ logInputOwners( "changed" );
+}
+
//-------------------------------------------------------------------------------------------------
void GameWindowManager::winSetLoneWindow( GameWindow *window )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 306e1ed8f..e9aebfdf5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1127,8 +1127,6 @@ InGameUI::InGameUI()
forgetPendingPlacements();
m_hudDisplayString = NULL;
m_peaceTimeDisplayString = NULL;
- m_incomeDisplayString = NULL;
- m_lastIncomeDisplayed = -1;
m_lastMoneyDisplayed = -1;
m_hudDrawCount = 0;
m_hudLastSampleFrame = 0;
@@ -1143,12 +1141,6 @@ InGameUI::InGameUI()
m_hudRealClockBaseMs = 0;
m_hudLastDrawMs = 0;
m_hudOverlayBottom = 0;
- for( Int incomeBucket = 0; incomeBucket < INCOME_SAMPLES; incomeBucket++ )
- m_incomeSamples[ incomeBucket ] = 0;
- m_incomeSampleCount = 0;
- m_incomeSamplePlayer = -1;
- m_hudLastMoneyFrame = 0;
- m_hudIncomePerMin = -1;
for( Int stripRow = 0; stripRow < PRODUCTION_STRIP_ROWS; stripRow++ )
{
m_productionStripCount[ stripRow ] = 0;
@@ -2214,10 +2206,6 @@ void InGameUI::update( void )
{
Int currentMoney = moneyPlayer->getMoney()->countMoney();
- // income per minute is drawn beside this window by drawIncomeRate(), not put inside it -
- // the money gadget wraps at its own width and a second line looked broken
- updateIncomeEstimate( moneyPlayer );
-
if( m_lastMoneyDisplayed != currentMoney )
{
UnicodeString buffer;
@@ -4251,7 +4239,6 @@ void InGameUI::disregardDrawable( Drawable *draw )
void InGameUI::postDraw( void )
{
// drawHudOverlay is NOT called here - it goes on top of everything, see W3DInGameUI::draw
- drawIncomeRate();
drawProductionStrip();
@@ -5859,116 +5846,10 @@ void InGameUI::updateFloatingText( void )
/** Itterates through and draws each floating text */
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-/** A one-line heads-up overlay: render rate, elapsed game time and the local player's income.
+/** A one-line heads-up overlay: render rate and elapsed game time.
* Off unless ShowHudOverlay is set in Options.ini. Retail only ever showed the frame rate, and
* only behind -displayDebug together with a screenful of engine internals. */
//-------------------------------------------------------------------------------------------------
-//-------------------------------------------------------------------------------------------------
-/** The ring math behind the income estimate: cash per minute from the oldest bucket we still hold
- * to the newest. A free function, not a member, so test_gameengine can drive it without a
- * Player. Returns -1 while there is only one bucket, i.e. no span to average over yet. */
-//-------------------------------------------------------------------------------------------------
-Int computeIncomePerMinute( const Int *samples, UnsignedInt ringSize, UnsignedInt count, Int sampleSeconds )
-{
- if( samples == NULL || ringSize == 0 || count < 2 || sampleSeconds <= 0 )
- return -1;
-
- const UnsignedInt newest = count - 1;
- const UnsignedInt oldest = (newest >= ringSize) ? newest - (ringSize - 1) : 0;
- const Int span = (Int)(newest - oldest); // buckets spanned, at least one
-
- return (samples[ newest % ringSize ] - samples[ oldest % ringSize ]) * 60 / (span * sampleSeconds);
-}
-
-//-------------------------------------------------------------------------------------------------
-/** Income per minute for the local player, averaged over the last 30 seconds of play.
- * Sampled off the score keeper's cumulative earnings, not off the balance: the balance falls
- * every time you build, and a balance delta therefore reads spending as zero income - which is
- * what you have while doing anything at all. What the score keeper counts is money that came
- * in (supplies, crates, oil, hackers, bounties); production refunds and script grants do not
- * count as income, which is the answer you want when comparing a rate against a build. */
-//-------------------------------------------------------------------------------------------------
-void InGameUI::updateIncomeEstimate( Player *player )
-{
- if( player == NULL || TheGameLogic == NULL )
- return;
-
- const UnsignedInt SAMPLE_FRAMES = INCOME_SAMPLE_SECONDS * LOGICFRAMES_PER_SECOND;
- const UnsignedInt logicFrame = TheGameLogic->getFrame();
- const Int playerIndex = player->getPlayerIndex();
- const Int earned = player->getScoreKeeper()->getTotalMoneyEarned();
-
- // a new game, or an observer looking at somebody else: start the window over
- if( m_incomeSampleCount == 0 || playerIndex != m_incomeSamplePlayer || logicFrame < m_hudLastMoneyFrame )
- {
- m_incomeSamplePlayer = playerIndex;
- m_incomeSamples[ 0 ] = earned;
- m_incomeSampleCount = 1;
- m_hudLastMoneyFrame = logicFrame;
- m_hudIncomePerMin = -1;
- return;
- }
-
- if( logicFrame < m_hudLastMoneyFrame + SAMPLE_FRAMES )
- return;
-
- m_incomeSamples[ m_incomeSampleCount % INCOME_SAMPLES ] = earned;
- ++m_incomeSampleCount;
- m_hudLastMoneyFrame = logicFrame;
-
- // average over every bucket we hold, so the number is live 2 seconds in and settles into a
- // true 30 second rate once the ring is full
- m_hudIncomePerMin = computeIncomePerMinute( m_incomeSamples, INCOME_SAMPLES,
- m_incomeSampleCount, INCOME_SAMPLE_SECONDS );
-}
-
-//-------------------------------------------------------------------------------------------------
-/** A small heads-up line in the top right: elapsed game time and the render rate, on a plate so it
- * stays readable over terrain. Income is not here - it lives next to the money, where it is
- * being compared to something. Off unless ShowHudOverlay is set in Options.ini. */
-//-------------------------------------------------------------------------------------------------
-void InGameUI::drawIncomeRate( void )
-{
- if( !TheGlobalData->m_showHudOverlay || m_hudIncomePerMin < 0 )
- return;
-
- if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
- return;
-
- static NameKeyType moneyWindowKey = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:MoneyDisplay" );
- GameWindow *moneyWin = TheWindowManager->winGetWindowFromId( NULL, moneyWindowKey );
- if( moneyWin == NULL || moneyWin->winIsHidden() )
- return;
-
- if( m_incomeDisplayString == NULL )
- {
- m_incomeDisplayString = TheDisplayStringManager->newDisplayString();
- m_incomeDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,
- TheGlobalLanguageData->adjustFontSize( HUD_OVERLAY_POINT_SIZE ),
- FALSE ) );
- }
-
- if( m_lastIncomeDisplayed != m_hudIncomePerMin )
- {
- UnicodeString buffer;
- buffer.format( L"(+%d/min)", m_hudIncomePerMin );
- m_incomeDisplayString->setText( buffer );
- m_lastIncomeDisplayed = m_hudIncomePerMin;
- }
-
- ICoord2D pos, size;
- moneyWin->winGetScreenPosition( &pos.x, &pos.y );
- moneyWin->winGetSize( &size.x, &size.y );
-
- Int textHeight = 0;
- m_incomeDisplayString->getSize( NULL, &textHeight );
-
- // tucked under the balance rather than after it: the money window runs to the bar's edge
- m_incomeDisplayString->draw( pos.x + 4, pos.y + size.y - 2,
- GameMakeColor( 180, 235, 180, 255 ),
- GameMakeColor( 0, 0, 0, 255 ) );
-}
-
//-------------------------------------------------------------------------------------------------
/** The lobby's peace time, counting down in the top right corner: red, bold, and bigger than the
* clock plate under it, because for as long as it is up it is the only number on the screen that
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 443c1e942..f6db75bc4 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -1557,44 +1557,6 @@ TEST(blob_never_smears_wider_than_the_cap)
CHECK(sy <= 300.0f);
}
-// ---------------------------------------------------------------------------------------------
-// The HUD income estimate (InGameUI.cpp). It samples the score keeper's cumulative earnings
-// into a ring of buckets and averages over every bucket it holds.
-// ---------------------------------------------------------------------------------------------
-extern Int computeIncomePerMinute( const Int *samples, UnsignedInt ringSize, UnsignedInt count, Int sampleSeconds );
-
-TEST(income_one_bucket_is_not_a_rate_yet)
-{
- const Int samples[4] = { 500, 0, 0, 0 };
- CHECK_EQ(computeIncomePerMinute(samples, 4, 1, 2), -1);
-}
-
-TEST(income_averages_over_the_buckets_held)
-{
- // two 2s buckets, 100 earned over them -> 100 per 2s -> 3000 a minute
- const Int samples[4] = { 1000, 1050, 1100, 0 };
- CHECK_EQ(computeIncomePerMinute(samples, 4, 2, 2), 1500);
- CHECK_EQ(computeIncomePerMinute(samples, 4, 3, 2), 1500);
-}
-
-TEST(income_window_slides_once_the_ring_wraps)
-{
- // ring of 4, so at most 3 buckets (6s) are spanned. Earnings: 0,10,20,30 then a 300 jump.
- Int samples[4] = { 0, 10, 20, 30 };
- CHECK_EQ(computeIncomePerMinute(samples, 4, 4, 2), 300); // (30-0) over 6s
-
- samples[4 % 4] = 330; // bucket 4 lands on index 0
- CHECK_EQ(computeIncomePerMinute(samples, 4, 5, 2), 3200); // (330-10) over 6s, bucket 0 gone
-}
-
-TEST(income_is_zero_not_negative_when_nothing_comes_in)
-{
- // cumulative earnings never fall, so a dry spell reads as a real zero
- const Int samples[4] = { 7000, 7000, 7000, 7000 };
- CHECK_EQ(computeIncomePerMinute(samples, 4, 4, 2), 0);
-}
-
-
//////////////////////////////////////////////////////////////////////////////
// The in-flight damage ledger
//////////////////////////////////////////////////////////////////////////////