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(gamelogic): answer isInGameLogicUpdate per thread

Olcay Seygan0f685050171d
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
index 73415225d..c669f1ff6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
@@ -157,7 +157,9 @@ public:
void setHeight( Real height ); ///< Sets the height of the world
Real getHeight( void ); ///< Returns the height of the world
- Bool isInGameLogicUpdate( void ) const { return m_isInUpdate; }
+ /** TRUE on the thread running GameLogic::update, inside it. Per thread (LOGIC-THREAD.md phase 3): once
+ * the render runs beside the tick, the main thread is not inside it and its client work runs at once. */
+ Bool isInGameLogicUpdate( void ) const { return s_isInUpdate; }
Bool isNewGamePending( void ) const { return m_startNewGame; } ///< the next update starts a map (LogicThread keeps that tick on the main thread)
UnsignedInt getFrame( void ); ///< Returns the current simulation frame number
UnsignedInt getFrameForClient( void ) const { return m_frameForClient; } ///< the frame the last tick ran, for the client's clock (LogicThread::runTick)
@@ -377,7 +379,7 @@ private:
Bool m_loadingWithoutScreen;
Bool m_clearingGameData;
- Bool m_isInUpdate;
+ static thread_local Bool s_isInUpdate;
Int m_rankPointsToAddAtGameStart;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 2287e849a..a71cfaba7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -222,16 +222,18 @@ static Waypoint * findNamedWaypoint(AsciiString name)
test can call it without linking the whole of GameLogic. */
+thread_local Bool GameLogic::s_isInUpdate = FALSE;
+
// ------------------------------------------------------------------------------------------------
/** GameLogic class constructor */
// ------------------------------------------------------------------------------------------------
GameLogic::GameLogic( void )
{
//Added By Sadullah Nader
- //Initializations missing and necessary
+ //Initializations missing and necessary
m_background = NULL;
m_CRC = 0;
- m_isInUpdate = FALSE;
+ s_isInUpdate = FALSE;
m_rankPointsToAddAtGameStart = 0;
@@ -439,8 +441,8 @@ void GameLogic::init( void )
m_drawIconUI = TRUE;
m_showDynamicLOD = TRUE;
m_scriptHulkMaxLifetimeOverride = -1;
-
- m_isInUpdate = FALSE;
+
+ s_isInUpdate = FALSE;
m_rankPointsToAddAtGameStart = 0;
}
@@ -4606,7 +4608,7 @@ void GameLogic::update( void )
USE_PERF_TIMER(GameLogic_update)
- LatchRestore<Bool> inUpdateLatch(m_isInUpdate, TRUE);
+ LatchRestore<Bool> inUpdateLatch(s_isInUpdate, TRUE);
#ifdef DO_UNIT_TIMINGS
unitTimings();
#endif