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
feat(gameengine): run the logic tick on its own thread behind -logicthread
Olcay Seyganca77fad781be
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 1103cdd09..b31fb106c 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -447,6 +447,7 @@ GameEngine/Include/Common/LatchRestore.hGameEngine/Include/Common/List.hGameEngine/Include/Common/LocalFile.hGameEngine/Include/Common/LocalFileSystem.h+GameEngine/Include/Common/LogicThread.hGameEngine/Include/Common/MapObject.hGameEngine/Include/Common/MapReaderWriterInfo.hGameEngine/Include/Common/MessageBoxFlags.h@@ -1083,6 +1084,7 @@ GameEngine/Source/Common/System/KindOf.cppGameEngine/Source/Common/System/List.cppGameEngine/Source/Common/System/LocalFile.cppGameEngine/Source/Common/System/LocalFileSystem.cpp+GameEngine/Source/Common/System/LogicThread.cppGameEngine/Source/Common/System/MemoryInit.cppGameEngine/Source/Common/System/ObjectStatusTypes.cppGameEngine/Source/Common/System/QuickTrig.cppdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.hnew file mode 100644index 000000000..4825ab14c--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h@@ -0,0 +1,100 @@+/*+** 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: LogicThread.h ////////////////////////////////////////////////////////////////////////////+// Desc: LOGIC-THREAD.md phase 1: GameLogic::update on a thread of its own, the main thread+// waiting for it, and a census of the client calls the tick makes from there.+////////////////////////////////////////////////////////////////////////////////////////////////////++#pragma once++#ifndef __LOGICTHREAD_H__+#define __LOGICTHREAD_H__++#include "Lib/BaseType.h"++/**+ * `-logicthread 0` (the default) runs the tick on the main thread, as it always ran.+ * `-logicthread 1` hands every tick to a dedicated thread and waits for it: nothing overlaps+ * yet, so nothing can race, and any code that cares which thread it is on shows itself.+ *+ * The census counts calls into the client made from the logic thread, one count per channel+ * of LOGIC-THREAD.md section 1's table. Each count is an entry point phase 2 has to turn into+ * a record replayed at the sync point; the phase 2 exit is every count at zero. At+ * `-logicthread 0` nothing runs on the logic thread and every count stays zero.+ */+namespace LogicThread+{++ enum Channel+ {+ CENSUS_DRAWABLE, ///< Object::getDrawable from the tick+ CENSUS_MODEL_CONDITION, ///< Drawable model condition setters+ CENSUS_AUDIO, ///< AudioManager add/remove event+ CENSUS_INGAMEUI, ///< TheInGameUI messages, floating text, selection, superweapons, idle workers+ CENSUS_CONTROLBAR, ///< TheControlBar dirty mark and command lookups+ CENSUS_TACTICALVIEW, ///< TheTacticalView camera moves, shakes, filters, the time freeze reads+ CENSUS_RADAR, ///< TheRadar objects, events, shroud+ CENSUS_FXLIST, ///< FXList::doFXPos / doFXObj+ CENSUS_TERRAINVISUAL, ///< TheTerrainVisual heights, bibs, the water grid+ CENSUS_PARTICLES, ///< ParticleSystemManager create, find, destroy+ CENSUS_GAMECLIENT, ///< TheGameClient destroyDrawable, findDrawableByID, addScorch, setFrame+ CENSUS_EVA, ///< TheEva setShouldPlay+ CENSUS_NEW_DRAWABLE, ///< ThingFactory::newDrawable+ CENSUS_CLIENT_RANDOM, ///< GameClientRandomValue draws+ CENSUS_GHOST, ///< GhostObjectManager add/remove+ CENSUS_MESSAGESTREAM, ///< MessageStream::appendMessage+ CENSUS_DISPLAY, ///< TheDisplay shroud levels+ CENSUS_JOBS, ///< JobSystem::parallel_for+ CENSUS_COUNT+ };++ /** TRUE on the logic thread, FALSE everywhere else. Constant-initialised, so a read is one+ * thread-local load. */+ extern thread_local Bool t_isLogicThread;++ void noteCensus( Channel channel );++ inline void census( Channel channel )+ {+ if( t_isLogicThread )+ noteCensus( channel );+ }++ /** Read -logicthread and start the thread if it asks for one. Called once, from GameEngine::init. */+ void init( void );++ /** Join the thread. Safe without an init(). */+ void shutdown( void );++ /** Run one TheGameLogic->UPDATE(): on the logic thread with this one waiting, or inline at+ * -logicthread 0 and on the ticks that load or tear down a map, which build windows, the load+ * screen and every render object on the device and stay on the main thread. An exception+ * the tick throws is thrown again here, on the main thread, where GameEngine::execute catches+ * it as it always did. */+ void runTick( void );++ /** The census and the handoff cost, as HEADLESS LOGICTHREAD lines. */+ void report( void );++} // namespace LogicThread++#define LOGIC_CENSUS( channel ) LogicThread::census( LogicThread::channel )++#endif // __LOGICTHREAD_H__diff --git a/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h b/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.hindex 87d7a4d00..1050a0f52 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/NameKeyGenerator.h@@ -40,6 +40,7 @@#include "Common/GameMemory.h"#include "Common/AsciiString.h"+#include <mutex>#include <vector>//-------------------------------------------------------------------------------------------------@@ -130,6 +131,9 @@ private:/// Every bucket again, at its key less one. keyToName used to walk all 45007 sockets for each/// call, and a player's AI scripts ask it thousands of times: a fifth of a replay rewind.std::vector<Bucket*> m_bucketsByKey;+ /// LOGIC-THREAD.md hazard 12: both threads mint keys at run time, and two inserts at once break a+ /// socket's chain. Taken by every lookup; it is a leaf, apart from the pool lock a new Bucket takes.+ std::mutex m_lock;}; // end class NameKeyGeneratordiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.hindex b00df017b..7d1a730d5 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h@@ -34,6 +34,7 @@#define _GAME_INTERFACE_H_#include "Common/GameType.h"+#include "Common/LogicThread.h"#include "Common/MessageStream.h" // for GameMessageTranslator#include "Common/Snapshot.h"#include "Common/STLTypedefs.h"@@ -110,7 +111,7 @@ public:virtual void update( void ); ///< Updates the GUI, display, audio, etcvirtual void reset( void ); ///< reset system- virtual void setFrame( UnsignedInt frame ) { m_frame = frame; } ///< Set the GameClient's internal frame number+ virtual void setFrame( UnsignedInt frame ) { LOGIC_CENSUS( CENSUS_GAMECLIENT ); m_frame = frame; } ///< Set the GameClient's internal frame numbervirtual void registerDrawable( Drawable *draw ); ///< Given a drawable, register it with the GameClient and give it a unique IDvoid addDrawableToLookupTable( Drawable *draw ); ///< add drawable ID to hash lookup table@@ -273,6 +274,7 @@ private:*/inline Drawable* GameClient::findDrawableByID( const DrawableID id ){+ LOGIC_CENSUS( CENSUS_GAMECLIENT );if( id == INVALID_DRAWABLE_ID )return NULL;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.hindex dde4e4b48..8d2deacc0 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h@@ -158,6 +158,7 @@ public:Real getHeight( void ); ///< Returns the height of the worldBool isInGameLogicUpdate( void ) const { return m_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 numberUnsignedInt getCRC( Int mode = CRC_CACHED, AsciiString deepCRCFileName = AsciiString::TheEmptyString ); ///< Returns the CRCdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex 43b5a03f0..02d59c71c 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -35,6 +35,7 @@#include "Lib/BaseType.h"#include "Common/Geometry.h"+#include "Common/LogicThread.h"#include "Common/Snapshot.h"#include "Common/SpecialPowerMaskType.h"#include "Common/DisabledTypes.h"@@ -236,7 +237,7 @@ public:// ids and bindingObjectID getID() const { return m_id; } ///< this object's unique IDvoid friend_bindToDrawable( Drawable *draw ); ///< set drawable association. for use ONLY by GameLogic!- Drawable* getDrawable() const { return m_drawable; } ///< drawable (if any) bound to obj+ Drawable* getDrawable() const { LOGIC_CENSUS( CENSUS_DRAWABLE ); return m_drawable; } ///< drawable (if any) bound to objObjectID getProducerID() const { return m_producerID; }void setProducer(const Object* obj);diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cppindex 493d53a5b..d463c3854 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp@@ -45,6 +45,7 @@//----------------------------------------------------------------------------#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#include "Common/GameAudio.h"#include "Common/AudioAffect.h"@@ -428,6 +429,7 @@ void AudioManager::getInfoForAudioEvent( const AudioEventRTS *eventToFindAndFill//-------------------------------------------------------------------------------------------------AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd){+ LOGIC_CENSUS( CENSUS_AUDIO );if (eventToAdd->getEventName().isEmpty() || eventToAdd->getEventName() == AsciiString("NoSound")) {return AHSV_NoSound;}@@ -596,6 +598,7 @@ AsciiString AudioManager::prevTrackName(const AsciiString& currentTrack )//-------------------------------------------------------------------------------------------------void AudioManager::removeAudioEvent(AudioHandle audioEvent){+ LOGIC_CENSUS( CENSUS_AUDIO );if (audioEvent == AHSV_StopTheMusic || audioEvent == AHSV_StopTheMusicFade) {m_music->removeAudioEvent(audioEvent);return;@@ -654,6 +657,7 @@ void AudioManager::setAudioEventVolumeOverride( AsciiString eventToAffect, Real//-------------------------------------------------------------------------------------------------void AudioManager::removeAudioEvent( AsciiString eventToRemove ){+ LOGIC_CENSUS( CENSUS_AUDIO );removePlayingAudio( eventToRemove );}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex c3729a632..856259ad7 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -64,6 +64,7 @@#include "Common/GlobalData.h"#include "Common/PerfTimer.h"#include "Common/JobSystem.h"+#include "Common/LogicThread.h"#include "GameLogic/TerrainLogic.h" // -autocamera needs the map extent and the ground height#include "Common/RandomValue.h"#include "Common/NameKeyGenerator.h"@@ -542,6 +543,7 @@ GameEngine::~GameEngine()there is nothing to drain here - but a worker parked on the semaphore still has to be toldto leave, or the process waits on it at exit. */JobSystem::shutdown();+ LogicThread::shutdown();#ifdef PERF_TIMERSPerfGather::termPerfDump();@@ -946,6 +948,9 @@ void GameEngine::init( int argc, char *argv[] )Costs one thread per spare core sitting on a semaphore until something uses it. */JobSystem::init();+ // LOGIC-THREAD.md phase 1: -logicthread 1 starts the thread the ticks run on.+ LogicThread::init();+TheSubsystemList = MSGNEW("GameEngineSubsystem") SubsystemInterfaceList;TheSubsystemList->addSubsystem(this);@@ -2715,6 +2720,9 @@ static void updateHeadlessRun( void )DEBUG_LOG(("HEADLESS JOBS: %d worker threads, %d allocations from a job\n",JobSystem::workerCount(), JobSystem::workerAllocationCount()));+ // LOGIC-THREAD.md phase 1: the handoff cost, and the client calls phase 2 has to take off the tick.+ LogicThread::report();+// THREADING-ROADMAP.md section 0 step 3. Only a PERF_TIMERS build has anything to say here.#ifdef PERF_TIMERSPerfGather::dumpSummary();@@ -2965,7 +2973,8 @@ void GameEngine::update( void )const UnsignedInt frameBeforeTicks = TheGameLogic->getFrame();for( ;; ){- TheGameLogic->UPDATE();+ // TheGameLogic->UPDATE(), on the logic thread at -logicthread 1+ LogicThread::runTick();++logicTicksThisPass;// -maxframes' frame ends the burst, its CRC logged as it finishes (noteFrameLimit)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex fac5d1e9e..159e7d40c 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -28,6 +28,7 @@// Author: Michael S. Booth, February 2001#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#include "Common/MessageStream.h"#include "Common/Player.h"@@ -902,6 +903,7 @@ void MessageStream::update( void )*/GameMessage *MessageStream::appendMessage( GameMessage::Type type ){+ LOGIC_CENSUS( CENSUS_MESSAGESTREAM );GameMessage *msg = newInstance(GameMessage)( type );// add message to listdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp b/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cppindex e6d7d0267..eb9018202 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/NameKeyGenerator.cpp@@ -69,6 +69,7 @@ void NameKeyGenerator::init()//-------------------------------------------------------------------------------------------------void NameKeyGenerator::reset(){+ std::lock_guard<std::mutex> lock( m_lock );freeSockets();m_nextID = 1;@@ -114,6 +115,7 @@ inline UnsignedInt calcHashForLowercaseString(const char* p)//-------------------------------------------------------------------------------------------------AsciiString NameKeyGenerator::keyToName(NameKeyType key){+ std::lock_guard<std::mutex> lock( m_lock );// NAMEKEY_INVALID wraps to the largest index and misses with every other unknown keyconst UnsignedInt index = (UnsignedInt)key - 1;if (index >= m_bucketsByKey.size())@@ -127,6 +129,7 @@ NameKeyType NameKeyGenerator::nameToKey(const char* nameString)Bucket *b;UnsignedInt hash = calcHashForString(nameString) % SOCKET_COUNT;+ std::lock_guard<std::mutex> lock( m_lock );// hmm, do we have it already?for (b = m_sockets[hash]; b; b = b->m_nextInSocket)@@ -176,6 +179,7 @@ NameKeyType NameKeyGenerator::nameToLowercaseKey(const char* nameString)Bucket *b;UnsignedInt hash = calcHashForLowercaseString(nameString) % SOCKET_COUNT;+ std::lock_guard<std::mutex> lock( m_lock );// hmm, do we have it already?for (b = m_sockets[hash]; b; b = b->m_nextInSocket)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RandomValue.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RandomValue.cppindex 06af3edcf..6f54062df 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RandomValue.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RandomValue.cpp@@ -29,6 +29,7 @@// Author: Michael S. Booth, January 1998#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#include "Lib/BaseType.h"@@ -290,6 +291,7 @@ Real GetGameLogicRandomValueRealUnchanged( Real lo, Real hi )//Int GetGameClientRandomValue( int lo, int hi, char *file, int line ){+ LOGIC_CENSUS( CENSUS_CLIENT_RANDOM );UnsignedInt delta = hi - lo + 1;Int rval;@@ -360,6 +362,7 @@ DEBUG_LOG(( "%d: GetGameLogicRandomValueReal = %f, %s line %d\n",//Real GetGameClientRandomValueReal( Real lo, Real hi, char *file, int line ){+ LOGIC_CENSUS( CENSUS_CLIENT_RANDOM );Real delta = hi - lo;Real rval;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cppindex a82b43a12..9bbfdadf1 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp@@ -318,6 +318,13 @@ static void flushLogFileAtMostOnceASecond(void)static void doLogOutput(const char *buffer){+ /* DebugLog already holds this lock around its static buffer; DebugCrash and the stack dump reach+ the file without it, and with the logic on a thread of its own (LOGIC-THREAD.md hazard 20) two+ threads writing at once tear a line. The lock is recursive, so DebugLog taking it twice is free. */+#ifdef DEBUG_THREADSAFE+ ScopedCriticalSection scopedCriticalSection(TheDebugLogCriticalSection);+#endif+// log message to fileif (theDebugFlags & DEBUG_FLAG_LOG_TO_FILE){diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/JobSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/JobSystem.cppindex c1fb7b485..8cca1fe81 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/JobSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/JobSystem.cpp@@ -23,6 +23,7 @@#include "PreRTS.h"#include "Common/JobSystem.h"+#include "Common/LogicThread.h"#include "Common/EarlyCommandLine.h"#include "GameLogic/FPUControl.h"@@ -324,6 +325,9 @@ void JobSystem::noteWorkerAllocation( void )//-------------------------------------------------------------------------------------------------void JobSystem::parallel_for( Int count, Int granularity, JobFunc fn, void *context ){+ // The fork state above is one global: only the main thread may fork (LOGIC-THREAD.md hazard 14).+ LOGIC_CENSUS( CENSUS_JOBS );+if( count <= 0 || fn == NULL )return;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cppnew file mode 100644index 000000000..720c4d00a--- /dev/null+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp@@ -0,0 +1,263 @@+/*+** 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: LogicThread.cpp //////////////////////////////////////////////////////////////////////////+// Desc: LOGIC-THREAD.md phase 1: the tick on its own thread, serialised with the main thread.+////////////////////////////////////////////////////////////////////////////////////////////////////++#include "PreRTS.h"+#include "Common/LogicThread.h"+#include "Common/EarlyCommandLine.h"+#include "Common/MessageStream.h"+#include "GameLogic/FPUControl.h"+#include "GameLogic/GameLogic.h"++#include <chrono>+#include <condition_variable>+#include <exception>+#include <mutex>+#include <thread>+#if defined(_WIN32)+#include <eh.h>+#endif++thread_local Bool LogicThread::t_isLogicThread = FALSE;++namespace+{+ typedef std::chrono::steady_clock LogicClock;++ Bool s_enabled = FALSE;+ /* A pointer, so a process that ends without ~GameEngine (a RELEASE_CRASH, exit() from a menu)+ does not run a joinable std::thread's destructor at static teardown, which is std::terminate. */+ std::thread *s_thread = NULL;++ /* One request and one answer, both under s_lock. The main thread sets s_tickPending and waits+ for s_tickDone; the logic thread waits for s_tickPending, runs the tick, sets s_tickDone. The+ lock's release and acquire on each side is what publishes everything the other thread wrote+ before it, which is the whole of the memory model phase 1 needs: one thread runs at a time. */+ std::mutex s_lock;+ std::condition_variable s_wakeCv;+ std::condition_variable s_doneCv;+ Bool s_tickPending = FALSE;+ Bool s_tickDone = FALSE;+ Bool s_quitting = FALSE;+ std::exception_ptr s_error;+ Real s_tickMS = 0.0f; ///< the tick as the logic thread timed it++ // Written by the logic thread only, read by the main thread after a handoff has published them.+ Int64 s_census[ LogicThread::CENSUS_COUNT ] = { 0 };++ // Main thread only.+ Int s_threadedTicks = 0;+ Int s_inlineTicks = 0;+ Real s_handoffTotalMS = 0.0f;+ Real s_handoffMaxMS = 0.0f;+ // The handoff in microseconds, one bucket each up to a millisecond; the last bucket is everything past it.+ const Int HANDOFF_BUCKETS = 1001;+ Int s_handoffHistogram[ HANDOFF_BUCKETS ] = { 0 };++ const char *const CHANNEL_NAMES[ LogicThread::CENSUS_COUNT ] =+ {+ "drawable", "modelcondition", "audio", "ingameui", "controlbar", "tacticalview", "radar",+ "fxlist", "terrainvisual", "particles", "gameclient", "eva", "newdrawable", "clientrandom",+ "ghost", "messagestream", "display", "jobs"+ };++ Real elapsedMS( LogicClock::time_point a, LogicClock::time_point b )+ {+ return std::chrono::duration<Real, std::milli>( b - a ).count();+ }++#if defined(_WIN32)+ /* WinMain's _set_se_translator covers only the thread that set it. Without it here a fault in the+ tick reached the catch below as a bare structured exception and the dump showed the main thread's+ stack after the rethrow, not the fault's. */+ _se_translator_function s_seTranslator = NULL;+#endif++ void threadMain( void )+ {+#if defined(_WIN32)+ _set_se_translator( s_seTranslator );+#endif+ LogicThread::t_isLogicThread = TRUE;+ // GameLogic::update sets it again on entry; a new thread starts on the CRT default.+ setFPMode();++ for( ;; )+ {+ {+ std::unique_lock<std::mutex> lock( s_lock );+ s_wakeCv.wait( lock, []{ return s_tickPending || s_quitting; } );+ if( s_quitting )+ break;+ s_tickPending = FALSE;+ }++ const LogicClock::time_point t0 = LogicClock::now();+ std::exception_ptr error;+ try+ {+ TheGameLogic->UPDATE();+ }+ catch( ... )+ {+ error = std::current_exception();+ }+ const LogicClock::time_point t1 = LogicClock::now();++ {+ std::lock_guard<std::mutex> lock( s_lock );+ s_error = error;+ s_tickMS = elapsedMS( t0, t1 );+ s_tickDone = TRUE;+ }+ s_doneCv.notify_one();+ }+ }++ /* A tick that starts or ends a map builds the load screen, pushes shell windows, pumps the window+ messages and creates every render object of the map on the device. The plan's invariant puts+ loading and teardown at the sync point with the logic thread parked, and in phase 1 that means+ these ticks run where they always ran. */+ Bool tickNeedsMainThread( void )+ {+ return TheGameLogic->isNewGamePending()+ || TheCommandList->containsMessageOfType( GameMessage::MSG_NEW_GAME )+ || TheCommandList->containsMessageOfType( GameMessage::MSG_CLEAR_GAME_DATA );+ }++ Int handoffPercentileMicros( Real fraction )+ {+ const Int want = (Int)( s_threadedTicks * fraction );+ Int seen = 0;+ for( Int i = 0; i < HANDOFF_BUCKETS; ++i )+ {+ seen += s_handoffHistogram[ i ];+ if( seen > want )+ return i;+ }+ return HANDOFF_BUCKETS - 1;+ }++} // anonymous namespace++//-------------------------------------------------------------------------------------------------+void LogicThread::noteCensus( Channel channel )+{+ ++s_census[ channel ];+}++//-------------------------------------------------------------------------------------------------+void LogicThread::init( void )+{+ char value[ 32 ];+ if( !findEarlyCommandLineValue( L"-logicthread", value, sizeof(value) ) || atoi( value ) == 0 )+ return;++ s_enabled = TRUE;+#if defined(_WIN32)+ // there is no getter: setting returns the one before, which goes straight back+ s_seTranslator = _set_se_translator( NULL );+ _set_se_translator( s_seTranslator );+#endif+ s_thread = new std::thread( threadMain );+ DEBUG_LOG(( "LOGICTHREAD: the tick runs on its own thread, the main thread waiting for it\n" ));+}++//-------------------------------------------------------------------------------------------------+void LogicThread::shutdown( void )+{+ if( s_thread == NULL )+ return;+ {+ std::lock_guard<std::mutex> lock( s_lock );+ s_quitting = TRUE;+ }+ s_wakeCv.notify_one();+ s_thread->join();+ delete s_thread;+ s_thread = NULL;+ s_enabled = FALSE;+}++//-------------------------------------------------------------------------------------------------+void LogicThread::runTick( void )+{+ if( !s_enabled || tickNeedsMainThread() )+ {+ ++s_inlineTicks;+ TheGameLogic->UPDATE();+ return;+ }++ const LogicClock::time_point t0 = LogicClock::now();+ {+ std::lock_guard<std::mutex> lock( s_lock );+ s_tickPending = TRUE;+ }+ s_wakeCv.notify_one();++ std::exception_ptr error;+ Real tickMS;+ {+ std::unique_lock<std::mutex> lock( s_lock );+ s_doneCv.wait( lock, []{ return s_tickDone; } );+ s_tickDone = FALSE;+ error = s_error;+ s_error = NULL;+ tickMS = s_tickMS;+ }+ const LogicClock::time_point t1 = LogicClock::now();++ // The inline tick left this thread's FPU in setFPMode's state; keep the main thread as it was at 0.+ setFPMode();++ // What the thread costs: the wait less the tick the logic thread timed for itself.+ Real handoffMS = elapsedMS( t0, t1 ) - tickMS;+ if( handoffMS < 0.0f )+ handoffMS = 0.0f;+ ++s_threadedTicks;+ s_handoffTotalMS += handoffMS;+ if( handoffMS > s_handoffMaxMS )+ s_handoffMaxMS = handoffMS;+ Int bucket = (Int)( handoffMS * 1000.0f );+ if( bucket >= HANDOFF_BUCKETS )+ bucket = HANDOFF_BUCKETS - 1;+ ++s_handoffHistogram[ bucket ];++ if( error )+ std::rethrow_exception( error );+}++//-------------------------------------------------------------------------------------------------+void LogicThread::report( void )+{+ DEBUG_LOG(( "HEADLESS LOGICTHREAD: %s | %d ticks on the logic thread, %d on the main thread | handoff %.3f/%.3f/%.3f max %.3f ms mean/p50/p99\n",+ s_enabled ? "on" : "off", s_threadedTicks, s_inlineTicks,+ s_threadedTicks ? s_handoffTotalMS / s_threadedTicks : 0.0f,+ handoffPercentileMicros( 0.5f ) / 1000.0f, handoffPercentileMicros( 0.99f ) / 1000.0f, s_handoffMaxMS ));++ char line[ 1024 ];+ Int used = 0;+ for( Int i = 0; i < CENSUS_COUNT; ++i )+ used += snprintf( line + used, sizeof(line) - used, "%s%s %lld", i ? " | " : "", CHANNEL_NAMES[ i ], (long long)s_census[ i ] );+ DEBUG_LOG(( "HEADLESS LOGICTHREAD CENSUS: %s\n", line ));+}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cppindex e60cd2197..a62c7eac9 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp@@ -32,6 +32,7 @@#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine#include "Common/GameAudio.h"+#include "Common/LogicThread.h"#include "Common/GameState.h"#include "Common/MiscAudio.h"#include "Common/Radar.h"@@ -401,6 +402,7 @@ void Radar::newMap( TerrainLogic *terrain )//-------------------------------------------------------------------------------------------------void Radar::addObject( Object *obj ){+ LOGIC_CENSUS( CENSUS_RADAR );// get the radar priority for this objectRadarPriorityType newPriority = obj->getRadarPriority();@@ -600,6 +602,7 @@ Bool Radar::deleteFromList( Object *obj, RadarObject **list )//-------------------------------------------------------------------------------------------------void Radar::removeObject( Object *obj ){+ LOGIC_CENSUS( CENSUS_RADAR );// sanityif( obj->friend_getRadarData() == NULL )@@ -1030,6 +1033,7 @@ static RadarColorLookup radarColorLookupTable[] =//-------------------------------------------------------------------------------------------------void Radar::createEvent( const Coord3D *world, RadarEventType type, Real secondsToLive ){+ LOGIC_CENSUS( CENSUS_RADAR );// sanityif( world == NULL )@@ -1280,6 +1284,7 @@ void Radar::tryUnderAttackEvent( const Object *obj )// ------------------------------------------------------------------------------------------------void Radar::tryInfiltrationEvent( const Object *obj ){+ LOGIC_CENSUS( CENSUS_RADAR );//Sanity!if( !obj )@@ -1316,6 +1321,7 @@ void Radar::tryInfiltrationEvent( const Object *obj )// ------------------------------------------------------------------------------------------------Bool Radar::tryEvent( RadarEventType event, const Coord3D *pos ){+ LOGIC_CENSUS( CENSUS_RADAR );// sanityif( event <= RADAR_EVENT_INVALID || event >= RADAR_EVENT_NUM_EVENTS || pos == NULL )diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cppindex 759dea87f..0efa68815 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp@@ -31,6 +31,7 @@// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#include "zhio.h"#include "Common/ThingFactory.h"@@ -368,6 +369,7 @@ Object *ThingFactory::newObject( const ThingTemplate *tmplate, Team *team, Objec//=============================================================================Drawable *ThingFactory::newDrawable(const ThingTemplate *tmplate, DrawableStatus statusBits){+ LOGIC_CENSUS( CENSUS_NEW_DRAWABLE );if (tmplate == NULL)throw ERROR_BAD_ARG;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex f06a59b4f..297c85177 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -33,6 +33,7 @@#include "Lib/Clock.h"#include "Common/AudioEventInfo.h"+#include "Common/LogicThread.h"#include "Common/DynamicAudioEventInfo.h"#include "Common/AudioSettings.h"#include "Common/BitFlagsIO.h"@@ -5063,6 +5064,7 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)//-------------------------------------------------------------------------------------------------void Drawable::clearAndSetModelConditionState( ModelConditionFlagType clr, ModelConditionFlagType set ){+ LOGIC_CENSUS( CENSUS_MODEL_CONDITION );ModelConditionFlags c, s;if (clr != MODELCONDITION_INVALID)c.set(clr);@@ -5141,6 +5143,7 @@ DrawModule const** Drawable::getDrawModules() const//-------------------------------------------------------------------------------------------------void Drawable::clearAndSetModelConditionFlags(const ModelConditionFlags& clr, const ModelConditionFlags& setf){+ LOGIC_CENSUS( CENSUS_MODEL_CONDITION );ModelConditionFlags oldFlags = m_conditionState;m_conditionState.clearAndSet(clr, setf);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cppindex 57fa77844..415c78b44 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp@@ -27,6 +27,7 @@// GameClient/Eva.cpp /////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#include "GameClient/Eva.h"#include "Common/Player.h"@@ -387,6 +388,7 @@ const EvaCheckInfo *Eva::getEvaCheckInfo(AsciiString name)//-------------------------------------------------------------------------------------------------void Eva::setShouldPlay(EvaMessage messageToPlay){+ LOGIC_CENSUS( CENSUS_EVA );m_shouldPlay[messageToPlay] = TRUE;// DEBUG_LOG( ( "Eva message %s play requested\n", messageToName( messageToPlay).str() ) );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cppindex b0104553c..3ffabf4fa 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/FXList.cpp@@ -35,6 +35,7 @@#include "GameClient/FXList.h"#include "Common/DrawModule.h"+#include "Common/LogicThread.h"#include "Common/GameAudio.h"#include "Common/INI.h"#include "Common/Player.h"@@ -870,6 +871,7 @@ void FXList::clear()//-------------------------------------------------------------------------------------------------void FXList::doFXPos(const Coord3D *primary, const Matrix3D* primaryMtx, const Real primarySpeed, const Coord3D *secondary, const Real overrideRadius ) const{+ LOGIC_CENSUS( CENSUS_FXLIST );if (ThePartitionManager->getShroudStatusForPlayer(TheObserverCamera.getShroudPlayerIndex(), primary) != CELLSHROUD_CLEAR)return;@@ -882,6 +884,7 @@ void FXList::doFXPos(const Coord3D *primary, const Matrix3D* primaryMtx, const R//-------------------------------------------------------------------------------------------------void FXList::doFXObj(const Object* primary, const Object* secondary) const{+ LOGIC_CENSUS( CENSUS_FXLIST );if (primary && primary->getShroudedStatus(TheObserverCamera.getShroudPlayerIndex()) > OBJECTSHROUD_PARTIAL_CLEAR)return; //the primary object is fogged or shrouded so don't bother with the effect.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex cdbccaa4c..2115a7935 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -32,6 +32,7 @@// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#include "Lib/Clock.h"#include <map>@@ -601,7 +602,8 @@ void ControlBar::pressCommandButton( Int place )/// mark the UI as dirty so the context of everything is re-evaluatedvoid ControlBar::markUIDirty( void )-{+{+ LOGIC_CENSUS( CENSUS_CONTROLBAR );m_UIDirty = TRUE;#if defined( _INTERNAL ) || defined( _DEBUG )@@ -3771,8 +3773,9 @@ CommandSet* ControlBar::findNonConstCommandSet( const AsciiString& name )//-------------------------------------------------------------------------------------------------/** find existing command button if present *///--------------------------------------------------------------------------------------------------const CommandButton *ControlBar::findCommandButton( const AsciiString& name )-{+const CommandButton *ControlBar::findCommandButton( const AsciiString& name )+{+ LOGIC_CENSUS( CENSUS_CONTROLBAR );CommandButton *btn = findNonConstCommandButton(name);if( btn ){@@ -3784,8 +3787,9 @@ const CommandButton *ControlBar::findCommandButton( const AsciiString& name )//-------------------------------------------------------------------------------------------------/** Find existing command set by name *///--------------------------------------------------------------------------------------------------const CommandSet *ControlBar::findCommandSet( const AsciiString& name )-{+const CommandSet *ControlBar::findCommandSet( const AsciiString& name )+{+ LOGIC_CENSUS( CENSUS_CONTROLBAR );CommandSet *set = findNonConstCommandSet(name);if (set)set = (CommandSet*)set->friend_getFinalOverride();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex bb98df302..9e225f421 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -1020,6 +1020,7 @@ void GameClient::updateFakeDrawables(void)*/void GameClient::destroyDrawable( Drawable *draw ){+ LOGIC_CENSUS( CENSUS_GAMECLIENT );// remove any notion of the Drawable in the in-game user interfaceTheInGameUI->disregardDrawable( draw );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 994db4400..3d8496761 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -30,6 +30,7 @@///////////////////////////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#if !defined(_WIN32)#include <unistd.h> // getpid, for the replay checkpoint folder#endif@@ -709,6 +710,7 @@ SuperweaponInfo* InGameUI::findSWInfo(Int playerIndex, const AsciiString& powerN// ------------------------------------------------------------------------------------------------void InGameUI::addSuperweapon(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate){+ LOGIC_CENSUS( CENSUS_INGAMEUI );if (powerTemplate == NULL)return;@@ -749,6 +751,7 @@ void InGameUI::addSuperweapon(Int playerIndex, const AsciiString& powerName, Obj// ------------------------------------------------------------------------------------------------Bool InGameUI::removeSuperweapon(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate){+ LOGIC_CENSUS( CENSUS_INGAMEUI );DEBUG_LOG(("Removing superweapon UI timer\n"));SuperweaponMap::iterator mapIt = m_superweapons[playerIndex].find(powerName);if (mapIt != m_superweapons[playerIndex].end())@@ -2927,6 +2930,7 @@ void InGameUI::drawClassicSuperweapon( SuperweaponInfo *info, const AsciiString// srj sez: passing as const-ref screws up varargs for some reason. dunno why. just pass by value.void InGameUI::message( AsciiString stringManagerLabel, ... ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );UnicodeString stringManagerString;UnicodeString formattedMessage;@@ -2958,6 +2962,7 @@ void InGameUI::message( AsciiString stringManagerLabel, ... )// srj sez: passing as const-ref screws up varargs for some reason. dunno why. just pass by value.void InGameUI::message( UnicodeString format, ... ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );UnicodeString formattedMessage;// construct the final text after formatting@@ -5997,6 +6002,7 @@ Bool InGameUI::rotatePendingPlacement( Int steps )//-------------------------------------------------------------------------------------------------void InGameUI::selectDrawable( Drawable *draw ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );if( draw->isSelected() == FALSE ){@@ -6027,6 +6033,7 @@ void InGameUI::selectDrawable( Drawable *draw )//-------------------------------------------------------------------------------------------------void InGameUI::deselectDrawable( Drawable *draw ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );if( draw->isSelected() ){@@ -6065,6 +6072,7 @@ void InGameUI::deselectDrawable( Drawable *draw )//-------------------------------------------------------------------------------------------------void InGameUI::deselectAllDrawables( void ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();const Bool hadSelectedDrawables = !selected->empty();@@ -6108,6 +6116,7 @@ void InGameUI::deselectAllDrawables( void )//-------------------------------------------------------------------------------------------------const DrawableList *InGameUI::getAllSelectedDrawables( void ) const{+ LOGIC_CENSUS( CENSUS_INGAMEUI );return &m_selectedDrawables;}@@ -6167,6 +6176,7 @@ const DrawableList *InGameUI::getAllSelectedLocalDrawables( void )//-------------------------------------------------------------------------------------------------Drawable *InGameUI::getFirstSelectedDrawable( void ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );// sanityif( m_selectedDrawables.empty() )@@ -7750,6 +7760,7 @@ void InGameUI::buildRegion( const ICoord2D *anchor, const ICoord2D *dest, IRegio//-------------------------------------------------------------------------------------------------FloatingTextData *InGameUI::addFloatingText(const UnicodeString& text,const Coord3D *pos, Color color){+ LOGIC_CENSUS( CENSUS_INGAMEUI );if( !TheGameLogic->getDrawIconUI() )return NULL;@@ -9881,6 +9892,7 @@ void InGameUI::addWorldAnimation( Anim2DTemplate *animTemplate,Real durationInSeconds,Real zRisePerSecond ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );// sanityif( animTemplate == NULL || pos == NULL || durationInSeconds <= 0.0f )@@ -10066,6 +10078,7 @@ Object *InGameUI::findIdleWorker( Object *obj)void InGameUI::addIdleWorker( Object *obj ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );if(!obj)return;@@ -10078,6 +10091,7 @@ void InGameUI::addIdleWorker( Object *obj )void InGameUI::removeIdleWorker( Object *obj, Int playerNumber ){+ LOGIC_CENSUS( CENSUS_INGAMEUI );if(!obj)return;if(playerNumber < 0 || playerNumber >= MAX_PLAYER_COUNT) // we're leaving the game, so this is all screweddiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cppindex 7d3120c2a..0b003aaaf 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/System/ParticleSys.cpp@@ -30,6 +30,7 @@///////////////////////////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine+#include "Common/LogicThread.h"#define DEFINE_PARTICLE_SYSTEM_NAMES@@ -3837,6 +3838,7 @@ void ParticleSystemManager::setOnScreenParticleCount(int count)// ------------------------------------------------------------------------------------------------ParticleSystem *ParticleSystemManager::createParticleSystem( const ParticleSystemTemplate *sysTemplate, Bool createSlaves ){+ LOGIC_CENSUS( CENSUS_PARTICLES );// sanityif (sysTemplate == NULL)return NULL;@@ -3865,6 +3867,7 @@ ParticleSystemID ParticleSystemManager::createAttachedParticleSystemID(// ------------------------------------------------------------------------------------------------ParticleSystem *ParticleSystemManager::findParticleSystem( ParticleSystemID id ){+ LOGIC_CENSUS( CENSUS_PARTICLES );if (id == INVALID_PARTICLE_SYSTEM_ID)return NULL; // my, that was easydiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.hindex 51041272f..083ac232b 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h@@ -42,6 +42,7 @@// SYSTEM INCLUDES ////////////////////////////////////////////////////////////////////////////////// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////+#include "Common/LogicThread.h"#include "Common/STLTypedefs.h"#include "GameClient/ParabolicEase.h"#include "GameClient/View.h"@@ -178,7 +179,7 @@ public:virtual void rotateCameraTowardPosition(const Coord3D *pLoc, Int milliseconds, Real easeIn, Real easeOut, Bool reverseRotation); ///< Rotate camera to face a location.virtual void cameraModFreezeTime(void){ m_freezeTimeForCameraMovement = true;} ///< Freezes time during the next camera movement.virtual void cameraModFreezeAngle(void); ///< Freezes time during the next camera movement.- virtual Bool isTimeFrozen(void){ return m_freezeTimeForCameraMovement;} ///< Freezes time during the next camera movement.+ virtual Bool isTimeFrozen(void){ LOGIC_CENSUS( CENSUS_TACTICALVIEW ); return m_freezeTimeForCameraMovement;} ///< Freezes time during the next camera movement.virtual void cameraModFinalZoom(Real finalZoom, Real easeIn, Real easeOut); ///< Final zoom for current camera movement.virtual void cameraModRollingAverage(Int framesToAverage); ///< Number of frames to average movement for current camera movement.virtual void cameraModFinalTimeMultiplier(Int finalMultiplier); ///< Final time multiplier for current camera movement.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cppindex 2f0be6bae..bf1c9605d 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp@@ -32,6 +32,7 @@// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////#include "Common/AudioEventRTS.h"+#include "Common/LogicThread.h"#include "Common/Debug.h"#include "Common/GlobalData.h"#include "Common/Player.h"@@ -1274,6 +1275,7 @@ void W3DRadar::clearShroud()//-------------------------------------------------------------------------------------------------void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting){+ LOGIC_CENSUS( CENSUS_RADAR );#if defined(_DEBUG) || defined(_INTERNAL)if (!TheGlobalData->m_shroudOn)return;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex 4062afc41..ce23f116f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -52,6 +52,7 @@ static void drawFramerateBar(void);// USER INCLUDES //////////////////////////////////////////////////////////////#include "Common/ThingFactory.h"+#include "Common/LogicThread.h"#include "Common/GameEngine.h"#include "Common/GlobalData.h"#include "Common/Monitors.h"@@ -3805,6 +3806,7 @@ void W3DDisplay::clearShroud()//=============================================================================void W3DDisplay::setBorderShroudLevel(UnsignedByte level){+ LOGIC_CENSUS( CENSUS_DISPLAY );if (TheTerrainRenderObject && TheTerrainRenderObject->getShroud()){TheTerrainRenderObject->getShroud()->setBorderShroudLevel((W3DShroudLevel)level);@@ -3814,6 +3816,7 @@ void W3DDisplay::setBorderShroudLevel(UnsignedByte level)//=============================================================================void W3DDisplay::setShroudLevel( Int x, Int y, CellShroudStatus setting ){+ LOGIC_CENSUS( CENSUS_DISPLAY );if (TheTerrainRenderObject && TheTerrainRenderObject->getShroud()){#ifdef INTENSE_DEBUGdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cppindex 1e0dac43e..b1e98da15 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp@@ -134,6 +134,7 @@ Drawable *W3DGameClient::friend_createDrawable( const ThingTemplate *tmplate,//-------------------------------------------------------------------------------------------------void W3DGameClient::addScorch(const Coord3D *pos, Real radius, Scorches type){+ LOGIC_CENSUS( CENSUS_GAMECLIENT );if (TheTerrainRenderObject){Vector3 loc(pos->x, pos->y, pos->z);diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cppindex aa096b7a6..02f909b9e 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp@@ -36,6 +36,7 @@#endif#include "Common/GameState.h"+#include "Common/LogicThread.h"#include "Common/GlobalData.h"#include "Common/PerfTimer.h"#include "Common/MapReaderWriterInfo.h"@@ -927,6 +928,7 @@ void W3DTerrainVisual::addWaterVelocity( Real worldX, Real worldY,// ------------------------------------------------------------------------------------------------void W3DTerrainVisual::updateWaterGrid( UnsignedInt logicFrame ){+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );// whether or not the grid is drawn: the simulation reads it either way, as update() stepped itif( m_waterRenderObject )m_waterRenderObject->updateMeshMotion( logicFrame );@@ -936,6 +938,7 @@ void W3DTerrainVisual::updateWaterGrid( UnsignedInt logicFrame )// ------------------------------------------------------------------------------------------------Bool W3DTerrainVisual::getWaterGridHeight( Real worldX, Real worldY, Real *height){+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );Real gridX, gridY;if (m_isWaterGridRenderingEnabled && m_waterRenderObject &&@@ -951,6 +954,7 @@ Bool W3DTerrainVisual::getWaterGridHeight( Real worldX, Real worldY, Real *heigh// ------------------------------------------------------------------------------------------------void W3DTerrainVisual::setRawMapHeight(const ICoord2D *gridPos, Int height){+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );// This method writes to the m_logicHeightMap member,// since m_logicHeightMap is the true, golden standard to which m_clientHeightMap// interpolates during or after its Seismic simulation displaces it..@@ -1104,6 +1108,7 @@ void W3DTerrainVisual::removeFactionBib(Object *factionBuilding)// ------------------------------------------------------------------------------------------------void W3DTerrainVisual::removeAllBibs(void){+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );if (m_terrainRenderObject) {m_terrainRenderObject->removeAllTerrainBibs();}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex 3acfd774f..e320baa25 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -2243,6 +2243,7 @@ Bool W3DView::setViewFilterMode(enum FilterModes filterMode)//-------------------------------------------------------------------------------------------------Bool W3DView::setViewFilter(enum FilterTypes filter){+ LOGIC_CENSUS( CENSUS_TACTICALVIEW );FilterTypes oldFilter = m_viewFilter; //save previous filter in case setup fails.m_viewFilter = filter;@@ -3289,8 +3290,9 @@ Bool W3DView::screenToTerrain( const ICoord2D *screen, Coord3D *world )//-------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------void W3DView::lookAt( const Coord3D *o )+void W3DView::lookAt( const Coord3D *o ){+ LOGIC_CENSUS( CENSUS_TACTICALVIEW );Coord3D pos = *o;@@ -3399,6 +3401,7 @@ void W3DView::initHeightForMap( void )//-------------------------------------------------------------------------------------------------void W3DView::moveCameraTo(const Coord3D *o, Int milliseconds, Int shutter, Bool orient, Real easeIn, Real easeOut){+ LOGIC_CENSUS( CENSUS_TACTICALVIEW );m_mcwpInfo.waypoints[0] = *getPosition();m_mcwpInfo.cameraAngle[0] = getAngle();m_mcwpInfo.waySegLength[0] = 0;@@ -3814,6 +3817,7 @@ void W3DView::resetCamera(const Coord3D *location, Int milliseconds, Real easeIn// ------------------------------------------------------------------------------------------------Bool W3DView::isCameraMovementFinished(void){+ LOGIC_CENSUS( CENSUS_TACTICALVIEW );if (m_viewFilter == FT_VIEW_MOTION_BLUR_FILTER) {// Several of the motion blur effects are similar to camera movements.if (m_viewFilterMode == FM_VIEW_MB_IN_AND_OUT_ALPHA ||@@ -4249,6 +4253,7 @@ void W3DView::moveAlongWaypointPath(Int milliseconds)// ------------------------------------------------------------------------------------------------void W3DView::shake( const Coord3D *epicenter, CameraShakeType shakeType ){+ LOGIC_CENSUS( CENSUS_TACTICALVIEW );Real angle = GameClientRandomValueReal( 0, 2*PI );m_shakeAngleCos = (Real)cos( angle );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cppindex cdb5f319f..cba106124 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp@@ -33,6 +33,7 @@///////////////////////////////////////////////////////////////////////////////#include "Common/Debug.h"+#include "Common/LogicThread.h"#include "Common/Player.h"#include "Common/PlayerList.h"#include "Common/ThingTemplate.h"@@ -913,6 +914,7 @@ void W3DGhostObjectManager::reset(void)// ------------------------------------------------------------------------------------------------void W3DGhostObjectManager::removeGhostObject(GhostObject *object){+ LOGIC_CENSUS( CENSUS_GHOST );if (!object)return;@@ -940,6 +942,7 @@ void W3DGhostObjectManager::removeGhostObject(GhostObject *object)// ------------------------------------------------------------------------------------------------GhostObject *W3DGhostObjectManager::addGhostObject(Object *object, PartitionData *pd){+ LOGIC_CENSUS( CENSUS_GHOST );// we disabled adding new ghost objects - used during map border resizing and loadingif (m_lockGhostObjects || m_saveLockGhostObjects )