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
fix(w3ddevice): move recorded overlays with the camera beside the tick
Olcay Seygand97dbb11dd91
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.hindex 61d43bd38..72526f34a 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h@@ -142,10 +142,12 @@ namespace LogicThreadvoid 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 );+ * another picture as long as pictureMS, the one just drawn, still ends before the pacer owes the next+ * one (a paced single-player pass). The window stays open and the draw presents the same state+ * again with only the camera moved. Under vsync a picture's length includes its wait for the+ * refresh, so a 60 Hz screen beside 60 ticks a second draws none and a faster one draws them on its+ * refreshes. FALSE closes it as close() does, waiting for the tick. */+ Bool closeOrDrawAgain( Real pictureMS );private:Bool m_open;};diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.hindex 3d197cb31..cb6d8d1c2 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h@@ -182,6 +182,10 @@ public:void record( std::function<void()> call ) { m_recording->push_back( std::move( call ) ); }/// kept for another replay: LOGIC-THREAD.md phase 4 draws the same pass's picture again; the next recording clears itstatic void replay( DrawCalls &calls ) { for( size_t i = 0; i < calls.size(); ++i ) calls[ i ](); }+ /// replay moved by (dx, dy) pixels, for a list recorded under a camera that has scrolled since+ virtual void replayShifted( DrawCalls &calls, Int dx, Int dy ) { replay( calls ); }+ /// the shift replayShifted is drawing with; a recorded string adds it to where it draws+ const ICoord2D &getReplayShift( void ) const { return m_replayShift; }void deferFree( DisplayString *string ) { m_deferredFrees.push_back( string ); }void freeDeferred( void );@@ -255,6 +259,7 @@ protected:UnsignedInt m_elapsedCopywriteTime; ///< Hold on the last frame until both have expiredDisplayString *m_copyrightDisplayString;///< this'll hold the display stringDrawCalls *m_recording = NULL; ///< see beginRecording+ ICoord2D m_replayShift = { 0, 0 }; ///< see replayShiftedstd::vector< DisplayString * > m_deferredFrees; ///< see beginRecording};diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex 9c7056ac1..142031514 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -2020,13 +2020,16 @@ static void reportFrameTimeStats( void )const Real over16 = 100.0f * theFrameTimes.countOver( 16.7f ) / theFrameTimes.count();const Real over33 = 100.0f * theFrameTimes.countOver( 33.3f ) / theFrameTimes.count();- DEBUG_LOG(("HEADLESS FRAMETIME: %d frames | mean %.2f p50 %.2f p95 %.2f p99 %.2f p99.9 %.2f worst %.2f ms (frame %d) | over 16.7ms %d (%.2f%%) | over 33.3ms %d (%.2f%%)\n",+ // over 25 ms is a picture that missed a refresh on a vsynced 60 Hz screen, where every frame is a+ // multiple of 16.7 and the 16.7 count catches the on-time ones that ran a fraction long+ DEBUG_LOG(("HEADLESS FRAMETIME: %d frames | mean %.2f p50 %.2f p95 %.2f p99 %.2f p99.9 %.2f worst %.2f ms (frame %d) | over 16.7ms %d (%.2f%%) | over 33.3ms %d (%.2f%%) | over 25.0ms %d\n",theFrameTimes.count(), theFrameTimes.meanMS(),theFrameTimes.percentileMS( 0.50f ), theFrameTimes.percentileMS( 0.95f ),theFrameTimes.percentileMS( 0.99f ), theFrameTimes.percentileMS( 0.999f ),theFrameTimes.worstMS(), theFrameTimes.worstAtFrame(),theFrameTimes.countOver( 16.7f ), over16,- theFrameTimes.countOver( 33.3f ), over33));+ theFrameTimes.countOver( 33.3f ), over33,+ theFrameTimes.countOver( 25.0f )));// the same passes split for the logic thread plan: mean/p50/p99 of each part#define PASS_SPLIT(h) (h).meanMS(), (h).percentileMS( 0.50f ), (h).percentileMS( 0.99f )DEBUG_LOG(("HEADLESS PASSES TICK: %d | pass %.2f/%.2f/%.2f | sync %.2f/%.2f/%.2f | render %.2f/%.2f/%.2f | logic %.2f/%.2f/%.2f ms mean/p50/p99\n",diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cppindex b5b6844c8..796c1b6b7 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp@@ -350,7 +350,7 @@ void LogicThread::OverlapWindow::open( Bool mayOverlap )}//--------------------------------------------------------------------------------------------------Bool LogicThread::OverlapWindow::closeOrDrawAgain( void )+Bool LogicThread::OverlapWindow::closeOrDrawAgain( Real pictureMS ){if( m_open && s_overlapRunning ){@@ -359,10 +359,9 @@ Bool LogicThread::OverlapWindow::closeOrDrawAgain( void )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 )+ // the plan's rule, wait only once the next tick is due, with the next picture's length taken off+ // so a picture never holds the next tick up; the last picture stands in for the next one+ if( running && TheGameEngine->msUntilNextTickDue() > pictureMS ){++s_extraPictures;return TRUE;diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.hindex 484c08ed2..5718c9227 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h@@ -123,6 +123,7 @@ public:virtual void beginBatch2D( void );virtual void endBatch2D( void );virtual void flushBatch2D( void );+ virtual void replayShifted( DrawCalls &calls, Int dx, Int dy );virtual VideoBuffer* createVideoBuffer( void ) ; ///< Create a video buffer that can be used for this displaydiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.hindex ac8da1c25..cf0f718ba 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h@@ -95,7 +95,8 @@ protected:HAnimClass *m_moveHintAnim[ MAX_MOVE_HINTS ];// recordDraw's lists, replayed by draw- Display::DrawCalls m_overWorldDraw; ///< preDraw to the guard markers+ Display::DrawCalls m_overWorldDraw; ///< preDraw to the guard markers, drawn where the world is+ Display::DrawCalls m_dragBoxDraw; ///< the drag box, drawn where the pointer isDisplay::DrawCalls m_postDrawCalls; ///< postDrawDisplay::DrawCalls m_hudOverlayDraw; ///< drawHudOverlaydiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.hindex 8f8d98892..9d1eb74a8 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h@@ -151,6 +151,9 @@ public:/** 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 );+ /// how far the ground under the camera moved on the screen since recordPostDraw; 0 unless a+ /// picture drawn again beside the tick scrolled, for the world-anchored overlays recorded there+ ICoord2D overlayShift( 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.@@ -362,6 +365,9 @@ private:AsciiString m_cameraSlaveObjectBoneName;Display::DrawCalls m_postDraw; ///< recordPostDraw's calls, replayed by draw+ Coord3D m_postDrawAnchor = { 0, 0, 0 }; ///< the ground under the camera when recordPostDraw ran+ ICoord2D m_postDrawAnchorAt = { 0, 0 }; ///< where m_postDrawAnchor was on the screen then+ Bool m_postDrawAnchorProjected = FALSE; ///< m_postDrawAnchorAt holds a projection, not WTS_INVALID's zeroDrawable *m_cameraLockDrawForDraw = NULL; ///< the camera lock's drawable, looked up by recordPostDraw for a filtered draw}; // end class W3DViewdiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cppindex 24ec2d3e6..961bc96e1 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp@@ -2569,6 +2569,7 @@ AGAIN:LogicThread::OverlapWindow overlapWindow;Bool drawAgain = FALSE;do {+ Int64 pictureStart = Clock_Ticks(); // phase 4 weighs the next picture by this one, sync point left out#ifdef DEBUG_LOGGINGInt64 tOverlapStart = 0; // the part a logic thread could run beside, TheOverlapWindowMS#endif@@ -2634,6 +2635,7 @@ AGAIN:TheParticleUpdateMS = w3dElapsedMS( tParticleStart, tParticleEnd );#endiftakeReadsForRender( rendersThisPass() );+ pictureStart = Clock_Ticks();#ifdef DEBUG_LOGGINGtOverlapStart = Clock_Ticks();#endif@@ -2906,7 +2908,8 @@ AGAIN:if (tOverlapStart)TheOverlapWindowMS += w3dElapsedMS( tOverlapStart, Clock_Ticks() );#endif- drawAgain = overlapWindow.closeOrDrawAgain();+ drawAgain = overlapWindow.closeOrDrawAgain(+ (Real)( (double)( Clock_Ticks() - pictureStart ) * 1000.0 / (double)Clock_Ticks_Per_Second() ) );if (drawAgain){GameEngine_noteExtraPicture();@@ -3197,6 +3200,29 @@ void W3DDisplay::flushBatch2D( void )} // end flushBatch2D+// W3DDisplay::replayShifted ==================================================+/** The 2D renderer turns a corner into screen space as it is added, so a coordinate range moved by+ * the shift moves every quad the list adds; strings add the shift themselves (getReplayShift). */+//=============================================================================+void W3DDisplay::replayShifted( DrawCalls &calls, Int dx, Int dy )+{+ if( dx == 0 && dy == 0 )+ {+ replay( calls );+ return;+ }+ flush2D();+ m_2DRender->Set_Coordinate_Range( RectClass( -dx, -dy, (Real)getWidth() - dx, (Real)getHeight() - dy ) );+ m_replayShift.x = dx;+ m_replayShift.y = dy;+ replay( calls );+ flush2D();+ m_replayShift.x = 0;+ m_replayShift.y = 0;+ m_2DRender->Set_Coordinate_Range( RectClass( 0, 0, getWidth(), getHeight() ) );++} // end replayShifted+// W3DDisplay::drawLine =======================================================/** draw a line on the display in pixel coordinates with the specified color *///=============================================================================diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cppindex 283899dd3..b833f6a73 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp@@ -188,7 +188,10 @@ void W3DDisplayString::draw( Int x, Int y, Color color, Color dropColor, Int xDr// text it holds now, which nothing changes before the replayif( TheDisplay && TheDisplay->isRecording() ){- TheDisplay->record( [=]() { draw( x, y, color, dropColor, xDrop, yDrop ); } );+ TheDisplay->record( [=]() {+ const ICoord2D &shift = TheDisplay->getReplayShift();+ draw( x + shift.x, y + shift.y, color, dropColor, xDrop, yDrop );+ } );return;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 42e990dbd..0b4fe741d 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -64,6 +64,7 @@#include "W3DDevice/GameClient/W3DInGameUI.h"#include "W3DDevice/GameClient/W3DDisplay.h"#include "W3DDevice/GameClient/W3DScene.h"+#include "W3DDevice/GameClient/W3DView.h"#include "W3DDevice/Common/W3DConvert.h"#include "WW3D2/ww3d.h"#include "WW3D2/hanim.h"@@ -401,6 +402,7 @@ void W3DInGameUI::reset( void )InGameUI::reset();// the recordings outlive their replays now (Display::replay); their strings go with Display::resetm_overWorldDraw.clear();+ m_dragBoxDraw.clear();m_postDrawCalls.clear();m_hudOverlayDraw.clear();@@ -519,17 +521,21 @@ static void fillAround( const IRegion2D &window, Int outside, Color color )void W3DInGameUI::recordDraw( void ){m_overWorldDraw.clear();+ m_dragBoxDraw.clear();m_postDrawCalls.clear();m_hudOverlayDraw.clear();if( CinemaDirector_hidesHud() )return;- TheDisplay->beginRecording( &m_overWorldDraw );- preDraw();-- // draw selection region if drag selecting+ // the drag box is the pointer's, so a picture drawn again beside the tick keeps it where it is+ // while the rest of this list moves with a scrolled camera; it draws after the guard markers now+ TheDisplay->beginRecording( &m_dragBoxDraw );if( m_isDragSelecting )drawSelectionRegion();+ TheDisplay->endRecording();++ TheDisplay->beginRecording( &m_overWorldDraw );+ preDraw();// draw the formation line if one is being dragged outif( m_isFormationDragging )@@ -637,9 +643,11 @@ void W3DInGameUI::draw( void )return;}- // preDraw, the drag box, the formation line, the attack circle and the guard markers, which- // recordDraw ran at the sync point- Display::replay( m_overWorldDraw );+ // preDraw, the formation line, the attack circle, the guard markers and the drag box, which+ // recordDraw ran at the sync point; the world's part moves with a camera scrolled since+ const ICoord2D shift = static_cast<W3DView *>( TheTacticalView )->overlayShift();+ TheDisplay->replayShifted( m_overWorldDraw, shift.x, shift.y );+ Display::replay( m_dragBoxDraw );// for each view draw hints/// @todo should the UI be iterating through views like this?diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex 87236207f..fbab987a0 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -1688,6 +1688,18 @@ void W3DView::updateCameraBesideTick( void )m_recalcCamera = false;}+ICoord2D W3DView::overlayShift( void )+{+ ICoord2D shift = { 0, 0 };+ ICoord2D anchorNow;+ if( m_postDrawAnchorProjected && worldToScreenTriReturn( &m_postDrawAnchor, &anchorNow ) != WTS_INVALID )+ {+ shift.x = anchorNow.x - m_postDrawAnchorAt.x;+ shift.y = anchorNow.y - m_postDrawAnchorAt.y;+ }+ return shift;+}+DECLARE_PERF_TIMER(W3DView_updateView)void W3DView::update(void){@@ -2366,6 +2378,12 @@ void W3DView::recordPostDraw( void )TheGameClient->iterateDrawablesInRegion( &axisAlignedRegion, drawablePostDraw, this );TheGameClient->flushTextBearingDrawables();TheDisplay->endRecording();++ // a picture drawn again beside the tick (phase 4) moves this list with its camera, by how far+ // the ground under the camera moved on the screen+ getPosition( &m_postDrawAnchor );+ m_postDrawAnchor.z = cameraGroundHeight( m_postDrawAnchor.x, m_postDrawAnchor.y );+ m_postDrawAnchorProjected = worldToScreenTriReturn( &m_postDrawAnchor, &m_postDrawAnchorAt ) != WTS_INVALID;#ifdef DEBUG_LOGGINGTheIconDrawMS = viewElapsedMS( tIconStart, Clock_Ticks() );#endif@@ -2723,8 +2741,13 @@ void W3DView::draw( void )ThePostChainMS = viewElapsedMS( tPostChainStart, tPostChainEnd );#endif- // the health bars and the rest of the post draw, recorded at the sync point by recordPostDraw- Display::replay( m_postDraw );+ // the health bars and the rest of the post draw, recorded at the sync point by recordPostDraw. A+ // picture drawn again beside the tick has a camera that scrolled since, so the list moves with+ // the ground under the camera. ponytail: one shift for the whole screen, so on a scroll a bar+ // near the camera or far from it is off by the perspective difference for one picture, and a+ // rotation or zoom keeps the sync point's layout; recording world anchors per entry fixes both+ const ICoord2D shift = overlayShift();+ TheDisplay->replayShifted( m_postDraw, shift.x, shift.y );// Render 2D sceneW3DDisplay::m_2DScene->doRender( m_2DCamera );