Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
refactor(gameclient): build a tick's new drawables and delete its dead ones after it
Olcay Seyganb1ebf248e273
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h b/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.hindex 0c2180d89..a6a1ce7cb 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h@@ -75,6 +75,12 @@ public:virtual void doDrawModule(const Matrix3D* transformMtx) = 0;+ /** LOGIC-THREAD.md phase 2, M4: what the constructor would do on the device, the asset manager or+ the scene (render objects, textures, emitters). The drawable calls it once, at the end of its+ own constructor, or after the tick for a drawable logic makes inside one, so a module's+ constructor touches none of that. madeInTick is the second case. */+ virtual void buildRenderObjects( Bool madeInTick ) { }+virtual void setShadowsEnabled(Bool enable) = 0;virtual void releaseShadows(void) = 0; ///< frees all shadow resources used by this module - used by Options screen.virtual void allocateShadows(void) = 0; ///< create shadow resources if not already present. Used by Options screen.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.hindex 738a8e734..1f3bb9f53 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h@@ -56,7 +56,7 @@ namespace LogicThreadCENSUS_PARTICLES, ///< ParticleSystemManager create, find, destroyCENSUS_GAMECLIENT, ///< TheGameClient destroyDrawable, findDrawableByID, addScorch, setFrameCENSUS_EVA, ///< TheEva setShouldPlay- CENSUS_NEW_DRAWABLE, ///< ThingFactory::newDrawable+ CENSUS_NEW_DRAWABLE, ///< Drawable::buildRenderObjects, a drawable's render objects built (M4: after the tick for one logic made)CENSUS_CLIENT_RANDOM, ///< GameClientRandomValue drawsCENSUS_GHOST, ///< GhostObjectManager add/removeCENSUS_MESSAGESTREAM, ///< MessageStream::appendMessage@@ -65,6 +65,7 @@ namespace LogicThreadCENSUS_ON_DEMAND_FLUSH, ///< Drawable::getDrawModulesFlushed applying deferred work inside the tickCENSUS_OBSERVER_LOOKAT, ///< ControlBar::getObserverLookAtPlayer, a logic read of client state (M7)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_COUNT};diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex bfc70a24d..451a6d732 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -367,6 +367,7 @@ public:DrawableID getID( void ) const; ///< return this drawable's unique IDvoid friend_bindToObject( Object *obj ); ///< bind this drawable to an object ID. for use ONLY by GameLogic!+ void friend_forgetObject( void ) { m_object = NULL; } ///< GameClient::destroyDrawable, for a deletion that waits for the flushvoid setIndicatorColor(Color color);void refreshIndicatorColor( void ); ///< re-apply the last colour asked for, under whatever scheme is on now@@ -445,6 +446,10 @@ public:DrawModule const** getDrawModules() const;DrawModule** getDrawModulesFlushed(); ///< applies what the tick deferred now, for a caller that needs the render object as it standsstatic void flushPendingClientWork(); ///< after each tick, on the main thread: the transforms and model conditions the tick deferred+ /** LOGIC-THREAD.md phase 2, M4: inside a tick, past the map load, a new drawable is a shell (ID,+ Thing, condition bits and its modules, everything logic reads) whose render objects are built+ after the tick, and a destroyed one leaves the client at once but is deleted after the tick. */+ static Bool tickDefersLifetime();void flushPendingTransform( Bool onDemand ); ///< tells the draw modules of a transform the tick deferred; GameClient::destroyDrawable/** Where a doClientWork goes among the model condition states the tick has not applied yet. */enum ClientWorkOrder@@ -841,6 +846,7 @@ private:#endifmutable Bool m_clientWorkQueued; ///< this drawable's ID is in the list flushPendingClientWork walksBool m_transformPending; ///< the tick moved it; the draw modules have not been told+ Bool m_renderPending; ///< made in a tick: the draw modules have not built their render objectsstruct PendingStep{ModelConditionFlags condition; ///< a state an in-tick flush would have applied, when work is empty@@ -850,6 +856,7 @@ private:mutable std::vector<PendingStep> m_pendingSteps; ///< what the tick deferred, in the order it happenedvoid queueClientWork() const;+ void buildRenderObjects();void recordConditionStep() const;void deferModelConditionFlush() const;void flushModelCondition( Bool onDemand ) const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.hindex 7d1a730d5..44d352b38 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h@@ -149,6 +149,7 @@ public:virtual Drawable *friend_createDrawable( const ThingTemplate *thing, DrawableStatus statusBits = DRAWABLE_STATUS_NONE ) = 0;virtual void destroyDrawable( Drawable *draw ); ///< Destroy the given drawable+ void flushDestroyedDrawables( void ); ///< delete what destroyDrawable left for after the tick (Drawable::tickDefersLifetime)virtual void setTimeOfDay( TimeOfDay tod ); ///< Tell all the drawables what time of day it is now@@ -187,6 +188,7 @@ protected:Drawable *m_drawableList; ///< All of the drawables in the world// DrawablePtrHash m_drawableHash; ///< Used for DrawableID lookupsDrawablePtrVector m_drawableVector;+ std::vector<Drawable*> m_destroyedInTick; ///< out of the list and the lookup, deleted by flushDestroyedDrawablesDrawableID m_nextDrawableID; ///< For allocating drawable id'sDrawableID allocDrawableID( void ); ///< Returns a new unique drawable iddiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cppindex 5d3eb81cb..b611d3d3e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp@@ -80,7 +80,7 @@ namespace"drawable", "modelcondition", "audio", "ingameui", "controlbar", "tacticalview", "radar","fxlist", "terrainvisual", "particles", "gameclient", "eva", "newdrawable", "clientrandom","ghost", "messagestream", "display", "jobs", "ondemandflush", "observerlookat",- "drawablepush"+ "drawablepush", "destroydrawable"};Real elapsedMS( LogicClock::time_point a, LogicClock::time_point b )diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cppindex 0efa68815..759dea87f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp@@ -31,7 +31,6 @@// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine-#include "Common/LogicThread.h"#include "zhio.h"#include "Common/ThingFactory.h"@@ -369,7 +368,6 @@ Object *ThingFactory::newObject( const ThingTemplate *tmplate, Team *team, Objec//=============================================================================Drawable *ThingFactory::newDrawable(const ThingTemplate *tmplate, DrawableStatus statusBits){- LOGIC_CENSUS( CENSUS_NEW_DRAWABLE );if (tmplate == NULL)throw ERROR_BAD_ARG;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex e96d14730..ad0f8ef3d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -548,7 +548,7 @@ Real Drawable::getEffectiveOpacity() const* graphical side of a logical object, whereas GameLogic objects encapsulate* behaviors and physics. *///--------------------------------------------------------------------------------------------------Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBits )+Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBits ): Thing( thingTemplate ){@@ -556,7 +556,8 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBitm_status = statusBits;m_clientWorkQueued = FALSE;m_transformPending = FALSE;-+ m_renderPending = FALSE;+// Added By Sadullah Nader// Initialization missing and neededm_nextDrawable = NULL;@@ -592,13 +593,7 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBitm_lastSupplyCashDisplayed = -1;m_productionTimeDisplayString = NULL;m_chargeTimeDisplayString = NULL;-- //Added By Sadullah Nader- //Fix for the building percent- m_constructDisplayString = TheDisplayStringManager->newDisplayString();- m_constructDisplayString->setFont(TheFontLibrary->getFont(TheInGameUI->getDrawableCaptionFontName(),- TheGlobalLanguageData->adjustFontSize(TheInGameUI->getDrawableCaptionPointSize()),- TheInGameUI->isDrawableCaptionBold() ));+ m_constructDisplayString = NULL; // buildRenderObjectsm_ambientSound = NULL;m_ambientSoundEnabled = true;@@ -723,9 +718,20 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBitm_selectionFlashEnvelope = NULL; // lazily allocate!m_colorTintEnvelope = NULL; // lazily allocate!- initStaticImages();+ initStaticImages();- // If we are inside GameLogic::startNewGame(), then starting the ambient sound+ // a drawable logic makes in a tick is a shell until the flush after it: its modules exist, so+ // everything logic asks of them (bones, barrels, launch points, the laser's client update) is+ // answered, and only the render objects wait+ if (tickDefersLifetime())+ {+ m_renderPending = TRUE;+ queueClientWork();+ }+ else+ buildRenderObjects();++ // If we are inside GameLogic::startNewGame(), then starting the ambient sound// will be taken care of by Drawable::onLevelStart(). It's important that we// wait until Drawable::onLevelStart(), because we may have a customized ambient// sound which we'll only learn about after the constructor is finished. The@@ -5160,6 +5166,36 @@ void Drawable::queueClientWork() consts_clientWorkQueue.push_back( getID() );}+//-------------------------------------------------------------------------------------------------+/** The map load makes, places and throws away the batched trees and props in one go, and builds+ its loading screen and every render object of the map on the main thread anyway (LogicThread's+ tickNeedsMainThread), so it keeps the drawable lifetime it always had. */+Bool Drawable::tickDefersLifetime()+{+ return TheGameLogic != NULL && TheGameLogic->isInGameLogicUpdate() && !TheGameLogic->isLoadingMap();+}++//-------------------------------------------------------------------------------------------------+/** The second half of the constructor: what the draw modules make on the device, the asset manager+ and the scene, and the construction percent's string. The census counts it from the logic+ thread, where only an on-demand flush of a shell inside the tick can run it. */+void Drawable::buildRenderObjects()+{+ LOGIC_CENSUS( CENSUS_NEW_DRAWABLE );+ const Bool madeInTick = m_renderPending;+ m_renderPending = FALSE;++ //Added By Sadullah Nader+ //Fix for the building percent+ m_constructDisplayString = TheDisplayStringManager->newDisplayString();+ m_constructDisplayString->setFont(TheFontLibrary->getFont(TheInGameUI->getDrawableCaptionFontName(),+ TheGlobalLanguageData->adjustFontSize(TheInGameUI->getDrawableCaptionPointSize()),+ TheInGameUI->isDrawableCaptionBold() ));++ for (DrawModule** dm = getDrawModulesNonDirty(); *dm; ++dm)+ (*dm)->buildRenderObjects( madeInTick );+}+//-------------------------------------------------------------------------------------------------/** The state the drawable holds now, as the next step, unless the last state step already is it. */void Drawable::recordConditionStep() const@@ -5207,6 +5243,10 @@ void Drawable::flushModelCondition( Bool onDemand ) constm_isModelDirty = false;return;}+ // a shell another drawable's work reaches before its own turn in the flush: the render objects+ // come first, as they did in the constructor+ if (m_renderPending)+ const_cast<Drawable*>(this)->buildRenderObjects();LogicThread::census( onDemand ? LogicThread::CENSUS_ON_DEMAND_FLUSH : LogicThread::CENSUS_MODEL_CONDITION );if (s_modelLockCount > 0){@@ -5259,6 +5299,8 @@ void Drawable::flushModelCondition( Bool onDemand ) const//-------------------------------------------------------------------------------------------------void Drawable::doPendingClientWork( Bool onDemand ){+ if (m_renderPending)+ buildRenderObjects();if (m_isModelDirty || !m_pendingSteps.empty())flushModelCondition( onDemand );flushPendingTransform( onDemand );@@ -5338,6 +5380,8 @@ void Drawable::flushPendingClientWork()draw->doPendingClientWork( FALSE );}s_clientWorkQueue.clear();+ // last, so a work above that holds a drawable the tick destroyed runs before it is deleted+ TheGameClient->flushDestroyedDrawables();}//-------------------------------------------------------------------------------------------------@@ -5521,11 +5565,11 @@ void Drawable::friend_bindToObject( Object *obj ) ///< bind this drawable to an}}- for (DrawModule** dm = getDrawModules(); *dm; ++dm)- {- (*dm)->onDrawableBoundToObject();- }-}+ doClientWork( [this]() {+ for (DrawModule** dm = getDrawModulesNonDirty(); *dm; ++dm)+ (*dm)->onDrawableBoundToObject();+ }, WORK_AFTER_FLUSH );+}//-------------------------------------------------------------------------------------------------// when our Object changes teams, it calls us to let us know, so// we can update our model, etc., if necessary. NOTE, we don't guarantee@@ -5605,6 +5649,12 @@ Bool Drawable::handleWeaponFireFX(WeaponSlotType wslot, Int specificBarrelToUse,}}+ // a drawable made this tick has no render object yet to take an FX bone or a muzzle flash from:+ // the weapon plays the FX at the drawable, as it does for a model with no FX bone (the jet+ // crash's impact and fire objects fire in the tick that makes them)+ if (m_renderPending)+ return false;+// the barrels, muzzle flash and FX bones of the state the shot set, where the tick left the drawablefor (DrawModule** dm = getDrawModulesFlushed(); *dm; ++dm){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex 82a9dab8e..918bd61a9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -239,6 +239,7 @@ GameClient::~GameClient()destroyDrawable( draw );}m_drawableList = NULL;+ flushDestroyedDrawables();// delete the ray effectsdelete TheRayEffects;@@ -560,6 +561,9 @@ void GameClient::reset( void )destroyDrawable( draw );}m_drawableList = NULL;+ // the clear-game tick resets from inside the tick, and what it and the ticks before left goes+ // before the scene does+ flushDestroyedDrawables();TheDisplay->reset();TheTerrainVisual->reset();@@ -1020,8 +1024,6 @@ void GameClient::updateFakeDrawables(void)*/void GameClient::destroyDrawable( Drawable *draw ){- LOGIC_CENSUS( CENSUS_GAMECLIENT );-// remove any notion of the Drawable in the in-game user interfaceTheInGameUI->disregardDrawable( draw );@@ -1042,6 +1044,20 @@ void GameClient::destroyDrawable( Drawable *draw )} // end if+ /* LOGIC-THREAD.md phase 2, M4. Inside a tick the drawable leaves the selection, the list and the+ lookup at once, so nothing finds it, and forgets its object, which the tick may delete before+ the flush. Its draw modules, render objects, shadows and sounds go after the tick, in+ flushDestroyedDrawables, once the flush has run the work other drawables deferred. */+ if( Drawable::tickDefersLifetime() )+ {+ removeDrawableFromLookupTable( draw );+ draw->friend_forgetObject();+ m_destroyedInTick.push_back( draw );+ return;+ }++ LOGIC_CENSUS( CENSUS_DESTROY_DRAWABLE );+// what the tick deferred on it happens now or never: the batched trees and props are made, placed// and destroyed in one go by startNewGame, and placing them is what hands them to the terraindraw->flushPendingTransform( TRUE );@@ -1054,6 +1070,19 @@ void GameClient::destroyDrawable( Drawable *draw )}+//-------------------------------------------------------------------------------------------------+void GameClient::flushDestroyedDrawables( void )+{+ for( size_t i = 0; i < m_destroyedInTick.size(); ++i )+ {+ LOGIC_CENSUS( CENSUS_DESTROY_DRAWABLE );+ // the move the tick deferred, as the immediate path above: a model's last place before it goes+ m_destroyedInTick[ i ]->flushPendingTransform( FALSE );+ m_destroyedInTick[ i ]->deleteInstance();+ }+ m_destroyedInTick.clear();+}+// ------------------------------------------------------------------------------------------------/** Add drawable to lookup table for fast id searching */// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDefaultDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDefaultDraw.hindex e3933485d..0e822fe51 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDefaultDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DDefaultDraw.h@@ -60,6 +60,7 @@ public:/// the draw methodvirtual void doDrawModule(const Matrix3D* transformMtx);+ virtual void buildRenderObjects( Bool madeInTick );virtual void setShadowsEnabled(Bool enable);virtual void releaseShadows(void) {}; ///< we don't care about preserving temporary shadows.diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.hindex 07cbbeb06..f8e90f260 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DLaserDraw.h@@ -82,6 +82,7 @@ public:// virtual destructor prototype provided by memory pool declarationvirtual void doDrawModule(const Matrix3D* transformMtx);+ virtual void buildRenderObjects( Bool madeInTick );virtual void releaseShadows(void) {}; ///< we don't care about preserving temporary shadows.virtual void allocateShadows(void) {}; ///< we don't care about preserving temporary shadows.virtual void setShadowsEnabled(Bool enable) { }diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.hindex 3cc0b8e7e..6ace497c5 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DModelDraw.h@@ -358,6 +358,7 @@ public:/// the draw methodvirtual void doDrawModule(const Matrix3D* transformMtx);+ virtual void buildRenderObjects( Bool madeInTick );/// the name the render object was made from; under -modfactions it keeps the "M<n>~" its Get_Name dropsconst AsciiString& getCurrentModelName() const { return m_curState->m_modelName; }diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DPoliceCarDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DPoliceCarDraw.hindex 6c1cd1d7c..803de72e7 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DPoliceCarDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DPoliceCarDraw.h@@ -55,6 +55,7 @@ public:// virtual destructor prototype provided by memory pool declarationvirtual void doDrawModule(const Matrix3D* transformMtx);+ virtual void buildRenderObjects( Bool madeInTick );protected:diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DProjectileStreamDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DProjectileStreamDraw.hindex 7571ed018..bd3b3b796 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DProjectileStreamDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DProjectileStreamDraw.h@@ -69,6 +69,7 @@ public:// virtual destructor prototype provided by memory pool declarationvirtual void doDrawModule(const Matrix3D* transformMtx);+ virtual void buildRenderObjects( Bool madeInTick );virtual void releaseShadows(void) {}; ///< we don't care about preserving temporary shadows.virtual void allocateShadows(void) {}; ///< we don't care about preserving temporary shadows.virtual void setShadowsEnabled(Bool ) { }diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.hindex 78ea40425..4ecd56d29 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/Module/W3DTankDraw.h@@ -71,6 +71,7 @@ public:virtual void setHidden(Bool h);virtual void doDrawModule(const Matrix3D* transformMtx);+ virtual void buildRenderObjects( Bool madeInTick );virtual void setFullyObscuredByShroud(Bool fullyObscured);protected:diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDefaultDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDefaultDraw.cppindex 45a943ae0..14c47ec13 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDefaultDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDefaultDraw.cpp@@ -57,6 +57,13 @@ W3DDefaultDraw::W3DDefaultDraw(Thing *thing, const ModuleData* moduleData) : Dra#ifdef LOAD_TEST_ASSETSm_renderObject = NULL;m_shadow = NULL;+#endif+}++//-------------------------------------------------------------------------------------------------+void W3DDefaultDraw::buildRenderObjects( Bool madeInTick )+{+#ifdef LOAD_TEST_ASSETSif (!getDrawable()->getTemplate()->getLTAName().isEmpty()){m_renderObject = W3DDisplay::m_assetManager->Create_Render_Obj(getDrawable()->getTemplate()->getLTAName().str(), getDrawable()->getScale(), 0);diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cppindex d5abacc69..b344fc049 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp@@ -270,6 +270,11 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :m_texture(NULL),m_textureAspectRatio(1.0f),m_selfDirty(TRUE)+{+}++//-------------------------------------------------------------------------------------------------+void W3DLaserDraw::buildRenderObjects( Bool madeInTick ){Vector3 dummyPos1( 0.0f, 0.0f, 0.0f );Vector3 dummyPos2( 1.0f, 1.0f, 1.0f );@@ -373,7 +378,7 @@ W3DLaserDraw::W3DLaserDraw( Thing *thing, const ModuleData* moduleData ) :} //end segment loop- if( beamGlows( thing ) )+ if( beamGlows( getDrawable() ) ){TextureClass *glowTexture = acquireGlowTexture();@@ -402,7 +407,8 @@ W3DLaserDraw::~W3DLaserDraw( void ){const W3DLaserDrawModuleData *data = getW3DLaserDrawModuleData();- for( int i = 0; i < data->m_numBeams * data->m_segments; i++ )+ // a beam logic made and destroyed in one tick never built its lines+ for( int i = 0; m_line3D && i < data->m_numBeams * data->m_segments; i++ ){// remove line from scenediff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cppindex 59c674113..fa077c54b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp@@ -40,6 +40,7 @@#include "Common/CRCDebug.h"#include "Common/GameState.h"#include "Common/GlobalData.h"+#include "Common/LatchRestore.h"#include "Common/PerfTimer.h"#include "Common/RandomValue.h"#include "Common/ThingTemplate.h"@@ -97,11 +98,15 @@ static Bool s_headlightDrawn = FALSE;//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")#endif+//-------------------------------------------------------------------------------------------------+/** W3DModelDraw::buildRenderObjects of a drawable logic made in a tick, run after it. */+static Bool s_fillingLogicCaches = FALSE;+//-------------------------------------------------------------------------------------------------static inline Bool isValidTimeToCalcLogicStuff(){return (TheGameLogic && TheGameLogic->isInGameLogicUpdate()) ||- (TheGameState && TheGameState->isInLoadGame());+ (TheGameState && TheGameState->isInLoadGame()) || s_fillingLogicCaches;}//-------------------------------------------------------------------------------------------------@@ -1782,11 +1787,6 @@ W3DModelDraw::W3DModelDraw(Thing *thing, const ModuleData* moduleData) : DrawModm_groundMotionAngle = 0.0f;m_groundMotionFrame = 0;- // only validate the current time-of-day and weather conditions by default.- getW3DModelDrawModuleData()->validateStuffForTimeAndWeather(getDrawable(),- TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT,- TheGlobalData->m_weather == WEATHER_SNOWY);-ModelConditionFlags emptyFlags;const ModelConditionInfo* info = findBestInfo(emptyFlags);if (!info)@@ -1817,8 +1817,26 @@ W3DModelDraw::W3DModelDraw(Thing *thing, const ModuleData* moduleData) : DrawModDEBUG_LOG(("setReceivesDynamicLights = FALSE: %s\n", draw->getTemplate()->getName().str()));}}+}- setModelState(info);+//-------------------------------------------------------------------------------------------------+/** The pristine bone, turret and barrel caches are logic's, and filling them loads every state's+ model. A drawable logic makes in a tick fills them here, after the tick, in a window where the+ caches count as logic's (isValidTimeToCalcLogicStuff), so they take the same values from the same+ unanimated models as they did in the constructor. Without that, the first fill could come from+ an on-demand setModelState inside a later tick with this machine's live render object. */+void W3DModelDraw::buildRenderObjects( Bool madeInTick )+{+ {+ LatchRestore<Bool> forLogic( s_fillingLogicCaches, s_fillingLogicCaches || madeInTick );+ // only validate the current time-of-day and weather conditions by default.+ getW3DModelDrawModuleData()->validateStuffForTimeAndWeather(getDrawable(),+ TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT,+ TheGlobalData->m_weather == WEATHER_SNOWY);+ }++ ModelConditionFlags emptyFlags;+ setModelState(findBestInfo(emptyFlags));}//-------------------------------------------------------------------------------------------------@@ -4269,7 +4287,9 @@ void W3DModelDraw::reactToTransformChange( const Matrix3D* oldMtx,Object *obj = getDrawable()->getObject();const Coord3D* pos = getDrawable()->getPosition();- if ( m_fullyObscuredByShroud || obj->testStatus( OBJECT_STATUS_STEALTHED ) == TRUE )+ // no object for a tank the tick destroyed: its last move reaches the track after the tick, as a+ // cap, since whether it was stealthed is gone with the object+ if ( m_fullyObscuredByShroud || obj == NULL || obj->testStatus( OBJECT_STATUS_STEALTHED ) == TRUE ){m_trackRenderObject->addCapEdgeToTrack(pos->x, pos->y);}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DPoliceCarDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DPoliceCarDraw.cppindex a11203c47..e22351fa0 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DPoliceCarDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DPoliceCarDraw.cpp@@ -78,10 +78,17 @@ W3DDynamicLight *W3DPoliceCarDraw::createDynamicLight( void )W3DPoliceCarDraw::W3DPoliceCarDraw( Thing *thing, const ModuleData* moduleData ) : W3DTruckDraw( thing, moduleData ){m_light = NULL;- m_curFrame = GameClientRandomValueReal(0, 10 );+ m_curFrame = 0.0f;m_lastAnimFrame = 0;-}+}++//-------------------------------------------------------------------------------------------------+void W3DPoliceCarDraw::buildRenderObjects( Bool madeInTick )+{+ W3DTruckDraw::buildRenderObjects( madeInTick );+ m_curFrame = GameClientRandomValueReal(0, 10 );+}//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DProjectileStreamDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DProjectileStreamDraw.cppindex 817bac469..03e35f668 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DProjectileStreamDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DProjectileStreamDraw.cpp@@ -91,13 +91,19 @@ W3DProjectileStreamDraw::~W3DProjectileStreamDraw()//-------------------------------------------------------------------------------------------------W3DProjectileStreamDraw::W3DProjectileStreamDraw( Thing *thing, const ModuleData* moduleData ) : DrawModule( thing, moduleData ){- const W3DProjectileStreamDrawModuleData* d = getW3DProjectileStreamDrawModuleData();- m_texture = WW3DAssetManager::Get_Instance()->Get_Texture( d->m_textureName.str() );+ m_texture = NULL;for( Int index = 0; index < MAX_PROJECTILE_STREAM; index++ )m_allLines[index] = NULL;m_linesValid = 0;}+//-------------------------------------------------------------------------------------------------+void W3DProjectileStreamDraw::buildRenderObjects( Bool madeInTick )+{+ const W3DProjectileStreamDrawModuleData* d = getW3DProjectileStreamDrawModuleData();+ m_texture = WW3DAssetManager::Get_Instance()->Get_Texture( d->m_textureName.str() );+}+void W3DProjectileStreamDraw::setFullyObscuredByShroud(Bool fullyObscured){if (fullyObscured)diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cppindex e453a63c5..d284aa1f9 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp@@ -101,7 +101,12 @@ W3DTankDraw::W3DTankDraw( Thing *thing, const ModuleData* moduleData )m_treads[i].m_robj = NULL;m_treadCount=0;+}+//-------------------------------------------------------------------------------------------------+void W3DTankDraw::buildRenderObjects( Bool madeInTick )+{+ W3DModelDraw::buildRenderObjects( madeInTick );createEmitters();}