Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
perf(gameengine): index message arguments, drop redundant selection clears
Olcay Seyganddb5d45788b1
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex 5a426cdde..92e61f795 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -31,6 +31,8 @@#ifndef _MESSAGE_STREAM_H_#define _MESSAGE_STREAM_H_+#include <vector>+#include "Common/GameCommon.h" // ensure we get DUMP_PERF_STATS, or not#include "Common/SubsystemInterface.h"#include "Lib/BaseType.h"@@ -671,10 +673,12 @@ public:GameMessage( Type type );GameMessage *next( void ) { return m_next; } ///< Return next message in the stream+ const GameMessage *next( void ) const { return m_next; } ///< Return next message in the streamGameMessage *prev( void ) { return m_prev; } ///< Return prev message in the stream+ const GameMessage *prev( void ) const { return m_prev; } ///< Return prev message in the streamType getType( void ) const { return m_type; } ///< Return the message type- UnsignedByte getArgumentCount( void ) const { return m_argCount; } ///< Return the number of arguments for this msg+ UnsignedByte getArgumentCount( void ) const { return (UnsignedByte)m_argList.size(); } ///< Return the number of arguments for this msgAsciiString getCommandAsAsciiString( void ); ///< returns a string representation of the command type.static AsciiString getCommandTypeAsAsciiString(GameMessage::Type t);@@ -697,10 +701,9 @@ public:/*** Return the given argument union.- * @todo This should be a more list-like interface. Very inefficient.*/const GameMessageArgumentType *getArgument( Int argIndex ) const;- GameMessageArgumentDataType getArgumentDataType( Int argIndex );+ GameMessageArgumentDataType getArgumentDataType( Int argIndex ) const;void friend_setNext(GameMessage* m) { m_next = m; }void friend_setPrev(GameMessage* m) { m_prev = m; }@@ -718,10 +721,9 @@ private:Int m_playerIndex; ///< The Player who issued the command- /// @todo If a GameMessage needs more than 255 arguments, it needs to be split up into multiple GameMessage's.- UnsignedByte m_argCount; ///< The number of arguments of this message-- GameMessageArgument *m_argList, *m_argTail; ///< This message's arguments+ // A message used to walk a linked list to reach argument n, which made reading every argument of+ // a message quadratic. The Recorder does exactly that for every command it writes.+ std::vector<GameMessageArgument *> m_argList; ///< This message's arguments/// allocate a new argument, add it to list, return pointer to its dataGameMessageArgument *allocArg( void );@@ -809,6 +811,9 @@ public:protected:+ /// True when the message says nothing the message right behind it does not already say.+ Bool isRedundantMessage( const GameMessage *msg ) const;+struct TranslatorData{TranslatorData *m_next, *m_prev; ///< List links for list of translatorsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 0700da921..8526b6403 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -653,7 +653,7 @@ public: // ********************************************************************// Drawable selection mechanismsvirtual void selectDrawable( Drawable *draw ); ///< Mark given Drawable as "selected"virtual void deselectDrawable( Drawable *draw ); ///< Clear "selected" status from Drawable- virtual void deselectAllDrawables( Bool postMsg = true ); ///< Clear the "select" flag from all drawables+ virtual void deselectAllDrawables( void ); ///< Clear the "select" flag from all drawablesvirtual Int getSelectCount( void ) { return m_selectCount; } ///< Get count of currently selected drawablesvirtual Int getMaxSelectCount( void ) { return m_maxSelectCount; } ///< Get the max number of selected drawablesvirtual UnsignedInt getFrameSelectionChanged( void ) { return m_frameSelectionChanged; } ///< Get the max number of selected drawablesdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex de0261da6..0e2aeb74f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -60,11 +60,8 @@ CommandList *TheCommandList = NULL;GameMessage::GameMessage( GameMessage::Type type ){m_playerIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();- m_type = type;- m_argList = NULL;- m_argTail = NULL;- m_argCount = 0;- m_list = 0;+ m_type = type;+ m_list = 0;}@@ -74,13 +71,8 @@ GameMessage::GameMessage( GameMessage::Type type )GameMessage::~GameMessage( ){// free all arguments- GameMessageArgument *arg, *nextArg;-- for( arg = m_argList; arg; arg=nextArg )- {- nextArg = arg->m_next;- arg->deleteInstance();- }+ for( size_t i = 0; i < m_argList.size(); ++i )+ m_argList[i]->deleteInstance();// detach message from listif (m_list)@@ -89,16 +81,13 @@ GameMessage::~GameMessage( )/*** Return the given argument union.- * @todo This should be a more list-like interface. Very inefficient.*/const GameMessageArgumentType *GameMessage::getArgument( Int argIndex ) const{static const GameMessageArgumentType junk = { 0 };- int i=0;- for( GameMessageArgument *a = m_argList; a; a=a->m_next, i++ )- if (i == argIndex)- return &a->m_data;+ if( argIndex >= 0 && (size_t)argIndex < m_argList.size() )+ return &m_argList[argIndex]->m_data;DEBUG_CRASH(("argument not found"));return &junk;@@ -107,19 +96,11 @@ const GameMessageArgumentType *GameMessage::getArgument( Int argIndex ) const/*** Return the given argument data type*/-GameMessageArgumentDataType GameMessage::getArgumentDataType( Int argIndex )+GameMessageArgumentDataType GameMessage::getArgumentDataType( Int argIndex ) const{- if (argIndex >= m_argCount) {- return ARGUMENTDATATYPE_UNKNOWN;- }- int i=0;- GameMessageArgument *a;- for (a = m_argList; a && (i < argIndex); a=a->m_next, ++i );+ if( argIndex >= 0 && (size_t)argIndex < m_argList.size() )+ return m_argList[argIndex]->m_type;- if (a != NULL)- {- return a->m_type;- }return ARGUMENTDATATYPE_UNKNOWN;}@@ -129,21 +110,12 @@ GameMessageArgumentDataType GameMessage::getArgumentDataType( Int argIndex )GameMessageArgument *GameMessage::allocArg( void ){// allocate a new argument- GameMessageArgument *arg = newInstance(GameMessageArgument);-- // add to end of argument list- if (m_argTail)- m_argTail->m_next = arg;- else- {- m_argList = arg;- m_argTail = arg;- }-+ GameMessageArgument *arg = newInstance(GameMessageArgument);arg->m_next = NULL;- m_argTail = arg;+ m_argList.push_back(arg);- m_argCount++;+ DEBUG_ASSERTCRASH( m_argList.size() <= 255,+ ("A GameMessage with more than 255 arguments has to be split into several messages.") );return arg;}@@ -1129,24 +1101,33 @@ void MessageStream::propagateMessages( void )for( ss=m_firstTranslator; ss; ss=ss->m_next ){for( msg=m_firstMessage; msg; msg=next )- {- if (ss->m_translator+ {+ // TheSuperHackers @tweak Drop messages we already know say nothing, before any translator+ // spends work on them. Fewer commands reach the network. Anything that needs to look back+ // at an earlier message has to invalidate here and delete later instead.+ if (isRedundantMessage(msg))+ {+ next = msg->next();+ msg->deleteInstance();+ continue;+ }++ if (ss->m_translator#if defined(_DEBUG) || defined(_INTERNAL)&& !isInvalidDebugCommand(msg->getType())#endif){GameMessageDisposition disp = ss->m_translator->translateGameMessage(msg);- next = msg->next();if (disp == DESTROY_MESSAGE){+ next = msg->next();msg->deleteInstance();+ continue;}- }- else- {- next = msg->next();}++ next = msg->next();}}@@ -1160,6 +1141,39 @@ void MessageStream::propagateMessages( void )}+Bool MessageStream::isRedundantMessage( const GameMessage *msg ) const+{+ if( msg->getType() != GameMessage::MSG_DESTROY_SELECTED_GROUP )+ return FALSE;++ const GameMessage *msgNext = msg->next();+ if( msgNext == NULL )+ return FALSE;++ switch( msgNext->getType() )+ {+ // A fresh group replaces the selection outright, so clearing it first says nothing.+ case GameMessage::MSG_CREATE_SELECTED_GROUP:+ case GameMessage::MSG_CREATE_SELECTED_GROUP_NO_SOUND:+ return msgNext->getArgumentCount() >= 1 && msgNext->getArgument( 0 )->boolean;++ case GameMessage::MSG_DESTROY_SELECTED_GROUP:+ case GameMessage::MSG_SELECT_TEAM0:+ case GameMessage::MSG_SELECT_TEAM1:+ case GameMessage::MSG_SELECT_TEAM2:+ case GameMessage::MSG_SELECT_TEAM3:+ case GameMessage::MSG_SELECT_TEAM4:+ case GameMessage::MSG_SELECT_TEAM5:+ case GameMessage::MSG_SELECT_TEAM6:+ case GameMessage::MSG_SELECT_TEAM7:+ case GameMessage::MSG_SELECT_TEAM8:+ case GameMessage::MSG_SELECT_TEAM9:+ return TRUE;+ }++ return FALSE;+}+//------------------------------------------------------------------------------------------------// CommandListdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cppindex e5b26a47f..b565a6c72 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp@@ -806,14 +806,8 @@ void RecorderClass::writeToFile(GameMessage * msg) {argType = argType->getNext();}-// UnsignedByte lasttype = (UnsignedByte)ARGUMENTDATATYPE_UNKNOWN;- Int numArgs = msg->getArgumentCount();+ const Int numArgs = msg->getArgumentCount();for (Int i = 0; i < numArgs; ++i) {-// UnsignedByte type = (UnsignedByte)(msg->getArgumentDataType(i));-// if (lasttype != type) {-// fwrite(&type, sizeof(type), 1, m_file);-// lasttype = type;-// }writeArgument(msg->getArgumentDataType(i), *(msg->getArgument(i)));}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarBeacon.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarBeacon.cppindex 6f62f9565..010ae87cd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarBeacon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarBeacon.cpp@@ -97,7 +97,7 @@ WindowMsgHandledType BeaconWindowInput( GameWindow *window, UnsignedInt msg,{if (msg == GWM_CHAR && mData1 == KEY_ESC){- TheInGameUI->deselectAllDrawables(TRUE); // there should only be one beacon and nothing else selected+ TheInGameUI->deselectAllDrawables(); // there should only be one beacon and nothing else selectedreturn MSG_HANDLED;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 16e1e4ca3..b8e841004 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -4587,9 +4587,10 @@ void InGameUI::deselectDrawable( Drawable *draw )//-------------------------------------------------------------------------------------------------/** Clear all drawables' "select" status *///--------------------------------------------------------------------------------------------------void InGameUI::deselectAllDrawables( Bool postMsg )+void InGameUI::deselectAllDrawables( void ){const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();+ const Bool hadSelectedDrawables = !selected->empty();// loop through all the selected drawablesfor ( DrawableListCIt it = selected->begin(); it != selected->end(); )@@ -4611,12 +4612,9 @@ void InGameUI::deselectAllDrawables( Bool postMsg )m_soloNexusSelectedDrawableID = INVALID_DRAWABLE_ID;- ///@todo don't we want to not emit this message if there wasn't a group at all? (CBD)- /** @todo also, we probably are sending this message too much, we should come up with- some kind of "selections are dirty" status that we can check once per frame and send- the correct group info over the network ... could be tricky tho (or impossible) given- the order of operations of things happening in the code (CBD) */- if( postMsg )+ // TheSuperHackers @tweak Only send this when something actually was selected. The rest of the+ // spam is dropped in the stream, where a clear followed by a fresh selection is recognised.+ if( hadSelectedDrawables ){// The message carried one boolean that nothing on the receiving side ever read: the handler// deselects the whole group and always did.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex e5008de30..f86d7eff0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -1260,7 +1260,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa}else{- TheInGameUI->deselectAllDrawables( false ); //No need to post message because we're just creating a new group!+ TheInGameUI->deselectAllDrawables(); //The clear is dropped in the stream, the new group follows it// no need to send two messages for selecting the same group.TheMessageStream->appendMessage((GameMessage::Type)(GameMessage::MSG_SELECT_TEAM0 + group));diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cppindex 7721b5ca1..5b1285d3a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp@@ -2622,13 +2622,15 @@ void JetAIUpdate::crc( Xfer *xfer )// ------------------------------------------------------------------------------------------------/** Xfer method* Version Info:- * 1: Initial version */+ * 1: Initial version+ * 2: Save engine on/off state.+ * 3: TheSuperHackers @bugfix Save the helipad landing position. */// ------------------------------------------------------------------------------------------------void JetAIUpdate::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 2;+ XferVersion currentVersion = 3;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -2680,6 +2682,11 @@ void JetAIUpdate::xfer( Xfer *xfer )}}+ if( version >= 3 )+ {+ xfer->xferCoord3D( &m_landingPosForHelipadStuff );+ }+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cppindex b4b3aabca..5746ee274 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp@@ -620,8 +620,9 @@ UpdateSleepTime SpectreGunshipUpdate::update()// GATTLING TARGETING LOGIC------------------------------------------- const ParticleSystemTemplate *tmp = data->m_gattlingStrafeFXParticleSystem;- if (tmp && gattling && gattling->testStatus( OBJECT_STATUS_IS_FIRING_WEAPON) )+ // TheSuperHackers @fix A missing client-side particle template used to switch off the+ // gattling's aiming and its howitzer counter, which are logic state and CRC'd.+ if (gattling && gattling->testStatus( OBJECT_STATUS_IS_FIRING_WEAPON) ){@@ -654,7 +655,7 @@ UpdateSleepTime SpectreGunshipUpdate::update(){// This makes the client smoke effects of the gattling cannon strafing the ground toward the attack position- ParticleSystem *sys = TheParticleSystemManager->createParticleSystem(tmp);+ ParticleSystem *sys = TheParticleSystemManager->createParticleSystem(data->m_gattlingStrafeFXParticleSystem);if (sys){Coord3D impactPosition;