Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): draw again while the tick runs on at -logicthread 1
Olcay Seygane63ccb46c40e
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h b/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.hindex 41529ed31..df4772b7e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h@@ -59,6 +59,11 @@ Int GameEngine_logicCatchupMaxFrames( Int logicFps );void GameEngine_noteLogicTickDone( Int logicFps, Bool fastMode );Real GameEngine_logicTickFraction( void );+/** LOGIC-THREAD.md phase 4: a picture presented while the pass's tick still runs beside the render,+ with another to follow in the same pass. The frame-time histograms count each picture as a pass of+ its own, the first with the tick, from the pass's start or the last picture to now. */+void GameEngine_noteExtraPicture( void );+/** -video and -directorrecord: whether the logic frame is one a range records. -recordfps drawsGameEngine_videoPictures() pictures of each of those, and the logic runs after the last; the comingdraw is picture GameEngine_videoPicture() of them, 0 first. 1 and 0 outside a range, and at LOGICFRAMES_PER_SECOND.@@ -163,6 +168,11 @@ public:* pacer here, and answers whether this pass's first tick is due and may run beside the render. */Bool planOverlappedTick( void );+ /** LOGIC-THREAD.md phase 4. How long until the pacer owes the next tick, asked while this pass's+ * first tick runs beside the render: the draw shows another picture while it waits only if one fits.+ * 0 outside a paced single-player pass that planOverlappedTick planned (fast mode, a network game). */+ Real msUntilNextTickDue( void );+/** What the pacer decided for one pass, see planLogicPass. */struct LogicPassPlan{diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.hindex fe4360e93..61d43bd38 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h@@ -141,6 +141,11 @@ namespace LogicThread~OverlapWindow( void ) { close(); }void open( Bool mayOverlap );void close( void );+ /** Phase 4, at the end of a picture: TRUE while the tick handed over at the opening still runs and+ * the pacer does not owe the next one yet (a paced single-player pass). The window stays open and+ * the draw presents the same state again with only the camera moved. FALSE closes it as close()+ * does, waiting for the tick. */+ Bool closeOrDrawAgain( void );private:Bool m_open;};diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.hindex 9ca9833fa..3d197cb31 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h@@ -180,7 +180,8 @@ public:void endRecording( void ) { m_recording = NULL; }Bool isRecording( void ) const { return m_recording != NULL; }void record( std::function<void()> call ) { m_recording->push_back( std::move( call ) ); }- static void replay( DrawCalls &calls ) { for( size_t i = 0; i < calls.size(); ++i ) calls[ i ](); calls.clear(); }+ /// kept for another replay: LOGIC-THREAD.md phase 4 draws the same pass's picture again; the next recording clears it+ static void replay( DrawCalls &calls ) { for( size_t i = 0; i < calls.size(); ++i ) calls[ i ](); }void deferFree( DisplayString *string ) { m_deferredFrees.push_back( string ); }void freeDeferred( void );diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.hindex 378c43a22..2506ec1fe 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h@@ -48,6 +48,8 @@ public:/// scrolling, turning or tilting the camera by hand, with the mouse or the keys, right nowBool isMovingCamera( void ) const { return m_isScrolling || m_isRotating || m_isPitching; }void setCurrentPos( const ICoord2D& pos );+ /// one step of the held scroll; the frame tick's, and a picture's drawn beside a tick (LOGIC-THREAD.md phase 4)+ void scrollView( void );void resetModes(); //Used when disabling input, so when we reenable it we aren't stuck in a mode.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex 1c1f23fdf..9c7056ac1 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -1898,6 +1898,23 @@ static Real thePassLogicMS = 0.0f;static Int thePassLogicTicks = 0;static FrameTimeHistogram theTickPass, theTickSync, theTickRender, theTickLogic;static FrameTimeHistogram theRenderPass, theRenderSync, theRenderRender, theOverlapped;+static Int64 thePassStart = 0; ///< execute's pass start, moved on by every extra picture+static Int thePassPictures = 0; ///< the extra pictures this pass presented before its last++void GameEngine_noteFrameTime( Real ms, UnsignedInt logicFrame );++void GameEngine_noteExtraPicture( void )+{+ Int64 now;+ now = Clock_Ticks();+ // the pass's first picture is the one its tick ran beside; a later one ran beside the rest of it+ thePassLogicMS = 0.0f;+ thePassLogicTicks = thePassPictures == 0 ? 1 : 0;+ GameEngine_noteFrameTime( engineElapsedMS( thePassStart, now ), TheGameClient->getFrame() );+ ++thePassPictures;+ thePassStart = now;+ TheOverlapWindowMS = 0.0f;+}void GameEngine_noteFrameTime( Real ms, UnsignedInt logicFrame ){@@ -2791,6 +2808,7 @@ static Real s_logicAccumMs = 0.0f;static Bool s_passPlanned = FALSE;static GameEngine::LogicPassPlan s_passPlan;static UnsignedInt s_frameBeforeOverlap = 0;+static UnsignedInt s_planTimeMs = 0; ///< when the pacer last spent the time since the one beforevoid GameEngine::planLogicPass( LogicPassPlan &plan ){@@ -2837,6 +2855,7 @@ void GameEngine::planLogicPass( LogicPassPlan &plan )UnsignedInt now = Clock_Milliseconds();Real elapsedMs = (Real)(now - prevLogicTime);prevLogicTime = now;+ s_planTimeMs = now;const Bool logicMayRun =((TheNetwork == NULL && !TheGameLogic->isGamePaused()) || (TheNetwork && TheNetwork->isFrameDataReady()));@@ -2911,6 +2930,15 @@ Bool GameEngine::planOverlappedTick( void )return s_passPlan.mayRun && s_passPlan.due;}+/* The pacer's next tick is due once its debt and the time since it last looked make a whole tick:+ GameEngine_isLogicFrameDue, asked without spending anything. */+Real GameEngine::msUntilNextTickDue( void )+{+ if (!s_passPlanned || s_passPlan.fastMode || s_passPlan.networkPaced || m_maxFPS <= 0)+ return 0.0f;+ return 1000.0f / m_maxFPS - s_logicAccumMs - (Real)( Clock_Milliseconds() - s_planTimeMs );+}+void GameEngine::update( void ){USE_PERF_TIMER(GameEngine_update)@@ -3110,7 +3138,8 @@ void GameEngine::update( void )#ifdef DEBUG_LOGGINGthePassLogicMS = logicMS;- thePassLogicTicks = logicTicks;+ // the overlapped tick was charged to the pass's first picture when there were more+ thePassLogicTicks = thePassPictures > 0 && overlapped ? logicTicks - 1 : logicTicks;if( logicTicks == 0 ){fpsNoTickPasses++;@@ -3279,6 +3308,8 @@ void GameEngine::execute( void )QueryPerformanceCounter reads a frame, which is why this is not behind a switch. */Int64 tFrameStart, tFrameEnd;tFrameStart = Clock_Ticks();+ thePassStart = tFrameStart;+ thePassPictures = 0;try{// compute a frame@@ -3306,7 +3337,8 @@ void GameEngine::execute( void )RELEASE_CRASH(("Uncaught Exception in GameEngine::update"));} // catchtFrameEnd = Clock_Ticks();- thisFrameMS = engineElapsedMS( tFrameStart, tFrameEnd );+ // from the last picture an earlier part of the pass presented, if it presented any+ thisFrameMS = engineElapsedMS( thePassStart, tFrameEnd );GameEngine_noteFrameTime( thisFrameMS,TheGameLogic ? TheGameLogic->getFrame() : 0 );} // perfdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cppindex 523ab1f42..b5b6844c8 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp@@ -108,6 +108,7 @@ namespaceReal s_overlapWaitMS = 0.0f;Int s_overlappedTicks = 0;Real s_overlapWaitTotalMS = 0.0f;+ Int s_extraPictures = 0; ///< phase 4: pictures drawn again while a tick ran on (closeOrDrawAgain)// the wait in tenths of a millisecond up to 50, the last bucket everything past itconst Int WAIT_BUCKETS = 501;Int s_waitHistogram[ WAIT_BUCKETS ] = { 0 };@@ -348,6 +349,29 @@ void LogicThread::OverlapWindow::open( Bool mayOverlap )g_windowOpen.store( 1, std::memory_order_relaxed );}+//-------------------------------------------------------------------------------------------------+Bool LogicThread::OverlapWindow::closeOrDrawAgain( void )+{+ if( m_open && s_overlapRunning )+ {+ Bool running;+ {+ std::lock_guard<std::mutex> lock( s_lock );+ running = !s_tickDone;+ }+ // the plan's rule: wait only once the next tick is due, where the serial game falls behind too.+ // ponytail: a picture started just before it is due holds the next tick up by up to its own+ // length; weigh the remaining time against the last picture's if catch-up ticks show it+ if( running && TheGameEngine->msUntilNextTickDue() > 0.0f )+ {+ ++s_extraPictures;+ return TRUE;+ }+ }+ close();+ return FALSE;+}+//-------------------------------------------------------------------------------------------------void LogicThread::OverlapWindow::close( void ){@@ -621,9 +645,9 @@ void LogicThread::report( void )waitP99 = i;seen += s_waitHistogram[ i ];}- DEBUG_LOG(( "HEADLESS LOGICTHREAD OVERLAP: %d ticks beside the render | wait %.2f/%.1f/%.1f ms mean/p50/p99\n",+ DEBUG_LOG(( "HEADLESS LOGICTHREAD OVERLAP: %d ticks beside the render | wait %.2f/%.1f/%.1f ms mean/p50/p99 | %d pictures drawn again while one ran\n",s_overlappedTicks, s_overlappedTicks ? s_overlapWaitTotalMS / s_overlappedTicks : 0.0f,- waitP50 / 10.0f, waitP99 / 10.0f ));+ waitP50 / 10.0f, waitP99 / 10.0f, s_extraPictures ));}char line[ 1024 ];diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cppindex 7e7070d26..5bbfee201 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -222,6 +222,113 @@ LookAtTranslator::LookAtTranslator() :TheLookAtTranslator = this;}+//-----------------------------------------------------------------------------+/* One step of the scroll the keys, the screen's edges or the right drag are holding, every client+ frame (MSG_FRAME_TICK), and on every picture W3DDisplay::draw shows again while a tick runs on+ (LOGIC-THREAD.md phase 4), which reads no logic and runs no message stream: the step is the scroll+ the last frame's input left, and the view's clock makes it as long as the time since the last. */+void LookAtTranslator::scrollView( void )+{+ Coord2D offset = {0, 0};++ // If we've been forced to stop scrolling (script action?) then stop+ if (m_isScrolling && !TheInGameUI->isScrolling())+ {+ TheInGameUI->setScrollAmount(offset);+ stopScrolling();+ }+ else+ // scroll the view+ if (m_isScrolling)+ {+ switch (m_scrollType)+ {+ case SCROLL_RMB:+ {+ // The anchor stays where the button went down and the camera runs away from it,+ // faster the further the cursor gets. This is the retail right-drag scroll, and it+ // is what the hand expects; a one-to-one drag of the world is not the same+ // gesture and reads as sluggish at these scroll factors.+ if (TheInGameUI->shouldMoveScrollAnchor())+ {+ Int maxX = TheDisplay->getWidth()/2;+ Int maxY = TheDisplay->getHeight()/2;++ if (m_currentPos.x + maxX < m_anchor.x)+ m_anchor.x = m_currentPos.x + maxX;+ else if (m_currentPos.x - maxX > m_anchor.x)+ m_anchor.x = m_currentPos.x - maxX;++ if (m_currentPos.y + maxY < m_anchor.y)+ m_anchor.y = m_currentPos.y + maxY;+ else if (m_currentPos.y - maxY > m_anchor.y)+ m_anchor.y = m_currentPos.y - maxY;+ }++ // The drag's own pull did not follow the scroll speed slider at all; only the+ // floor added below did. Scaled against the default so the default drags as it did.+ const Real dragSpeed = TheGlobalData->m_keyboardDefaultScrollFactor > 0.0f+ ? TheGlobalData->m_keyboardScrollFactor / TheGlobalData->m_keyboardDefaultScrollFactor : 1.0f;+ offset.x = TheGlobalData->m_horizontalScrollSpeedFactor * (m_currentPos.x - m_anchor.x) * dragSpeed;+ offset.y = TheGlobalData->m_verticalScrollSpeedFactor * (m_currentPos.y - m_anchor.y) * dragSpeed;+ Coord2D vec;+ vec.x = offset.x;+ vec.y = offset.y;+ vec.normalize();+ // Add in the window scroll amount as the minimum.+ offset.x += TheGlobalData->m_horizontalScrollSpeedFactor * vec.x * sqr(TheGlobalData->m_keyboardScrollFactor);+ offset.y += TheGlobalData->m_verticalScrollSpeedFactor * vec.y * sqr(TheGlobalData->m_keyboardScrollFactor);+ }+ break;+ case SCROLL_KEY:+ {+ if (scrollDir[DIR_UP])+ {+ offset.y -= TheGlobalData->m_verticalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;+ }+ if (scrollDir[DIR_DOWN])+ {+ offset.y += TheGlobalData->m_verticalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;+ }+ if (scrollDir[DIR_LEFT])+ {+ offset.x -= TheGlobalData->m_horizontalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;+ }+ if (scrollDir[DIR_RIGHT])+ {+ offset.x += TheGlobalData->m_horizontalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;+ }+ }+ break;+ case SCROLL_SCREENEDGE:+ {+ // The speed the last three pixels always gave, scaled by how deep into the band+ // the pointer is: barely moving where it enters, all of it at the edge itself.+ const Coord2D pull = edgeScrollPull( m_currentPos );+ offset.x = TheGlobalData->m_horizontalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor * pull.x;+ offset.y = TheGlobalData->m_verticalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor * pull.y;+ }+ break;+ }++ TheInGameUI->setScrollAmount(offset);+ }+ else //not scrolling so reset amount+ TheInGameUI->setScrollAmount(offset);++ // The view turns this into the same number of world units at any height, so a pan crossed+ // the screen ten times faster right down on the ground than from the farthest zoom, and+ // zoomed out no setting of the scroll speed made it feel like it moved. Scaled by the+ // height against MaxCameraHeight, where maps open, it crosses the screen at one pace at+ // every zoom: the pace it always had at that height.+ const Real zoomScale = TheTacticalView->getHeightAboveGround() / TheGlobalData->m_maxCameraHeight;+ offset.x *= zoomScale;+ offset.y *= zoomScale;++ // Advance the pan clock even while stationary, so restarting does not include idle time.+ TheTacticalView->scrollBy( &offset );+}+//-----------------------------------------------------------------------------LookAtTranslator::~LookAtTranslator(){@@ -616,104 +723,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage//-----------------------------------------------------------------------------case GameMessage::MSG_FRAME_TICK:{- Coord2D offset = {0, 0};-- // If we've been forced to stop scrolling (script action?) then stop- if (m_isScrolling && !TheInGameUI->isScrolling())- {- TheInGameUI->setScrollAmount(offset);- stopScrolling();- }- else- // scroll the view- if (m_isScrolling)- {- switch (m_scrollType)- {- case SCROLL_RMB:- {- // The anchor stays where the button went down and the camera runs away from it,- // faster the further the cursor gets. This is the retail right-drag scroll, and it- // is what the hand expects; a one-to-one drag of the world is not the same- // gesture and reads as sluggish at these scroll factors.- if (TheInGameUI->shouldMoveScrollAnchor())- {- Int maxX = TheDisplay->getWidth()/2;- Int maxY = TheDisplay->getHeight()/2;-- if (m_currentPos.x + maxX < m_anchor.x)- m_anchor.x = m_currentPos.x + maxX;- else if (m_currentPos.x - maxX > m_anchor.x)- m_anchor.x = m_currentPos.x - maxX;-- if (m_currentPos.y + maxY < m_anchor.y)- m_anchor.y = m_currentPos.y + maxY;- else if (m_currentPos.y - maxY > m_anchor.y)- m_anchor.y = m_currentPos.y - maxY;- }-- // The drag's own pull did not follow the scroll speed slider at all; only the- // floor added below did. Scaled against the default so the default drags as it did.- const Real dragSpeed = TheGlobalData->m_keyboardDefaultScrollFactor > 0.0f- ? TheGlobalData->m_keyboardScrollFactor / TheGlobalData->m_keyboardDefaultScrollFactor : 1.0f;- offset.x = TheGlobalData->m_horizontalScrollSpeedFactor * (m_currentPos.x - m_anchor.x) * dragSpeed;- offset.y = TheGlobalData->m_verticalScrollSpeedFactor * (m_currentPos.y - m_anchor.y) * dragSpeed;- Coord2D vec;- vec.x = offset.x;- vec.y = offset.y;- vec.normalize();- // Add in the window scroll amount as the minimum.- offset.x += TheGlobalData->m_horizontalScrollSpeedFactor * vec.x * sqr(TheGlobalData->m_keyboardScrollFactor);- offset.y += TheGlobalData->m_verticalScrollSpeedFactor * vec.y * sqr(TheGlobalData->m_keyboardScrollFactor);- }- break;- case SCROLL_KEY:- {- if (scrollDir[DIR_UP])- {- offset.y -= TheGlobalData->m_verticalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;- }- if (scrollDir[DIR_DOWN])- {- offset.y += TheGlobalData->m_verticalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;- }- if (scrollDir[DIR_LEFT])- {- offset.x -= TheGlobalData->m_horizontalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;- }- if (scrollDir[DIR_RIGHT])- {- offset.x += TheGlobalData->m_horizontalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor;- }- }- break;- case SCROLL_SCREENEDGE:- {- // The speed the last three pixels always gave, scaled by how deep into the band- // the pointer is: barely moving where it enters, all of it at the edge itself.- const Coord2D pull = edgeScrollPull( m_currentPos );- offset.x = TheGlobalData->m_horizontalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor * pull.x;- offset.y = TheGlobalData->m_verticalScrollSpeedFactor * SCROLL_AMT * TheGlobalData->m_keyboardScrollFactor * pull.y;- }- break;- }-- TheInGameUI->setScrollAmount(offset);- }- else //not scrolling so reset amount- TheInGameUI->setScrollAmount(offset);-- // The view turns this into the same number of world units at any height, so a pan crossed- // the screen ten times faster right down on the ground than from the farthest zoom, and- // zoomed out no setting of the scroll speed made it feel like it moved. Scaled by the- // height against MaxCameraHeight, where maps open, it crosses the screen at one pace at- // every zoom: the pace it always had at that height.- const Real zoomScale = TheTacticalView->getHeightAboveGround() / TheGlobalData->m_maxCameraHeight;- offset.x *= zoomScale;- offset.y *= zoomScale;-- // Advance the pan clock even while stationary, so restarting does not include idle time.- TheTacticalView->scrollBy( &offset );+ scrollView();// A playing player's camera goes to the other machines too, so an observer can watch his// screen: every CAMERA_NETWORK_FRAMES logic frames at most and only when it moved, wherediff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.hindex ffa01d69a..8f8d98892 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h@@ -148,6 +148,9 @@ public:virtual void draw( ); ///< draw this viewvoid recordPostDraw( void ); ///< the post draw over the world, recorded at the sync point for draw to replay+ /** LOGIC-THREAD.md phase 4: the camera of a picture drawn again while a tick runs on, built from what the+ * scroll moved; the lock, the scripted moves, the shake and the height settle wait for the next update. */+ void updateCameraBesideTick( void );virtual void update( ); ///<called once per frame to determine the final camera and object transformsvirtual Drawable *pickDrawable( const ICoord2D *screen, Bool forceAttack, PickType pickType ); ///< pick drawable given the screen pixel coords. If force attack, picks bridges.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex bd8e68819..24ec2d3e6 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -54,6 +54,7 @@ static void drawFramerateBar(void);#include "Common/ThingFactory.h"#include "Common/LogicThread.h"#include "Common/GameEngine.h"+#include "GameClient/LookAtXlat.h"#include "Common/GlobalData.h"#include "Common/Monitors.h"#include "Common/OptionsCatalog.h"@@ -2561,13 +2562,16 @@ AGAIN:}+ // the span a logic thread could run beside, marked for LOGIC-THREAD.md phase 3's count of logic reads+ // made inside it; opened each time round below and closed after End_Render, or after the loop when+ // a continue skips that. Phase 4: while the tick handed over at its opening runs on and another+ // picture fits before the next tick is due, it stays open and the loop draws the same state again+ LogicThread::OverlapWindow overlapWindow;+ Bool drawAgain = FALSE;do {#ifdef DEBUG_LOGGINGInt64 tOverlapStart = 0; // the part a logic thread could run beside, TheOverlapWindowMS#endif- // the same span, marked for LOGIC-THREAD.md phase 3's count of logic reads made inside it;- // closed below after End_Render, or here at the end of the pass when a continue skips that- LogicThread::OverlapWindow overlapWindow;{if(TheGlobalData->m_loadScreenRender != TRUE)@@ -2594,47 +2598,63 @@ AGAIN:if (DX8Wrapper::_Get_D3D_Device() && (DX8Wrapper::_Get_D3D_Device()->TestCooperativeLevel()) == D3D_OK){ //Checking if we have the device before updating views because the heightmap crashes otherwise while//trying to refresh the visible terrain geometry.- smoothMotionBegin();-// if(TheGlobalData->m_loadScreenRender != TRUE)- updateViews();+ if (drawAgain)+ {+ // Phase 4: the last tick's state again, with only the scroll the input holds applied to the+ // camera. No view update, particle update or sync point, which read logic, and W3D's clock+ // stands still, so nothing that steps on the frame time steps twice+ WW3D::Sync( syncTime );+ now = Clock_Milliseconds(); // the letterbox's fade runs on it+ TheLookAtTranslator->scrollView();+ primaryW3DView->updateCameraBesideTick();+#ifdef DEBUG_LOGGING+ tOverlapStart = Clock_Ticks();+#endif+ }+ else+ {+ smoothMotionBegin();+// if(TheGlobalData->m_loadScreenRender != TRUE)+ updateViews();#ifdef DEBUG_LOGGING- Int64 tParticleStart, tParticleEnd;- tParticleStart = Clock_Ticks();+ Int64 tParticleStart, tParticleEnd;+ tParticleStart = Clock_Ticks();#endif- TheParticleSystemManager->update();//LORENZEN AND WILCZYNSKI MOVED THIS FROM ITS NATIVE POSITION, ABOVE- //FOR THE PURPOSE OF LETTING THE PARTICLE SYSTEM LOOK UP THE RENDER OBJECT"S- //TRANSFORM MATRIX, WHILE IT IS STILL VALID (HAVING DONE ITS CLIENT TRANSFORMS- //BUT NOT YET RESETTING TOT HE LOGICAL TRANSFORM)- //THE RESULT IS THAT PARTICLESYSTEMS LINKED TO BONES IN DRAWABLES.OBJECTS- //MOVE WITH THE CLIENT TRANSFORMS, NOW.- //REVOLUTIONARY!- //-LORENZEN+ TheParticleSystemManager->update();//LORENZEN AND WILCZYNSKI MOVED THIS FROM ITS NATIVE POSITION, ABOVE+ //FOR THE PURPOSE OF LETTING THE PARTICLE SYSTEM LOOK UP THE RENDER OBJECT"S+ //TRANSFORM MATRIX, WHILE IT IS STILL VALID (HAVING DONE ITS CLIENT TRANSFORMS+ //BUT NOT YET RESETTING TOT HE LOGICAL TRANSFORM)+ //THE RESULT IS THAT PARTICLESYSTEMS LINKED TO BONES IN DRAWABLES.OBJECTS+ //MOVE WITH THE CLIENT TRANSFORMS, NOW.+ //REVOLUTIONARY!+ //-LORENZEN#ifdef DEBUG_LOGGING- tParticleEnd = Clock_Ticks();- TheParticleUpdateMS = w3dElapsedMS( tParticleStart, tParticleEnd );+ tParticleEnd = Clock_Ticks();+ TheParticleUpdateMS = w3dElapsedMS( tParticleStart, tParticleEnd );#endif- takeReadsForRender( rendersThisPass() );+ takeReadsForRender( rendersThisPass() );#ifdef DEBUG_LOGGING- tOverlapStart = Clock_Ticks();+ tOverlapStart = Clock_Ticks();#endif- // a draw from inside a tick (the load screen the map start paints) is the tick's own. The- // tick runs beside a render that reads logic only through the sync point's copies, which- // rules out the scripted camera's loop of renders, the debug overlays and displays that walk- // the objects live, -cinema's own interface, smooth motion's restore and the load screen.- if( !TheGameLogic->isInGameLogicUpdate() )- {- Bool mayOverlap = !loopForCameraMovement && rendersThisPass() && !TheSmoothMotionActive- && m_debugDisplayCallback == NULL && !TheGlobalData->m_loadScreenRender- && !TheGlobalData->m_showLanes && !CinemaDirector_hidesHud()- && TheObserverCamera.getDrawnPaneCount() <= 1;+ // a draw from inside a tick (the load screen the map start paints) is the tick's own. The+ // tick runs beside a render that reads logic only through the sync point's copies, which+ // rules out the scripted camera's loop of renders, the debug overlays and displays that walk+ // the objects live, -cinema's own interface, smooth motion's restore and the load screen.+ if( !TheGameLogic->isInGameLogicUpdate() )+ {+ Bool mayOverlap = !loopForCameraMovement && rendersThisPass() && !TheSmoothMotionActive+ && m_debugDisplayCallback == NULL && !TheGlobalData->m_loadScreenRender+ && !TheGlobalData->m_showLanes && !CinemaDirector_hidesHud()+ && TheObserverCamera.getDrawnPaneCount() <= 1;#if defined(_DEBUG) || defined(_INTERNAL)- mayOverlap = mayOverlap && !TheGlobalData->m_debugAI && !TheGlobalData->m_debugCamera- && !TheGlobalData->m_showAudioLocations;+ mayOverlap = mayOverlap && !TheGlobalData->m_debugAI && !TheGlobalData->m_debugCamera+ && !TheGlobalData->m_showAudioLocations;#else- mayOverlap = mayOverlap && !TheGlobalData->m_debugAI;+ mayOverlap = mayOverlap && !TheGlobalData->m_debugAI;#endif- overlapWindow.open( mayOverlap );+ overlapWindow.open( mayOverlap );+ }}// R1: after the particles read the logic bones (Lorenzen's note above), before anything renders.@@ -2666,8 +2686,10 @@ AGAIN:// Above it runs right after updateViews on purpose (see Lorenzen's note), so the systems// read the client transform while it is still valid. There is no updateViews here and// nothing to draw the result of, so a frame's worth of stale transforms costs nothing.+ // Not beside a tick (phase 4's pictures drawn again), which may be making systems.//- TheParticleSystemManager->update();+ if (!drawAgain)+ TheParticleSystemManager->update();}Debug_Statistics::End_Statistics(); //record number of polygons rendered in RenderTargetTextures.@@ -2689,7 +2711,9 @@ AGAIN:TheInGameUI->draw();if( TheMouse )TheMouse->draw(); //keep applying the current cursor style so it remains hidden if needed.- WW3D::End_Render();+ WW3D::End_Render();+ overlapWindow.close();+ drawAgain = FALSE;continue;}couldRender = true;@@ -2775,7 +2799,9 @@ AGAIN:width = ( TheDisplay->getWidth() - displayString->getWidth() ) / 2;displayString->draw( width, height, color, backColor );- m_cinematicTextFrames--;+ // counted in passes; a picture drawn again beside a tick is not one+ if (!drawAgain)+ m_cinematicTextFrames--;}if ( m_debugDisplayCallback )@@ -2880,7 +2906,12 @@ AGAIN:if (tOverlapStart)TheOverlapWindowMS += w3dElapsedMS( tOverlapStart, Clock_Ticks() );#endif- overlapWindow.close();+ drawAgain = overlapWindow.closeOrDrawAgain();+ if (drawAgain)+ {+ GameEngine_noteExtraPicture();+ continue;+ }if (TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript() || TheGameLogic->isGamePaused()){@@ -2892,7 +2923,8 @@ AGAIN:if (loopForCameraMovement)TheGameEngine->serviceWindowsOS();- } while (loopForCameraMovement && !TheTacticalView->isCameraMovementFinished());+ } while (drawAgain || (loopForCameraMovement && !TheTacticalView->isCameraMovementFinished()));+ overlapWindow.close();// R1: the logic transforms back on every model, before picking (the message stream) and the logic.smoothMotionRestore();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 5cbd056e7..42e990dbd 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -399,6 +399,10 @@ void W3DInGameUI::reset( void )// call baseInGameUI::reset();+ // the recordings outlive their replays now (Display::replay); their strings go with Display::reset+ m_overWorldDraw.clear();+ m_postDrawCalls.clear();+ m_hudOverlayDraw.clear();} // end resetdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex 43d94ac76..87236207f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -183,17 +183,25 @@ static void normAngle(Real &angle)}#define TERRAIN_SAMPLE_SIZE 40.0f+/* What W3DTerrainLogic::getGroundHeight answers, asked of the terrain object directly: the camera of a+ picture drawn beside a tick (LOGIC-THREAD.md phase 4) builds inside the overlap window, where the+ object reads the drawn map, and the logic accessor would count it as a read of logic's heights. */+static Real cameraGroundHeight(Real x, Real y)+{+ return TheTerrainRenderObject ? TheTerrainRenderObject->getHeightMapHeight(x, y, NULL) : 0.0f;+}+static Real getHeightAroundPos(Real x, Real y){// terrain height + desired height offset == cameraOffset * actual zoom- Real terrainHeight = TheTerrainLogic->getGroundHeight(x, y);+ Real terrainHeight = cameraGroundHeight(x, y);// find best approximation of max terrain height we can seeReal terrainHeightMax = terrainHeight;- terrainHeightMax = max(terrainHeightMax, TheTerrainLogic->getGroundHeight(x+TERRAIN_SAMPLE_SIZE, y-TERRAIN_SAMPLE_SIZE));- terrainHeightMax = max(terrainHeightMax, TheTerrainLogic->getGroundHeight(x-TERRAIN_SAMPLE_SIZE, y-TERRAIN_SAMPLE_SIZE));- terrainHeightMax = max(terrainHeightMax, TheTerrainLogic->getGroundHeight(x+TERRAIN_SAMPLE_SIZE, y+TERRAIN_SAMPLE_SIZE));- terrainHeightMax = max(terrainHeightMax, TheTerrainLogic->getGroundHeight(x-TERRAIN_SAMPLE_SIZE, y+TERRAIN_SAMPLE_SIZE));+ terrainHeightMax = max(terrainHeightMax, cameraGroundHeight(x+TERRAIN_SAMPLE_SIZE, y-TERRAIN_SAMPLE_SIZE));+ terrainHeightMax = max(terrainHeightMax, cameraGroundHeight(x-TERRAIN_SAMPLE_SIZE, y-TERRAIN_SAMPLE_SIZE));+ terrainHeightMax = max(terrainHeightMax, cameraGroundHeight(x+TERRAIN_SAMPLE_SIZE, y+TERRAIN_SAMPLE_SIZE));+ terrainHeightMax = max(terrainHeightMax, cameraGroundHeight(x-TERRAIN_SAMPLE_SIZE, y+TERRAIN_SAMPLE_SIZE));return terrainHeightMax;}@@ -1254,6 +1262,8 @@ const Coord3D& W3DView::get3DCameraPosition() constvoid W3DView::reset( void ){View::reset();+ // the recording outlives its replays now (Display::replay); its strings go with Display::reset+ m_postDraw.clear();// a match that ends in the freecam leaves it there; the next one starts on the player's cameraif (m_freeCamera)@@ -1670,6 +1680,14 @@ void W3DView::updateView(void)UPDATE();}+void W3DView::updateCameraBesideTick( void )+{+ // a slaved camera (the 3DS Max playback) looks its unit up through the script engine as it builds+ if (m_recalcCamera && !m_freeCamera && !m_isCameraSlaved)+ setCameraTransform();+ m_recalcCamera = false;+}+DECLARE_PERF_TIMER(W3DView_updateView)void W3DView::update(void){