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
refactor(gamelogic): ask the tick's selection block whether a drawable is selected
Olcay Seygan4a3c82d6ec59
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.hindex f6ac23f76..b694fb8e2 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h@@ -33,6 +33,7 @@#include <functional>#include <vector>+class Drawable;class Player;/**@@ -156,6 +157,10 @@ namespace LogicThreadvoid noteSelected( DrawableID drawable, ObjectID object, Bool selected );void noteSelectionCleared( void );+ /** Drawable::isSelected for logic: inside a tick, whether the block's selection holds the drawable;+ * anywhere else the drawable's own flag, since there a select or deselect runs at the call. */+ Bool isSelectedForTick( const Drawable *draw );+/** What a queued camera call does to the two answers logic reads (time frozen, movement finished),* written to the block at the call. This is the camera's state machine in four words, not the* camera: a move whose path collapses to one point, or a motion blur the device refuses, leaves thediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex 451a6d732..da56080af 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -35,6 +35,7 @@#include "Common/AudioEventRTS.h"#include "Common/DisabledTypes.h"#include "Common/GameType.h"+#include "Common/LogicThread.h"#include "Common/ModelState.h"#include "Common/ModuleFactory.h"#include "Common/Thing.h"@@ -493,7 +494,7 @@ public:void flashAsSelected( const RGBColor *color = NULL ); ///< drawable takes care of the details if you spec no color/// Return true if drawable has been marked as "selected"- Bool isSelected( void ) const { return m_selected; }+ Bool isSelected( void ) const { LOGIC_CENSUS( CENSUS_CLIENT_READ ); return m_selected; } ///< logic asks LogicThread::isSelectedForTickvoid onSelected(); ///< Work unrelated to selection that must happen at time of selectionvoid onUnselected(); ///< Work unrelated to selection that must happen at time of unselectiondiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cppindex 7c3c12605..ad7e6232e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp@@ -415,6 +415,18 @@ void LogicThread::noteSelectionCleared( void )s_block.frameSelectionChanged = TheGameLogic->getFrame();}+//-------------------------------------------------------------------------------------------------+Bool LogicThread::isSelectedForTick( const Drawable *draw )+{+ if( !defersEffects() )+ return draw->isSelected();+ const DrawableID id = draw->getID();+ for( size_t i = 0; i < s_block.selection.size(); ++i )+ if( s_block.selection[ i ].drawable == id )+ return TRUE;+ return FALSE;+}+//-------------------------------------------------------------------------------------------------void LogicThread::noteViewEffect( ViewEffect effect ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SpawnBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SpawnBehavior.cppindex 884bdbd21..da9aeab70 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SpawnBehavior.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SpawnBehavior.cpp@@ -954,7 +954,7 @@ void SpawnBehavior::computeAggregateStates(void)spawnDraw = currentSpawn->getDrawable();- if ( spawnDraw->isSelected() )+ if ( LogicThread::isSelectedForTick( spawnDraw ) ){SomebodyIsSelected = TRUE;}@@ -976,7 +976,8 @@ void SpawnBehavior::computeAggregateStates(void)// THIS WAY WE ARE ALWAYS ONE BIG HAPPY MOB// BUT I ONLY PROCEED IF THERE IS ONE AMONG ALL OF US WHO IS NOT SELECTED- if ( SomebodyIsSelected && ( ! obj->getDrawable()->isSelected() || SomebodyIsNotSelected ) )+ // the selection as the tick sees it: the sync point's, with what this tick selected since (M7)+ if ( SomebodyIsSelected && ( ! LogicThread::isSelectedForTick( obj->getDrawable() ) || SomebodyIsNotSelected ) ){GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );teamMsg->appendBooleanArgument( FALSE );// not creating new team so pass false@@ -992,7 +993,7 @@ void SpawnBehavior::computeAggregateStates(void)spawnDraw = currentSpawn->getDrawable();- if ( ! spawnDraw->isSelected())+ if ( ! LogicThread::isSelectedForTick( spawnDraw ) ){TheInGameUI->selectDrawable( spawnDraw );TheInGameUI->setDisplayedMaxWarning( FALSE );@@ -1003,7 +1004,7 @@ void SpawnBehavior::computeAggregateStates(void)} // next iter}// if somebody is selected then I sure need to be!- if ( ! obj->getDrawable()->isSelected())+ if ( ! LogicThread::isSelectedForTick( obj->getDrawable() ) ){TheInGameUI->selectDrawable( obj->getDrawable() );TheInGameUI->setDisplayedMaxWarning( FALSE );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cppindex 6bf5fcca0..71c046e46 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp@@ -313,7 +313,7 @@ void OpenContain::addToContain( Object *rider )Drawable *riderDraw = rider->getDrawable();Bool wasSelected = FALSE;- if( riderDraw && riderDraw->isSelected() )+ if( riderDraw && LogicThread::isSelectedForTick( riderDraw ) ){wasSelected = TRUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cppindex 433ed3067..f6aa431f1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/RiderChangeContain.cpp@@ -205,7 +205,7 @@ void RiderChangeContain::onContaining( Object *rider, Bool wasSelected )//that may be already selected. Note that containing the rider will automatically cause it to be//deselected, so all we have to do is select the container (if not already selected)!Drawable *containDraw = getObject()->getDrawable();- if( containDraw && wasSelected && !containDraw->isSelected() )+ if( containDraw && wasSelected && !LogicThread::isSelectedForTick( containDraw ) ){//Create the selection messageGameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );@@ -336,7 +336,7 @@ void RiderChangeContain::onRemoving( Object *rider )if( containDraw && riderDraw ){//Create the selection message for the rider if it's ours and SELECTED!- if( bike->getControllingPlayer() == ThePlayerList->getLocalPlayer() && containDraw->isSelected() )+ if( bike->getControllingPlayer() == ThePlayerList->getLocalPlayer() && LogicThread::isSelectedForTick( containDraw ) ){GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );teamMsg->appendBooleanArgument( FALSE );// not creating new team so pass falsediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Die/CreateObjectDie.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Die/CreateObjectDie.cppindex 3f9cc03cd..a0942508e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Die/CreateObjectDie.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Die/CreateObjectDie.cpp@@ -116,7 +116,7 @@ void CreateObjectDie::onDie( const DamageInfo * damageInfo )Drawable *oldDraw = getObject()->getDrawable();Drawable *newDraw = newObject->getDrawable();- if( oldDraw && newDraw && oldDraw->isSelected() && !newDraw->isSelected() )+ if( oldDraw && newDraw && LogicThread::isSelectedForTick( oldDraw ) && !LogicThread::isSelectedForTick( newDraw ) ){TheInGameUI->selectDrawable( newDraw );TheInGameUI->deselectDrawable( oldDraw );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cppindex 26932668b..573723345 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp@@ -1002,7 +1002,7 @@ void StealthUpdate::disguiseAsObject( const Object *target )}Drawable *draw = self->getDrawable();- if( draw && draw->isSelected() )+ if( draw && LogicThread::isSelectedForTick( draw ) ){TheControlBar->markUIDirty();}@@ -1017,7 +1017,7 @@ void StealthUpdate::changeVisualDisguise()Drawable *draw = self->getDrawable();// We need to maintain our selection across the un/disguise, so pull selected out here.- Bool selected = draw->isSelected();+ Bool selected = LogicThread::isSelectedForTick( draw );if( m_disguiseAsTemplate ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex f21653452..b38452de0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -262,7 +262,7 @@ static void doSetRallyPoint( Object *obj, const Coord3D& pos )// mark the UI as dirty so that we re-evaluate the selection and show the rally pointDrawable *draw = obj->getDrawable();- if( draw && draw->isSelected() )+ if( draw && LogicThread::isSelectedForTick( draw ) )TheControlBar->markUIDirty();} // end if@@ -293,7 +293,7 @@ static void doClearRallyPoint( Object *obj )// mark the UI as dirty so that we re-evaluate the selection and take the flag downDrawable *draw = obj->getDrawable();- if( obj->isLocallyControlled() && draw && draw->isSelected() )+ if( obj->isLocallyControlled() && draw && LogicThread::isSelectedForTick( draw ) )TheControlBar->markUIDirty();}