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.

refactor(gameengine): move command buttons and sets into a logic-owned store

Olcay Seyganffa313d7fa45
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index b31fb106c..47d40d750 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -399,6 +399,7 @@ GameEngine/Include/Common/CDManager.h
GameEngine/Include/Common/CRCDebug.h
GameEngine/Include/Common/ClientUpdateModule.h
GameEngine/Include/Common/CommandLine.h
+GameEngine/Include/Common/CommandStore.h
GameEngine/Include/Common/ControlServer.h
GameEngine/Include/Common/CopyProtection.h
GameEngine/Include/Common/CrashHandler.h
@@ -1062,6 +1063,7 @@ GameEngine/Source/Common/System/ArchiveFileSystem.cpp
GameEngine/Source/Common/System/AsciiString.cpp
GameEngine/Source/Common/System/BuildAssistant.cpp
GameEngine/Source/Common/System/CDManager.cpp
+GameEngine/Source/Common/System/CommandStore.cpp
GameEngine/Source/Common/System/Compression.cpp
GameEngine/Source/Common/System/ControlServer.cpp
GameEngine/Source/Common/System/CopyProtection.cpp
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/CommandStore.h b/GeneralsMD/Code/GameEngine/Include/Common/CommandStore.h
new file mode 100644
index 000000000..eb61f5955
--- /dev/null
+++ b/GeneralsMD/Code/GameEngine/Include/Common/CommandStore.h
@@ -0,0 +1,82 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
+
+// FILE: CommandStore.h ///////////////////////////////////////////////////////////////////////////
+// Desc: Every CommandButton and CommandSet definition, owned by logic (LOGIC-THREAD.md phase 2,
+// M2). The AI, the scripts and the build checks look their buttons and sets up here; the
+// control bar reads the same lists to draw them.
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+#ifndef __COMMANDSTORE_H__
+#define __COMMANDSTORE_H__
+
+#include "Common/AsciiString.h"
+#include "Common/SubsystemInterface.h"
+
+class CommandButton;
+class CommandSet;
+class INI;
+
+/**
+ * What logic reads from a button or a set (its command, object, upgrade, special power, options,
+ * slots) does not change during a match. The fields that do, the cached button image and the
+ * cameo flash count, belong to the client and only the control bar touches them. A map.ini or
+ * solo.ini adds overrides at map load; reset() removes them between games.
+ */
+class CommandStore : public SubsystemInterface
+{
+
+public:
+
+ CommandStore( void );
+ virtual ~CommandStore( void );
+
+ void init( void ); ///< load CommandButton.ini, CommandSet.ini, the mods' copies and CommandSetReforged.ini
+ void reset( void ); ///< remove the map's overrides
+ void update( void ) { }
+
+ const CommandButton *findCommandButton( const AsciiString& name ); ///< the button's final override
+ const CommandSet *findCommandSet( const AsciiString& name ); ///< the set's final override
+
+ CommandButton *findNonConstCommandButton( const AsciiString& name );
+ CommandSet *findNonConstCommandSet( const AsciiString& name );
+
+ const CommandButton *getCommandButtons( void ) { return m_commandButtons; }
+ CommandButton *friend_getCommandButtons( void ) { return m_commandButtons; } ///< for ControlBar::postProcessCommands' image cache
+
+ static void parseCommandButtonDefinition( INI *ini );
+ static void parseCommandSetDefinition( INI *ini );
+
+private:
+
+ CommandButton *newCommandButton( const AsciiString& name );
+ CommandButton *newCommandButtonOverride( CommandButton *buttonToOverride );
+ CommandSet *newCommandSet( const AsciiString& name );
+ CommandSet *newCommandSetOverride( CommandSet *setToOverride );
+
+ CommandButton *m_commandButtons; ///< every button defined
+ CommandSet *m_commandSets; ///< every set defined
+
+};
+
+extern CommandStore *TheCommandStore;
+
+#endif // __COMMANDSTORE_H__
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
index a158bfb00..cc638f208 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
@@ -63,6 +63,7 @@ namespace LogicThread
CENSUS_DISPLAY, ///< TheDisplay shroud levels
CENSUS_JOBS, ///< JobSystem::parallel_for
CENSUS_ON_DEMAND_FLUSH, ///< Drawable::getDrawModulesFlushed applying deferred work inside the tick
+ CENSUS_OBSERVER_LOOKAT, ///< ControlBar::getObserverLookAtPlayer, a logic read of client state (M7)
CENSUS_COUNT
};
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index ce703fc0c..4f63e4d6b 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -36,7 +36,9 @@
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "Common/AudioEventRTS.h"
+#include "Common/CommandStore.h"
#include "Common/GameType.h"
+#include "Common/LogicThread.h"
#include "Common/Overridable.h"
#include "Common/Science.h"
#include "GameClient/Color.h"
@@ -44,6 +46,8 @@
#include "GameLogic/WeaponBonusConditionFlags.h"
#include "GameLogic/WeaponSetFlags.h"
+#include <functional>
+
// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class Drawable;
class GameWindow;
@@ -368,7 +372,7 @@ public:
void copyButtonTextFrom( const CommandButton *button, Bool shortcutButton, Bool markUIDirtyIfChanged ) const;
// bleah. shouldn't be const, but is. sue me. (srj)
- void setFlashCount(Int c) const { m_flashCount = c; }
+ void setFlashCount(Int c) const { LOGIC_CENSUS( CENSUS_CONTROLBAR ); m_flashCount = c; }
// only for ControlBar!
void friend_addToList(CommandButton** list) { m_next = *list; *list = this; }
@@ -815,8 +819,14 @@ public:
void initWindows( void );
void shutdownWindows( void );
- /// mark the UI as dirty so the context of everything is re-evaluated
+ /// mark the UI as dirty so the context of everything is re-evaluated; inside a tick it waits for the sync point
void markUIDirty( void );
+
+ /** LOGIC-THREAD.md phase 2, M2: a call the tick makes on the bar. Inside GameLogic::update it is
+ kept and run by flushLogicCalls on the main thread right after the tick, at both -logicthread
+ settings; outside a tick it runs at once. The map start calls in startNewGame stay direct. */
+ static void callFromLogic( const std::function<void()>& call );
+ static void flushLogicCalls( void ); ///< LogicThread::runTick, after every tick
Bool selectionRepeatsUnit( const ThingTemplate *thing ); ///< a selected factory of ours builds it on repeat
void toggleRepeatUnit( const ThingTemplate *thing ); ///< Ctrl+Alt on a build button: repeat on or off
@@ -918,10 +928,8 @@ public:
// the command bar
//-----------------------------------------------------------------------------------------------
- /// find existing command button if present
+ /// TheCommandStore's lookups, for the client; logic asks the store itself
const CommandButton *findCommandButton( const AsciiString& name );
-
- /// find existing command set
const CommandSet *findCommandSet( const AsciiString& name );
/// whose promotion screen and skills are shown: your own while playing, the selected or
@@ -982,7 +990,7 @@ public:
// Initialize the Observer controls Must be called after we've already loaded the window
void initObserverControls( void );
void setObserverLookAtPlayer (Player *p) { m_observerLookAtPlayer = p;}
- Player *getObserverLookAtPlayer (void ) { return m_observerLookAtPlayer;}
+ Player *getObserverLookAtPlayer (void ) { LOGIC_CENSUS( CENSUS_OBSERVER_LOOKAT ); return m_observerLookAtPlayer;}
void populateObserverInfoWindow ( void );
void populateObserverList( void );
Bool isObserverControlBarOn( void ) { return m_isObserverCommandBar;}
@@ -1007,10 +1015,6 @@ public:
void getForegroundMarkerPos(Int *x, Int *y);
void getBackgroundMarkerPos(Int *x, Int *y);
-
- static void parseCommandSetDefinition( INI *ini );
- static void parseCommandButtonDefinition( INI *ini );
-
void drawTransitionHandler( void );
const Image *getArrowImage( void ){ return m_genArrow; }
void setArrowImage( const Image *arrowImage ){ m_genArrow = arrowImage; }
@@ -1092,18 +1096,6 @@ protected:
void setLowControlBarConfig( void );
void setHiddenControlBar( void );
- /// find existing command button if present
- CommandButton* findNonConstCommandButton( const AsciiString& name );
-
- /// allocate a new command button, link to list, initialize to default, and return
- CommandButton *newCommandButton( const AsciiString& name );
- CommandButton *newCommandButtonOverride( CommandButton *buttonToOverride );
-
- /// allocate a new command set, link to list, initialize to default, and return it
- CommandSet *newCommandSet( const AsciiString& name );
- CommandSet *newCommandSetOverride( CommandSet *setToOverride );
-
-
/// evaluate what the user should see based on what selected drawables we have in our UI
void evaluateContextUI( void );
@@ -1216,10 +1208,10 @@ protected:
void setUpDownImages( void );
// methods for flashing cameos
public:
- void setFlash( Bool b ) { m_flash = b; }
+ void setFlash( Bool b ) { LOGIC_CENSUS( CENSUS_CONTROLBAR ); m_flash = b; }
// get method for list of commandbuttons
- const CommandButton *getCommandButtons( void ) { return m_commandButtons; }
+ const CommandButton *getCommandButtons( void ) { return TheCommandStore->getCommandButtons(); }
Drawable *findStandInBuilder( Bool freeOnly ); ///< with BuildWithoutWorker on, the local player's free builder (or, unless freeOnly, any builder) to stand in for an empty selection
@@ -1232,8 +1224,6 @@ protected:
ICoord2D m_panelOrigin; ///< where the frame was put, so the plates can follow it
Bool m_UIDirty; ///< the context UI must be re-evaluated
- CommandButton *m_commandButtons; ///< list of possible commands to have
- CommandSet *m_commandSets; ///< list of all command sets defined
ControlBarSchemeManager *m_controlBarSchemeManager; ///< The Scheme singleton
GameWindow *m_contextParent[ NUM_CONTEXT_PARENTS ]; ///< "parent" window for buttons that are part of the context sensitive interface
@@ -1394,9 +1384,6 @@ public:
private:
- /// find existing command set
- CommandSet *findNonConstCommandSet( const AsciiString& name );
-
const Image *m_genStarOn;
const Image *m_genStarOff;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 856259ad7..c0cb0dcb1 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -42,6 +42,7 @@
#include "Common/ActionManager.h"
#include "Common/AudioAffect.h"
#include "Common/BuildAssistant.h"
+#include "Common/CommandStore.h"
#include "Common/CRCDebug.h"
#include "Common/crc.h"
#include "Common/Radar.h"
@@ -1239,6 +1240,10 @@ void GameEngine::init( int argc, char *argv[] )
initFactionSubsystem(TheUpgradeCenter,"TheUpgradeCenter", MSGNEW("GameEngineSubsystem") UpgradeCenter, &xferCRC, "Data\\INI\\Default\\Upgrade.ini", "Data\\INI\\Upgrade.ini");
// An upgrade parsed again is edited in place, so this file names only what changes
ini.load( AsciiString( "Data\\INI\\UpgradeReforged.ini" ), INI_LOAD_MULTIFILE, &xferCRC );
+ /* Command buttons and sets, which the AI, the scripts and the build checks read: logic's, so
+ before the client and the logic (LOGIC-THREAD.md phase 2, M2). A button names objects,
+ upgrades and special powers, so after them; the INI CRC takes the files at the end. */
+ initSubsystem(TheCommandStore,"TheCommandStore", MSGNEW("GameEngineSubsystem") CommandStore, NULL);
initSubsystem(TheGameClient,"TheGameClient", createGameClient(), NULL);
@@ -1311,7 +1316,7 @@ void GameEngine::init( int argc, char *argv[] )
#endif/////////////////////////////////////////////////////////////////////////////////////////////
- // the control bar parses these without the checksum, and the AI builds and hunts from them
+ // TheCommandStore parses these without the checksum, and the AI builds and hunts from them
checksumFileContents( xferCRC, "Data\\INI\\Default\\CommandButton.ini" );
checksumFactionFile( xferCRC, "Data\\INI\\CommandButton.ini" );
checksumFactionFile( xferCRC, "Data\\INI\\CommandSet.ini" );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp
index a8bbc2486..a53e289ef 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp
@@ -34,6 +34,7 @@
#include "Common/INI.h"
#include "Common/SpecialPower.h"
+#include "Common/CommandStore.h"
#include "GameClient/ControlBar.h"
//-------------------------------------------------------------------------------------------------
@@ -41,23 +42,23 @@
//-------------------------------------------------------------------------------------------------
void INI::parseCommandButtonDefinition( INI *ini )
{
- ControlBar::parseCommandButtonDefinition(ini);
+ CommandStore::parseCommandButtonDefinition(ini);
}
//-------------------------------------------------------------------------------------------------
/** Parse a command button */
//-------------------------------------------------------------------------------------------------
-void ControlBar::parseCommandButtonDefinition( INI *ini )
+void CommandStore::parseCommandButtonDefinition( INI *ini )
{
// read the name
AsciiString name = ini->getNextToken();
// find existing item if present
- CommandButton *button = TheControlBar->findNonConstCommandButton( name );
+ CommandButton *button = TheCommandStore->findNonConstCommandButton( name );
if( button == NULL )
{
// allocate a new item
- button = TheControlBar->newCommandButton( name );
+ button = TheCommandStore->newCommandButton( name );
if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES)
{
button->markAsOverride();
@@ -73,7 +74,7 @@ void ControlBar::parseCommandButtonDefinition( INI *ini )
}
else
{
- button = TheControlBar->newCommandButtonOverride( button );
+ button = TheCommandStore->newCommandButtonOverride( button );
}
// parse the ini definition
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp
index 9d8a3584d..5322644f0 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandSet.cpp
@@ -15,6 +15,7 @@
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
////////////////////////////////////////////////////////////////////////////////
// //
@@ -32,12 +33,12 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
#include "Common/INI.h"
-#include "GameClient/ControlBar.h"
+#include "Common/CommandStore.h"
//-------------------------------------------------------------------------------------------------
/** Parse a command set */
//-------------------------------------------------------------------------------------------------
void INI::parseCommandSetDefinition( INI *ini )
{
- ControlBar::parseCommandSetDefinition(ini);
+ CommandStore::parseCommandSetDefinition(ini);
} // end parseCommandSetDefinition
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/AcademyStats.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/AcademyStats.cpp
index cc36c5b39..6eeb27474 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/AcademyStats.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/AcademyStats.cpp
@@ -96,7 +96,7 @@ void findDozerCommandSet( Object *object, void *userData )
}
if( object && object->isKindOf( KINDOF_DOZER ) )
{
- dozerCommandSet = TheControlBar->findCommandSet( object->getCommandSetString() );
+ dozerCommandSet = TheCommandStore->findCommandSet( object->getCommandSetString() );
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index d9ea923f8..548c2f061 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -2242,11 +2242,12 @@ void Player::killPlayer(void)
{
if (isPlayerActive())
{
- TheControlBar->setControlBarSchemeByPlayer(this);
+ ControlBar::callFromLogic( [this]{ TheControlBar->setControlBarSchemeByPlayer(this); } );
}
else
{
- TheControlBar->setControlBarSchemeByPlayerTemplate(ThePlayerTemplateStore->findPlayerTemplate(NAMEKEY("FactionObserver")));
+ const PlayerTemplate *observer = ThePlayerTemplateStore->findPlayerTemplate(NAMEKEY("FactionObserver"));
+ ControlBar::callFromLogic( [observer]{ TheControlBar->setControlBarSchemeByPlayerTemplate(observer); } );
}
}
@@ -2802,7 +2803,7 @@ void Player::addSciencePurchasePoints(Int delta)
m_sciencePurchasePoints = 0;
if (oldSPP != m_sciencePurchasePoints && TheControlBar != NULL)
- TheControlBar->onPlayerSciencePurchasePointsChanged(this);
+ ControlBar::callFromLogic( [this]{ TheControlBar->onPlayerSciencePurchasePointsChanged(this); } );
}
@@ -2965,12 +2966,14 @@ Bool Player::setRankLevel(Int newLevel)
TheEva->setShouldPlay( EVA_GeneralLevelUp );
}
- // notify of rank-change first
- TheControlBar->onPlayerRankChanged(this);
-
- // then of SPP change, if any
- if (oldSPP != m_sciencePurchasePoints)
- TheControlBar->onPlayerSciencePurchasePointsChanged(this);
+ // notify of rank-change first, then of SPP change, if any
+ const Bool sppChanged = oldSPP != m_sciencePurchasePoints;
+ ControlBar::callFromLogic( [this, sppChanged]
+ {
+ TheControlBar->onPlayerRankChanged(this);
+ if (sppChanged)
+ TheControlBar->onPlayerSciencePurchasePointsChanged(this);
+ } );
}
return true;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
index 68c2a0081..3551ff480 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
@@ -1391,7 +1391,7 @@ Bool BuildAssistant::isPossibleToMakeUnit( Object *builder, const ThingTemplate
return FALSE;
// get the command set for the producer object
- const CommandSet *commandSet = TheControlBar->findCommandSet( builder->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( builder->getCommandSetString() );
// if no command set we cannot build anything
if( commandSet == NULL )
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/CommandStore.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/CommandStore.cpp
new file mode 100644
index 000000000..c653470d7
--- /dev/null
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/CommandStore.cpp
@@ -0,0 +1,283 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+// Modified 2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
+
+// FILE: CommandStore.cpp /////////////////////////////////////////////////////////////////////////
+// Desc: The CommandButton and CommandSet lists, moved out of ControlBar (LOGIC-THREAD.md phase 2,
+// M2) so the tick finds its buttons and sets without asking the client.
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
+
+#include "Common/CommandStore.h"
+#include "Common/INI.h"
+#include "GameClient/ControlBar.h"
+
+CommandStore *TheCommandStore = NULL;
+
+//-------------------------------------------------------------------------------------------------
+CommandStore::CommandStore( void ) :
+ m_commandButtons( NULL ),
+ m_commandSets( NULL )
+{
+}
+
+//-------------------------------------------------------------------------------------------------
+CommandStore::~CommandStore( void )
+{
+ while( m_commandSets )
+ {
+ CommandSet *set = m_commandSets->friend_getNext();
+ m_commandSets->deleteInstance();
+ m_commandSets = set;
+ }
+
+ while( m_commandButtons )
+ {
+ CommandButton *button = m_commandButtons->friend_getNext();
+ m_commandButtons->deleteInstance();
+ m_commandButtons = button;
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The same files in the same order ControlBar::init read them. The INI CRC takes them at the end
+ of GameEngine::init, not here. */
+//-------------------------------------------------------------------------------------------------
+void CommandStore::init( void )
+{
+ INI ini;
+ ini.load( AsciiString( "Data\\INI\\Default\\CommandButton.ini" ), INI_LOAD_OVERWRITE, NULL );
+ ini.load( AsciiString( "Data\\INI\\CommandButton.ini" ), INI_LOAD_OVERWRITE, NULL );
+ ini.load( AsciiString( "Data\\INI\\CommandSet.ini" ), INI_LOAD_OVERWRITE, NULL );
+
+ // -modfactions: each mod's buttons and sets after retail's, under its names
+ INI::loadModPasses( "Data\\INI\\CommandButton.ini", NULL );
+ INI::loadModPasses( "Data\\INI\\CommandSet.ini", NULL );
+
+ // the fork's corrections to EA's buttons and sets, edited in place
+ ini.load( AsciiString( "Data\\INI\\CommandSetReforged.ini" ), INI_LOAD_MULTIFILE, NULL );
+
+ Int buttons = 0;
+ for( const CommandButton *b = m_commandButtons; b; b = b->getNext() )
+ ++buttons;
+ Int sets = 0;
+ for( CommandSet *s = m_commandSets; s; s = s->friend_getNext() )
+ ++sets;
+ DEBUG_LOG(( "CommandStore: %d command buttons, %d command sets\n", buttons, sets ));
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Remove the overrides a map.ini or solo.ini added. */
+//-------------------------------------------------------------------------------------------------
+void CommandStore::reset( void )
+{
+ CommandSet *set = m_commandSets;
+ while( set )
+ {
+ CommandSet *nextSet = set->friend_getNext();
+ Bool possibleAdjustment = ( set == m_commandSets );
+ Overridable *stillValid = set->deleteOverrides();
+ if( stillValid == NULL && possibleAdjustment )
+ m_commandSets = nextSet;
+ set = nextSet;
+ }
+
+ CommandButton *button = m_commandButtons;
+ while( button )
+ {
+ CommandButton *nextButton = button->friend_getNext();
+ Bool possibleAdjustment = ( button == m_commandButtons );
+ Overridable *stillValid = button->deleteOverrides();
+ if( stillValid == NULL && possibleAdjustment )
+ m_commandButtons = nextButton;
+ button = nextButton;
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Find a command button of the given name if present */
+//-------------------------------------------------------------------------------------------------
+CommandButton *CommandStore::findNonConstCommandButton( const AsciiString& name )
+{
+ for( const CommandButton *command = m_commandButtons; command; command = command->getNext() )
+ if( command->getName() == name )
+ return const_cast<CommandButton*>((const CommandButton*)command->getFinalOverride());
+
+ AsciiString retailName;
+ if( TheModNamespace.findRetailName( name, MODNAME_COMMANDBUTTON, &retailName ) )
+ return findNonConstCommandButton( retailName );
+ return NULL; // not found
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Find existing command set by name */
+//-------------------------------------------------------------------------------------------------
+CommandSet* CommandStore::findNonConstCommandSet( const AsciiString& name )
+{
+ for( CommandSet *set = m_commandSets; set != NULL; set = set->friend_getNext() )
+ if( set->getName() == name )
+ return const_cast<CommandSet*>((const CommandSet *) set);
+
+ AsciiString retailName;
+ if( TheModNamespace.findRetailName( name, MODNAME_COMMANDSET, &retailName ) )
+ return findNonConstCommandSet( retailName );
+ return NULL; // set not found
+}
+
+//-------------------------------------------------------------------------------------------------
+const CommandButton *CommandStore::findCommandButton( const AsciiString& name )
+{
+ CommandButton *btn = findNonConstCommandButton( name );
+ if( btn )
+ btn = (CommandButton *)btn->friend_getFinalOverride();
+ return btn;
+}
+
+//-------------------------------------------------------------------------------------------------
+const CommandSet *CommandStore::findCommandSet( const AsciiString& name )
+{
+ CommandSet *set = findNonConstCommandSet( name );
+ if( set )
+ set = (CommandSet*)set->friend_getFinalOverride();
+ return set;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Allocate a new command button, assign name, and tie to list */
+//-------------------------------------------------------------------------------------------------
+CommandButton *CommandStore::newCommandButton( const AsciiString& name )
+{
+ CommandButton *newButton = newInstance(CommandButton);
+ newButton->setName(name);
+ newButton->friend_addToList(&m_commandButtons);
+ return newButton;
+}
+
+//-------------------------------------------------------------------------------------------------
+CommandButton *CommandStore::newCommandButtonOverride( CommandButton *buttonToOverride )
+{
+ if (!buttonToOverride) {
+ return NULL;
+ }
+
+ CommandButton *newOverride = newInstance(CommandButton);
+ *newOverride = *buttonToOverride;
+ newOverride->markAsOverride();
+ buttonToOverride->setNextOverride(newOverride);
+ return newOverride;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Allocate a new command set, link to list, initialize to default, and return it */
+//-------------------------------------------------------------------------------------------------
+CommandSet *CommandStore::newCommandSet( const AsciiString& name )
+{
+ CommandSet* set = newInstance(CommandSet)(name);
+ set->friend_addToList(&m_commandSets);
+ return set;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Create an overridden command set. */
+//-------------------------------------------------------------------------------------------------
+CommandSet *CommandStore::newCommandSetOverride( CommandSet *setToOverride )
+{
+ if (!setToOverride) {
+ return NULL;
+ }
+
+ /* Hang the override off the end of the chain. findNonConstCommandSet hands back the base set (the
+ button lookup hands back the final override), so a set map.ini and solo.ini both edit, or one
+ file edits twice, copied the base, next-override pointer and all, and hung the copy off the
+ base: the chain ran base, second, first, the final override was the first edit and the second
+ never showed. */
+ setToOverride = (CommandSet *)setToOverride->friend_getFinalOverride();
+
+ CommandSet* set = newInstance(CommandSet)(setToOverride->getName());
+
+ // it's an override; DON'T add it to the main list.
+ // !!! DO NOT DO THIS !!! -- > set->friend_addToList(&m_commandSets); <-- !!! DO NOT DO THIS !!!
+
+ *set = *setToOverride;
+ set->markAsOverride();
+
+ setToOverride->setNextOverride(set);
+
+ return set;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Parse a command set */
+//-------------------------------------------------------------------------------------------------
+/*static*/ void CommandStore::parseCommandSetDefinition( INI *ini )
+{
+ AsciiString name;
+ CommandSet *commandSet;
+
+ // read the name
+ const char* c = ini->getNextToken();
+ name.set( c );
+
+ // find existing item if present
+ commandSet = TheCommandStore->findNonConstCommandSet( name );
+ if( commandSet == NULL )
+ {
+
+ // allocate a new item
+ commandSet = TheCommandStore->newCommandSet( name );
+ if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
+ commandSet->markAsOverride();
+ }
+ } // end if
+ else if( ini->getLoadType() == INI_LOAD_MULTIFILE )
+ {
+ // a patch file's set replaces the set whole, in place, so every pointer to it stays good
+ commandSet->friend_clearCommands();
+ }
+ else if( ini->getLoadType() == INI_LOAD_OVERWRITE )
+ {
+ // two mods under -modfactions can both name a set "CommandSet GLA" once their Side names are
+ // stripped; the later one wins, as a patch file's does, instead of refusing the whole load
+ DEBUG_LOG(( "[LINE: %d in '%s'] commandset %s defined again, the later one replaces it\n",
+ ini->getLineNum(), ini->getFilename().str(), name.str() ));
+ commandSet->friend_clearCommands();
+ }
+ else if( ini->getLoadType() != INI_LOAD_CREATE_OVERRIDES )
+ {
+ //Holy crap, this sucks to debug!!!
+ //If you have two different command sets, the previous
+ //code would simply allow you to define multiple command set
+ //with the same name, and just nuke the old button with the new one.
+ //So, I (KM) have added this assert to notify in case of two same-name
+ //command set.
+ DEBUG_CRASH(( "[LINE: %d in '%s'] Duplicate commandset %s found!", ini->getLineNum(), ini->getFilename().str(), name.str() ));
+ throw INI_INVALID_DATA;
+
+ //@todo SUPPORT OVERRIDES -- JM
+ } else {
+ commandSet = TheCommandStore->newCommandSetOverride(commandSet);
+ }
+
+ // sanity
+ DEBUG_ASSERTCRASH( commandSet, ("parseCommandSetDefinition: Unable to allocate set '%s'\n", name.str()) );
+
+ // parse the ini definition
+ ini->initFromINI( commandSet, commandSet->friend_getFieldParse() );
+
+} // end parseCommandSetDefinition
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
index 6329c5946..e5253fa22 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
@@ -25,6 +25,7 @@
#include "Common/LogicThread.h"
#include "Common/EarlyCommandLine.h"
#include "Common/MessageStream.h"
+#include "GameClient/ControlBar.h"
#include "GameClient/Drawable.h"
#include "GameLogic/FPUControl.h"
#include "GameLogic/GameLogic.h"
@@ -78,7 +79,7 @@ namespace
{
"drawable", "modelcondition", "audio", "ingameui", "controlbar", "tacticalview", "radar",
"fxlist", "terrainvisual", "particles", "gameclient", "eva", "newdrawable", "clientrandom",
- "ghost", "messagestream", "display", "jobs", "ondemandflush"
+ "ghost", "messagestream", "display", "jobs", "ondemandflush", "observerlookat"
};
Real elapsedMS( LogicClock::time_point a, LogicClock::time_point b )
@@ -207,6 +208,7 @@ void LogicThread::runTick( void )
++s_inlineTicks;
TheGameLogic->UPDATE();
Drawable::flushPendingClientWork();
+ ControlBar::flushLogicCalls();
return;
}
@@ -248,8 +250,10 @@ void LogicThread::runTick( void )
if( error )
std::rethrow_exception( error );
- // What the tick deferred on the drawables (phase 2, M1), here on the main thread at both settings.
+ // What the tick deferred on the drawables (phase 2, M1) and on the control bar (M2), here on the
+ // main thread at both settings.
Drawable::flushPendingClientWork();
+ ControlBar::flushLogicCalls();
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
index a62c7eac9..200675478 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
@@ -1210,7 +1210,7 @@ void Radar::tryUnderAttackEvent( const Object *obj )
{
// the lamp beside the radar
if( TheControlBar )
- TheControlBar->triggerRadarAttackGlow();
+ ControlBar::callFromLogic( []{ TheControlBar->triggerRadarAttackGlow(); } );
//
///@todo Should make an INI data driven table for radar event strings, and audio events
//
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 2115a7935..c2e01ab6e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -600,9 +600,45 @@ void ControlBar::pressCommandButton( Int place )
} // end pressCommandButton
+/* LOGIC-THREAD.md phase 2, M2: what the tick asks of the bar waits here for LogicThread::runTick to
+ call flushLogicCalls on the main thread. Keyed on isInGameLogicUpdate rather than on the thread, so
+ -logicthread 0 and 1 run one path, as the drawables' deferred work does. */
+static Bool s_logicMarkedUIDirty = FALSE;
+static std::vector< std::function<void()> > s_logicCalls;
+
+//-------------------------------------------------------------------------------------------------
+void ControlBar::callFromLogic( const std::function<void()>& call )
+{
+ if( TheGameLogic->isInGameLogicUpdate() )
+ s_logicCalls.push_back( call );
+ else
+ call();
+}
+
+//-------------------------------------------------------------------------------------------------
+void ControlBar::flushLogicCalls( void )
+{
+ // a call may queue nothing more: none of them runs inside a tick
+ for( size_t i = 0; i < s_logicCalls.size(); ++i )
+ s_logicCalls[ i ]();
+ s_logicCalls.clear();
+
+ if( s_logicMarkedUIDirty )
+ {
+ s_logicMarkedUIDirty = FALSE;
+ TheControlBar->markUIDirty();
+ }
+}
+
/// mark the UI as dirty so the context of everything is re-evaluated
void ControlBar::markUIDirty( void )
{
+ if( TheGameLogic->isInGameLogicUpdate() )
+ {
+ s_logicMarkedUIDirty = TRUE;
+ return;
+ }
+
LOGIC_CENSUS( CENSUS_CONTROLBAR );
m_UIDirty = TRUE;
@@ -1425,7 +1461,7 @@ void CommandSet::parseCommandButton( INI* ini, void *instance, void *store, cons
const char *token = ini->getNextToken();
// get find the command button from this name
- const CommandButton *commandButton = TheControlBar->findCommandButton( AsciiString( token ) );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( AsciiString( token ) );
// get the index to store the command at, and the command array itself
const CommandButton **buttonArray = (const CommandButton **)store;
Int buttonIndex = (Int)(intptr_t)userData;
@@ -1506,8 +1542,6 @@ CommandSet::~CommandSet( void )
ControlBar::ControlBar( void )
{
Int i;
- m_commandButtons = NULL;
- m_commandSets = NULL;
m_controlBarSchemeManager = NULL;
m_isObserverCommandBar = FALSE;
m_observerLookAtPlayer = NULL;
@@ -1648,26 +1682,6 @@ ControlBar::~ControlBar( void )
delete m_controlBarSchemeManager;
m_controlBarSchemeManager = NULL;
- // destroy all the command set definitions
- CommandSet *set;
- while( m_commandSets )
- {
- set = m_commandSets->friend_getNext();
- m_commandSets->deleteInstance();
- m_commandSets = set;
-
- } // end while
-
- // destroy all our command button definitions
- CommandButton *button;
- while( m_commandButtons )
- {
- button = m_commandButtons->friend_getNext();
- m_commandButtons->deleteInstance();
- m_commandButtons = button;
-
- } // end while
-
} // end ~ControlBar
void ControlBarPopupDescriptionUpdateFunc( WindowLayout *layout, void *param );
void ControlBarPopupDescription_forgetOffset( void );
@@ -2162,6 +2176,7 @@ static const std::vector<UnsignedByte> &plateMask( const ControlBarPlate *plate
//-------------------------------------------------------------------------------------------------
void ControlBar::triggerRadarAttackGlow( void )
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
if( m_radarAttackGlowWindow == NULL )
return;
m_remainingRadarAttackGlowFrames = ConvertRetailFrames( 150 );
@@ -2515,22 +2530,9 @@ void ControlBar::layoutPanels( void )
//-------------------------------------------------------------------------------------------------
void ControlBar::init( void )
{
- INI ini;
m_sideSelectAnimateDown = FALSE;
- // load the command buttons
- ini.load( AsciiString( "Data\\INI\\Default\\CommandButton.ini" ), INI_LOAD_OVERWRITE, NULL );
- ini.load( AsciiString( "Data\\INI\\CommandButton.ini" ), INI_LOAD_OVERWRITE, NULL );
-
- // load the command sets
- ini.load( AsciiString( "Data\\INI\\CommandSet.ini" ), INI_LOAD_OVERWRITE, NULL );
- // -modfactions: each mod's buttons and sets after retail's, under its names
- INI::loadModPasses( "Data\\INI\\CommandButton.ini", NULL );
- INI::loadModPasses( "Data\\INI\\CommandSet.ini", NULL );
- // the fork's corrections to EA's buttons and sets, edited in place; GameEngine::init checksums it
- ini.load( AsciiString( "Data\\INI\\CommandSetReforged.ini" ), INI_LOAD_MULTIFILE, NULL );
-
- // post process step after loading the command buttons and command sets
+ // TheCommandStore loaded the buttons and sets before the game logic existed; their images are ours
postProcessCommands();
// Init the scheme manager, this will call it's won INI init funciton.
@@ -2931,41 +2933,10 @@ void ControlBar::reset( void )
m_animateDownWindow = NULL;
}
- // Remove any overridden sets.
- CommandSet *set, *nextSet;
- set = m_commandSets;
- while (set) {
- Bool possibleAdjustment = FALSE;
- nextSet = set->friend_getNext();
- if (set == m_commandSets) {
- possibleAdjustment = TRUE;
- }
-
- Overridable *stillValid = set->deleteOverrides();
- if (stillValid == NULL && possibleAdjustment) {
- m_commandSets = nextSet;
- }
-
- set = nextSet;
- }
-
- // Remove any overridden command buttons.
- CommandButton *button, *nextButton;
- button = m_commandButtons;
- while (button) {
- Bool possibleAdjustment = FALSE;
- nextButton = button->friend_getNext();
- if (button == m_commandButtons) {
- possibleAdjustment = TRUE;
- }
-
- Overridable *stillValid = button->deleteOverrides();
- if (stillValid == NULL && possibleAdjustment) {
- m_commandButtons = nextButton;
- }
+ // the map's overrides go in TheCommandStore's reset; what the tick asked of the old match goes here
+ s_logicCalls.clear();
+ s_logicMarkedUIDirty = FALSE;
- button = nextButton;
- }
if(TheTransitionHandler)
TheTransitionHandler->remove("ControlBarArrow");
m_genArrow = NULL;
@@ -3383,6 +3354,7 @@ const Image *ControlBar::getStarImage(void )
//-------------------------------------------------------------------------------------------------
void ControlBar::onPlayerRankChanged(const Player *p)
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
if (!p->isLocalPlayer())
return;
@@ -3401,6 +3373,7 @@ void ControlBar::onPlayerRankChanged(const Player *p)
//-------------------------------------------------------------------------------------------------
void ControlBar::onPlayerSciencePurchasePointsChanged(const Player *p)
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
if (!p->isLocalPlayer())
return;
if(!(m_lastFlashedAtPointValue > ThePlayerList->getLocalPlayer()->getSciencePurchasePoints()))
@@ -3635,209 +3608,20 @@ void ControlBar::evaluateContextUI( void )
} // end evaluateContextUI
//-------------------------------------------------------------------------------------------------
-/** Find a command button of the given name if present */
-//-------------------------------------------------------------------------------------------------
-CommandButton *ControlBar::findNonConstCommandButton( const AsciiString& name )
-{
-
- for( const CommandButton *command = m_commandButtons; command; command = command->getNext() )
- if( command->getName() == name )
- return const_cast<CommandButton*>((const CommandButton*)command->getFinalOverride());
-
- AsciiString retailName;
- if( TheModNamespace.findRetailName( name, MODNAME_COMMANDBUTTON, &retailName ) )
- return findNonConstCommandButton( retailName );
- return NULL; // not found
-
-} // end findCommandButton
-
-//-------------------------------------------------------------------------------------------------
-/** Allocate a new command button, assign name, and tie to list */
-//-------------------------------------------------------------------------------------------------
-CommandButton *ControlBar::newCommandButton( const AsciiString& name )
-{
- CommandButton *newButton;
-
- // allocate new button
- newButton = newInstance(CommandButton);
-
- // assign name
- newButton->setName(name);
-
- // link to list
- newButton->friend_addToList(&m_commandButtons);
-
- // return the new button
- return newButton;
-
-} // end newCommandButton
-
-//-------------------------------------------------------------------------------------------------
-//-------------------------------------------------------------------------------------------------
-CommandButton *ControlBar::newCommandButtonOverride( CommandButton *buttonToOverride )
-{
- if (!buttonToOverride) {
- return NULL;
- }
-
- CommandButton *newOverride;
-
- // allocate new button
- newOverride = newInstance(CommandButton);
-
- *newOverride = *buttonToOverride;
-
- newOverride->markAsOverride();
- buttonToOverride->setNextOverride(newOverride);
-
- return newOverride;
-}
-
-//-------------------------------------------------------------------------------------------------
-/** Parse a command set */
-//-------------------------------------------------------------------------------------------------
-/*static*/ void ControlBar::parseCommandSetDefinition( INI *ini )
-{
- AsciiString name;
- CommandSet *commandSet;
-
- // read the name
- const char* c = ini->getNextToken();
- name.set( c );
-
- // find existing item if present
- commandSet = TheControlBar->findNonConstCommandSet( name );
- if( commandSet == NULL )
- {
-
- // allocate a new item
- commandSet = TheControlBar->newCommandSet( name );
- if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
- commandSet->markAsOverride();
- }
- } // end if
- else if( ini->getLoadType() == INI_LOAD_MULTIFILE )
- {
- // a patch file's set replaces the set whole, in place, so every pointer to it stays good
- commandSet->friend_clearCommands();
- }
- else if( ini->getLoadType() == INI_LOAD_OVERWRITE )
- {
- // two mods under -modfactions can both name a set "CommandSet GLA" once their Side names are
- // stripped; the later one wins, as a patch file's does, instead of refusing the whole load
- DEBUG_LOG(( "[LINE: %d in '%s'] commandset %s defined again, the later one replaces it\n",
- ini->getLineNum(), ini->getFilename().str(), name.str() ));
- commandSet->friend_clearCommands();
- }
- else if( ini->getLoadType() != INI_LOAD_CREATE_OVERRIDES )
- {
- //Holy crap, this sucks to debug!!!
- //If you have two different command sets, the previous
- //code would simply allow you to define multiple command set
- //with the same name, and just nuke the old button with the new one.
- //So, I (KM) have added this assert to notify in case of two same-name
- //command set.
- DEBUG_CRASH(( "[LINE: %d in '%s'] Duplicate commandset %s found!", ini->getLineNum(), ini->getFilename().str(), name.str() ));
- throw INI_INVALID_DATA;
-
- //@todo SUPPORT OVERRIDES -- JM
- } else {
- commandSet = TheControlBar->newCommandSetOverride(commandSet);
- }
-
- // sanity
- DEBUG_ASSERTCRASH( commandSet, ("parseCommandSetDefinition: Unable to allocate set '%s'\n", name.str()) );
-
- // parse the ini definition
- ini->initFromINI( commandSet, commandSet->friend_getFieldParse() );
-
-} // end parseCommandSetDefinition
-
-//-------------------------------------------------------------------------------------------------
-/** Find existing command set by name */
-//-------------------------------------------------------------------------------------------------
-CommandSet* ControlBar::findNonConstCommandSet( const AsciiString& name )
-{
- CommandSet* set;
-
- for( set = m_commandSets; set != NULL; set = set->friend_getNext() )
- if( set->getName() == name )
- return const_cast<CommandSet*>((const CommandSet *) set);
-
- AsciiString retailName;
- if( TheModNamespace.findRetailName( name, MODNAME_COMMANDSET, &retailName ) )
- return findNonConstCommandSet( retailName );
- return NULL; // set not found
-
-}
-//-------------------------------------------------------------------------------------------------
-/** find existing command button if present */
+/** The client's way to TheCommandStore. The census hook stays, so a logic site still asking the
+ bar shows up from the tick. */
//-------------------------------------------------------------------------------------------------
const CommandButton *ControlBar::findCommandButton( const AsciiString& name )
{
LOGIC_CENSUS( CENSUS_CONTROLBAR );
- CommandButton *btn = findNonConstCommandButton(name);
- if( btn )
- {
- btn = (CommandButton *)btn->friend_getFinalOverride();
- }
- return btn;
+ return TheCommandStore->findCommandButton( name );
}
-//-------------------------------------------------------------------------------------------------
-/** Find existing command set by name */
//-------------------------------------------------------------------------------------------------
const CommandSet *ControlBar::findCommandSet( const AsciiString& name )
{
LOGIC_CENSUS( CENSUS_CONTROLBAR );
- CommandSet *set = findNonConstCommandSet(name);
- if (set)
- set = (CommandSet*)set->friend_getFinalOverride();
- return set;
-}
-
-//-------------------------------------------------------------------------------------------------
-/** Allocate a new command set, link to list, initialize to default, and return it */
-//-------------------------------------------------------------------------------------------------
-CommandSet *ControlBar::newCommandSet( const AsciiString& name )
-{
- // allocate a new set
- CommandSet* set = newInstance(CommandSet)(name);
- // add it to the list.
- set->friend_addToList(&m_commandSets);
- // return the newly created set
- return set;
-
-} // end newCommandSet
-
-//-------------------------------------------------------------------------------------------------
-/** Create an overridden command set. */
-//-------------------------------------------------------------------------------------------------
-CommandSet *ControlBar::newCommandSetOverride( CommandSet *setToOverride )
-{
- if (!setToOverride) {
- return NULL;
- }
-
- /* Hang the override off the end of the chain. findNonConstCommandSet hands back the base set (the
- button lookup hands back the final override), so a set map.ini and solo.ini both edit, or one
- file edits twice, copied the base, next-override pointer and all, and hung the copy off the
- base: the chain ran base, second, first, the final override was the first edit and the second
- never showed. */
- setToOverride = (CommandSet *)setToOverride->friend_getFinalOverride();
-
- // allocate a new set
- CommandSet* set = newInstance(CommandSet)(setToOverride->getName());
-
- // it's an override; DON'T add it to the main list.
- // !!! DO NOT DO THIS !!! -- > set->friend_addToList(&m_commandSets); <-- !!! DO NOT DO THIS !!!
-
- *set = *setToOverride;
- set->markAsOverride();
-
- setToOverride->setNextOverride(set);
-
- return set;
+ return TheCommandStore->findCommandSet( name );
}
//-------------------------------------------------------------------------------------------------
@@ -4673,7 +4457,8 @@ void CommandButton::cacheButtonImage()
//-------------------------------------------------------------------------------------------------
void ControlBar::postProcessCommands( void )
{
- for ( CommandButton *button = m_commandButtons; button; button = button->friend_getNext() )
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
+ for ( CommandButton *button = TheCommandStore->friend_getCommandButtons(); button; button = button->friend_getNext() )
{
// a map.ini's edit of a button is an override hanging off it, not a button in this list
for ( Overridable *o = button; o; o = o->friend_getNextOverride() )
@@ -4925,6 +4710,7 @@ void ControlBar::showRallyPoint( const Coord3D *loc )
// ------------------------------------------------------------------------------------------------
void ControlBar::setControlBarSchemeByPlayer(Player *p)
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
if(m_controlBarSchemeManager)
m_controlBarSchemeManager->setControlBarSchemeByPlayer(p);
@@ -4977,6 +4763,7 @@ void ControlBar::restoreStageAfterScheme( void )
void ControlBar::setControlBarSchemeByPlayerTemplate( const PlayerTemplate *pt)
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
if(m_controlBarSchemeManager)
m_controlBarSchemeManager->setControlBarSchemeByPlayerTemplate(pt);
@@ -5098,6 +4885,7 @@ void ControlBar::updateCommanBarBorderColors(Color build, Color action, Color up
// hides the communicator button
void ControlBar::hideCommunicator( Bool b )
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
//sanity
if( m_communicatorButton != NULL )
m_communicatorButton->winHide( b );
@@ -5156,6 +4944,7 @@ void ControlBar::showPurchaseScience( void )
void ControlBar::hidePurchaseScience( void )
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
clearPurchaseScienceColumn();
const Bool wasOpen = m_purchaseScienceOpen;
@@ -5527,19 +5316,20 @@ void ControlBar::updateSlotExitImage( const Image *image )
//for neutral buildings which can have a different empty inventory icon based
//on the faction player.
- CommandButton *cmdButton = findNonConstCommandButton( "Command_StructureExit" );
+ // the button image is the client's field on a logic-owned button
+ CommandButton *cmdButton = TheCommandStore->findNonConstCommandButton( "Command_StructureExit" );
if(cmdButton)
cmdButton->setButtonImage(image);
- cmdButton = findNonConstCommandButton( "Command_TransportExit" );
+ cmdButton = TheCommandStore->findNonConstCommandButton( "Command_TransportExit" );
if(cmdButton)
cmdButton->setButtonImage(image);
- cmdButton = findNonConstCommandButton( "Command_BunkerExit" );
+ cmdButton = TheCommandStore->findNonConstCommandButton( "Command_BunkerExit" );
if(cmdButton)
cmdButton->setButtonImage(image);
- cmdButton = findNonConstCommandButton( "Command_FireBaseExit" );
+ cmdButton = TheCommandStore->findNonConstCommandButton( "Command_FireBaseExit" );
if(cmdButton)
cmdButton->setButtonImage(image);
@@ -5602,6 +5392,7 @@ void ControlBar::drawTransitionHandler( void )
}
void ControlBar::initSpecialPowershortcutBar( Player *player)
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
// Second loop further down reuses this i under VC6 for-scope.
Int i;
@@ -6241,6 +6032,7 @@ void ControlBar::showSpecialPowerShortcut( void )
void ControlBar::hideSpecialPowerShortcut( void )
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
if(!m_specialPowerShortcutParent)
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp
index 09f171d9d..c52a376ba 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp
@@ -302,7 +302,7 @@ Bool ControlBar::describePortraitBarWindow( GameWindow *window, UnicodeString &n
name = TheGameText->fetch( shown->getDisplayNameLabel().str() );
// the description is the one on the button that buys it, when there is such a button
description.clear();
- for( const CommandButton *button = m_commandButtons; button; button = button->getNext() )
+ for( const CommandButton *button = TheCommandStore->getCommandButtons(); button; button = button->getNext() )
{
if( button->getUpgradeTemplate() == shown && button->getDescriptionLabel().isNotEmpty() )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
index 5bdf359df..40d60d02f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp
@@ -1244,6 +1244,7 @@ void ControlBar::hideBuildTooltipLayout()
void ControlBar::deleteBuildTooltipLayout( void )
{
+ LOGIC_CENSUS( CENSUS_CONTROLBAR );
m_showBuildToolTipLayout = FALSE;
prevWindow= NULL;
m_buildToolTipLayout->hide(TRUE);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
index 439e589d8..39e976fda 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp
@@ -3724,7 +3724,7 @@ static Bool mayPlayerSell( const Object *obj )
if( obj->testScriptStatusBit( OBJECT_STATUS_SCRIPT_UNSELLABLE ) || obj->isDisabledByType( DISABLED_SUBDUED ) )
return FALSE;
- const CommandSet *commandSet = TheControlBar->findCommandSet( obj->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( obj->getCommandSetString() );
if( commandSet == NULL )
return FALSE;
@@ -4182,7 +4182,7 @@ Object *AIGroup::getCommandButtonSourceObject( GUICommandType type )
continue;
}
- const CommandSet *commandSet = TheControlBar->findCommandSet( object->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( object->getCommandSetString() );
if (!commandSet) {
continue;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 2fe5592ac..d47e136ed 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -3447,7 +3447,7 @@ void AIPlayer::buildUpgrade(const AsciiString &upgrade)
if( factory->getStatusBits().test( OBJECT_STATUS_SOLD ) )
continue;
Bool canUpgradeHere = false;
- const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factory->getCommandSetString() );
if( commandSet == NULL) continue;
for( Int j = 0; j < MAX_COMMANDS_PER_SET; j++ )
{
@@ -5439,7 +5439,7 @@ static Bool footprintOnClearGround( const Coord3D *pos, Real half )
* the bank cannot pay for yet, for a request the purchase queue saves up for. */
static const ThingTemplate *buildableOfKind( Object *builder, GUICommandType commandType, KindOfType kind, Bool moneyLater = FALSE )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( builder->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( builder->getCommandSetString() );
if( commandSet == NULL )
return NULL;
@@ -5468,7 +5468,7 @@ static Bool priorityBuildPending( Player *player, const ThingTemplate *tmpl );
//----------------------------------------------------------------------------------------------------------
const ThingTemplate *AIPlayer::nextBaseDefense( Object *dozer )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( dozer->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( dozer->getCommandSetString() );
if( commandSet == NULL )
return NULL;
@@ -6184,7 +6184,7 @@ Bool AIPlayer::readyToPush( void )
return TRUE;
Object *dozer = NULL;
m_player->iterateObjects( findAnyDozer, &dozer );
- const CommandSet *commandSet = dozer ? TheControlBar->findCommandSet( dozer->getCommandSetString() ) : NULL;
+ const CommandSet *commandSet = dozer ? TheCommandStore->findCommandSet( dozer->getCommandSetString() ) : NULL;
if( commandSet == NULL )
return TRUE;
// one the dozer has the prerequisites for, whatever else stops it this moment: asking for one it
@@ -6365,7 +6365,7 @@ static const Real FORWARD_TUNNEL_SHARE = 0.75f;
* FS_BASE_DEFENSE like the guns, so the kind cannot tell them apart; the module can. */
static const ThingTemplate *buildableTunnel( Object *builder )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( builder->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( builder->getCommandSetString() );
if( commandSet == NULL )
return NULL;
@@ -7398,7 +7398,7 @@ static void findDefenseUnderConstruction( Object *obj, void *userData )
static const ThingTemplate *bestDefender( Object *factory, const Player *owner, const AIVisibleEnemy &enemy,
Bool allowHelicopters = FALSE, Real *outScore = NULL )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factory->getCommandSetString() );
if( commandSet == NULL )
return NULL;
@@ -7717,7 +7717,7 @@ static Real armyMatchup( const ThingTemplate *tmpl, const Player *owner, const s
* worker, a gatherer, a hacker or a jet; a helicopter stays with the army, so it may. */
static const ThingTemplate *surplusUnit( Object *factory, const Player *owner, const std::vector<AIVisibleEnemy> &army, Real weight )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factory->getCommandSetString() );
if( commandSet == NULL )
return NULL;
@@ -7844,7 +7844,7 @@ void AIPlayer::buyUpgradesForArmy( Bool overTarget )
std::vector<Object *> where;
for( std::vector<Object *>::const_iterator f = factories.begin(); f != factories.end(); ++f )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( (*f)->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( (*f)->getCommandSetString() );
if( commandSet == NULL )
continue;
const UnsignedInt queued = (*f)->getProductionUpdateInterface()->getProductionCount();
@@ -8031,7 +8031,7 @@ static const Int MASS_RESERVE = 1500;
/** This factory has a button for that unit. */
static Bool factoryOffers( Object *factory, const ThingTemplate *tmpl )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factory->getCommandSetString() );
for( Int i = 0; commandSet && i < MAX_COMMANDS_PER_SET; ++i )
{
const CommandButton *button = commandSet->getCommandButton( i );
@@ -8053,7 +8053,7 @@ const ThingTemplate *AIPlayer::pickMassUnit( const std::vector<AIVisibleEnemy> &
Int bestCost = 0;
for( std::vector<Object *>::const_iterator f = factories.begin(); f != factories.end(); ++f )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( (*f)->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( (*f)->getCommandSetString() );
for( Int i = 0; commandSet && i < MAX_COMMANDS_PER_SET; ++i )
{
const CommandButton *button = commandSet->getCommandButton( i );
@@ -9373,7 +9373,7 @@ void AIPlayer::garrisonBuildings( void )
* kills it fastest: the Tank Hunter a bunkered Helix is bought for, a Missile Defender in a Humvee. */
static const ThingTemplate *gunshipRiderTemplate( Object *factory, const ThingTemplate *armour )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factory->getCommandSetString() );
if( commandSet == NULL )
return NULL;
const ThingTemplate *best = NULL;
@@ -9504,7 +9504,7 @@ static Bool passengersFireFrom( const ThingTemplate *tmpl )
* which the shuttle buys as a transport. */
static const ThingTemplate *chinookTemplate( Object *factory, Bool firing )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factory->getCommandSetString() );
if( commandSet == NULL )
return NULL;
for( Int i = 0; i < MAX_COMMANDS_PER_SET; ++i )
@@ -10422,7 +10422,7 @@ static const Real NO_GUN_DEPTH = -1.0e9f;
* The built-with set, because an upgraded Helix swaps its own for a shorter one. */
static const UpgradeTemplate *helixUpgradeOn( const ThingTemplate *tmpl, Int kind )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( tmpl->friend_getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( tmpl->friend_getCommandSetString() );
if( commandSet == NULL )
return NULL;
for( Int i = 0; i < MAX_COMMANDS_PER_SET; ++i )
@@ -10568,7 +10568,7 @@ void AIPlayer::buyDutyHelix( void )
m_player->iterateObjects( collectFactories, &factories );
for( size_t f = 0; f < factories.size(); ++f )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factories[ f ]->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factories[ f ]->getCommandSetString() );
if( commandSet == NULL )
continue;
for( Int i = 0; i < MAX_COMMANDS_PER_SET; ++i )
@@ -11393,7 +11393,7 @@ void AIPlayer::doAmbulances( void )
Bool ordered = FALSE;
for( size_t f = 0; f < factories.size() && !ordered; ++f )
{
- const CommandSet *commandSet = TheControlBar->findCommandSet( factories[ f ]->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( factories[ f ]->getCommandSetString() );
if( commandSet == NULL )
continue;
for( Int i = 0; i < MAX_COMMANDS_PER_SET && !ordered; ++i )
@@ -13550,9 +13550,6 @@ Bool AIPlayer::nextScoutTarget( Int slot, const Coord3D *from, Coord3D *pos )
* Red Guard - and on whatever a mod gave the ability to. */
static const ThingTemplate *cheapestCapturerTemplate( Player *player )
{
- if( TheControlBar == NULL )
- return NULL;
-
const ThingTemplate *best = NULL;
Int bestCost = 0;
@@ -13567,7 +13564,7 @@ static const ThingTemplate *cheapestCapturerTemplate( Player *player )
if( cost <= 0 || (best != NULL && cost >= bestCost) )
continue;
- const CommandSet *set = TheControlBar->findCommandSet( t->friend_getCommandSetString() );
+ const CommandSet *set = TheCommandStore->findCommandSet( t->friend_getCommandSetString() );
if( set == NULL )
continue;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 0544f7b5d..8274cc28c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -192,7 +192,7 @@ void AICommandParmsStorage::doXfer(Xfer *xfer)
}
xfer->xferAsciiString(&cmdName);
if (cmdName.isNotEmpty() && m_commandButton==NULL) {
- m_commandButton = TheControlBar->findCommandButton(cmdName);
+ m_commandButton = TheCommandStore->findCommandButton(cmdName);
}
Bool hasPath = m_path!=NULL;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index ec73d6ab3..d1b28b08b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -6744,7 +6744,7 @@ const AsciiString& Object::getCommandSetString() const
Bool Object::canProduceUpgrade( const UpgradeTemplate *upgrade )
{
// We need to have the button to make the upgrade. CommandSets are a weird Logic/Client hybrid.
- const CommandSet *set = TheControlBar->findCommandSet(getCommandSetString());
+ const CommandSet *set = TheCommandStore->findCommandSet(getCommandSetString());
if( set == NULL )
return FALSE; // a Supply Drop Zone, a GLA hole or a captured Oil Derrick has no command set
@@ -6764,7 +6764,7 @@ Bool Object::canProduceUpgrade( const UpgradeTemplate *upgrade )
* lock on its laser-guided missiles and fired them at anything, as fast as they reload. */
Bool Object::canSwitchToWeapon( WeaponSlotType weaponSlot ) const
{
- const CommandSet *set = TheControlBar->findCommandSet(getCommandSetString());
+ const CommandSet *set = TheCommandStore->findCommandSet(getCommandSetString());
if( set == NULL )
return FALSE; // an object with no command set has no buttons at all
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
index 252a45b16..f0fed2ef5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp
@@ -7294,7 +7294,7 @@ void AIUpdateInterface::privateCommandButton( const CommandButton *commandButton
if( ai )
{
//Make sure the owner has the same command button.
- const CommandSet *commandSet = TheControlBar->findCommandSet( owner->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( owner->getCommandSetString() );
if( commandSet )
{
for( int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -7349,7 +7349,7 @@ void AIUpdateInterface::privateCommandButtonPosition( const CommandButton *comma
if( ai )
{
//Make sure the owner has the same command button.
- const CommandSet *commandSet = TheControlBar->findCommandSet( owner->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( owner->getCommandSetString() );
if( commandSet )
{
for( int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -7401,7 +7401,7 @@ void AIUpdateInterface::privateCommandButtonObject( const CommandButton *command
{
AIUpdateInterface *ai = owner->getAI();
//Make sure the owner has the same command button.
- const CommandSet *commandSet = TheControlBar->findCommandSet( owner->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( owner->getCommandSetString() );
if( commandSet )
{
for( int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp
index b2be43354..b0ef50422 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp
@@ -112,7 +112,7 @@ void CommandButtonHuntUpdate::setCommandButton(const AsciiString& buttonName)
Object *obj = getObject();
m_commandButtonName = buttonName;
m_commandButton = NULL;
- const CommandSet *commandSet = TheControlBar->findCommandSet( obj->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( obj->getCommandSetString() );
if( commandSet )
{
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -441,7 +441,7 @@ void CommandButtonHuntUpdate::xfer( Xfer *xfer )
if( m_commandButtonName.isEmpty() == FALSE )
{
Object *us = getObject();
- const CommandSet *commandSet = TheControlBar->findCommandSet( us->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( us->getCommandSetString() );
if( commandSet )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
index fd5b5c7f4..868afb44a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
@@ -2074,7 +2074,7 @@ void ScriptActions::doTeamHuntWithCommandButton(const AsciiString& teamName, con
}
- const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( ability );
if( !commandButton )
{
return;
@@ -2157,7 +2157,7 @@ void ScriptActions::doTeamHuntWithCommandButton(const AsciiString& teamName, con
continue;
}
Bool foundCommand = false;
- const CommandSet *commandSet = TheControlBar->findCommandSet( obj->getCommandSetString( ) );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( obj->getCommandSetString( ) );
if( commandSet )
{
for( int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -2672,7 +2672,7 @@ void ScriptActions::doCameoFlash(const AsciiString& name, Int timeInSeconds)
const CommandButton *button;
//sanity
- button = TheControlBar->findCommandButton( name );
+ button = TheCommandStore->findCommandButton( name );
if( button == NULL )
{
DEBUG_CRASH(( "ScriptActions::doCameoFlash can't find AsciiString cameoflash" ));
@@ -2685,8 +2685,8 @@ void ScriptActions::doCameoFlash(const AsciiString& name, Int timeInSeconds)
if( count % 2 == 1 )
count++;
- button->setFlashCount(count);
- TheControlBar->setFlash( TRUE );
+ // the flash count is the client's field on the button; both wait for the sync point
+ ControlBar::callFromLogic( [button, count]{ button->setFlashCount(count); TheControlBar->setFlash( TRUE ); } );
}
@@ -3258,7 +3258,7 @@ void ScriptActions::doDisableInput()
TheInGameUI->deselectAllDrawables();
TheInGameUI->clearAttackMoveToMode();
TheInGameUI->setWaypointMode( FALSE );
- TheControlBar->deleteBuildTooltipLayout();
+ ControlBar::callFromLogic( []{ TheControlBar->deleteBuildTooltipLayout(); } );
TheLookAtTranslator->resetModes();
}
}
@@ -4314,7 +4314,7 @@ void ScriptActions::doNamedUseCommandButtonAbility( const AsciiString& unit, con
return;
}
- const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( theObj->getCommandSetString() );
if( commandSet )
{
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -4348,7 +4348,7 @@ void ScriptActions::doNamedUseCommandButtonAbilityOnNamed( const AsciiString& un
return;
}
- const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( theObj->getCommandSetString() );
if( commandSet )
{
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -4382,7 +4382,7 @@ void ScriptActions::doNamedUseCommandButtonAbilityAtWaypoint( const AsciiString&
return;
}
- const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( theObj->getCommandSetString() );
if( commandSet )
{
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -4421,7 +4421,7 @@ void ScriptActions::doNamedUseCommandButtonAbilityUsingWaypointPath( const Ascii
return;
}
- const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
+ const CommandSet *commandSet = TheCommandStore->findCommandSet( theObj->getCommandSetString() );
if( commandSet )
{
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -4454,7 +4454,7 @@ void ScriptActions::doTeamUseCommandButtonAbility( const AsciiString& team, cons
return;
}
- const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( ability );
if( !commandButton )
{
return;
@@ -4489,7 +4489,7 @@ void ScriptActions::doTeamUseCommandButtonAbilityOnNamed( const AsciiString& tea
return;
}
- const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( ability );
if( !commandButton )
{
return;
@@ -4524,7 +4524,7 @@ void ScriptActions::doTeamUseCommandButtonAbilityAtWaypoint( const AsciiString&
return;
}
- const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( ability );
if( !commandButton )
{
return;
@@ -5451,7 +5451,7 @@ void ScriptActions::doSkirmishCommandButtonOnMostValuable( const AsciiString& te
if (!player)
return;
- const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( ability );
if( !commandButton ) {
return;
}
@@ -5510,7 +5510,7 @@ void ScriptActions::doTeamUseCommandButtonOnNamed( const AsciiString& teamName,
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if(!commandButton) {
return;
}
@@ -5549,7 +5549,7 @@ void ScriptActions::doTeamUseCommandButtonOnNearestEnemy( const AsciiString& tea
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if(!commandButton) {
return;
}
@@ -5595,7 +5595,7 @@ void ScriptActions::doTeamUseCommandButtonOnNearestGarrisonedBuilding( const Asc
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if(!commandButton) {
return;
}
@@ -5645,7 +5645,7 @@ void ScriptActions::doTeamUseCommandButtonOnNearestKindof( const AsciiString& te
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if (!commandButton) {
return;
}
@@ -5692,7 +5692,7 @@ void ScriptActions::doTeamUseCommandButtonOnNearestBuilding( const AsciiString&
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if (!commandButton) {
return;
}
@@ -5739,7 +5739,7 @@ void ScriptActions::doTeamUseCommandButtonOnNearestBuildingClass( const AsciiStr
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if (!commandButton) {
return;
}
@@ -5787,7 +5787,7 @@ void ScriptActions::doTeamUseCommandButtonOnNearestObjectType( const AsciiString
AIGroup *theGroup = TheAI->createGroup();
team->getTeamAsAIGroup(theGroup);
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if (!commandButton) {
return;
}
@@ -5875,7 +5875,7 @@ void ScriptActions::doTeamPartialUseCommandButton( Real percentage, const AsciiS
return;
}
- const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
+ const CommandButton *commandButton = TheCommandStore->findCommandButton(commandAbility);
if (!commandButton) {
return;
}
@@ -6336,7 +6336,7 @@ void ScriptActions::doRemoveCommandBarButton(const AsciiString& buttonName, cons
if (!templ) {
return;
}
- const CommandSet *cs = TheControlBar->findCommandSet(templ->friend_getCommandSetString());
+ const CommandSet *cs = TheCommandStore->findCommandSet(templ->friend_getCommandSetString());
if (!cs) {
return;
}
@@ -6365,7 +6365,7 @@ void ScriptActions::doAddCommandBarButton(const AsciiString& buttonName, const A
return;
}
- const CommandButton *commandButton = TheControlBar->findCommandButton( buttonName );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( buttonName );
if (commandButton == NULL)
{
// not here. use doRemoveCommandBarButton to remove one.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
index 0626210fa..8413ce2d7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
@@ -2302,7 +2302,7 @@ Bool ScriptConditions::evaluateSkirmishCommandButtonIsReady( Parameter * /* pSki
return false;
}
- const CommandButton *commandButton = TheControlBar->findCommandButton( pCommandButtonParm->getString() );
+ const CommandButton *commandButton = TheCommandStore->findCommandButton( pCommandButtonParm->getString() );
if( !commandButton ) {
return false;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 7921aab52..6f42e1d4f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -6298,7 +6298,7 @@ void GameLogic::xfer( Xfer *xfer )
ConstCommandButtonPtr button = NULL;
if (value.isNotEmpty())
{
- button = TheControlBar->findCommandButton(value);
+ button = TheCommandStore->findCommandButton(value);
DEBUG_ASSERTCRASH(button != NULL, ("Could not find button %s\n",value.str()));
}
m_controlBarOverrides[name] = button;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index e897b1347..c50533307 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -347,8 +347,7 @@ void GameLogic::closeWindows( void )
TheGameConsole->resetCheatWindow();
HideInGameChat();
ResetInGameChat();
- TheControlBar->hidePurchaseScience();
- TheControlBar->hideSpecialPowerShortcut();
+ ControlBar::callFromLogic( []{ TheControlBar->hidePurchaseScience(); TheControlBar->hideSpecialPowerShortcut(); } );
HideQuitMenu();
// hide the options menu
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index d838e3632..dff358c20 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -15973,10 +15973,6 @@ TEST(the_bars_windows_can_be_torn_down_twice_without_taking_the_bar_with_them)
// again, on a bar that is already holding nothing - which is what the destructor does
bar.shutdownWindows();
CHECK( !bar.getShowBuildTooltipLayout() );
-
- // the command buttons are not window state and are not touched by any of it
- CHECK( bar.getCommandButtons() == NULL );
- CHECK( bar.findCommandButton( AsciiString( "NoSuchCommandButton" ) ) == NULL );
}
/* CommandSetReforged.ini names EA's Early_Command_ChinaCarpetBomb in slot 2 of a China command center
@@ -15986,9 +15982,9 @@ TEST(command_set_slot_naming_an_unknown_button_is_skipped)
{
CHECK( bootOnce() );
- ControlBar bar;
- ControlBar *savedBar = TheControlBar;
- TheControlBar = &bar;
+ CommandStore store;
+ CommandStore *savedStore = TheCommandStore;
+ TheCommandStore = &store;
writeFile( TEST_INI,
"CommandButton ProbeButton\r\n"
@@ -16000,8 +15996,8 @@ TEST(command_set_slot_naming_an_unknown_button_is_skipped)
"End\r\n" );
CHECK( loadIni( TEST_INI ) );
- const CommandButton *probe = bar.findCommandButton( AsciiString( "ProbeButton" ) );
- const CommandSet *set = bar.findCommandSet( AsciiString( "ProbeCommandSet" ) );
+ const CommandButton *probe = store.findCommandButton( AsciiString( "ProbeButton" ) );
+ const CommandSet *set = store.findCommandSet( AsciiString( "ProbeCommandSet" ) );
CHECK( probe != NULL );
CHECK( set != NULL );
if( set != NULL )
@@ -16012,7 +16008,7 @@ TEST(command_set_slot_naming_an_unknown_button_is_skipped)
}
remove( TEST_INI );
- TheControlBar = savedBar;
+ TheCommandStore = savedStore;
}
/* Mouse.cpp: the tooltip box was placed by two flips and nothing else, under EA's own note that