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): queue the tick's ui, camera, radar and terrain calls

Olcay Seygan910b4614a194
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
index 737304aa1..afa15787a 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
@@ -69,6 +69,7 @@ namespace LogicThread
CENSUS_DRAWABLE_PUSH, ///< Drawable::doClientWork run inside the tick: hidden, colour, decal, shadows, sub-objects, ambient sound, caption
CENSUS_DESTROY_DRAWABLE, ///< a drawable deleted: draw modules, render objects, shadows (M4: after the tick for one logic destroyed)
CENSUS_AUDIO_READ, ///< a logic read of the audio device: sound lengths, a track done, a handle still playing (hazard 4, M7)
+ CENSUS_CLIENT_READ, ///< a logic read of other client state: selection, input enabled, camera, the water grid (hazard 4, M7)
CENSUS_COUNT
};
@@ -110,6 +111,17 @@ namespace LogicThread
/** Inside a tick, queue `call` for after it; anywhere else, run it now. */
void callAfterTick( const std::function<void()>& call );
+ /** LOGIC-THREAD.md phase 2, M6. The camera calls a tick's scripts make (moves, filters, letterbox,
+ * fades, the time freeze) wait in a queue of their own, run first after the tick. Their own queue,
+ * because a script asks the camera back in the same tick whether its move is finished and whether
+ * time is frozen: readViewFromTick runs what is queued before such a read, so the answer is the
+ * one an immediate call gave. That run counts as ondemandflush, not tacticalview; the read itself
+ * counts as clientread, which M7's captured block replaces. */
+ void callViewAfterTick( const std::function<void()>& call );
+ void readViewFromTick( void );
+ /** defersEffects, except while readViewFromTick runs the queue: then a camera call runs its body. */
+ Bool defersView( void );
+
/** The tick cleared the game: what it queued has no game left to play in. GameEngine::reset. */
void discardEffects( void );
@@ -117,4 +129,10 @@ namespace LogicThread
#define LOGIC_CENSUS( channel ) LogicThread::census( LogicThread::channel )
+/** LOGIC-THREAD.md phase 2, M6. First line of a client entry point logic calls: inside a tick the
+ * call queues itself (a lambda calling the function again with copies of its arguments) and returns;
+ * after the tick the copy runs the body on the main thread. A void function only. */
+#define LOGIC_AFTER_TICK( ... ) \
+ if( LogicThread::defersEffects() ) { LogicThread::callAfterTick( __VA_ARGS__ ); return; }
+
#endif // __LOGICTHREAD_H__
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Radar.h b/GeneralsMD/Code/GameEngine/Include/Common/Radar.h
index 4599b0569..b92260650 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Radar.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Radar.h
@@ -112,6 +112,12 @@ public:
Bool isTemporarilyHidden() const;
+ /** The object's radar priority when it went on the list. The insert walks the list by it rather
+ * than through the objects, because after a tick (LOGIC-THREAD.md M6) the list can still hold
+ * the entry of an object that tick destroyed, its removal queued behind the insert. */
+ inline void friend_setPriority( Int priority ) { m_priority = priority; }
+ inline Int friend_getPriority( void ) const { return m_priority; }
+
protected:
// snapshot methods
@@ -122,6 +128,7 @@ protected:
Object *m_object; ///< the object
RadarObject *m_next; ///< next radar object
Color m_color; ///< color to draw for this object on the radar
+ Int m_priority; ///< RadarPriorityType at the add, see friend_getPriority
};
@@ -239,6 +246,7 @@ protected:
void deleteListResources( void ); ///< delete list radar resources used
Bool deleteFromList( Object *obj, RadarObject **list ); ///< try to remove object from specific list
+ Bool unlinkEntry( RadarObject *entry, RadarObject **list ); ///< take an entry off a list by its address
inline Real getTerrainAverageZ() const { return m_terrainAverageZ; }
inline Real getWaterAverageZ() const { return m_waterAverageZ; }
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index b3cda1099..6e45bc7c7 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -543,6 +543,7 @@ public: // ********************************************************************
virtual void hideObjectSuperweaponDisplayByScript(const Object *obj);
virtual void showObjectSuperweaponDisplayByScript(const Object *obj);
+ void setObjectSuperweaponHiddenByScript( ObjectID objID, Bool hidden ); ///< both of the above, after the tick when a tick asks
void addNamedTimer( const AsciiString& timerName, const UnicodeString& text, Bool isCountdown );
void removeNamedTimer( const AsciiString& timerName );
@@ -1075,7 +1076,7 @@ public: // ********************************************************************
virtual void buildRegion( const ICoord2D *anchor, const ICoord2D *dest, IRegion2D *region ); ///< builds a region around the specified coordinates
virtual Bool getDisplayedMaxWarning( void ) { return m_displayedMaxWarning; }
- virtual void setDisplayedMaxWarning( Bool selected ) { m_displayedMaxWarning = selected; }
+ virtual void setDisplayedMaxWarning( Bool selected );
// Floating Test Methods
/// the text it added, for a caller that wants to hold it longer; NULL while icons are not drawn
@@ -1162,6 +1163,7 @@ public: // ********************************************************************
void resetCamera();
virtual void addIdleWorker( Object *obj );
+ void addIdleWorkerFor( Object *obj, Int playerIndex ); ///< addIdleWorker with the owner read at the call
virtual void removeIdleWorker( Object *obj, Int playerNumber );
virtual Object *selectNextIdleWorker( void ); ///< what it selected, NULL with no idle worker; never moves the camera
void selectNextIdleUnit( KindOfMaskType mustBeSet, KindOfMaskType mustBeClear ); ///< the same cycle for fighting units of those kinds standing with no order
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
index 159e7d40c..06982d750 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
@@ -903,9 +903,19 @@ void MessageStream::update( void )
*/
GameMessage *MessageStream::appendMessage( GameMessage::Type type )
{
- LOGIC_CENSUS( CENSUS_MESSAGESTREAM );
GameMessage *msg = newInstance(GameMessage)( type );
+ /* LOGIC-THREAD.md phase 2, M6. A message the tick appends (its CRC, a selection it changes) is
+ made and handed back at once, so the caller can fill in its arguments, and joins the stream after
+ the tick, in order with everything else the tick queued; propagateMessages comes later either way,
+ in the client pass or between network catch-up ticks. */
+ if( LogicThread::defersEffects() )
+ {
+ LogicThread::callAfterTick( [this, msg]() { GameMessageList::appendMessage( msg ); } );
+ return msg;
+ }
+
+ LOGIC_CENSUS( CENSUS_MESSAGESTREAM );
// add message to list
GameMessageList::appendMessage( msg );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
index c4364fe00..895ec9f3b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
@@ -83,20 +83,34 @@ namespace
"drawable", "modelcondition", "audio", "ingameui", "controlbar", "tacticalview", "radar",
"fxlist", "terrainvisual", "particles", "gameclient", "eva", "newdrawable", "clientrandom",
"ghost", "messagestream", "display", "jobs", "ondemandflush", "observerlookat",
- "drawablepush", "destroydrawable", "audioread"
+ "drawablepush", "destroydrawable", "audioread", "clientread"
};
// M5: what the tick asked of the audio, the FX lists and the particle systems, in call order.
// Filled inside the tick, run and emptied by flushAfterTick; one thread touches it at a time.
std::vector< std::function<void()> > s_effects;
+ // M6: the camera calls of the tick, see callViewAfterTick
+ std::vector< std::function<void()> > s_viewCalls;
+
+ void runViewCalls( void )
+ {
+ // swapped out first: a call that queues another (none does today) waits for the next run
+ std::vector< std::function<void()> > calls;
+ calls.swap( s_viewCalls );
+ for( size_t i = 0; i < calls.size(); ++i )
+ calls[ i ]();
+ }
+
/* Everything a tick left for the main thread, in the order it has to run: the drawables' work first
- (M1, M3, M4 builds the render objects of the drawables the tick made), then the effects, which
- attach to those drawables and read their bones, then the deletion of the drawables the tick
- destroyed, whose bones a death effect may still have read, then the control bar (M2). */
+ (M1, M3, M4 builds the render objects of the drawables the tick made), the camera (M6), then the
+ effects (M5, and M6's interface, radar, EVA, display and terrain pushes), which attach to those
+ drawables and read their bones, then the deletion of the drawables the tick destroyed, whose
+ bones a death effect may still have read, then the control bar (M2). */
void flushAfterTick( void )
{
Drawable::flushPendingClientWork();
+ runViewCalls();
// an effect queues nothing more: none of them runs inside a tick
for( size_t i = 0; i < s_effects.size(); ++i )
s_effects[ i ]();
@@ -293,10 +307,45 @@ void LogicThread::callAfterTick( const std::function<void()>& call )
call();
}
+//-------------------------------------------------------------------------------------------------
+// TRUE while readViewFromTick runs the queue inside the tick: a queued call runs its body then
+static Bool s_runningViewNow = FALSE;
+
+Bool LogicThread::defersView( void )
+{
+ return defersEffects() && !s_runningViewNow;
+}
+
+//-------------------------------------------------------------------------------------------------
+void LogicThread::callViewAfterTick( const std::function<void()>& call )
+{
+ if( defersView() )
+ s_viewCalls.push_back( call );
+ else
+ call();
+}
+
+//-------------------------------------------------------------------------------------------------
+void LogicThread::readViewFromTick( void )
+{
+ census( CENSUS_CLIENT_READ );
+ if( s_viewCalls.empty() )
+ return;
+ census( CENSUS_ON_DEMAND_FLUSH );
+ // the camera's own hooks would count this as the tick's tacticalview work; it is counted above
+ const Bool onLogicThread = t_isLogicThread;
+ t_isLogicThread = FALSE;
+ s_runningViewNow = TRUE;
+ runViewCalls();
+ s_runningViewNow = FALSE;
+ t_isLogicThread = onLogicThread;
+}
+
//-------------------------------------------------------------------------------------------------
void LogicThread::discardEffects( void )
{
s_effects.clear();
+ s_viewCalls.clear();
AudioEventRTS::forgetHeldCallers();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
index 200675478..b0b5015ae 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp
@@ -82,8 +82,9 @@ void Radar::deleteListResources( void )
// get next object
nextObject = m_localObjectList->friend_getNext();
- // remove radar data from object
- m_localObjectList->friend_getObject()->friend_setRadarData( NULL );
+ // remove radar data from object; none when a tick's remove was still queued (removeObject)
+ if( m_localObjectList->friend_getObject() )
+ m_localObjectList->friend_getObject()->friend_setRadarData( NULL );
// delete the head of the list
m_localObjectList->deleteInstance();
@@ -100,8 +101,9 @@ void Radar::deleteListResources( void )
// get next object
nextObject = m_objectList->friend_getNext();
- // remove radar data from object
- m_objectList->friend_getObject()->friend_setRadarData( NULL );
+ // remove radar data from object; none when a tick's remove was still queued (removeObject)
+ if( m_objectList->friend_getObject() )
+ m_objectList->friend_getObject()->friend_setRadarData( NULL );
// delete the head of the list
m_objectList->deleteInstance();
@@ -130,6 +132,7 @@ RadarObject::RadarObject( void )
m_object = NULL;
m_next = NULL;
m_color = GameMakeColor( 255, 255, 255, 255 );
+ m_priority = 0;
}
@@ -190,6 +193,7 @@ void RadarObject::xfer( Xfer *xfer )
// tell the object we now have some radar data
m_object->friend_setRadarData( this );
+ m_priority = m_object->getRadarPriority();
} // end if
@@ -402,6 +406,19 @@ void Radar::newMap( TerrainLogic *terrain )
//-------------------------------------------------------------------------------------------------
void Radar::addObject( Object *obj )
{
+ /* LOGIC-THREAD.md phase 2, M6. The tick's adds and removes wait for its end, in order. By ID,
+ since the tick may destroy the object first; then it never goes on, and a remove queued after
+ the add finds it on and takes it off again. */
+ if( LogicThread::defersEffects() )
+ {
+ const ObjectID id = obj->getID();
+ LogicThread::callAfterTick( [this, id]() {
+ Object *live = TheGameLogic->findObjectByID( id );
+ if( live && live->friend_getRadarData() == NULL )
+ addObject( live );
+ } );
+ return;
+ }
LOGIC_CENSUS( CENSUS_RADAR );
// get the radar priority for this object
@@ -475,6 +492,7 @@ void Radar::addObject( Object *obj )
// set a chunk of radar data in the object
obj->friend_setRadarData( newObj );
+ newObj->friend_setPriority( newPriority );
//
// we will put this on either the local object list for objects that belong to the
@@ -502,7 +520,7 @@ void Radar::addObject( Object *obj )
nextObject = currObject->friend_getNext();
// get the priority of this entry in the list (currPriority)
- currPriority = currObject->friend_getObject()->getRadarPriority();
+ currPriority = (RadarPriorityType)currObject->friend_getPriority();
//
// if there is no previous object, or the previous priority is less than the
@@ -597,11 +615,57 @@ Bool Radar::deleteFromList( Object *obj, RadarObject **list )
} // end deleteFromList
+//-------------------------------------------------------------------------------------------------
+/** Take `entry` off `list` by its own address, never reading its object. TRUE if it was there. */
+//-------------------------------------------------------------------------------------------------
+Bool Radar::unlinkEntry( RadarObject *entry, RadarObject **list )
+{
+ RadarObject *prev = NULL;
+ for( RadarObject *at = *list; at; prev = at, at = at->friend_getNext() )
+ {
+ if( at != entry )
+ continue;
+ if( prev == NULL )
+ *list = at->friend_getNext();
+ else
+ prev->friend_setNext( at->friend_getNext() );
+ return TRUE;
+ }
+ return FALSE;
+}
+
//-------------------------------------------------------------------------------------------------
/** Remove an object from the radar, the object may reside in any list */
//-------------------------------------------------------------------------------------------------
void Radar::removeObject( Object *obj )
{
+ if( LogicThread::defersEffects() )
+ {
+ // an entry the object has is taken from it now and off the list after the tick, without a look
+ // at the object, which the tick may free; one it has not got yet may be an add still queued
+ RadarObject *entry = obj->friend_getRadarData();
+ if( entry )
+ {
+ // a list torn down before the flush (the game cleared) then frees the entry without its object
+ obj->friend_setRadarData( NULL );
+ entry->friend_setObject( NULL );
+ LogicThread::callAfterTick( [this, entry]() {
+ if( !unlinkEntry( entry, &m_localObjectList ) )
+ unlinkEntry( entry, &m_objectList );
+ entry->deleteInstance();
+ } );
+ }
+ else
+ {
+ const ObjectID id = obj->getID();
+ LogicThread::callAfterTick( [this, id]() {
+ Object *live = TheGameLogic->findObjectByID( id );
+ if( live && live->friend_getRadarData() )
+ removeObject( live );
+ } );
+ }
+ return;
+ }
LOGIC_CENSUS( CENSUS_RADAR );
// sanity
@@ -1033,12 +1097,18 @@ static RadarColorLookup radarColorLookupTable[] =
//-------------------------------------------------------------------------------------------------
void Radar::createEvent( const Coord3D *world, RadarEventType type, Real secondsToLive )
{
- LOGIC_CENSUS( CENSUS_RADAR );
-
// sanity
if( world == NULL )
return;
+ if( LogicThread::defersEffects() )
+ {
+ const Coord3D at = *world;
+ LogicThread::callAfterTick( [=]() { createEvent( &at, type, secondsToLive ); } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_RADAR );
+
// lookup the colors we are to used based on the event
RGBAColorInt color[ 2 ];
// i is read after the loop to tell "found" from "ran off the end", so it
@@ -1086,6 +1156,14 @@ void Radar::createPlayerEvent( Player *player, const Coord3D *world,
if( player == NULL || world == NULL )
return;
+ if( LogicThread::defersEffects() )
+ {
+ const Coord3D at = *world;
+ LogicThread::callAfterTick( [=]() { createPlayerEvent( player, &at, type, secondsToLive ); } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_RADAR );
+
// figure out the two colors we should use
Color c;
UnsignedByte r, g, b, a;
@@ -1202,15 +1280,27 @@ void Radar::tryUnderAttackEvent( const Object *obj )
if( obj->isKindOf( KINDOF_NO_ATTACK_WARNING ) )
return;
- // try to create the event
- Bool eventCreated = tryEvent( RADAR_EVENT_UNDER_ATTACK, obj->getPosition() );
-
- // if event created, do some more feedback
- if( eventCreated )
+ /* LOGIC-THREAD.md phase 2, M6. What the warning says is read from the object at the call, since the
+ hit may kill it; whether it is given at all, and everything it shows and plays, waits for the end
+ of the tick (callAfterTick runs it at once outside one). */
+ enum { WARN_HARVESTER, WARN_UNIT, WARN_BASE, WARN_OTHER } kind = WARN_OTHER;
+ if( obj->isKindOf( KINDOF_INFANTRY ) || obj->isKindOf( KINDOF_VEHICLE ) )
+ kind = obj->isKindOf( KINDOF_HARVESTER ) ? WARN_HARVESTER : WARN_UNIT;
+ else if( obj->isKindOf( KINDOF_STRUCTURE ) && obj->isKindOf( KINDOF_MP_COUNT_FOR_VICTORY ) )
+ kind = WARN_BASE;
+ const Bool ours = obj->getControllingPlayer()->isLocalPlayer();
+ const Bool allied = ThePlayerList->getLocalPlayer()->getRelationship( obj->getTeam() ) == ALLIES;
+ const Coord3D at = *obj->getPosition();
+
+ LogicThread::callAfterTick( [this, kind, ours, allied, at]()
{
+ // try to create the event
+ if( !tryEvent( RADAR_EVENT_UNDER_ATTACK, &at ) )
+ return;
+
// the lamp beside the radar
if( TheControlBar )
- ControlBar::callFromLogic( []{ TheControlBar->triggerRadarAttackGlow(); } );
+ TheControlBar->triggerRadarAttackGlow();
//
///@todo Should make an INI data driven table for radar event strings, and audio events
//
@@ -1220,60 +1310,45 @@ void Radar::tryUnderAttackEvent( const Object *obj )
Player *player = ThePlayerList->getLocalPlayer();
// create a message for the attack event
- if( obj->isKindOf( KINDOF_INFANTRY ) || obj->isKindOf( KINDOF_VEHICLE ) )
+ if( kind == WARN_HARVESTER || kind == WARN_UNIT )
{
AudioEventRTS unitAttackSound;
- if( obj->isKindOf(KINDOF_HARVESTER) )
+ if( kind == WARN_HARVESTER )
{
- // display special message
TheInGameUI->message( "RADAR:HarvesterUnderAttack" );
-
- // play special audio event
unitAttackSound = TheAudio->getMiscAudio()->m_radarHarvesterUnderAttackSound;
}
else
{
- // display message
TheInGameUI->message( "RADAR:UnitUnderAttack" );
-
- // play audio event
unitAttackSound = TheAudio->getMiscAudio()->m_radarStructureUnderAttackSound;
}
unitAttackSound.setPlayerIndex(player->getPlayerIndex());
TheAudio->addAudioEvent( &unitAttackSound );
-
- } // end if
- else if( obj->isKindOf( KINDOF_STRUCTURE ) && obj->isKindOf( KINDOF_MP_COUNT_FOR_VICTORY ) )
+ }
+ else if( kind == WARN_BASE )
{
// play EVA. If its our object, play Base under attack.
- if (obj->getControllingPlayer()->isLocalPlayer())
+ if (ours)
TheEva->setShouldPlay(EVA_BaseUnderAttack);
- else if (ThePlayerList->getLocalPlayer()->getRelationship(obj->getTeam()) == ALLIES)
+ else if (allied)
TheEva->setShouldPlay(EVA_AllyUnderAttack);
- // display message
TheInGameUI->message( "RADAR:StructureUnderAttack" );
- // play audio event
static AudioEventRTS structureAttackSound = TheAudio->getMiscAudio()->m_radarStructureUnderAttackSound;
structureAttackSound.setPlayerIndex(player->getPlayerIndex());
TheAudio->addAudioEvent( &structureAttackSound );
-
- } // end else if
+ }
else
{
-
- // display message
TheInGameUI->message( "RADAR:UnderAttack" );
- // play audio event
static AudioEventRTS underAttackSound = TheAudio->getMiscAudio()->m_radarStructureUnderAttackSound;
underAttackSound.setPlayerIndex(player->getPlayerIndex());
TheAudio->addAudioEvent( &underAttackSound );
-
- } // end else
-
- } // end if
+ }
+ } );
} // end tryUnderAttackEvent
@@ -1284,7 +1359,7 @@ void Radar::tryUnderAttackEvent( const Object *obj )
// ------------------------------------------------------------------------------------------------
void Radar::tryInfiltrationEvent( const Object *obj )
{
- LOGIC_CENSUS( CENSUS_RADAR );
+ // the event, the message and the sound below each wait for the end of a tick themselves
//Sanity!
if( !obj )
@@ -1321,6 +1396,14 @@ void Radar::tryInfiltrationEvent( const Object *obj )
// ------------------------------------------------------------------------------------------------
Bool Radar::tryEvent( RadarEventType event, const Coord3D *pos )
{
+ // inside a tick the try waits for its end and the answer is FALSE: a caller that acts on the answer
+ // asks from callAfterTick (StealthDetectorUpdate, tryUnderAttackEvent)
+ if( LogicThread::defersEffects() && pos != NULL )
+ {
+ const Coord3D at = *pos;
+ LogicThread::callAfterTick( [=]() { tryEvent( event, &at ); } );
+ return FALSE;
+ }
LOGIC_CENSUS( CENSUS_RADAR );
// sanity
@@ -1403,7 +1486,8 @@ void Radar::queueTerrainRefresh( void )
// proximity for us to overwrite something, we're changing the terrain features
// quite often and can't afford the expense of rebuilding the radar visual
//
- m_queueTerrainRefreshFrame = TheGameLogic->getFrame();
+ const UnsignedInt frame = TheGameLogic->getFrame();
+ LogicThread::callAfterTick( [this, frame]() { m_queueTerrainRefreshFrame = frame; } );
} // end queueTerrainRefresh
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp
index 415c78b44..96d7081f6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp
@@ -388,6 +388,8 @@ const EvaCheckInfo *Eva::getEvaCheckInfo(AsciiString name)
//-------------------------------------------------------------------------------------------------
void Eva::setShouldPlay(EvaMessage messageToPlay)
{
+ // LOGIC-THREAD.md M6: a tick's request waits for the end of it
+ LOGIC_AFTER_TICK( [=]() { setShouldPlay( messageToPlay ); } );
LOGIC_CENSUS( CENSUS_EVA );
m_shouldPlay[messageToPlay] = TRUE;
@@ -397,6 +399,8 @@ void Eva::setShouldPlay(EvaMessage messageToPlay)
//-------------------------------------------------------------------------------------------------
void Eva::setEvaEnabled(Bool enabled)
{
+ LOGIC_AFTER_TICK( [=]() { setEvaEnabled( enabled ); } );
+ LOGIC_CENSUS( CENSUS_EVA );
// clear out any waiting messages.
for (Int i = EVA_FIRST; i < EVA_COUNT; ++i) {
m_shouldPlay[i] = FALSE;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 3d8496761..684c6df43 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -710,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_AFTER_TICK( [=]() { addSuperweapon( playerIndex, powerName, id, powerTemplate ); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
if (powerTemplate == NULL)
return;
@@ -751,6 +752,12 @@ void InGameUI::addSuperweapon(Int playerIndex, const AsciiString& powerName, Obj
// ------------------------------------------------------------------------------------------------
Bool InGameUI::removeSuperweapon(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate)
{
+ // logic never reads the answer, which after the tick is not known yet
+ if( LogicThread::defersEffects() )
+ {
+ LogicThread::callAfterTick( [=]() { removeSuperweapon( playerIndex, powerName, id, powerTemplate ); } );
+ return FALSE;
+ }
LOGIC_CENSUS( CENSUS_INGAMEUI );
DEBUG_LOG(("Removing superweapon UI timer\n"));
SuperweaponMap::iterator mapIt = m_superweapons[playerIndex].find(powerName);
@@ -780,6 +787,18 @@ Bool InGameUI::removeSuperweapon(Int playerIndex, const AsciiString& powerName,
// ------------------------------------------------------------------------------------------------
void InGameUI::objectChangedTeam(const Object *obj, Int oldPlayerIndex, Int newPlayerIndex)
{
+ if( LogicThread::defersEffects() )
+ {
+ // by ID: the tick may destroy it before its end, and a dead object's timers went with it
+ const ObjectID id = obj->getID();
+ LogicThread::callAfterTick( [=]() {
+ const Object *live = TheGameLogic->findObjectByID( id );
+ if( live )
+ objectChangedTeam( live, oldPlayerIndex, newPlayerIndex );
+ } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
// if we already had it listed, remove and re-add it
if (obj && oldPlayerIndex >= 0 && newPlayerIndex >= 0)
{
@@ -823,27 +842,22 @@ void InGameUI::objectChangedTeam(const Object *obj, Int oldPlayerIndex, Int newP
// ------------------------------------------------------------------------------------------------
void InGameUI::hideObjectSuperweaponDisplayByScript(const Object *obj)
{
- ObjectID objID = obj->getID();
- for (Int playerIndex = 0; playerIndex < MAX_PLAYER_COUNT; ++playerIndex)
- {
- for (SuperweaponMap::iterator mapIt = m_superweapons[playerIndex].begin(); mapIt != m_superweapons[playerIndex].end(); ++mapIt)
- {
- for (SuperweaponList::iterator listIt = mapIt->second.begin(); listIt != mapIt->second.end(); ++listIt)
- {
- if ((*listIt)->m_id == objID)
- {
- (*listIt)->m_hiddenByScript = TRUE;
- }
- }
- }
- }
+ setObjectSuperweaponHiddenByScript( obj->getID(), TRUE );
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void InGameUI::showObjectSuperweaponDisplayByScript(const Object *obj)
{
- ObjectID objID = obj->getID();
+ setObjectSuperweaponHiddenByScript( obj->getID(), FALSE );
+}
+
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+void InGameUI::setObjectSuperweaponHiddenByScript( ObjectID objID, Bool hidden )
+{
+ LOGIC_AFTER_TICK( [=]() { setObjectSuperweaponHiddenByScript( objID, hidden ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
for (Int playerIndex = 0; playerIndex < MAX_PLAYER_COUNT; ++playerIndex)
{
for (SuperweaponMap::iterator mapIt = m_superweapons[playerIndex].begin(); mapIt != m_superweapons[playerIndex].end(); ++mapIt)
@@ -852,7 +866,7 @@ void InGameUI::showObjectSuperweaponDisplayByScript(const Object *obj)
{
if ((*listIt)->m_id == objID)
{
- (*listIt)->m_hiddenByScript = FALSE;
+ (*listIt)->m_hiddenByScript = hidden;
}
}
}
@@ -863,6 +877,8 @@ void InGameUI::showObjectSuperweaponDisplayByScript(const Object *obj)
// ------------------------------------------------------------------------------------------------
void InGameUI::setSuperweaponDisplayEnabledByScript(Bool enable)
{
+ LOGIC_AFTER_TICK( [=]() { setSuperweaponDisplayEnabledByScript( enable ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
m_superweaponHiddenByScript = !enable;
}
@@ -879,6 +895,8 @@ Bool InGameUI::getSuperweaponDisplayEnabledByScript(void) const
// ------------------------------------------------------------------------------------------------
void InGameUI::addNamedTimer( const AsciiString& timerName, const UnicodeString& text, Bool isCountdown )
{
+ LOGIC_AFTER_TICK( [=]() { addNamedTimer( timerName, text, isCountdown ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
NamedTimerInfo *info = newInstance( NamedTimerInfo );
info->m_timerName = timerName;
info->color = m_namedTimerNormalColor;
@@ -901,6 +919,8 @@ void InGameUI::addNamedTimer( const AsciiString& timerName, const UnicodeString&
// ------------------------------------------------------------------------------------------------
void InGameUI::removeNamedTimer( const AsciiString& timerName )
{
+ LOGIC_AFTER_TICK( [=]() { removeNamedTimer( timerName ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
NamedTimerMapIt mapIt = m_namedTimers.find(timerName);
if (mapIt != m_namedTimers.end())
{
@@ -915,6 +935,8 @@ void InGameUI::removeNamedTimer( const AsciiString& timerName )
// ------------------------------------------------------------------------------------------------
void InGameUI::showNamedTimerDisplay( Bool show )
{
+ LOGIC_AFTER_TICK( [=]() { showNamedTimerDisplay( show ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
m_showNamedTimers = show;
}
@@ -2798,6 +2820,15 @@ void InGameUI::freeClassicMessages( void )
//-------------------------------------------------------------------------------------------------
void InGameUI::addClassicMessage( const UnicodeString &text, const Color *color )
{
+ // a tick's line (message, playerMessage, chatMessage) is formatted at the call and added after it
+ if( LogicThread::defersEffects() )
+ {
+ const Bool hasColor = color != NULL;
+ const Color colorValue = hasColor ? *color : 0;
+ LogicThread::callAfterTick( [=]() { addClassicMessage( text, hasColor ? &colorValue : NULL ); } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
const Color color1 = color ? ( *color | GameMakeColor( 0, 0, 0, 255 ) ) : m_messageColor1;
const Color color2 = color ? ( *color | GameMakeColor( 0, 0, 0, 255 ) ) : m_messageColor2;
@@ -2930,7 +2961,6 @@ 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;
@@ -2962,7 +2992,6 @@ 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
@@ -6002,6 +6031,8 @@ Bool InGameUI::rotatePendingPlacement( Int steps )
//-------------------------------------------------------------------------------------------------
void InGameUI::selectDrawable( Drawable *draw )
{
+ // a drawable the tick destroys leaves the selection in this queue too, before it is deleted
+ LOGIC_AFTER_TICK( [=]() { selectDrawable( draw ); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
if( draw->isSelected() == FALSE )
@@ -6028,11 +6059,21 @@ void InGameUI::selectDrawable( Drawable *draw )
} // end selectDrawable
+//-------------------------------------------------------------------------------------------------
+void InGameUI::setDisplayedMaxWarning( Bool selected )
+{
+ // in order with the selectDrawable the tick queued before it
+ LOGIC_AFTER_TICK( [=]() { setDisplayedMaxWarning( selected ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
+ m_displayedMaxWarning = selected;
+}
+
//-------------------------------------------------------------------------------------------------
/** Clear "selected" status of Drawable. */
//-------------------------------------------------------------------------------------------------
void InGameUI::deselectDrawable( Drawable *draw )
{
+ LOGIC_AFTER_TICK( [=]() { deselectDrawable( draw ); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
if( draw->isSelected() )
@@ -6072,6 +6113,7 @@ void InGameUI::deselectDrawable( Drawable *draw )
//-------------------------------------------------------------------------------------------------
void InGameUI::deselectAllDrawables( void )
{
+ LOGIC_AFTER_TICK( [=]() { deselectAllDrawables(); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
const Bool hadSelectedDrawables = !selected->empty();
@@ -6116,7 +6158,7 @@ void InGameUI::deselectAllDrawables( void )
//-------------------------------------------------------------------------------------------------
const DrawableList *InGameUI::getAllSelectedDrawables( void ) const
{
- LOGIC_CENSUS( CENSUS_INGAMEUI );
+ LOGIC_CENSUS( CENSUS_CLIENT_READ );
return &m_selectedDrawables;
}
@@ -6176,7 +6218,7 @@ const DrawableList *InGameUI::getAllSelectedLocalDrawables( void )
//-------------------------------------------------------------------------------------------------
Drawable *InGameUI::getFirstSelectedDrawable( void )
{
- LOGIC_CENSUS( CENSUS_INGAMEUI );
+ LOGIC_CENSUS( CENSUS_CLIENT_READ );
// sanity
if( m_selectedDrawables.empty() )
@@ -6257,6 +6299,8 @@ Bool InGameUI::isAllSelectedKindOf( KindOfType kindOf ) const
//-------------------------------------------------------------------------------------------------
void InGameUI::setInputEnabled( Bool enable )
{
+ LOGIC_AFTER_TICK( [=]() { setInputEnabled( enable ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
if(!enable)
setSelecting( FALSE );
@@ -6666,6 +6710,8 @@ void InGameUI::createReplayControl( void )
// ------------------------------------------------------------------------------------------------
void InGameUI::playMovie( const AsciiString& movieName )
{
+ LOGIC_AFTER_TICK( [=]() { playMovie( movieName ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
stopMovie();
@@ -6841,6 +6887,8 @@ void InGameUI::displayCantBuildMessage( LegalBuildCode lbc )
// ------------------------------------------------------------------------------------------------
void InGameUI::militarySubtitle( const AsciiString& label, Int duration )
{
+ LOGIC_AFTER_TICK( [=]() { militarySubtitle( label, duration ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
// make sure we don't already have a subtitle up there
removeMilitarySubtitle();
@@ -7760,6 +7808,13 @@ void InGameUI::buildRegion( const ICoord2D *anchor, const ICoord2D *dest, IRegio
//-------------------------------------------------------------------------------------------------
FloatingTextData *InGameUI::addFloatingText(const UnicodeString& text,const Coord3D *pos, Color color)
{
+ // nobody in logic keeps the answer
+ if( LogicThread::defersEffects() )
+ {
+ const Coord3D at = *pos;
+ LogicThread::callAfterTick( [=]() { addFloatingText( text, &at, color ); } );
+ return NULL;
+ }
LOGIC_CENSUS( CENSUS_INGAMEUI );
if( !TheGameLogic->getDrawIconUI() )
return NULL;
@@ -7807,6 +7862,8 @@ enum
//-------------------------------------------------------------------------------------------------
void InGameUI::addSignalMark( SignalKind kind, const Coord3D &pos, Color color, ParticleSystemID smoke )
{
+ LOGIC_AFTER_TICK( [=]() { addSignalMark( kind, pos, color, smoke ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
// No decal manager without a renderer (headless, or off Windows until the D track): no mark.
// GameLogicDispatch calls this for every signal a player sends, replays included.
if( TheProjectedShadowManager == NULL )
@@ -7897,6 +7954,13 @@ inline Bool isClose(const Coord3D& a, const Coord3D& b)
}
void InGameUI::DEBUG_addFloatingText(const AsciiString& text, const Coord3D * pos, Color color)
{
+ if( LogicThread::defersEffects() )
+ {
+ const Coord3D at = *pos;
+ LogicThread::callAfterTick( [=]() { DEBUG_addFloatingText( text, &at, color ); } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
const Int POINTSIZE = 8;
const Int LEADING = 0;
@@ -9775,6 +9839,9 @@ void InGameUI::popupMessage( const AsciiString& message, Int x, Int y, Int width
//-------------------------------------------------------------------------------------------------
void InGameUI::popupMessage( const AsciiString& identifier, Int x, Int y, Int width, Color textColor, Bool pause, Bool pauseMusic)
{
+ // the pause it may ask for stops the next tick either way
+ LOGIC_AFTER_TICK( [=]() { popupMessage( identifier, x, y, width, textColor, pause, pauseMusic ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
if(m_popupMessageData)
clearPopupMessageData();
@@ -9818,6 +9885,8 @@ void InGameUI::popupMessage( const AsciiString& identifier, Int x, Int y, Int wi
//-------------------------------------------------------------------------------------------------
void InGameUI::clearPopupMessageData( void )
{
+ LOGIC_AFTER_TICK( [=]() { clearPopupMessageData(); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
if(!m_popupMessageData)
return;
if(m_popupMessageData->layout)
@@ -9892,6 +9961,12 @@ void InGameUI::addWorldAnimation( Anim2DTemplate *animTemplate,
Real durationInSeconds,
Real zRisePerSecond )
{
+ if( LogicThread::defersEffects() && pos != NULL )
+ {
+ const Coord3D at = *pos;
+ LogicThread::callAfterTick( [=]() { addWorldAnimation( animTemplate, &at, options, durationInSeconds, zRisePerSecond ); } );
+ return;
+ }
LOGIC_CENSUS( CENSUS_INGAMEUI );
// sanity
@@ -10078,22 +10153,30 @@ Object *InGameUI::findIdleWorker( Object *obj)
void InGameUI::addIdleWorker( Object *obj )
{
- LOGIC_CENSUS( CENSUS_INGAMEUI );
if(!obj)
return;
+ addIdleWorkerFor( obj, obj->getControllingPlayer()->getPlayerIndex() );
+}
- if(findIdleWorker(obj))
+/* The list keeps the pointer and never reads through it here, so after a tick it may name an object
+ that tick destroyed: the destroy queued its removeIdleWorker behind this add. */
+void InGameUI::addIdleWorkerFor( Object *obj, Int index )
+{
+ LOGIC_AFTER_TICK( [=]() { addIdleWorkerFor( obj, index ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
+ if( std::find( m_idleWorkers[index].begin(), m_idleWorkers[index].end(), obj ) != m_idleWorkers[index].end() )
return;
- Int index = obj->getControllingPlayer()->getPlayerIndex();
m_idleWorkers[index].push_back(obj);
}
void InGameUI::removeIdleWorker( Object *obj, Int playerNumber )
{
- LOGIC_CENSUS( CENSUS_INGAMEUI );
if(!obj)
return;
+ // compares the pointer only, so the object may be gone by the time this runs
+ LOGIC_AFTER_TICK( [=]() { removeIdleWorker( obj, playerNumber ); } );
+ LOGIC_CENSUS( CENSUS_INGAMEUI );
if(playerNumber < 0 || playerNumber >= MAX_PLAYER_COUNT) // we're leaving the game, so this is all screwed
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
index c7cd8fe35..82280438a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
@@ -2669,9 +2669,12 @@ void TerrainLogic::setActiveBoundary(Int newActiveBoundary)
ThePartitionManager->init();
// newMap resets the radar, and a reset stops forcing it on: a replay, an observer or a beaten
// player lost the minimap for the rest of the match the moment a script moved the border
- const Bool radarForced = TheRadar->isRadarForced();
- TheRadar->newMap(TheTerrainLogic);
- TheRadar->forceOn(radarForced);
+ // after the tick, between the radar removes queued above and the adds and shroud queued below
+ LogicThread::callAfterTick( []() {
+ const Bool radarForced = TheRadar->isRadarForced();
+ TheRadar->newMap(TheTerrainLogic);
+ TheRadar->forceOn(radarForced);
+ } );
ThePartitionManager->restoreFoggedCells(partitionStore, FALSE);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp
index d24d3b614..22fa16edb 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp
@@ -1648,8 +1648,9 @@ void GarrisonContain::onContaining( Object *obj, Bool wasSelected )
//
recalcApparentControllingPlayer();
+ // whether it is selected is asked after the tick, where a select queued earlier in it has landed
Drawable *draw = obj->getDrawable();
- if ( draw && draw->isSelected() )
+ if ( draw )
TheInGameUI->deselectDrawable( draw );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp
index e4b6c68db..8912b1627 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp
@@ -33,6 +33,7 @@
#define DEFINE_STEALTHLEVEL_NAMES
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
+#include "Common/LogicThread.h"
#include "Common/MiscAudio.h"
#include "Common/Radar.h"
#include "Common/ThingTemplate.h"
@@ -240,41 +241,28 @@ UpdateSleepTime StealthDetectorUpdate::update( void )
if( ThePlayerList->getLocalPlayer() == self->getControllingPlayer() &&
self->getRelationship( them ) != ALLIES )
{
- Bool doFeedback = TRUE;
-
//Kris: Aug 18, 2003 -- This whole system is no longer viable with the inclusion of so many
//stealth units. It's possible to get spammed hundreds of times in a row in MD_GLA02 because
//we're blindly creating radar events for each detection (unless they are mines). The best thing
//to do is tryEvent for everything...
- doFeedback = TheRadar->tryEvent( RADAR_EVENT_STEALTH_DISCOVERED, them->getPosition() );
- //OLD CODE:
- /*
- // do a radar event, for mines we only make events if there weren't other
- // mine events within close proximity and time to other mines
//
- if( them->isKindOf( KINDOF_MINE ) || them->isKindOf( KINDOF_BOOBY_TRAP ) || them->isKindOf( KINDOF_DEMOTRAP ) )
- doFeedback = TheRadar->tryEvent( RADAR_EVENT_STEALTH_DISCOVERED, them->getPosition() );
- else
- TheRadar->createEvent( them->getPosition(), RADAR_EVENT_STEALTH_DISCOVERED );
- */
-
- // do audio and UI message if we need to do feedback
- if( doFeedback )
+ // The try and the feedback it allows are the client's and wait for the end of the tick
+ // (LOGIC-THREAD.md M6); what they need of the objects is read here.
+ const Coord3D at = *them->getPosition();
+ const Int playerIndex = self->getControllingPlayer()->getPlayerIndex();
+ const EvaMessage message = stealth->getEnemyDetectionEvaEvent();
+ LogicThread::callAfterTick( [at, playerIndex, message]()
{
- // audio msg
- static AudioEventRTS discoveredSound = TheAudio->getMiscAudio()->m_stealthDiscoveredSound;
- discoveredSound.setPlayerIndex( self->getControllingPlayer()->getPlayerIndex() );
- TheAudio->addAudioEvent( &discoveredSound );
- // ui msg
- TheInGameUI->message( TheGameText->fetch( "MESSAGE:StealthDiscovered" ) );
-
- // If revealing this unit is suppose to cause an Eva event, do it
- EvaMessage message = stealth->getEnemyDetectionEvaEvent();
- if ( message != EVA_Invalid && TheEva != NULL )
- {
- TheEva->setShouldPlay( message );
- }
- } // end if
+ if( !TheRadar->tryEvent( RADAR_EVENT_STEALTH_DISCOVERED, &at ) )
+ return;
+ static AudioEventRTS discoveredSound = TheAudio->getMiscAudio()->m_stealthDiscoveredSound;
+ discoveredSound.setPlayerIndex( playerIndex );
+ TheAudio->addAudioEvent( &discoveredSound );
+ TheInGameUI->message( TheGameText->fetch( "MESSAGE:StealthDiscovered" ) );
+ // If revealing this unit is suppose to cause an Eva event, do it
+ if ( message != EVA_Invalid && TheEva != NULL )
+ TheEva->setShouldPlay( message );
+ } );
} // end if
@@ -282,36 +270,32 @@ UpdateSleepTime StealthDetectorUpdate::update( void )
if( ThePlayerList->getLocalPlayer() == them->getControllingPlayer() &&
self->getRelationship( them ) != ALLIES )
{
- Bool doFeedback = TRUE;
-
//
// do a radar event, for mines we only make events if there weren't other
- // mine events within close proximity and time to other mines
+ // mine events within close proximity and time to other mines; after the tick, as above
//
- if( them->isKindOf( KINDOF_MINE ) || them->isKindOf( KINDOF_BOOBY_TRAP ) || them->isKindOf( KINDOF_DEMOTRAP ) )
- doFeedback = TheRadar->tryEvent( RADAR_EVENT_STEALTH_NEUTRALIZED, them->getPosition() );
- else
- TheRadar->createEvent( them->getPosition(), RADAR_EVENT_STEALTH_NEUTRALIZED );
-
- // do audio and UI message if we need to do feedback
- if( doFeedback )
+ const Bool trap = them->isKindOf( KINDOF_MINE ) || them->isKindOf( KINDOF_BOOBY_TRAP ) || them->isKindOf( KINDOF_DEMOTRAP );
+ const Coord3D at = *them->getPosition();
+ const Int playerIndex = them->getControllingPlayer()->getPlayerIndex();
+ const EvaMessage message = stealth->getOwnDetectionEvaEvent();
+ LogicThread::callAfterTick( [trap, at, playerIndex, message]()
{
+ if( trap )
+ {
+ if( !TheRadar->tryEvent( RADAR_EVENT_STEALTH_NEUTRALIZED, &at ) )
+ return;
+ }
+ else
+ TheRadar->createEvent( &at, RADAR_EVENT_STEALTH_NEUTRALIZED );
+ static AudioEventRTS neutralizedSound = TheAudio->getMiscAudio()->m_stealthNeutralizedSound;
+ neutralizedSound.setPlayerIndex( playerIndex );
+ TheAudio->addAudioEvent( &neutralizedSound );
+ TheInGameUI->message( TheGameText->fetch( "MESSAGE:StealthNeutralized" ) );
+ // If revealing this unit is suppose to cause an Eva event, do it
+ if ( message != EVA_Invalid && TheEva != NULL )
+ TheEva->setShouldPlay( message );
+ } );
- // audio msg
- static AudioEventRTS neutralizedSound = TheAudio->getMiscAudio()->m_stealthNeutralizedSound;
- neutralizedSound.setPlayerIndex( them->getControllingPlayer()->getPlayerIndex() );
- TheAudio->addAudioEvent( &neutralizedSound );
- // ui msg
- TheInGameUI->message( TheGameText->fetch( "MESSAGE:StealthNeutralized" ) );
-
- // If revealing this unit is suppose to cause an Eva event, do it
- EvaMessage message = stealth->getOwnDetectionEvaEvent();
- if ( message != EVA_Invalid && TheEva != NULL )
- {
- TheEva->setShouldPlay( message );
- }
- } // end if
-
} // end if
} // end if, them was not previously detected
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
index d7f4c95c8..e790d94d2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
@@ -131,6 +131,12 @@ static void updateTeamAndPlayerStuff( Object *obj, void *userData )
// DEFINES ////////////////////////////////////////////////////////////////////////////////////////
#define REALLY_FAR (100000 * MAP_XY_FACTOR)
+/** LOGIC-THREAD.md phase 2, M6. First line of an action that only drives the camera, the letterbox,
+ * the cinematic text or a movie: inside a tick the whole action runs after it, in the camera's own
+ * queue (LogicThread::callViewAfterTick), waypoint lookups included, since waypoints do not move. */
+#define VIEW_AFTER_TICK( ... ) \
+ if( LogicThread::defersView() ) { LogicThread::callViewAfterTick( __VA_ARGS__ ); return; }
+
// GLOBALS ////////////////////////////////////////////////////////////////////////////////////////
ScriptActionsInterface *TheScriptActions = NULL;
GameWindow *ScriptActions::m_messageWindow = NULL;
@@ -187,11 +193,14 @@ void ScriptActions::closeWindows( Bool suppressNewWindows )
{
m_suppressNewWindows = suppressNewWindows;
- if (m_messageWindow) {
- TheWindowManager->winDestroy(m_messageWindow);
- m_messageWindow = NULL;
- }
-}
+ // the window is the client's: after the tick, in order with the one doVictory opens
+ LogicThread::callAfterTick( []{
+ if (m_messageWindow) {
+ TheWindowManager->winDestroy(m_messageWindow);
+ m_messageWindow = NULL;
+ }
+ } );
+}
//-------------------------------------------------------------------------------------------------
/** doQuickVictory */
@@ -211,6 +220,8 @@ void ScriptActions::doQuickVictory( void )
//-------------------------------------------------------------------------------------------------
void ScriptActions::doSetInfantryLightingOverride(Real setting)
{
+ // a renderer setting (LOGIC-THREAD.md hazard 24): written after the tick
+ LOGIC_AFTER_TICK( [=]() { doSetInfantryLightingOverride( setting ); } );
DEBUG_ASSERTCRASH( (setting == -1.0f) || (setting > 0.0f), ("Invalid setting (%d) in Infantry Lighting Override script.", setting) );
TheWritableGlobalData->m_scriptOverrideInfantryLightScale = setting;
}
@@ -227,13 +238,10 @@ void ScriptActions::doVictory( void )
{
const Player *localPlayer = ThePlayerList->getLocalPlayer();
Bool showObserverWindow = localPlayer->isPlayerObserver() || TheScriptEngine->hasShownMPLocalDefeatWindow();
- if(showObserverWindow)
- m_messageWindow = TheWindowManager->winCreateFromScript("Menus/ObserverQuit.wnd");
- else
- {
- m_messageWindow = TheWindowManager->winCreateFromScript("Menus/Victorious.wnd");
- }
- }
+ LogicThread::callAfterTick( [showObserverWindow]{
+ m_messageWindow = TheWindowManager->winCreateFromScript(showObserverWindow ? "Menus/ObserverQuit.wnd" : "Menus/Victorious.wnd");
+ } );
+ }
if(TheCampaignManager)
TheCampaignManager->SetVictorious(TRUE);
TheScriptEngine->startEndGameTimer();
@@ -251,12 +259,9 @@ void ScriptActions::doDefeat( void )
{
const Player *localPlayer = ThePlayerList->getLocalPlayer();
Bool showObserverWindow = localPlayer->isPlayerObserver() || TheScriptEngine->hasShownMPLocalDefeatWindow();
- if(showObserverWindow)
- m_messageWindow = TheWindowManager->winCreateFromScript("Menus/ObserverQuit.wnd");
- else
- {
- m_messageWindow = TheWindowManager->winCreateFromScript("Menus/Defeat.wnd");
- }
+ LogicThread::callAfterTick( [showObserverWindow]{
+ m_messageWindow = TheWindowManager->winCreateFromScript(showObserverWindow ? "Menus/ObserverQuit.wnd" : "Menus/Defeat.wnd");
+ } );
}
if(TheCampaignManager)
TheCampaignManager->SetVictorious(FALSE);
@@ -274,7 +279,7 @@ void ScriptActions::doLocalDefeat( void )
if (!m_suppressNewWindows)
{
if(!TheVictoryConditions->amIObserver())
- m_messageWindow = TheWindowManager->winCreateFromScript("Menus/LocalDefeat.wnd");
+ LogicThread::callAfterTick( []{ m_messageWindow = TheWindowManager->winCreateFromScript("Menus/LocalDefeat.wnd"); } );
}
if(TheCampaignManager)
TheCampaignManager->SetVictorious(FALSE);
@@ -473,6 +478,7 @@ void ScriptActions::doNamedMoveToWaypoint(const AsciiString& unit, const AsciiSt
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraFollowNamed(const AsciiString& unit, Bool snapToUnit)
{
+ VIEW_AFTER_TICK( [=]() { doCameraFollowNamed( unit, snapToUnit ); } );
Object *theObj = TheScriptEngine->getUnitNamed( unit );
if (theObj)
{
@@ -489,6 +495,7 @@ void ScriptActions::doCameraFollowNamed(const AsciiString& unit, Bool snapToUnit
//-------------------------------------------------------------------------------------------------
void ScriptActions::doStopCameraFollowUnit(void)
{
+ VIEW_AFTER_TICK( [=]() { doStopCameraFollowUnit(); } );
TheTacticalView->setCameraLock(INVALID_ID);
}
@@ -806,6 +813,7 @@ void ScriptActions::doCreateReinforcements(const AsciiString& team, const AsciiS
//-------------------------------------------------------------------------------------------------
void ScriptActions::doMoveCameraTo(const AsciiString& waypoint, Real sec, Real cameraStutterSec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doMoveCameraTo( waypoint, sec, cameraStutterSec, easeIn, easeOut ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
Coord3D destination = *way->getLocation();
@@ -820,6 +828,7 @@ void ScriptActions::doMoveCameraTo(const AsciiString& waypoint, Real sec, Real c
//-------------------------------------------------------------------------------------------------
void ScriptActions::doZoomCamera(Real zoom, Real sec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doZoomCamera( zoom, sec, easeIn, easeOut ); } );
TheTacticalView->zoomCamera(zoom, sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f);
}
@@ -828,6 +837,7 @@ void ScriptActions::doZoomCamera(Real zoom, Real sec, Real easeIn, Real easeOut)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doPitchCamera(Real pitch, Real sec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doPitchCamera( pitch, sec, easeIn, easeOut ); } );
TheTacticalView->pitchCamera(pitch, sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f);
}
@@ -836,6 +846,7 @@ void ScriptActions::doPitchCamera(Real pitch, Real sec, Real easeIn, Real easeOu
//-------------------------------------------------------------------------------------------------
void ScriptActions::doOversizeTheTerrain(Int amount)
{
+ VIEW_AFTER_TICK( [=]() { doOversizeTheTerrain( amount ); } );
oversizeTheTerrain(amount);
// The two cancelling scrolls were only here to make the view notice it was dirty.
TheTacticalView->forceRedraw();
@@ -846,6 +857,7 @@ void ScriptActions::doOversizeTheTerrain(Int amount)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doSetupCamera(const AsciiString& waypoint, Real zoom, Real pitch, const AsciiString& lookAtWaypoint)
{
+ VIEW_AFTER_TICK( [=]() { doSetupCamera( waypoint, zoom, pitch, lookAtWaypoint ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
if (way==NULL) return;
Coord3D pos = *way->getLocation();
@@ -863,6 +875,7 @@ void ScriptActions::doSetupCamera(const AsciiString& waypoint, Real zoom, Real p
//-------------------------------------------------------------------------------------------------
void ScriptActions::doModCameraLookToward(const AsciiString& waypoint)
{
+ VIEW_AFTER_TICK( [=]() { doModCameraLookToward( waypoint ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
Coord3D destination = *way->getLocation();
@@ -877,6 +890,7 @@ void ScriptActions::doModCameraLookToward(const AsciiString& waypoint)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doModCameraFinalLookToward(const AsciiString& waypoint)
{
+ VIEW_AFTER_TICK( [=]() { doModCameraFinalLookToward( waypoint ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
Coord3D destination = *way->getLocation();
@@ -891,6 +905,9 @@ void ScriptActions::doModCameraFinalLookToward(const AsciiString& waypoint)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doModCameraMoveToSelection(void)
{
+ // the selection it reads is the client's too, and a script selecting first queued that with the
+ // effects: so this waits in the effects queue behind it, not with the camera calls
+ LOGIC_AFTER_TICK( [=]() { doModCameraMoveToSelection(); } );
Int count=0;
Coord3D destination;
destination.x=destination.y=destination.z = 0;
@@ -920,6 +937,7 @@ void ScriptActions::doModCameraMoveToSelection(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doResetCamera(const AsciiString& waypoint, Real sec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doResetCamera( waypoint, sec, easeIn, easeOut ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
Coord3D destination = *way->getLocation();
@@ -934,6 +952,7 @@ void ScriptActions::doResetCamera(const AsciiString& waypoint, Real sec, Real ea
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRotateCamera(Real rotations, Real sec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doRotateCamera( rotations, sec, easeIn, easeOut ); } );
TheTacticalView->rotateCamera(rotations, sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f);
}
@@ -942,6 +961,7 @@ void ScriptActions::doRotateCamera(Real rotations, Real sec, Real easeIn, Real e
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRotateCameraTowardObject(const AsciiString& unitName, Real sec, Real holdSec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doRotateCameraTowardObject( unitName, sec, holdSec, easeIn, easeOut ); } );
const Object *unit = TheScriptEngine->getUnitNamed(unitName);
if (!unit)
return;
@@ -953,6 +973,7 @@ void ScriptActions::doRotateCameraTowardObject(const AsciiString& unitName, Real
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRotateCameraTowardWaypoint(const AsciiString& waypointName, Real sec, Real easeIn, Real easeOut, Bool reverseRotation)
{
+ VIEW_AFTER_TICK( [=]() { doRotateCameraTowardWaypoint( waypointName, sec, easeIn, easeOut, reverseRotation ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
if (way==NULL) return;
TheTacticalView->rotateCameraTowardPosition(way->getLocation(), sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f, reverseRotation);
@@ -963,6 +984,7 @@ void ScriptActions::doRotateCameraTowardWaypoint(const AsciiString& waypointName
//-------------------------------------------------------------------------------------------------
void ScriptActions::doMoveCameraAlongWaypointPath(const AsciiString& waypoint, Real sec, Real cameraStutterSec, Real easeIn, Real easeOut)
{
+ VIEW_AFTER_TICK( [=]() { doMoveCameraAlongWaypointPath( waypoint, sec, cameraStutterSec, easeIn, easeOut ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
TheTacticalView->moveCameraAlongWaypointPath(way, sec*1000, cameraStutterSec*1000, true, easeIn*1000.0f, easeOut*1000.0f);
@@ -2607,6 +2629,7 @@ void ScriptActions::doInGamePopupMessage( const AsciiString& message, Int x, Int
//-------------------------------------------------------------------------------------------------
void ScriptActions::doDisplayCinematicText(const AsciiString& displayText, const AsciiString& fontType, Int timeInSeconds)
{
+ VIEW_AFTER_TICK( [=]() { doDisplayCinematicText( displayText, fontType, timeInSeconds ); } );
// set the text
UnicodeString uStr = TheGameText->fetch( displayText );
AsciiString aStr;
@@ -2780,6 +2803,7 @@ void ScriptActions::doTeamFlash(const AsciiString& teamName, Int timeInSeconds,
//-------------------------------------------------------------------------------------------------
void ScriptActions::doMoviePlayFullScreen(const AsciiString& movieName)
{
+ VIEW_AFTER_TICK( [=]() { doMoviePlayFullScreen( movieName ); } );
TheDisplay->playMovie(movieName);
}
@@ -2963,7 +2987,7 @@ void ScriptActions::doTeamRadarCreateEvent(const AsciiString& teamName, Int even
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRadarDisable(void)
{
- TheRadar->hide(true);
+ LogicThread::callAfterTick( []{ TheRadar->hide(true); } );
}
//-------------------------------------------------------------------------------------------------
@@ -2971,7 +2995,7 @@ void ScriptActions::doRadarDisable(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRadarEnable(void)
{
- TheRadar->hide(false);
+ LogicThread::callAfterTick( []{ TheRadar->hide(false); } );
}
//-------------------------------------------------------------------------------------------------
@@ -2979,6 +3003,7 @@ void ScriptActions::doRadarEnable(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraMotionBlurJump(const AsciiString& waypointName, Bool saturate)
{
+ VIEW_AFTER_TICK( [=]() { doCameraMotionBlurJump( waypointName, saturate ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
if (!way) {
return;
@@ -3017,6 +3042,7 @@ void ScriptActions::doCameraMotionBlurJump(const AsciiString& waypointName, Bool
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraMotionBlur(Bool zoomIn, Bool saturate)
{
+ VIEW_AFTER_TICK( [=]() { doCameraMotionBlur( zoomIn, saturate ); } );
if (TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER))
{
enum FilterModes mode;
@@ -3254,13 +3280,16 @@ void ScriptActions::doDisableInput()
if (!TheGlobalData->m_disableScriptedInputDisabling)
#endif
{
- TheInGameUI->setInputEnabled(false);
- TheMouse->setVisibility(false);
- TheInGameUI->deselectAllDrawables();
- TheInGameUI->clearAttackMoveToMode();
- TheInGameUI->setWaypointMode( FALSE );
- ControlBar::callFromLogic( []{ TheControlBar->deleteBuildTooltipLayout(); } );
- TheLookAtTranslator->resetModes();
+ // all of it is the client's: after the tick (LOGIC-THREAD.md M6)
+ LogicThread::callAfterTick( []{
+ TheInGameUI->setInputEnabled(false);
+ TheMouse->setVisibility(false);
+ TheInGameUI->deselectAllDrawables();
+ TheInGameUI->clearAttackMoveToMode();
+ TheInGameUI->setWaypointMode( FALSE );
+ TheControlBar->deleteBuildTooltipLayout();
+ TheLookAtTranslator->resetModes();
+ } );
}
}
@@ -3269,8 +3298,10 @@ void ScriptActions::doDisableInput()
//-------------------------------------------------------------------------------------------------
void ScriptActions::doEnableInput()
{
- TheInGameUI->setInputEnabled(true);
- TheMouse->setVisibility(true);
+ LogicThread::callAfterTick( []{
+ TheInGameUI->setInputEnabled(true);
+ TheMouse->setVisibility(true);
+ } );
}
//-------------------------------------------------------------------------------------------------
@@ -3824,6 +3855,7 @@ void ScriptActions::doPlayerExitAllBuildings(const AsciiString& playerName)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doLetterBoxMode(Bool startLetterbox)
{
+ VIEW_AFTER_TICK( [=]() { doLetterBoxMode( startLetterbox ); } );
if (startLetterbox)
{
HideControlBar(TRUE);
@@ -3841,6 +3873,8 @@ void ScriptActions::doLetterBoxMode(Bool startLetterbox)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doBlackWhiteMode(Bool startBWMode, Int frames)
{
+ // which filter is on is the client's to read, after the tick
+ VIEW_AFTER_TICK( [=]() { doBlackWhiteMode( startBWMode, frames ); } );
if (startBWMode)
{
TheTacticalView->setViewFilterMode(FM_VIEW_BW_BLACK_AND_WHITE);
@@ -3863,6 +3897,7 @@ extern void doSkyBoxSet(Bool startDraw); //hack to avoid including globaldata he
void ScriptActions::doSkyBox(Bool startDraw)
{
+ VIEW_AFTER_TICK( [=]() { doSkyBox( startDraw ); } );
if (startDraw)
{
doSkyBoxSet(1);
@@ -4553,7 +4588,7 @@ void ScriptActions::doTeamUseCommandButtonAbilityAtWaypoint( const AsciiString&
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRadarRefresh( void )
{
- TheRadar->refreshTerrain( TheTerrainLogic );
+ LogicThread::callAfterTick( []{ TheRadar->refreshTerrain( TheTerrainLogic ); } );
}
@@ -4562,6 +4597,7 @@ void ScriptActions::doRadarRefresh( void )
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraTetherNamed(const AsciiString& unit, Bool snapToUnit, Real play)
{
+ VIEW_AFTER_TICK( [=]() { doCameraTetherNamed( unit, snapToUnit, play ); } );
Object *theObj = TheScriptEngine->getUnitNamed( unit );
if (theObj)
{
@@ -4578,6 +4614,7 @@ void ScriptActions::doCameraTetherNamed(const AsciiString& unit, Bool snapToUnit
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraStopTetherNamed(void)
{
+ VIEW_AFTER_TICK( [=]() { doCameraStopTetherNamed(); } );
TheTacticalView->setCameraLock(INVALID_ID);
}
@@ -4586,6 +4623,7 @@ void ScriptActions::doCameraStopTetherNamed(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real maxHeight)
{
+ VIEW_AFTER_TICK( [=]() { doCameraSetDefault( pitch, angle, maxHeight ); } );
TheTacticalView->setDefaultView(pitch, angle, maxHeight);
}
@@ -5050,7 +5088,7 @@ void ScriptActions::doForceObjectSelection(const AsciiString& teamName, const As
if (centerInView) {
Coord3D pos = *bestGuess->getPosition();
- TheTacticalView->moveCameraTo(&pos, 0, 0, FALSE, 0.0f, 0.0f);
+ LogicThread::callViewAfterTick( [pos]() mutable { TheTacticalView->moveCameraTo(&pos, 0, 0, FALSE, 0.0f, 0.0f); } );
}
}
@@ -5086,7 +5124,7 @@ void ScriptActions::doDestroyAllContained(const AsciiString& unitName, Int damag
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRadarForceEnable(void)
{
- TheRadar->forceOn(true);
+ LogicThread::callAfterTick( []{ TheRadar->forceOn(true); } );
}
//-------------------------------------------------------------------------------------------------
@@ -5094,7 +5132,7 @@ void ScriptActions::doRadarForceEnable(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRadarRevertNormal(void)
{
- TheRadar->forceOn(false);
+ LogicThread::callAfterTick( []{ TheRadar->forceOn(false); } );
}
//-------------------------------------------------------------------------------------------------
@@ -5102,6 +5140,7 @@ void ScriptActions::doRadarRevertNormal(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doScreenShake( UnsignedInt intensity )
{
+ VIEW_AFTER_TICK( [=]() { doScreenShake( intensity ); } );
Coord3D pos;
TheTacticalView->getPosition( &pos );
TheTacticalView->shake( &pos, (View::CameraShakeType)intensity );
@@ -6130,12 +6169,14 @@ void ScriptActions::doC3CameraEnableSlaveMode
const AsciiString& boneName
)
{
+ VIEW_AFTER_TICK( [=]() { doC3CameraEnableSlaveMode( thingTemplateName, boneName ); } );
TheTacticalView->cameraEnableSlaveMode( thingTemplateName, boneName );
}
//-------------------------------------------------------------------------------------------------
void ScriptActions::doC3CameraDisableSlaveMode( void )
{
+ VIEW_AFTER_TICK( [=]() { doC3CameraDisableSlaveMode(); } );
TheTacticalView->cameraDisableSlaveMode();
}
@@ -6150,6 +6191,7 @@ void ScriptActions::doC3CameraShake
const Real radius
)
{
+ VIEW_AFTER_TICK( [=]() { doC3CameraShake( waypointName, amplitude, duration_seconds, radius ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
DEBUG_ASSERTLOG( (way != NULL), ("Camera shake with No Valid Waypoint\n") );
if( way == NULL )
@@ -6399,6 +6441,7 @@ void ScriptActions::doAffectSkillPointsModifier(const AsciiString& playerName, R
//-------------------------------------------------------------------------------------------------
void ScriptActions::doResizeViewGuardband(const Real gbx, const Real gby)
{
+ VIEW_AFTER_TICK( [=]() { doResizeViewGuardband( gbx, gby ); } );
Coord2D newGuardBand = { gbx, gby };
@@ -6585,27 +6628,43 @@ void ScriptActions::executeAction( ScriptAction *pAction )
case ScriptAction::MOVE_CAMERA_TO_SELECTION:
doModCameraMoveToSelection();
return;
- case ScriptAction::CAMERA_MOD_FREEZE_TIME:
- TheTacticalView->cameraModFreezeTime();
+ // the camera's own calls go to its queue (VIEW_AFTER_TICK), the parameters read now
+ case ScriptAction::CAMERA_MOD_FREEZE_TIME:
+ LogicThread::callViewAfterTick( []{ TheTacticalView->cameraModFreezeTime(); } );
return;
- case ScriptAction::CAMERA_MOD_FREEZE_ANGLE:
- TheTacticalView->cameraModFreezeAngle();
+ case ScriptAction::CAMERA_MOD_FREEZE_ANGLE:
+ LogicThread::callViewAfterTick( []{ TheTacticalView->cameraModFreezeAngle(); } );
return;
- case ScriptAction::CAMERA_MOD_SET_FINAL_ZOOM:
- TheTacticalView->cameraModFinalZoom(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal());
+ case ScriptAction::CAMERA_MOD_SET_FINAL_ZOOM:
+ {
+ const Real a = pAction->getParameter(0)->getReal(), b = pAction->getParameter(1)->getReal(), c = pAction->getParameter(2)->getReal();
+ LogicThread::callViewAfterTick( [=]{ TheTacticalView->cameraModFinalZoom(a, b, c); } );
return;
- case ScriptAction::CAMERA_MOD_SET_FINAL_PITCH:
- TheTacticalView->cameraModFinalPitch(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal());
+ }
+ case ScriptAction::CAMERA_MOD_SET_FINAL_PITCH:
+ {
+ const Real a = pAction->getParameter(0)->getReal(), b = pAction->getParameter(1)->getReal(), c = pAction->getParameter(2)->getReal();
+ LogicThread::callViewAfterTick( [=]{ TheTacticalView->cameraModFinalPitch(a, b, c); } );
return;
- case ScriptAction::CAMERA_MOD_SET_FINAL_SPEED_MULTIPLIER:
- TheTacticalView->cameraModFinalTimeMultiplier(pAction->getParameter(0)->getInt());
+ }
+ case ScriptAction::CAMERA_MOD_SET_FINAL_SPEED_MULTIPLIER:
+ {
+ const Int m = pAction->getParameter(0)->getInt();
+ LogicThread::callViewAfterTick( [=]{ TheTacticalView->cameraModFinalTimeMultiplier(m); } );
return;
- case ScriptAction::CAMERA_MOD_SET_ROLLING_AVERAGE:
- TheTacticalView->cameraModRollingAverage(pAction->getParameter(0)->getInt());
+ }
+ case ScriptAction::CAMERA_MOD_SET_ROLLING_AVERAGE:
+ {
+ const Int frames = pAction->getParameter(0)->getInt();
+ LogicThread::callViewAfterTick( [=]{ TheTacticalView->cameraModRollingAverage(frames); } );
return;
- case ScriptAction::SET_VISUAL_SPEED_MULTIPLIER:
- TheTacticalView->setTimeMultiplier(pAction->getParameter(0)->getInt());
+ }
+ case ScriptAction::SET_VISUAL_SPEED_MULTIPLIER:
+ {
+ const Int m = pAction->getParameter(0)->getInt();
+ LogicThread::callViewAfterTick( [=]{ TheTacticalView->setTimeMultiplier(m); } );
return;
+ }
case ScriptAction::SUSPEND_BACKGROUND_SOUNDS:
LogicThread::callAfterTick( []{ TheAudio->pauseAudio(AudioAffect_Sound); } );
return;
@@ -7026,12 +7085,19 @@ void ScriptActions::executeAction( ScriptAction *pAction )
doCameraMotionBlurJump(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
return;
case ScriptAction::CAMERA_MOTION_BLUR_FOLLOW:
- TheTacticalView->setViewFilterMode((enum FilterModes)(FM_VIEW_MB_PAN_ALPHA+pAction->getParameter(0)->getInt()));
- TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
+ {
+ const FilterModes mode = (enum FilterModes)(FM_VIEW_MB_PAN_ALPHA+pAction->getParameter(0)->getInt());
+ LogicThread::callViewAfterTick( [=]{
+ TheTacticalView->setViewFilterMode(mode);
+ TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
+ } );
return;
+ }
case ScriptAction::CAMERA_MOTION_BLUR_END_FOLLOW:
- TheTacticalView->setViewFilterMode(FM_VIEW_MB_END_PAN_ALPHA);
- TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
+ LogicThread::callViewAfterTick( []{
+ TheTacticalView->setViewFilterMode(FM_VIEW_MB_END_PAN_ALPHA);
+ TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
+ } );
return;
case ScriptAction::FREEZE_TIME:
doFreezeTime();
@@ -7049,22 +7115,29 @@ void ScriptActions::executeAction( ScriptAction *pAction )
doSetStoppingDistance(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
return;
case ScriptAction::SET_FPS_LIMIT:
- if (!pAction->getParameter(0)->getInt())
- {
- TheGameEngine->setFramesPerSecondLimit(TheGlobalData->m_framesPerSecondLimit);
- }
- else
- {
- // the map asks for a 30 Hz logic rate; 30 is normal speed. A mission or skirmish map gets
- // half speed to normal like the player does, never faster
- Int fps = ConvertRetailFrames(pAction->getParameter(0)->getInt());
- if (TheGameLogic->isInSkirmishGame() || TheGameLogic->isInSinglePlayerGame())
- fps = ClampPlayerGameSpeed(fps);
- TheGameEngine->setFramesPerSecondLimit(fps);
- }
- // Setting the fps limit doesn't do much good if we don't use it. jba.
- TheWritableGlobalData->m_useFpsLimit = true;
+ {
+ // the engine's pacing and TheWritableGlobalData are the main thread's: after the tick
+ // (LOGIC-THREAD.md hazard 24), which is when the engine next paces anyway
+ const Int asked = pAction->getParameter(0)->getInt();
+ LogicThread::callAfterTick( [asked]{
+ if (!asked)
+ {
+ TheGameEngine->setFramesPerSecondLimit(TheGlobalData->m_framesPerSecondLimit);
+ }
+ else
+ {
+ // the map asks for a 30 Hz logic rate; 30 is normal speed. A mission or skirmish map gets
+ // half speed to normal like the player does, never faster
+ Int fps = ConvertRetailFrames(asked);
+ if (TheGameLogic->isInSkirmishGame() || TheGameLogic->isInSinglePlayerGame())
+ fps = ClampPlayerGameSpeed(fps);
+ TheGameEngine->setFramesPerSecondLimit(fps);
+ }
+ // Setting the fps limit doesn't do much good if we don't use it. jba.
+ TheWritableGlobalData->m_useFpsLimit = true;
+ } );
return;
+ }
case ScriptAction::DISABLE_SPECIAL_POWER_DISPLAY:
doDisableSpecialPowerDisplay();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
index 8413ce2d7..9e9172a67 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
@@ -2764,6 +2764,7 @@ Bool ScriptConditions::evaluateCondition( Condition *pCondition )
// multiplayer or skirmish session it counts as finished at once on every machine.
if (TheGameEngine->isMultiplayerSession())
return TRUE;
+ LogicThread::readViewFromTick();
return TheTacticalView->isCameraMovementFinished();
case Condition::TEAM_STATE_IS:
return evaluateTeamStateIs(pCondition->getParameter(0), pCondition->getParameter(1));
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
index c8d56a332..743467b1f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
@@ -8574,7 +8574,8 @@ void ScriptEngine::particleEditorUpdate( void )
{
int newCap = _getNewCurrentParticleCap();
if (newCap >= 0) {
- TheWritableGlobalData->m_maxParticleCount = newCap;
+ // the client's particle cap (LOGIC-THREAD.md hazard 24): after the tick
+ LogicThread::callAfterTick( [newCap]() { TheWritableGlobalData->m_maxParticleCount = newCap; } );
}
busyWait = false;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp
index 6cdb4d482..63ce0fbac 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/VictoryConditions.cpp
@@ -241,8 +241,10 @@ void VictoryConditions::update( void )
//MessageBoxOk(TheGameText->fetch("GUI:Defeat"), TheGameText->fetch("GUI:LocalDefeat"), NULL);
}
m_localPlayerDefeated = true; // don't check again
- TheRadar->forceOn(TRUE);
- SetInGameChatType( INGAME_CHAT_EVERYONE ); // can't chat to allies after death. Only to other observers.
+ LogicThread::callAfterTick( []() {
+ TheRadar->forceOn(TRUE);
+ SetInGameChatType( INGAME_CHAT_EVERYONE ); // can't chat to allies after death. Only to other observers.
+ } );
}
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 6f42e1d4f..6dcf3ca34 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -4709,6 +4709,8 @@ void GameLogic::update( void )
once per frozen pass: in a multiplayer or skirmish session a machine whose camera took longer
counted its script timers down further. There the camera freezes nothing, as the camera
condition in ScriptConditions already reports every move finished. */
+ if( !TheGameEngine->isMultiplayerSession() )
+ LogicThread::readViewFromTick();
Bool freezeTime = !TheGameEngine->isMultiplayerSession()
&& TheTacticalView->isTimeFrozen() && !TheTacticalView->isCameraMovementFinished();
freezeTime = freezeTime || TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index c50533307..e0b80766b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -37,6 +37,7 @@
#include "Common/CRCDebug.h"
#include "Common/DrawnPath.h"
#include "Common/GameAudio.h"
+#include "Common/LogicThread.h"
#include "Common/GameEngine.h"
#include "Common/GlobalData.h"
#include "Common/NameKeyGenerator.h"
@@ -341,6 +342,8 @@ static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGro
// ------------------------------------------------------------------------------------------------
void GameLogic::closeWindows( void )
{
+ // every window here is the client's: a tick's call waits for its end (LOGIC-THREAD.md M6)
+ LOGIC_AFTER_TICK( [this]() { closeWindows(); } );
HideDiplomacy();
ResetDiplomacy();
if( TheGameConsole )
@@ -655,8 +658,11 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
if (maxFPS < 1 || maxFPS > 1000)
maxFPS = TheGlobalData->m_framesPerSecondLimit;
DEBUG_LOG(("Setting max FPS limit to %d FPS\n", maxFPS));
- TheGameEngine->setFramesPerSecondLimit(maxFPS);
- TheWritableGlobalData->m_useFpsLimit = true;
+ // the engine's pacing (LOGIC-THREAD.md hazard 24): after the tick
+ LogicThread::callAfterTick( [maxFPS]() {
+ TheGameEngine->setFramesPerSecondLimit(maxFPS);
+ TheWritableGlobalData->m_useFpsLimit = true;
+ } );
}
/* Seed again from the number the start was seeded with. Every start seeds when it appends
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index 083ac232b..26bb0d581 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -179,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){ LOGIC_CENSUS( CENSUS_TACTICALVIEW ); return m_freezeTimeForCameraMovement;} ///< Freezes time during the next camera movement.
+ virtual Bool isTimeFrozen(void){ LOGIC_CENSUS( CENSUS_CLIENT_READ ); 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/Include/W3DDevice/GameLogic/W3DGhostObject.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.h
index 9babf15aa..ccddce8e6 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameLogic/W3DGhostObject.h
@@ -39,6 +39,8 @@
#include "Common/GameCommon.h"
#include "GameClient/DrawableInfo.h"
+#include <vector>
+
class Object;
class W3DGhostObjectManager;
class W3DRenderObjectSnapshot;
@@ -65,12 +67,14 @@ protected:
void release(void); ///< used by manager to return object to free store.
void getShroudStatus(int playerIndex); ///< used to get the partition manager to update ghost objects without parent objects.
void freeAllSnapShots(void); ///< used to free all snapshots from all players.
+ void freeSnapShotNow(int playerIndex); ///< freeSnapShot's body, never queued: the manager's own teardown
W3DRenderObjectSnapshot *m_parentSnapshots[MAX_PLAYER_COUNT];
DrawableInfo m_drawableInfo;
///@todo this list should really be part of the device independent base class (CBD 12-3-2002)
W3DGhostObject *m_nextSystem;
W3DGhostObject *m_prevSystem;
+ ObjectID m_dyingParentID; ///< LOGIC-THREAD.md M6: the parent of a ghost removed inside a tick, found again at its release
};
class W3DGhostObjectManager : public GhostObjectManager
@@ -90,10 +94,14 @@ protected:
virtual void crc( Xfer *xfer );
virtual void xfer( Xfer *xfer );
virtual void loadPostProcess( void );
+ void releaseModule(W3DGhostObject *mod); ///< free its snapshots and put it on the free list
+ void releaseDying(W3DGhostObject *mod); ///< one the tick removed, unless reset released it
+ void freeDyingModules(void); ///< release every one the tick removed
///@todo this list should really be part of the device independent base class (CBD 12-3-2002)
W3DGhostObject *m_freeModules;
W3DGhostObject *m_usedModules;
+ std::vector<W3DGhostObject *> m_dyingModules; ///< LOGIC-THREAD.md M6: removed inside a tick, released after it
};
#endif // _W3DGHOSTOBJECT_H_
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
index bf1c9605d..09a1b52a8 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
@@ -1262,6 +1262,8 @@ void W3DRadar::buildTerrainTexture( TerrainLogic *terrain )
//-------------------------------------------------------------------------------------------------
void W3DRadar::clearShroud()
{
+ LOGIC_AFTER_TICK( [this]() { clearShroud(); } );
+ LOGIC_CENSUS( CENSUS_RADAR );
#if defined(_DEBUG) || defined(_INTERNAL)
if (!TheGlobalData->m_shroudOn)
return;
@@ -1275,6 +1277,7 @@ void W3DRadar::clearShroud()
//-------------------------------------------------------------------------------------------------
void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting)
{
+ LOGIC_AFTER_TICK( [this, shroudX, shroudY, setting]() { setShroudLevel( shroudX, shroudY, setting ); } );
LOGIC_CENSUS( CENSUS_RADAR );
#if defined(_DEBUG) || defined(_INTERNAL)
if (!TheGlobalData->m_shroudOn)
@@ -1451,6 +1454,7 @@ void W3DRadar::draw( Int pixelX, Int pixelY, Int width, Int height )
// ------------------------------------------------------------------------------------------------
void W3DRadar::refreshTerrain( TerrainLogic *terrain )
{
+ LOGIC_AFTER_TICK( [this, terrain]() { refreshTerrain( terrain ); } );
// extend base class
Radar::refreshTerrain( terrain );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index ce23f116f..bf768528c 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -3806,6 +3806,8 @@ void W3DDisplay::clearShroud()
//=============================================================================
void W3DDisplay::setBorderShroudLevel(UnsignedByte level)
{
+ // LOGIC-THREAD.md M6: what a tick pushes here waits for the end of it, in order
+ LOGIC_AFTER_TICK( [=]() { setBorderShroudLevel( level ); } );
LOGIC_CENSUS( CENSUS_DISPLAY );
if (TheTerrainRenderObject && TheTerrainRenderObject->getShroud())
{
@@ -3816,6 +3818,7 @@ void W3DDisplay::setBorderShroudLevel(UnsignedByte level)
//=============================================================================
void W3DDisplay::setShroudLevel( Int x, Int y, CellShroudStatus setting )
{
+ LOGIC_AFTER_TICK( [=]() { setShroudLevel( x, y, setting ); } );
LOGIC_CENSUS( CENSUS_DISPLAY );
if (TheTerrainRenderObject && TheTerrainRenderObject->getShroud())
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
index 02f909b9e..b8193a9fa 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
@@ -384,7 +384,8 @@ void W3DTerrainVisual::addSeismicSimulation( const SeismicSimulationNode& sim )
// HERE WOULD BE A GREAT PLACE FOR AN IDIOT TEST:
// REJECT SIMULATION NODES THAT ARE OFF SCREEN!!!!!!!!!!
-
+ LOGIC_AFTER_TICK( [this, sim]() { addSeismicSimulation( sim ); } );
+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );
m_seismicSimulationList.push_back( sim );
}
@@ -918,7 +919,7 @@ void W3DTerrainVisual::changeWaterHeight( Real x, Real y, Real delta )
void W3DTerrainVisual::addWaterVelocity( Real worldX, Real worldY,
Real velocity, Real preferredHeight )
{
-
+ LOGIC_CENSUS( CENSUS_CLIENT_READ ); // the water grid's motion, as updateWaterGrid
if( m_waterRenderObject )
m_waterRenderObject->addVelocity( worldX, worldY, velocity, preferredHeight );
@@ -928,7 +929,10 @@ void W3DTerrainVisual::addWaterVelocity( Real worldX, Real worldY,
// ------------------------------------------------------------------------------------------------
void W3DTerrainVisual::updateWaterGrid( UnsignedInt logicFrame )
{
- LOGIC_CENSUS( CENSUS_TERRAINVISUAL );
+ /* The water grid's motion is simulation: logic steps it here and reads it back through
+ getWaterGridHeight, so it cannot wait for the tick's end. It lives in the render object,
+ which makes it client state logic reads (M7 moves the grid into TerrainLogic). */
+ LOGIC_CENSUS( CENSUS_CLIENT_READ );
// whether or not the grid is drawn: the simulation reads it either way, as update() stepped it
if( m_waterRenderObject )
m_waterRenderObject->updateMeshMotion( logicFrame );
@@ -938,7 +942,7 @@ void W3DTerrainVisual::updateWaterGrid( UnsignedInt logicFrame )
// ------------------------------------------------------------------------------------------------
Bool W3DTerrainVisual::getWaterGridHeight( Real worldX, Real worldY, Real *height)
{
- LOGIC_CENSUS( CENSUS_TERRAINVISUAL );
+ LOGIC_CENSUS( CENSUS_CLIENT_READ );
Real gridX, gridY;
if (m_isWaterGridRenderingEnabled && m_waterRenderObject &&
@@ -954,8 +958,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,
+ // 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..
// THIS IS TRUE ONLY WHEN DO_SEISMIC_SIMULATIONS is defined M Lorenzen, 8/23/03
@@ -967,22 +970,23 @@ void W3DTerrainVisual::setRawMapHeight(const ICoord2D *gridPos, Int height)
//if (m_logicHeightMap->getHeight(x,y) != height) //ML changed to prevent scissoring with roads
if (m_logicHeightMap->getHeight(x,y) > height)
{
+ // logic's own height, read back by getGroundHeight, so now; the drawn terrain after the tick
m_logicHeightMap->setRawHeight(x, y, height);
- /* This used to be staticLightingChanged(), which rebuilds and re-lights every drawn
- vertex on the map - 61 ms, measured, a visible stutter - because one cell moved. EA
- had noticed: "OOH! this could benefit from the new Seismic update code". It gets a
- partial rebuild of the cell's neighbourhood instead. */
- m_terrainRenderObject->terrainHeightChanged(x, y);
-
+ LogicThread::callAfterTick( [this, x, y, height]() {
+ /* This used to be staticLightingChanged(), which rebuilds and re-lights every drawn
+ vertex on the map - 61 ms, measured, a visible stutter - because one cell moved. EA
+ had noticed: "OOH! this could benefit from the new Seismic update code". It gets a
+ partial rebuild of the cell's neighbourhood instead. */
+ m_terrainRenderObject->terrainHeightChanged(x, y);
-#ifdef DO_SEISMIC_SIMULATIONS
- if ( m_clientHeightMap )
- {
- if ( height < m_clientHeightMap->getHeight( x,y ) )
- m_clientHeightMap->setRawHeight( x, y, height ); // if the client map is heigher than this height, it will fall down to it anyway!
- }
+#ifdef DO_SEISMIC_SIMULATIONS
+ if ( m_clientHeightMap )
+ {
+ if ( height < m_clientHeightMap->getHeight( x,y ) )
+ m_clientHeightMap->setRawHeight( x, y, height ); // if the client map is heigher than this height, it will fall down to it anyway!
+ }
#endif
-
+ } );
}
}
}
@@ -1048,6 +1052,18 @@ void W3DTerrainVisual::addFactionBibDrawable(Drawable *factionBuilding, Bool hig
// ------------------------------------------------------------------------------------------------
void W3DTerrainVisual::addFactionBib(Object *factionBuilding, Bool highlight, Real extra)
{
+ if( LogicThread::defersEffects() )
+ {
+ // the AI's placement tests: by ID, since the tick may destroy the building first
+ const ObjectID id = factionBuilding->getID();
+ LogicThread::callAfterTick( [this, id, highlight, extra]() {
+ Object *live = TheGameLogic->findObjectByID( id );
+ if( live )
+ addFactionBib( live, highlight, extra );
+ } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );
#ifdef DO_SEISMIC_SIMULATIONS
if (m_clientHeightMap)
#else
@@ -1108,6 +1124,7 @@ void W3DTerrainVisual::removeFactionBib(Object *factionBuilding)
// ------------------------------------------------------------------------------------------------
void W3DTerrainVisual::removeAllBibs(void)
{
+ LOGIC_AFTER_TICK( [this]() { removeAllBibs(); } );
LOGIC_CENSUS( CENSUS_TERRAINVISUAL );
if (m_terrainRenderObject) {
m_terrainRenderObject->removeAllTerrainBibs();
@@ -1129,6 +1146,13 @@ void W3DTerrainVisual::removeTreesAndPropsForConstruction(const Coord3D* pos,
const GeometryInfo& geom,
Real angle)
{
+ if( LogicThread::defersEffects() )
+ {
+ const Coord3D at = *pos;
+ LogicThread::callAfterTick( [this, at, geom, angle]() { removeTreesAndPropsForConstruction( &at, geom, angle ); } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_TERRAINVISUAL );
if (m_terrainRenderObject) {
m_terrainRenderObject->removeTreesAndPropsForConstruction(pos, geom, angle);
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index e320baa25..eb8635dcd 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -3817,7 +3817,7 @@ void W3DView::resetCamera(const Coord3D *location, Int milliseconds, Real easeIn
// ------------------------------------------------------------------------------------------------
Bool W3DView::isCameraMovementFinished(void)
{
- LOGIC_CENSUS( CENSUS_TACTICALVIEW );
+ LOGIC_CENSUS( CENSUS_CLIENT_READ );
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 ||
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp
index 094a0230b..c87c131d3 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp
@@ -32,6 +32,8 @@
// Author: Mark Wilczynski, August 2002
///////////////////////////////////////////////////////////////////////////////
+#include <algorithm>
+
#include "Common/Debug.h"
#include "Common/LogicThread.h"
#include "Common/Player.h"
@@ -323,6 +325,7 @@ W3DGhostObject::W3DGhostObject()
m_nextSystem = NULL;
m_prevSystem = NULL;
+ m_dyingParentID = INVALID_ID;
}
@@ -343,6 +346,17 @@ Should only be called when object enters the fogged state.*/
// ------------------------------------------------------------------------------------------------
void W3DGhostObject::snapShot(int playerIndex)
{
+ // the shroud decides when; the drawable's render objects are read after the tick
+ if( LogicThread::defersEffects() )
+ {
+ LogicThread::callAfterTick( [this, playerIndex]() {
+ if( m_parentObject ) // the parent died in the same tick: nothing left to remember
+ snapShot( playerIndex );
+ } );
+ return;
+ }
+ LOGIC_CENSUS( CENSUS_GHOST );
+
//every player's memory is kept only where the fog can be handed to somebody else, an observer's
//machine; without it a building the new viewer saw lost its snapshot and left its shadow behind
if (playerIndex != TheGhostObjectManager->getLocalPlayerIndex() && !TheGhostObjectManager->trackAllPlayers())
@@ -494,13 +508,23 @@ void W3DGhostObject::restoreParentObject(void)
void W3DGhostObject::freeAllSnapShots(void)
{
for (Int playerIndex=0; playerIndex<MAX_PLAYER_COUNT; playerIndex++)
- freeSnapShot(playerIndex);
+ freeSnapShotNow(playerIndex);
}
// ------------------------------------------------------------------------------------------------
/** Player has unfogged the object so he no longer needs the snapshot*/
// ------------------------------------------------------------------------------------------------
void W3DGhostObject::freeSnapShot(int playerIndex)
+{
+ // the shroud decides when; the scene work after the tick
+ LOGIC_AFTER_TICK( [this, playerIndex]() { freeSnapShot( playerIndex ); } );
+ LOGIC_CENSUS( CENSUS_GHOST );
+ freeSnapShotNow( playerIndex );
+}
+
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+void W3DGhostObject::freeSnapShotNow(int playerIndex)
{
if (m_parentSnapshots[playerIndex])
{ //if we have a snapshot for this object, remove it from
@@ -859,7 +883,7 @@ W3DGhostObjectManager::W3DGhostObjectManager(void)
m_freeModules = NULL;
m_usedModules = NULL;
-
+
}
// ------------------------------------------------------------------------------------------------
@@ -908,20 +932,20 @@ void W3DGhostObjectManager::reset(void)
removeGhostObject(mod);
mod=nextmod;
}
+
+ // the clear-game tick removed these from inside the tick, and its queue is thrown away after
+ freeDyingModules();
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void W3DGhostObjectManager::removeGhostObject(GhostObject *object)
{
- LOGIC_CENSUS( CENSUS_GHOST );
if (!object)
return;
W3DGhostObject *mod = (W3DGhostObject *)object;
- mod->freeAllSnapShots();
-
// remove module from used list
if( mod->m_nextSystem )
mod->m_nextSystem->m_prevSystem = mod->m_prevSystem;
@@ -930,6 +954,43 @@ void W3DGhostObjectManager::removeGhostObject(GhostObject *object)
else
m_usedModules = mod->m_nextSystem;
+ /* LOGIC-THREAD.md phase 2, M6. Off the used list now, so the tick's own walks (the map border's
+ partition release) no longer meet it; the snapshots' scene work after the tick, in its place in
+ the queue, and the free list with it, so nothing reuses the module while its queued snapshot calls
+ wait. Those skip a ghost with no parent, and the tick may delete the parent, so it goes now and
+ comes back by ID at the release: a live object re-registered in the tick (a new geometry) has its
+ render objects put back in the scene there, as the release inside the tick did. */
+ if( LogicThread::defersEffects() )
+ {
+ mod->m_dyingParentID = mod->m_parentObject ? mod->m_parentObject->getID() : INVALID_ID;
+ mod->m_parentObject = NULL;
+ mod->m_prevSystem = NULL;
+ mod->m_nextSystem = NULL;
+ m_dyingModules.push_back( mod );
+ LogicThread::callAfterTick( [this, mod]() { releaseDying( mod ); } );
+ return;
+ }
+ releaseModule( mod );
+}
+
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+void W3DGhostObjectManager::releaseDying(W3DGhostObject *mod)
+{
+ std::vector<W3DGhostObject *>::iterator it = std::find( m_dyingModules.begin(), m_dyingModules.end(), mod );
+ if( it == m_dyingModules.end() )
+ return; // reset released it already
+ m_dyingModules.erase( it );
+ mod->m_parentObject = TheGameLogic->findObjectByID( mod->m_dyingParentID );
+ releaseModule( mod );
+}
+
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+void W3DGhostObjectManager::releaseModule(W3DGhostObject *mod)
+{
+ mod->freeAllSnapShots();
+
// add module to free list
mod->m_prevSystem = NULL;
mod->m_nextSystem = m_freeModules;
@@ -938,11 +999,20 @@ void W3DGhostObjectManager::removeGhostObject(GhostObject *object)
m_freeModules = mod;
}
+// ------------------------------------------------------------------------------------------------
+/** The ghosts the tick removed, after it; reset too, since the clear-game tick's queue is thrown away */
+// ------------------------------------------------------------------------------------------------
+void W3DGhostObjectManager::freeDyingModules(void)
+{
+ while (!m_dyingModules.empty())
+ releaseDying(m_dyingModules.back());
+}
+
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
GhostObject *W3DGhostObjectManager::addGhostObject(Object *object, PartitionData *pd)
{
- LOGIC_CENSUS( CENSUS_GHOST );
+ // bookkeeping only, and logic's: a fogged object without a ghost reads as shrouded
// we disabled adding new ghost objects - used during map border resizing and loading
if (m_lockGhostObjects || m_saveLockGhostObjects )