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(w3ddevice): render reads logic only from the sync point

Olcay Seygan670ffb848ef6
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
index ddd894300..8026dd5d8 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
@@ -103,7 +103,7 @@ namespace LogicThread
WINDOW_DRAWABLE_OBJECT, ///< Drawable::getObject: the render's way into an Object
WINDOW_FIND_OBJECT, ///< GameLogic::findObjectByID
WINDOW_OBJECT_LIST, ///< GameLogic::getFirstObject, a walk of logic's object list
- WINDOW_LOGIC_FRAME, ///< GameLogic::getFrame, which the tick advances
+ WINDOW_LOGIC_FRAME, ///< GameLogic::getFrame, which the tick advances; inside the window it answers from takeFrameForDraw's copy and counts nothing
WINDOW_THING, ///< Thing::getPosition and getTransformMatrix: an Object's, or a Drawable's the tick writes at once
WINDOW_SHROUD, ///< PartitionData::getShroudedStatus, a cache it fills
WINDOW_PARTITION, ///< PartitionManager's cell shroud reads
@@ -117,9 +117,15 @@ namespace LogicThread
extern std::atomic<Int> g_windowOpen;
void noteWindow( WindowRead read );
+ /** TRUE on the main thread inside the window, where a read has to come from a copy. */
+ inline Bool isInsideWindow( void )
+ {
+ return g_windowOpen.load( std::memory_order_relaxed ) && !t_isLogicThread;
+ }
+
inline void windowRead( WindowRead read )
{
- if( g_windowOpen.load( std::memory_order_relaxed ) && !t_isLogicThread )
+ if( isInsideWindow() )
noteWindow( read );
}
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h
index db8b1904e..9ca9833fa 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Display.h
@@ -34,6 +34,8 @@
#define _GAME_DISPLAY_H_
#include <stdio.h>
+#include <functional>
+#include <vector>
#include "Common/SubsystemInterface.h"
#include "View.h"
#include "GameClient/Color.h"
@@ -166,7 +168,23 @@ public:
* first, or the batch it did not join lands on top of it when it is finally drawn. */
virtual void flushBatch2D( void ) { }
- /// FullScreen video playback
+ /** LOGIC-THREAD.md phase 3. The overlays drawn over the world read logic as they draw: the health
+ * bar asks the object its health, the superweapon clock asks the module its frame. Those run at
+ * the sync point instead, recording what they draw: between beginRecording and endRecording every
+ * 2D call above and every DisplayString draw goes into the list with its arguments, and replay
+ * draws the list where the overlay used to be drawn, inside the render, in the same order. A
+ * string freed while recording is freed by freeDeferred, at the next sync point, after the replay
+ * that draws it or the pass that skipped the render. */
+ typedef std::vector< std::function<void()> > DrawCalls;
+ void beginRecording( DrawCalls *into ) { into->clear(); m_recording = into; }
+ 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(); }
+ void deferFree( DisplayString *string ) { m_deferredFrees.push_back( string ); }
+ void freeDeferred( void );
+
+ /// FullScreen video playback
virtual void playLogoMovie( AsciiString movieName, Int minMovieLength, Int minCopyrightLength );
virtual void playMovie( AsciiString movieName );
virtual void stopMovie( void );
@@ -235,6 +253,8 @@ protected:
UnsignedInt m_elapsedMovieTime; ///< used to make sure we show the stuff long enough
UnsignedInt m_elapsedCopywriteTime; ///< Hold on the last frame until both have expired
DisplayString *m_copyrightDisplayString;///< this'll hold the display string
+ DrawCalls *m_recording = NULL; ///< see beginRecording
+ std::vector< DisplayString * > m_deferredFrees; ///< see beginRecording
};
// the singleton
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 72b994ee5..398bfbff0 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -484,7 +484,25 @@ public:
void setShroudForDraw( ObjectShroudStatus status, Bool objectDead ) { m_shroudForDraw = status; m_objectDeadForDraw = objectDead; }
ObjectShroudStatus getShroudForDraw( void ) const { return m_shroudForDraw; }
Bool isObjectDeadForDraw( void ) const { return m_objectDeadForDraw; }
-
+
+ /** The rest of what the render asks of the object, taken by the same walk: the scene's look and
+ * occlusion, the translucent silhouette of a building waiting for its builder, a projected shadow
+ * lifted onto a bridge. The render reads these and calls no getObject. */
+ struct ObjectForDraw
+ {
+ Bool hasObject;
+ Bool awaitingBuilder; ///< Object_isAwaitingBuilder, for getEffectiveOpacity
+ Bool empDisabled; ///< DISABLED_EMP
+ Bool outage; ///< a structure underpowered, script underpowered or hacked
+ Int playerIndex; ///< the controlling player's
+ Color playerColor; ///< clientPlayerColor of the controlling player
+ UnsignedInt safeOcclusionFrame;
+ PathfindLayerEnum layer;
+ Real layerHeight; ///< getLayerHeight at the drawable, off LAYER_GROUND only
+ };
+ void setObjectForDraw( const ObjectForDraw &forDraw ) { m_objectForDraw = forDraw; }
+ const ObjectForDraw &getObjectForDraw( void ) const { return m_objectForDraw; }
+
void setShadowsEnabled(Bool enable);
Bool getShadowsEnabled() const { return BitTest(m_status, DRAWABLE_STATUS_SHADOWS); }
@@ -809,6 +827,7 @@ private:
UnsignedInt m_shroudClearFrame; ///< Last frame the local player saw this drawable "OBJECTSHROUD_CLEAR"
ObjectShroudStatus m_shroudForDraw; ///< see setShroudForDraw
Bool m_objectDeadForDraw; ///< see setShroudForDraw
+ ObjectForDraw m_objectForDraw; ///< see setObjectForDraw
DrawableLocoInfo* m_locoInfo; // lazily allocated
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index bd8ee428f..6754888d9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -1004,6 +1004,7 @@ public: // ********************************************************************
virtual void preDraw( void ); ///< Logic which needs to occur before the UI renders
virtual void draw( void ) = 0; ///< Render the in-game user interface
+ virtual void recordDraw( void ) { } ///< what draw asks of logic, at the sync point (W3DInGameUI)
virtual void postDraw( void ); ///< Logic which needs to occur after the UI renders
/// -directorrecord's broadcast over the director's picture: a score bar along the top with every
/// player's name, side, cash and army and the match clock, the armies' tug of war under it, and a
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
index f28139ec3..157b511de 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
@@ -163,6 +163,9 @@ public:
Bool isInGameLogicUpdate( void ) const { return s_isInUpdate; }
Bool isNewGamePending( void ) const { return m_startNewGame; } ///< the next update starts a map (LogicThread keeps that tick on the main thread)
UnsignedInt getFrame( void ); ///< Returns the current simulation frame number
+ /** LOGIC-THREAD.md phase 3: the frame as the render's sync point found it, which getFrame answers the
+ * main thread with inside the overlap window, where the tick may be advancing m_frame beside it. */
+ void takeFrameForDraw( void ) { m_frameForDraw = m_frame; }
UnsignedInt getFrameForClient( void ) const { return m_frameForClient; } ///< the frame the last tick ran, for the client's clock (LogicThread::runTick)
UnsignedInt getCRC( Int mode = CRC_CACHED, AsciiString deepCRCFileName = AsciiString::TheEmptyString ); ///< Returns the CRC
@@ -363,6 +366,7 @@ private:
Real m_width, m_height; ///< Dimensions of the world
UnsignedInt m_frame; ///< Simulation frame number
UnsignedInt m_frameForClient; ///< m_frame at the top of the last update that got past the intro movie
+ UnsignedInt m_frameForDraw = 0; ///< see takeFrameForDraw
// CRC cache system -----------------------------------------------------------------------------
UnsignedInt m_CRC; ///< Cache of previous CRC value
@@ -494,7 +498,7 @@ inline void GameLogic::setWidth( Real width ) { m_width = width; }
inline Real GameLogic::getWidth( void ) { return m_width; }
inline void GameLogic::setHeight( Real height ) { m_height = height; }
inline Real GameLogic::getHeight( void ) { return m_height; }
-inline UnsignedInt GameLogic::getFrame( void ) { LOGIC_WINDOW_READ( WINDOW_LOGIC_FRAME ); return m_frame; }
+inline UnsignedInt GameLogic::getFrame( void ) { return LogicThread::isInsideWindow() ? m_frameForDraw : m_frame; }
inline Bool GameLogic::isInGame( void ) { return !(m_gameMode == GAME_NONE); }
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/PolygonTrigger.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/PolygonTrigger.h
index a242285f2..50aaec59c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/PolygonTrigger.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/PolygonTrigger.h
@@ -138,6 +138,7 @@ public:
Bool getSelected() {return m_selected;}
void getCenterPoint(Coord3D* pOutCoord) const;
+ void getCenterXY(Coord3D* pOutCoord) const;
Real getRadius(void) const;
public:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp
index 39693d449..fe9b885f0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp
@@ -95,6 +95,8 @@ Display::~Display()
stopMovie();
// delete all our views if present
deleteViews();
+ // before the string manager goes (GameClient's destructor deletes this first)
+ freeDeferred();
}
@@ -123,6 +125,16 @@ void Display::attachView( View *view )
m_viewList = view->prependViewToList( m_viewList );
}
+/**
+ * The strings a recorded overlay freed (beginRecording), once nothing recorded can draw them
+ */
+void Display::freeDeferred( void )
+{
+ for( size_t i = 0; i < m_deferredFrees.size(); ++i )
+ TheDisplayStringManager->freeDisplayString( m_deferredFrees[ i ] );
+ m_deferredFrees.clear();
+}
+
/**
* Render all views of the world
*/
@@ -365,6 +377,7 @@ void Display::reset()
m_letterBoxFadeLevel = 0;
m_letterBoxEnabled = FALSE;
stopMovie();
+ freeDeferred();
// Reset all views that need resetting
for( View *v = m_viewList; v; v = v->getNextView() )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 99ac6fbb7..f22f6d1b2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -532,15 +532,12 @@ Bool Drawable_disabledShowsBlueHealthBar( DisabledMaskType disabledFlags )
/** The silhouette is the finished building, not a foundation: the construction model conditions are
* left alone until the builder arrives, so what stands on the map is the shape that was under the
* cursor. A drawable with no object behind it is the placement preview itself, which carries the
- * same opacity explicitly. */
+ * same opacity explicitly. The render asks this, so the object's half is the sync point's
+ * (setObjectForDraw). */
//-------------------------------------------------------------------------------------------------
Real Drawable::getEffectiveOpacity() const
{
- const Object *obj = getObject();
- Bool awaitingBuilder = obj && Object_isAwaitingBuilder( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ),
- obj->getConstructionPercent() );
-
- return Drawable_effectiveOpacity( m_explicitOpacity, m_effectiveStealthOpacity, awaitingBuilder );
+ return Drawable_effectiveOpacity( m_explicitOpacity, m_effectiveStealthOpacity, m_objectForDraw.awaitingBuilder );
}
//-------------------------------------------------------------------------------------------------
@@ -616,6 +613,15 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBit
m_shroudClearFrame = 0;
m_shroudForDraw = OBJECTSHROUD_CLEAR;
m_objectDeadForDraw = FALSE;
+ m_objectForDraw.hasObject = FALSE;
+ m_objectForDraw.awaitingBuilder = FALSE;
+ m_objectForDraw.empDisabled = FALSE;
+ m_objectForDraw.outage = FALSE;
+ m_objectForDraw.playerIndex = 0;
+ m_objectForDraw.playerColor = 0;
+ m_objectForDraw.safeOcclusionFrame = 0;
+ m_objectForDraw.layer = LAYER_GROUND;
+ m_objectForDraw.layerHeight = 0.0f;
for (i = 0; i < NUM_DRAWABLE_MODULE_TYPES; ++i)
m_modules[i] = NULL;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
index 382e53f2c..b968ab4b1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
@@ -86,6 +86,7 @@
#include "GameClient/Shell.h"
#include "GameClient/Snow.h"
#include "GameClient/TerrainVisual.h"
+#include "GameLogic/TerrainLogic.h"
#include "GameClient/View.h"
#include "GameClient/VideoPlayer.h"
#include "GameClient/WindowXlat.h"
@@ -908,12 +909,31 @@ void GameClient::update( void )
// so this reads it; the draw no longer calls into the partition beside a tick.
for( Drawable *draw = m_drawableList; draw; draw = draw->getNextDrawable() )
{
- const Object *object = draw->getObject();
+ Object *object = draw->getObject();
+ Drawable::ObjectForDraw forDraw = draw->getObjectForDraw();
+ forDraw.hasObject = object != NULL;
if( object )
{
draw->setShroudForDraw( object->getShroudedStatus( localPlayerIndex ), object->isEffectivelyDead() );
+ // and the rest of what the scene asks of it
+ forDraw.awaitingBuilder = Object_isAwaitingBuilder( object->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ),
+ object->getConstructionPercent() );
+ forDraw.empDisabled = object->isDisabledByType( DISABLED_EMP );
+ forDraw.outage = object->isKindOf( KINDOF_STRUCTURE )
+ && ( object->isDisabledByType( DISABLED_UNDERPOWERED ) || object->isDisabledByType( DISABLED_SCRIPT_UNDERPOWERED )
+ || object->isDisabledByType( DISABLED_HACKED ) );
+ const Player *player = object->getControllingPlayer();
+ forDraw.playerIndex = player->getPlayerIndex();
+ forDraw.playerColor = clientPlayerColor( player );
+ forDraw.safeOcclusionFrame = object->getSafeOcclusionFrame();
+ forDraw.layer = object->getLayer();
+ if( forDraw.layer != LAYER_GROUND )
+ forDraw.layerHeight = TheTerrainLogic->getLayerHeight( draw->getPosition()->x, draw->getPosition()->y, forDraw.layer );
+ draw->setObjectForDraw( forDraw );
continue;
}
+ forDraw.awaitingBuilder = FALSE;
+ draw->setObjectForDraw( forDraw );
//Hack for prison camps which contain enemy prisoner drawables: another object holds the shroud
ObjectShroudStatus status = OBJECTSHROUD_CLEAR;
const ObjectID shroudObjectID = draw->getDrawableInfo()->m_shroudStatusObjectID;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp
index 242cc05ef..193f32fd7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp
@@ -431,13 +431,18 @@ void PolygonTrigger::getCenterPoint(Coord3D* pOutCoord) const
return;
}
+ getCenterXY(pOutCoord);
+ (*pOutCoord).z = TheTerrainLogic->getGroundHeight(pOutCoord->x, pOutCoord->y);
+}
+
+/** The middle of the bounds, z left alone: the render asks its own copy of the ground there */
+void PolygonTrigger::getCenterXY(Coord3D* pOutCoord) const
+{
if (m_boundsNeedsUpdate) {
updateBounds();
}
(*pOutCoord).x = (m_bounds.lo.x + m_bounds.hi.x) / 2.0f;
(*pOutCoord).y = (m_bounds.lo.y + m_bounds.hi.y) / 2.0f;
-
- (*pOutCoord).z = TheTerrainLogic->getGroundHeight(pOutCoord->x, pOutCoord->y);
}
Real PolygonTrigger::getRadius(void) const
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
index 1ec769f0d..39407bef8 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
@@ -105,6 +105,8 @@ protected:
WW3DFormat m_overlayTextureFormat; ///< format to use for overlay texture
Image *m_overlayImage; ///< overlay image abstraction for drawing
TextureClass *m_overlayTexture; ///< overlay texture
+ Bool m_overlayDrawn; ///< draw showed the overlay since update last refreshed it
+ Bool m_eventsDrawn; ///< draw showed the events since update last played their sounds
WW3DFormat m_shroudTextureFormat; ///< format to use for shroud texture
Image *m_shroudImage; ///< shroud image abstraction for drawing
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h
index e5768c51b..276f60706 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h
@@ -30,6 +30,7 @@
#ifndef __BASE_HEIGHTMAP_H_
#define __BASE_HEIGHTMAP_H_
+#include <vector>
#include "always.h"
#include "rendobj.h"
#include "w3d_file.h"
@@ -61,6 +62,27 @@ class W3DPropBuffer;
class W3DTreeDrawModuleData;
class GeometryInfo;
+/** LOGIC-THREAD.md phase 3: the drawn map's heights as the last sync point left them. The map the
+ * terrain draws is logic's own, and a structure flattening its footprint lowers it inside the tick;
+ * this copy takes a cell only when terrainHeightChanged tells the terrain, after the tick. */
+class DrawHeightMapData : public WorldHeightMapData
+{
+public:
+ ~DrawHeightMapData( void ) { m_data = NULL; } // m_heights owns them, not the base
+ void copyFrom( WorldHeightMapData *map )
+ {
+ m_width = map->getXExtent();
+ m_height = map->getYExtent();
+ m_borderSize = map->getBorderSizeInline();
+ m_dataSize = m_width * m_height;
+ m_heights.assign( map->getDataPtr(), map->getDataPtr() + m_dataSize );
+ m_data = m_heights.empty() ? NULL : &m_heights[ 0 ];
+ }
+ void copyCell( WorldHeightMapData *map, Int x, Int y ) { m_heights[ x + y * m_width ] = map->getDataPtr()[ x + y * m_width ]; }
+private:
+ std::vector< UnsignedByte > m_heights;
+};
+
#define no_TIMING_TESTS 1
#define no_PRE_TRANSFORM_VERTEX // Don't do this, not a performance win. jba.
@@ -174,6 +196,7 @@ public:
void removeAllTrees(void);
void removeTree(DrawableID id);
Bool updateTreePosition(DrawableID id, Coord3D location, Real angle);
+ void stepTrees(void); ///< W3DTreeBuffer::stepTrees, at the render's sync point
void renderTrees(CameraClass * camera); ///< renders the tree buffer.
void addProp(Int id, Coord3D location, Real angle, Real scale, const AsciiString &modelName);
@@ -220,6 +243,8 @@ public:
void setShoreLineDetail(void); ///<update shoreline tiles in case the feature was toggled by user.
Bool getMaximumVisibleBox(const FrustumClass &frustum, AABoxClass *box, Bool ignoreMaxHeight); ///<3d extent of visible terrain.
Real getHeightMapHeight(Real x, Real y, Coord3D* normal) const; ///<return height and normal at given point
+ Real getDrawHeight(Real x, Real y) const; ///< getHeightMapHeight from the sync point's copy, for the render beside a tick
+ void heightsLoaded(void) { m_drawHeights.copyFrom(m_map); staticLightingChanged(); } ///< a save wrote every height at once
Bool isCliffCell(Real x, Real y); ///<return height and normal at given point
Real getMinHeight(void) const {return m_minHeight;} ///<return minimum height of entire terrain
Real getMaxHeight(void) const {return m_maxHeight;} ///<return maximum height of entire terrain
@@ -288,6 +313,7 @@ protected:
void drawScorches(void); ///< Draws the scorch mark polygons in m_vertexScorch.
#endif
WorldHeightMap *m_map;
+ mutable DrawHeightMapData m_drawHeights; ///< getDrawHeight's, see DrawHeightMapData
Bool m_useDepthFade; ///<fade terrain lighting under water
Bool m_updating;
Vector3 m_depthFade; ///<depth based fall off values for r,g,b
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h
index 91004ff46..484c08ed2 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h
@@ -79,7 +79,7 @@ public:
// Drawing management
virtual void setClipRegion( IRegion2D *region ); ///< Set clip rectangle for 2D draw operations.
virtual Bool isClippingEnabled( void ) { return m_isClippedEnabled; }
- virtual void enableClipping( Bool onoff ) { m_isClippedEnabled = onoff; }
+ virtual void enableClipping( Bool onoff ) { if( isRecording() ) { record( [=]() { enableClipping( onoff ); } ); return; } m_isClippedEnabled = onoff; }
virtual void draw( void ); ///< redraw the entire display
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
index 3bcef48b2..ac8da1c25 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
@@ -70,6 +70,7 @@ public:
//-----------------------------------------------------------------------------------------------
virtual void draw( void ); ///< Render the in-game user interface
+ virtual void recordDraw( void ); ///< what draw asks of logic, run at the sync point (LOGIC-THREAD.md phase 3)
protected:
@@ -93,6 +94,11 @@ protected:
RenderObjClass *m_moveHintRenderObj[ MAX_MOVE_HINTS ];
HAnimClass *m_moveHintAnim[ MAX_MOVE_HINTS ];
+ // recordDraw's lists, replayed by draw
+ Display::DrawCalls m_overWorldDraw; ///< preDraw to the guard markers
+ Display::DrawCalls m_postDrawCalls; ///< postDraw
+ Display::DrawCalls m_hudOverlayDraw; ///< drawHudOverlay
+
}; // end class W3DInGameUI
#endif // end __W3DINGAMEUI_H_
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h
index a65e85f2d..abefe02bd 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h
@@ -56,6 +56,8 @@ public:
virtual void queueParticleRender();
///< returns the number of particles shown on screen per frame
virtual Int getOnScreenParticleCount() { return m_onScreenParticleCount; }
+ /// at the render's sync point: the systems' stealth fades and the fields' fades, which read the logic
+ void takeReadsForRender( void );
private:
enum { MAX_POINTS_PER_GROUP = 512 };
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h
index d066541ad..ecc5d2797 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h
@@ -223,6 +223,7 @@ public:
void setBounds(const Region2D &bounds) {m_bounds = bounds;}
/// Draws the trees. Uses camera for culling.
void drawTrees(CameraClass * camera, RefRenderObjListIterator *pDynamicLightsIterator);
+ void stepTrees(void); ///< the toppling and pushed trees, once a logic frame, at the render's sync point
/// Called when the view changes, and sort key needs to be recalculated.
/// Normally sortKey gets calculated when a tree becomes visible.
void doFullUpdate(void) {m_updateAllKeys = true;};
@@ -289,6 +290,7 @@ private:
Real m_curSwayOffset[MAX_SWAY_TYPES];
UnsignedInt m_lastSwayFrame; ///< last logic frame the sway was stepped on (drawTrees runs per render frame)
+ UnsignedInt m_lastTreeStepFrame; ///< last logic frame stepTrees moved the toppling and pushed trees on
Real m_curSwayStep[MAX_SWAY_TYPES];
Real m_curSwayFactor[MAX_SWAY_TYPES];
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index cd5f387ec..726c41b54 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -44,6 +44,7 @@
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "Common/LogicThread.h"
#include "Common/STLTypedefs.h"
+#include "GameClient/Display.h"
#include "GameClient/ParabolicEase.h"
#include "GameClient/View.h"
#include "GameClient/CameraScrollClock.h"
@@ -146,6 +147,7 @@ public:
virtual void updateView(void); ///<called once per frame to determine the final camera and object transforms
virtual void draw( ); ///< draw this view
+ void recordPostDraw( void ); ///< the post draw over the world, recorded at the sync point for draw to replay
virtual void update( ); ///<called once per frame to determine the final camera and object transforms
virtual Drawable *pickDrawable( const ICoord2D *screen, Bool forceAttack, PickType pickType ); ///< pick drawable given the screen pixel coords. If force attack, picks bridges.
@@ -355,6 +357,8 @@ private:
Bool m_useRealZoomCam;
AsciiString m_cameraSlaveObjectName;
AsciiString m_cameraSlaveObjectBoneName;
+
+ Display::DrawCalls m_postDraw; ///< recordPostDraw's calls, replayed by draw
}; // end class W3DView
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
index 09a1b52a8..aa27bea61 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
@@ -559,6 +559,10 @@ void W3DRadar::drawEvents( Int pixelX, Int pixelY, Int width, Int height )
{
Int i;
+ // update plays the sound of an event drawn for the first time: the sound asks the player list who
+ // may hear it, and draw runs inside the render
+ m_eventsDrawn = TRUE;
+
for( i = 0; i < MAX_RADAR_EVENTS; i++ )
{
@@ -566,16 +570,6 @@ void W3DRadar::drawEvents( Int pixelX, Int pixelY, Int width, Int height )
if( m_event[ i ].active == TRUE && m_event[ i ].type != RADAR_EVENT_FAKE )
{
- // if we haven't played the sound for this event, do it now that we can see it
- if( m_event[ i ].soundPlayed == FALSE && m_event[i].type != RADAR_EVENT_BEACON_PULSE )
- {
- static AudioEventRTS eventSound("RadarEvent");
- TheAudio->addAudioEvent( &eventSound );
-
- } // end if
-
- m_event[ i ].soundPlayed = TRUE;
-
if ( m_event[ i ].type == RADAR_EVENT_BEACON_PULSE )
drawSingleBeaconEvent( pixelX, pixelY, width, height, i );
else
@@ -823,6 +817,8 @@ W3DRadar::W3DRadar( void )
m_overlayTextureFormat = WW3D_FORMAT_UNKNOWN;
m_overlayImage = NULL;
m_overlayTexture = NULL;
+ m_overlayDrawn = FALSE;
+ m_eventsDrawn = FALSE;
m_shroudTextureFormat = WW3D_FORMAT_UNKNOWN;
m_shroudImage = NULL;
@@ -990,6 +986,42 @@ void W3DRadar::update( void )
// extend base class
Radar::update();
+ // the sound of each event the last draw showed for the first time
+ if( m_eventsDrawn )
+ {
+ m_eventsDrawn = FALSE;
+ for( Int i = 0; i < MAX_RADAR_EVENTS; i++ )
+ {
+ if( m_event[ i ].active == FALSE || m_event[ i ].type == RADAR_EVENT_FAKE )
+ continue;
+ if( m_event[ i ].soundPlayed == FALSE && m_event[ i ].type != RADAR_EVENT_BEACON_PULSE )
+ {
+ static AudioEventRTS eventSound("RadarEvent");
+ TheAudio->addAudioEvent( &eventSound );
+ }
+ m_event[ i ].soundPlayed = TRUE;
+ }
+ }
+
+ // Refresh the overlay texture once every so many frames, while the radar is shown. Here, not in
+ // draw: the blips ask each object where it is, whether the drawn player sees it and whether it is
+ // stealthed, and draw runs inside the render, beside the tick once it runs there (LOGIC-THREAD.md
+ // phase 3).
+ if( m_overlayDrawn && TheGameClient->getFrame() % OVERLAY_REFRESH_RATE == 0 )
+ {
+ m_overlayDrawn = FALSE;
+
+ // reset the overlay texture
+ SurfaceClass *surface = m_overlayTexture->Get_Surface_Level();
+ surface->Clear();
+ REF_PTR_RELEASE(surface);
+
+ // rebuild the object overlay
+ renderObjectList( getObjectList(), m_overlayTexture );
+ renderObjectList( getLocalObjectList(), m_overlayTexture, TRUE );
+
+ } // end if
+
} // end update
//-------------------------------------------------------------------------------------------------
@@ -1391,22 +1423,8 @@ void W3DRadar::draw( Int pixelX, Int pixelY, Int width, Int height )
// draw the terrain texture
TheDisplay->drawImage( m_terrainImage, ul.x, ul.y, lr.x, lr.y );
- // refresh the overlay texture once every so many frames
- if( TheGameClient->getFrame() % OVERLAY_REFRESH_RATE == 0 )
- {
-
- // reset the overlay texture
- SurfaceClass *surface = m_overlayTexture->Get_Surface_Level();
- surface->Clear();
- REF_PTR_RELEASE(surface);
-
- // rebuild the object overlay
- renderObjectList( getObjectList(), m_overlayTexture );
- renderObjectList( getLocalObjectList(), m_overlayTexture, TRUE );
-
- } // end if
-
- // draw the overlay image
+ // draw the overlay image, which update refreshes
+ m_overlayDrawn = TRUE;
TheDisplay->drawImage( m_overlayImage, ul.x, ul.y, lr.x, lr.y );
// draw the shroud image
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
index 0c08de680..7697fcfcf 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
@@ -936,6 +936,15 @@ Real BaseHeightMapRenderObjClass::getHeightMapHeight(Real x, Real y, Coord3D* no
return TerrainHeightSampling::getHeightMapHeight(m_map, logicHeightMap, x, y, normal);
}
+//=============================================================================
+/** getHeightMapHeight for the render: the same sampling over the heights the last sync point left
+ (DrawHeightMapData), which a tick running beside the render does not write. */
+//=============================================================================
+Real BaseHeightMapRenderObjClass::getDrawHeight(Real x, Real y) const
+{
+ return TerrainHeightSampling::getHeightMapHeight(&m_drawHeights, &m_drawHeights, x, y, NULL);
+}
+
//=============================================================================
Bool BaseHeightMapRenderObjClass::isClearLineOfSight(const Coord3D& pos, const Coord3D& posOther) const
{
@@ -1489,6 +1498,8 @@ Int BaseHeightMapRenderObjClass::initHeightData(Int x, Int y, WorldHeightMap *pM
{
REF_PTR_SET(m_map, pMap); //update our heightmap pointer in case it changed since last call.
+ if (pMap)
+ m_drawHeights.copyFrom(pMap);
m_staticDiffuseStale = true;
m_terrainContentVersion++;
@@ -2079,6 +2090,12 @@ void BaseHeightMapRenderObjClass::removeAllTrees()
// BaseHeightMapRenderObjClass::updateTreePosition
//=============================================================================
/** Updates a tree's position and angle in the tree buffer.*/
+//=============================================================================
+void BaseHeightMapRenderObjClass::stepTrees(void)
+{
+ m_treeBuffer->stepTrees();
+}
+
//=============================================================================
Bool BaseHeightMapRenderObjClass::updateTreePosition(DrawableID id, Coord3D location, Real angle)
{
@@ -2260,6 +2277,7 @@ void BaseHeightMapRenderObjClass::terrainHeightChanged( Int x, Int y )
rebuilding only the cell that moved leaves a seam of stale shading around it. */
const Int PAD = 2;
m_terrainContentVersion++;
+ m_drawHeights.copyCell(m_map, x, y);
if (!m_hasDirtyRegion)
{
m_dirtyRegion.lo.x = x - PAD;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp
index a90a1d590..5c2a1f80b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DProjectedShadow.cpp
@@ -996,11 +996,11 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow, Bool sunC
if (robj->Get_User_Data())
{
Drawable *draw=((DrawableInfo *)robj->Get_User_Data())->m_drawable;
- const Object *object=draw->getObject();
- PathfindLayerEnum objectLayer;
- if (object && (objectLayer=object->getLayer()) != LAYER_GROUND)
+ // the object's layer and its height under the drawable, as the sync point took them
+ const Drawable::ObjectForDraw &forDraw = draw->getObjectForDraw();
+ if (forDraw.hasObject && forDraw.layer != LAYER_GROUND)
{ //check if object that this decal belongs to is not on the ground (bridge?)
- layerHeight=BRIDGE_OFFSET_FACTOR+TheTerrainLogic->getLayerHeight(objPos.X,objPos.Y,objectLayer);
+ layerHeight=BRIDGE_OFFSET_FACTOR+forDraw.layerHeight;
}
}
}
@@ -1031,7 +1031,7 @@ void W3DProjectedShadowManager::queueDecal(W3DProjectedShadow *shadow, Bool sunC
Real heightAboveGround = 0.0f;
if (layerHeight == 0.0f && TheW3DShadowManager != NULL && TheTerrainLogic != NULL)
{
- heightAboveGround = objPos.Z - TheTerrainLogic->getGroundHeight(objPos.X, objPos.Y);
+ heightAboveGround = objPos.Z - TheTerrainRenderObject->getDrawHeight(objPos.X, objPos.Y);
toSun = TheW3DShadowManager->getLightPosWorld(0);
const Real MIN_SUN_HEIGHT = 0.01f; // a sun on the horizon casts a shadow of infinite length
sunCasts = sunCast && toSun.Z > MIN_SUN_HEIGHT; //a marker ring stays under its object
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index db796c884..cec6a70ee 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -4266,7 +4266,7 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
{
Coord3D look;
TheTacticalView->getPosition( &look );
- focus.Set( look.x, look.y, TheTerrainLogic->getGroundHeight( look.x, look.y ) );
+ focus.Set( look.x, look.y, TheTerrainRenderObject->getDrawHeight( look.x, look.y ) );
transform.Look_At( focus + toSun * sunDistance, focus, 0.0f );
halfWidth = shadowMapHalfWidth( sceneCamera, transform, lowestReceiver,
TheTerrainRenderObject->getMaxHeight() );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
index 6cd038a98..bc05c550a 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
@@ -102,6 +102,8 @@ static void drawFramerateBar(void);
#include "W3DDevice/GameClient/HeightMap.h"
#include "W3DDevice/GameClient/WorldHeightMap.h"
#include "W3DDevice/GameClient/W3DScene.h"
+#include "W3DDevice/GameClient/W3DParticleSys.h"
+#include "W3DDevice/GameClient/W3DView.h"
#include "W3DDevice/GameClient/W3DTerrainTracks.h"
#include "W3DDevice/GameClient/W3DWater.h"
#include "W3DDevice/GameClient/W3DVideobuffer.h"
@@ -2289,6 +2291,36 @@ static Real w3dElapsedMS( const Int64 &from, const Int64 &to )
}
#endif
+/* Whether this pass draws a picture. TiVO's fast forward through a replay draws one logic frame a
+ second of game time. */
+static Bool rendersThisPass( void )
+{
+#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
+ return (TheGameLogic->getFrame() % LOGICFRAMES_PER_SECOND == 1) || ( ! ( !TheGameLogic->isGamePaused() && TheGlobalData->m_TiVOFastMode) );
+#else
+ return (TheGameLogic->getFrame() % LOGICFRAMES_PER_SECOND == 1) || ( ! (!TheGameLogic->isGamePaused() && TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame()) );
+#endif
+}
+
+/* LOGIC-THREAD.md phase 3. The sync point of the render: everything the render below reads of logic
+ is taken here, before the overlap window opens, and the render reads only these. The logic frame,
+ the overlays that ask objects what to show, recorded for the render to replay, the particles'
+ stealth fades and fields, the toppling trees, and the strings the last pass's overlays freed, now
+ that nothing recorded draws them. The scene's own reads of an object were taken by
+ GameClient::update's drawable walk (Drawable::getObjectForDraw) and the radar's blips by its update. */
+static void takeReadsForRender( Bool renders )
+{
+ TheDisplay->freeDeferred();
+ TheGameLogic->takeFrameForDraw();
+ if( !renders || TheGlobalData->m_breakTheMovie || TheGlobalData->m_disableRender )
+ return;
+ for( View *view = TheDisplay->getFirstView(); view; view = TheDisplay->getNextView( view ) )
+ static_cast<W3DView *>( view )->recordPostDraw();
+ TheInGameUI->recordDraw();
+ TheTerrainRenderObject->stepTrees(); // before the particles: a falling tree's FX makes systems
+ static_cast<W3DParticleSystemManager *>( TheParticleSystemManager )->takeReadsForRender();
+}
+
void W3DDisplay::draw( void )
{
USE_PERF_TIMER(W3DDisplay_draw)
@@ -2567,9 +2599,14 @@ AGAIN:
#ifdef DEBUG_LOGGING
tParticleEnd = Clock_Ticks();
TheParticleUpdateMS = w3dElapsedMS( tParticleStart, tParticleEnd );
- tOverlapStart = tParticleEnd;
#endif
- overlapWindow.open();
+ takeReadsForRender( rendersThisPass() );
+#ifdef DEBUG_LOGGING
+ tOverlapStart = Clock_Ticks();
+#endif
+ // a draw from inside a tick (the load screen the map start paints) is the tick's own
+ if( !TheGameLogic->isInGameLogicUpdate() )
+ overlapWindow.open();
// R1: after the particles read the logic bones (Lorenzen's note above), before anything renders.
smoothMotionApply();
@@ -2611,11 +2648,7 @@ AGAIN:
Int numRenderTargetVertices=Debug_Statistics::Get_DX8_Vertices();
// start render block
- #if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
- if ( (TheGameLogic->getFrame() % LOGICFRAMES_PER_SECOND == 1) || ( ! ( !TheGameLogic->isGamePaused() && TheGlobalData->m_TiVOFastMode) ) )
- #else
- if ( (TheGameLogic->getFrame() % LOGICFRAMES_PER_SECOND == 1) || ( ! (!TheGameLogic->isGamePaused() && TheGlobalData->m_TiVOFastMode && TheGameLogic->isInReplayGame())) )
- #endif
+ if ( rendersThisPass() )
{
USE_PERF_TIMER(BigAssRenderLoop)
static Bool couldRender = true;
@@ -3070,6 +3103,7 @@ void W3DDisplay::flush2D( void )
//=============================================================================
void W3DDisplay::beginBatch2D( void )
{
+ if( isRecording() ) { record( [=]() { beginBatch2D(); } ); return; }
flush2D();
m_batch2D = TRUE;
@@ -3080,6 +3114,7 @@ void W3DDisplay::beginBatch2D( void )
//=============================================================================
void W3DDisplay::endBatch2D( void )
{
+ if( isRecording() ) { record( [=]() { endBatch2D(); } ); return; }
flush2D();
m_batch2D = FALSE;
@@ -3091,6 +3126,7 @@ void W3DDisplay::endBatch2D( void )
//=============================================================================
void W3DDisplay::flushBatch2D( void )
{
+ if( isRecording() ) { record( [=]() { flushBatch2D(); } ); return; }
flush2D();
@@ -3104,6 +3140,7 @@ void W3DDisplay::drawLine( Int startX, Int startY,
Real lineWidth,
UnsignedInt lineColor )
{
+ if( isRecording() ) { record( [=]() { drawLine( startX, startY, endX, endY, lineWidth, lineColor ); } ); return; }
if( setup2D( NULL, TRUE ) )
m_2DRender->Enable_Texturing( FALSE );
@@ -3121,7 +3158,8 @@ void W3DDisplay::drawLine( Int startX, Int startY,
Real lineWidth,
UnsignedInt lineColor1,UnsignedInt lineColor2 )
{
-
+ if( isRecording() ) { record( [=]() { drawLine( startX, startY, endX, endY, lineWidth, lineColor1, lineColor2 ); } ); return; }
+
if( setup2D( NULL, TRUE ) )
m_2DRender->Enable_Texturing( FALSE );
m_2DRender->Add_Line( Vector2( startX, startY ), Vector2( endX, endY ),
@@ -3136,7 +3174,8 @@ void W3DDisplay::drawLine( Int startX, Int startY,
void W3DDisplay::drawOpenRect( Int startX, Int startY, Int width, Int height,
Real lineWidth, UnsignedInt lineColor )
{
-
+ if( isRecording() ) { record( [=]() { drawOpenRect( startX, startY, width, height, lineWidth, lineColor ); } ); return; }
+
if (m_isClippedEnabled)
{
ICoord2D start, end, returnStart, returnEnd;
@@ -3186,6 +3225,7 @@ void W3DDisplay::drawOpenRect( Int startX, Int startY, Int width, Int height,
void W3DDisplay::drawFillRect( Int startX, Int startY, Int width, Int height,
UnsignedInt color )
{
+ if( isRecording() ) { record( [=]() { drawFillRect( startX, startY, width, height, color ); } ); return; }
if( setup2D( NULL, TRUE ) )
m_2DRender->Enable_Texturing( FALSE );
@@ -3199,6 +3239,7 @@ void W3DDisplay::drawFillRect( Int startX, Int startY, Int width, Int height,
void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, Int percent, UnsignedInt color)
{
+ if( isRecording() ) { record( [=]() { drawRectClock( startX, startY, width, height, percent, color ); } ); return; }
// sanity
if(percent < 1 || percent > 100)
return;
@@ -3362,6 +3403,7 @@ void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, In
//--------------------------------------------------------------------------------------------------------------------
void W3DDisplay::drawRemainingRectClock(Int startX, Int startY, Int width, Int height, Int percent, UnsignedInt color)
{
+ if( isRecording() ) { record( [=]() { drawRemainingRectClock( startX, startY, width, height, percent, color ); } ); return; }
// sanity
if( percent < 0 || percent > 99 )
return;
@@ -3542,6 +3584,7 @@ void W3DDisplay::drawImage( const Image *image, Int startX, Int startY,
// sanity
if( image == NULL )
return;
+ if( isRecording() ) { record( [=]() { drawImage( image, startX, startY, endX, endY, color, mode ); } ); return; }
// !!
// Remember to update the GUIEditDisplay::drawImage when you make
@@ -3776,6 +3819,7 @@ VideoBuffer* W3DDisplay::createVideoBuffer( void )
void W3DDisplay::drawVideoBuffer( VideoBuffer *buffer, Int startX, Int startY, Int endX, Int endY )
{
+ if( isRecording() ) { record( [=]() { drawVideoBuffer( buffer, startX, startY, endX, endY ); } ); return; }
W3DVideoBuffer *vbuffer = (W3DVideoBuffer*) buffer;
setup2D( NULL, FALSE );
@@ -3793,6 +3837,7 @@ void W3DDisplay::drawVideoBuffer( VideoBuffer *buffer, Int startX, Int startY, I
//=============================================================================
void W3DDisplay::setClipRegion( IRegion2D *region )
{
+ if( isRecording() ) { const IRegion2D at = *region; record( [=]() { IRegion2D copy = at; setClipRegion( &copy ); } ); return; }
// assign new region
m_clipRegion = *region;
m_isClippedEnabled = TRUE;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
index ee1fc2dcc..283899dd3 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp
@@ -184,6 +184,14 @@ void W3DDisplayString::draw( Int x, Int y, Color color, Color dropColor, Int xDr
if( getTextLength() == 0 )
return; // nothing to draw
+ // an overlay drawn at the sync point (Display::beginRecording): the string is drawn with the
+ // text it holds now, which nothing changes before the replay
+ if( TheDisplay && TheDisplay->isRecording() )
+ {
+ TheDisplay->record( [=]() { draw( x, y, color, dropColor, xDrop, yDrop ); } );
+ return;
+ }
+
//
// Text draws through its own renderer, so it goes to the device the moment it is asked for -
// while the display may still be holding 2D geometry that was handed over before it. That
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp
index eb5f6a6eb..75405f20e 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayStringManager.cpp
@@ -34,6 +34,7 @@
#include "Common/Debug.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameText.h"
+#include "GameClient/Display.h"
#include "GameClient/DisplayString.h"
#include "GameClient/DrawGroupInfo.h"
#include "GameClient/GlobalLanguage.h"
@@ -152,7 +153,9 @@ void W3DDisplayStringManager::freeDisplayString( DisplayString *string )
// sanity
if( string == NULL )
return;
-
+ // a recorded draw of it is still to come (Display::beginRecording)
+ if( TheDisplay && TheDisplay->isRecording() ) { TheDisplay->deferFree( string ); return; }
+
// unlink
unLink( string );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 1dd6b8a20..5cbd056e7 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -506,6 +506,52 @@ static void fillAround( const IRegion2D &window, Int outside, Color color )
window.hi.x - window.lo.x + 2 * outside, window.hi.y - window.lo.y + 2 * outside, color );
}
+//-------------------------------------------------------------------------------------------------
+/** LOGIC-THREAD.md phase 3. The parts of draw that ask logic what to show (the superweapon clocks,
+ * the guard markers, the world animations' fog, the production list) run here, at the sync point
+ * before the render, and record what they draw; draw replays each list where the part used to run.
+ * Under -cinema draw takes its own branch and none of this is drawn. */
+//-------------------------------------------------------------------------------------------------
+void W3DInGameUI::recordDraw( void )
+{
+ m_overWorldDraw.clear();
+ m_postDrawCalls.clear();
+ m_hudOverlayDraw.clear();
+ if( CinemaDirector_hidesHud() )
+ return;
+
+ TheDisplay->beginRecording( &m_overWorldDraw );
+ preDraw();
+
+ // draw selection region if drag selecting
+ if( m_isDragSelecting )
+ drawSelectionRegion();
+
+ // draw the formation line if one is being dragged out
+ if( m_isFormationDragging )
+ drawFormationLine();
+
+ // the attack circle, while the left button is still sweeping it out
+ if( isAttackCircling() )
+ drawAttackCircle();
+
+ // which of the local player's units are holding a guard
+ drawGuardMarkers();
+ TheDisplay->endRecording();
+
+ // While the map loads the display calls this every pass to paint the load screen's windows, and
+ // the match is already "in game" with its peace time set: the truce plate, the corner readout and
+ // the lists drew over the load screen. Only the windows belong there.
+ if( TheGlobalData->m_loadScreenRender )
+ return;
+ TheDisplay->beginRecording( &m_postDrawCalls );
+ postDraw();
+ TheDisplay->endRecording();
+ TheDisplay->beginRecording( &m_hudOverlayDraw );
+ drawHudOverlay();
+ TheDisplay->endRecording();
+}
+
//-------------------------------------------------------------------------------------------------
/** Draw member for the W3D implemenation of the game user interface */
//-------------------------------------------------------------------------------------------------
@@ -587,22 +633,9 @@ void W3DInGameUI::draw( void )
return;
}
- preDraw();
-
- // draw selection region if drag selecting
- if( m_isDragSelecting )
- drawSelectionRegion();
-
- // draw the formation line if one is being dragged out
- if( m_isFormationDragging )
- drawFormationLine();
-
- // the attack circle, while the left button is still sweeping it out
- if( isAttackCircling() )
- drawAttackCircle();
-
- // which of the local player's units are holding a guard
- drawGuardMarkers();
+ // 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 );
// for each view draw hints
/// @todo should the UI be iterating through views like this?
@@ -651,12 +684,8 @@ void W3DInGameUI::draw( void )
tPostStart = Clock_Ticks();
#endif
- // While the map loads the display calls this every pass to paint the load screen's windows, and
- // the match is already "in game" with its peace time set: the truce plate, the corner readout and
- // the lists drew over the load screen. Only the windows belong there.
- const Bool matchOnScreen = !TheGlobalData->m_loadScreenRender;
- if( matchOnScreen )
- postDraw();
+ // postDraw, as recordDraw ran it
+ Display::replay( m_postDrawCalls );
#ifdef DEBUG_LOGGING
tPostEnd = Clock_Ticks();
@@ -679,8 +708,7 @@ void W3DInGameUI::draw( void )
// painted: drawn before the window manager, a dialog, the menu or the control bar's own art
// covered it.
//
- if( matchOnScreen )
- drawHudOverlay();
+ Display::replay( m_hudOverlayDraw );
#ifdef EXTENDED_STATS
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp
index 6aa7a2368..d1a06a0ec 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp
@@ -695,6 +695,7 @@ struct FieldState
ParticleSystemInfo::ParticleShaderType shader;
AsciiString texture;
Real stealth; ///< ParticleSystem::getStealthFade of the last system seen at it
+ Real lifeFade; ///< fieldFade's answer at the last sync point
};
static const Int FIELD_GRACE = LOGICFRAMES_PER_SECOND; ///< logic frames a field with no object outlives its systems
@@ -813,16 +814,12 @@ static Real fieldFade( FieldState &state, Int now )
return state.shown;
}
-/** Collects this frame's fields from their systems and lays them on the terrain into the field
- * buffers; drawGroundFields draws them. Returns the puddles laid. `systems` is every isGroundField
- * system in list order, empty ones too. */
-static Int collectGroundFields( const std::vector<ParticleSystem *> &systems, const AABoxClass &view )
+/** This frame's fields from their systems, and each one's fade, at the sync point before the render:
+ * finding a field's object, its life and the fog over it read the logic (LOGIC-THREAD.md phase 3).
+ * `systems` is every isGroundField system in list order, empty ones too. */
+static void updateGroundFields( const std::vector<ParticleSystem *> &systems )
{
const Int now = (Int)TheGameLogic->getFrame();
- // between the last two logic ticks, as the models are, so a pulse does not step at the logic rate
- const Real seconds = ((Real)now + (TheSmoothMotionActive ? TheSmoothMotionAlpha : 0.0f)) / LOGICFRAMES_PER_SECOND;
- s_fieldPuddles.clear();
- s_fieldDraws.clear();
// where the fields are this frame, and what each one looks like
for (size_t f = 0; f < systems.size(); ++f)
@@ -886,25 +883,42 @@ static Int collectGroundFields( const std::vector<ParticleSystem *> &systems, co
st->second.stealth = sys->getStealthFade();
}
- Int laid = 0;
for (std::map<FieldKey, FieldState>::iterator st = s_fieldStates.begin(); st != s_fieldStates.end(); )
{
- const FieldKey &key = st->first;
FieldState &state = st->second;
// Kept while its systems are, even faded out: the systems outlive the object by a few
// seconds, and a field forgotten under them would be found again as a new one.
- const Real lifeFade = fieldFade( state, now );
+ state.lifeFade = fieldFade( state, now );
const Bool stale = now - state.seen > FIELD_GRACE;
- if ((stale && lifeFade <= 0.0f) || now < state.seen)
+ if ((stale && state.lifeFade <= 0.0f) || now < state.seen)
{
// out, or a frame count from before a load
s_fieldStates.erase( st++ );
continue;
}
++st;
+ }
+}
+
+/** Lays the fields updateGroundFields found on the terrain into the field buffers; drawGroundFields
+ * draws them. Returns the puddles laid. */
+static Int collectGroundFields( const AABoxClass &view )
+{
+ const Int now = (Int)TheGameLogic->getFrame();
+ // between the last two logic ticks, as the models are, so a pulse does not step at the logic rate
+ const Real seconds = ((Real)now + (TheSmoothMotionActive ? TheSmoothMotionAlpha : 0.0f)) / LOGICFRAMES_PER_SECOND;
+ s_fieldPuddles.clear();
+ s_fieldDraws.clear();
+
+ Int laid = 0;
+ for (std::map<FieldKey, FieldState>::iterator st = s_fieldStates.begin(); st != s_fieldStates.end(); ++st)
+ {
+ const FieldKey &key = st->first;
+ FieldState &state = st->second;
+
// a field on a stealthed thing goes with it, as its other particles do
- const Real fade = lifeFade * state.stealth;
+ const Real fade = state.lifeFade * state.stealth;
if (fade <= 0.0f)
continue;
@@ -1239,6 +1253,15 @@ void W3DParticleSystemManager::reset()
s_fieldStates.clear(); // the object IDs it holds belong to the game that ended
}
+/** LOGIC-THREAD.md phase 3. A system's stealth fade asks its object's drawable, and a field asks for
+ * its object, its life and the fog, so the frame view and the fields are taken here, before the
+ * render; the render's own refreshFrameView finds the view still valid. */
+void W3DParticleSystemManager::takeReadsForRender( void )
+{
+ refreshFrameView();
+ updateGroundFields( m_fieldSystems );
+}
+
/** The systems a pass draws from, walked again only when a particle update or anything else that
* adds or takes away a system or a particle has run since the last walk. A system with no
* particles draws nothing and one the local player cannot see is skipped, so neither is kept. */
@@ -1524,7 +1547,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)
s_fieldIndex.clear();
s_fieldChunks.clear();
{
- const Int puddles = collectGroundFields( m_fieldSystems, bbox );
+ const Int puddles = collectGroundFields( bbox );
// counted as field particles on purpose: past MaxFieldParticleCount the field systems keep
// one particle each, and that one is all the steady pool needs from them
m_fieldParticleCount += puddles;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index db8c3a178..93db2541d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -573,9 +573,9 @@ void RTS3DScene::Visibility_Check(CameraClass * camera)
drawInfo->m_flags |= DrawableInfo::ERF_POTENTIAL_OCCLUDER;
}
else
- if (draw->getObject() &&
+ if (draw->getObjectForDraw().hasObject &&
(draw->isKindOf(KINDOF_SCORE) || draw->isKindOf(KINDOF_SCORE_CREATE) || draw->isKindOf(KINDOF_SCORE_DESTROY) || draw->isKindOf(KINDOF_MP_COUNT_FOR_VICTORY)) &&
- (draw->getObject()->getSafeOcclusionFrame()) <= currentFrame && m_numPotentialOccludees < TheGlobalData->m_maxVisibleOccludeeObjects)
+ draw->getObjectForDraw().safeOcclusionFrame <= currentFrame && m_numPotentialOccludees < TheGlobalData->m_maxVisibleOccludeeObjects)
{ //object which could be occluded but still needs to be visible.
//We process transucent units twice (also in m_translucentObjectsBuffer) because we need to see them when occluded.
m_potentialOccludees[m_numPotentialOccludees++]=robj;
@@ -656,8 +656,8 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable
//=============================================================================
/** Which of the Direct3D 11 frame's own looks a drawable wears this frame, and its four numbers
* (DRAW_EFFECT_SAMPLING in ffshader.h): seconds, strength, a seed from the drawable's id and the
- * drawable's opacity. Only reads the object, which the renderer is allowed to do; nothing here
- * goes back into the logic. None under -d3d9, -headless or Classic graphics, where the heat
+ * drawable's opacity. The object's half is the sync point's copy (Drawable::getObjectForDraw);
+ * nothing here goes back into the logic. None under -d3d9, -headless or Classic graphics, where the heat
* vision pass and the disabled tint draw what they always drew.
*
* An enemy a detector found is revealed, and an own stealthed unit is cloaked whatever its opacity
@@ -666,7 +666,7 @@ void RTS3DScene::renderSpecificDrawables(RenderInfoClass &rinfo, Int numDrawable
* markers draw an occluded unit early, mid-way through the opaque world. Mines keep the heat vision's old exception.
* An EMP takes precedence over power: an EMP'd building is out of power as well. */
//=============================================================================
-static unsigned chooseDrawEffect( const Drawable *draw, const Object *obj, Bool translucentPass, float parameters[4] )
+static unsigned chooseDrawEffect( const Drawable *draw, Bool translucentPass, float parameters[4] )
{
if ( !Direct3D11_Draw_Effects() )
return DRAW_EFFECT_NONE;
@@ -693,13 +693,11 @@ static unsigned chooseDrawEffect( const Drawable *draw, const Object *obj, Bool
effect = DRAW_EFFECT_CLOAK;
strength = ( look == STEALTHLOOK_VISIBLE_FRIENDLY_DETECTED ) ? MAX( 0.6f, pulse ) : 0.0f;
}
- else if ( obj && !obj->isEffectivelyDead() )
+ else if ( draw->getObjectForDraw().hasObject && !draw->isObjectDeadForDraw() )
{
- if ( obj->isDisabledByType( DISABLED_EMP ) )
+ if ( draw->getObjectForDraw().empDisabled )
effect = DRAW_EFFECT_EMP;
- else if ( obj->isKindOf( KINDOF_STRUCTURE )
- && ( obj->isDisabledByType( DISABLED_UNDERPOWERED ) || obj->isDisabledByType( DISABLED_SCRIPT_UNDERPOWERED )
- || obj->isDisabledByType( DISABLED_HACKED ) ) )
+ else if ( draw->getObjectForDraw().outage )
effect = DRAW_EFFECT_OUTAGE;
}
@@ -725,7 +723,6 @@ void RTS3DScene::renderOneObject(RenderInfoClass &rinfo, RenderObjClass *robj, I
Drawable *draw = NULL;
DrawableInfo *drawInfo = NULL;
Bool drawableHidden=FALSE;
- Object* obj = NULL;
ObjectShroudStatus ss=OBJECTSHROUD_INVALID;
Bool doExtraMaterialPop=FALSE;
Bool doExtraFlagsPop=FALSE;
@@ -761,10 +758,9 @@ void RTS3DScene::renderOneObject(RenderInfoClass &rinfo, RenderObjClass *robj, I
if (drawAmbient)
ambient.Add(ambient, *drawAmbient, &ambient);
#endif
- obj = draw->getObject();
// the shroud as GameClient::update's pass asked it for this player, ahead of the draw
- // (LOGIC-THREAD.md phase 3: the draw does not call into the partition)
- if (obj) {
+ // (LOGIC-THREAD.md phase 3: the draw does not call into the partition, nor into the object)
+ if (draw->getObjectForDraw().hasObject) {
ss = draw->getShroudForDraw();
// For objects like planes, that pop out of the shroud, fire, then head back,
// we keep drawing them for 2 seconds after they return to the fogged area,
@@ -801,7 +797,7 @@ void RTS3DScene::renderOneObject(RenderInfoClass &rinfo, RenderObjClass *robj, I
// The Direct3D 11 frame's own look for this object, if it is in one of the four states that
// have one. The two that replace the disabled tint skip it: the dark grey under them only
// muddied the cold grey they draw.
- rinfo.drawEffect = chooseDrawEffect( draw, obj, theTranslucentPass, rinfo.drawEffectParameters );
+ rinfo.drawEffect = chooseDrawEffect( draw, theTranslucentPass, rinfo.drawEffectParameters );
// HANDLE THE SPECIAL DRAWABLE-LEVEL COLORING SETTINGS FIRST
@@ -1636,9 +1632,7 @@ void RTS3DScene::flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo)
robj=m_potentialOccludees[i];
draw = ((DrawableInfo *)robj->Get_User_Data())->m_drawable;
- Object *object=draw->getObject();
-
- Int index=object->getControllingPlayer()->getPlayerIndex();
+ Int index=draw->getObjectForDraw().playerIndex;
if ((lastPlayerObject[index]-&playerObjects[index][0]) >= MAX_VISIBLE_OCCLUDED_PLAYER_OBJECTS)
{
@@ -1676,9 +1670,7 @@ void RTS3DScene::flushOccludedObjectsIntoStencil(RenderInfoClass & rinfo)
//assign a color to this index by copying it from the controlling player
//of all objects in this list.
draw = ((DrawableInfo *)playerObjects[i][0]->Get_User_Data())->m_drawable;
- Object *object=draw->getObject();
-
- Int color=clientPlayerColor(object->getControllingPlayer());
+ Int color=draw->getObjectForDraw().playerColor;
RGB_To_HSV(hsv,Vector3(((color>>16)&0xff)/255.0f,((color>>8)&0xff)/255.0f,(color &0xff)/255.0f));
hsv.Z*=TheGlobalData->m_occludedLuminanceScale;
HSV_To_RGB(rgb,hsv);
@@ -1847,9 +1839,7 @@ void RTS3DScene::flushOccludedObjects(RenderInfoClass & rinfo)
robj=m_potentialOccludees[i];
draw = ((DrawableInfo *)robj->Get_User_Data())->m_drawable;
- Object *object=draw->getObject();
-
- Int index=object->getControllingPlayer()->getPlayerIndex();
+ Int index=draw->getObjectForDraw().playerIndex;
rinfo.Push_Material_Pass(m_occludedMaterialPass[index]);
robj->Render(rinfo);
@@ -2246,9 +2236,9 @@ void RTS3DScene::Visibility_Check(CameraClass * camera)
drawInfo->m_flags |= DrawableInfo::ERF_POTENTIAL_OCCLUDER;
}
else
- if (draw->getObject() &&
+ if (draw->getObjectForDraw().hasObject &&
(draw->isKindOf(KINDOF_SCORE) || draw->isKindOf(KINDOF_SCORE_CREATE) || draw->isKindOf(KINDOF_SCORE_DESTROY) || draw->isKindOf(KINDOF_MP_COUNT_FOR_VICTORY)) &&
- (draw->getObject()->getSafeOcclusionFrame()) <= currentFrame && m_numPotentialOccludees < TheGlobalData->m_maxVisibleOccludeeObjects)
+ draw->getObjectForDraw().safeOcclusionFrame <= currentFrame && m_numPotentialOccludees < TheGlobalData->m_maxVisibleOccludeeObjects)
{ //object which could be occluded but still needs to be visible.
//We process transucent units twice (also in m_translucentObjectsBuffer) because we need to see them when occluded.
m_potentialOccludees[m_numPotentialOccludees++]=robj;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
index 3723ac07b..0f0ed167a 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
@@ -1169,7 +1169,7 @@ void W3DTerrainVisual::xfer( Xfer *xfer )
if (xfer->getXferMode() == XFER_LOAD)
{
// Update the display height map.
- m_terrainRenderObject->staticLightingChanged();
+ m_terrainRenderObject->heightsLoaded();
}
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
index 286380042..cb36c02b2 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
@@ -1236,6 +1236,7 @@ W3DTreeBuffer::W3DTreeBuffer(void)
m_initialized = true;
m_curSwayVersion = -1;
m_lastSwayFrame = 0xffffffff; // so the first drawTrees always steps
+ m_lastTreeStepFrame = 0xffffffff;
m_shadow = NULL;
@@ -2089,6 +2090,55 @@ DECLARE_PERF_TIMER(Tree_Render)
//=============================================================================
/** Draws the trees. Uses camera to cull. */
//=============================================================================
+//-------------------------------------------------------------------------------------------------
+/** Update pushed aside and toppling trees, once a logic frame like the sway: the push and sink
+ counts are logic frames, and the topple's speeds were converted to them. Run every render pass,
+ they went as much faster as the picture rate was over the logic's. Called at the render's sync
+ point rather than from drawTrees: a toppling tree asks the partition whether the drawn player sees
+ its cell, and its bounce plays an effect (LOGIC-THREAD.md phase 3). */
+//-------------------------------------------------------------------------------------------------
+void W3DTreeBuffer::stepTrees( void )
+{
+ Bool pause = TheScriptEngine->isTimeFrozenScript() || TheScriptEngine->isTimeFrozenDebug();
+ if (TheGameLogic && TheGameLogic->isGamePaused()) {
+ pause = true;
+ }
+ const UnsignedInt now = TheGameClient ? TheGameClient->getFrame() : 0;
+ if (pause || now == m_lastTreeStepFrame) {
+ return;
+ }
+ m_lastTreeStepFrame = now;
+
+ for (Int curTree=0; curTree<m_numTrees; curTree++) {
+ Int type = m_trees[curTree].treeType;
+ if (type<0) { // deleted.
+ continue;
+ }
+ if(m_trees[curTree].m_toppleState == TOPPLE_FALLING ||
+ m_trees[curTree].m_toppleState == TOPPLE_FOGGED) {
+ updateTopplingTree(m_trees+curTree);
+ } else if(m_trees[curTree].m_toppleState == TOPPLE_DOWN) {
+ if (m_treeTypes[type].m_data->m_killWhenToppled) {
+ if (m_trees[curTree].m_sinkFramesLeft==0) {
+ m_trees[curTree].treeType = DELETED_TREE_TYPE; // delete it. [7/11/2003]
+ m_anythingChanged = true; // need to regenerate trees. [7/11/2003]
+ }
+ m_trees[curTree].m_sinkFramesLeft--;
+ m_trees[curTree].location.Z -= m_treeTypes[type].m_data->m_sinkDistance/m_treeTypes[type].m_data->m_sinkFrames;
+ m_trees[curTree].m_mtx.Set_Translation(m_trees[curTree].location);
+ }
+ } else if (m_trees[curTree].pushAsideDelta!=0.0f) {
+ m_trees[curTree].pushAside += m_trees[curTree].pushAsideDelta;
+ if (m_trees[curTree].pushAside>=1.0f) {
+ m_trees[curTree].pushAsideDelta = -1.0/(Real)m_treeTypes[type].m_data->m_framesToMoveInward;
+ } else if (m_trees[curTree].pushAside<=0.0f) {
+ m_trees[curTree].pushAsideDelta = 0.0f;
+ m_trees[curTree].pushAside = 0.0f;
+ }
+ }
+ }
+}
+
void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pDynamicLightsIterator)
{
USE_PERF_TIMER(Tree_Render)
@@ -2191,40 +2241,7 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pD
TheW3DProjectedShadowManager->flushDecals(m_shadow->getTexture(0), SHADOW_DECAL);
}
- // Update pushed aside and toppling trees, once a logic frame like the sway: the push and sink
- // counts are logic frames, and the topple's speeds were converted to them. Run every render
- // pass, they went as much faster as the picture rate was over the logic's.
- for (curTree=0; curTree<m_numTrees; curTree++) {
- if (!stepSway) {
- break;
- }
- Int type = m_trees[curTree].treeType;
- if (type<0) { // deleted.
- continue;
- }
- if(m_trees[curTree].m_toppleState == TOPPLE_FALLING ||
- m_trees[curTree].m_toppleState == TOPPLE_FOGGED) {
- updateTopplingTree(m_trees+curTree);
- } else if(m_trees[curTree].m_toppleState == TOPPLE_DOWN) {
- if (m_treeTypes[type].m_data->m_killWhenToppled) {
- if (m_trees[curTree].m_sinkFramesLeft==0) {
- m_trees[curTree].treeType = DELETED_TREE_TYPE; // delete it. [7/11/2003]
- m_anythingChanged = true; // need to regenerate trees. [7/11/2003]
- }
- m_trees[curTree].m_sinkFramesLeft--;
- m_trees[curTree].location.Z -= m_treeTypes[type].m_data->m_sinkDistance/m_treeTypes[type].m_data->m_sinkFrames;
- m_trees[curTree].m_mtx.Set_Translation(m_trees[curTree].location);
- }
- } else if (m_trees[curTree].pushAsideDelta!=0.0f) {
- m_trees[curTree].pushAside += m_trees[curTree].pushAsideDelta;
- if (m_trees[curTree].pushAside>=1.0f) {
- m_trees[curTree].pushAsideDelta = -1.0/(Real)m_treeTypes[type].m_data->m_framesToMoveInward;
- } else if (m_trees[curTree].pushAside<=0.0f) {
- m_trees[curTree].pushAsideDelta = 0.0f;
- m_trees[curTree].pushAside = 0.0f;
- }
- }
- }
+ // the pushed aside and toppling trees moved in stepTrees, at the sync point
if (m_anythingChanged) {
loadTreesInVertexAndIndexBuffers(pDynamicLightsIterator);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 8c3b446ea..da4f079de 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -2323,6 +2323,32 @@ static Real viewElapsedMS( const Int64 &from, const Int64 &to )
}
#endif
+//-------------------------------------------------------------------------------------------------
+/** LOGIC-THREAD.md phase 3. The post draw over the finished world - health bars, ranks, ammo, the
+ * capture clock, captions, group numbers - asks each object what to show, so it runs here, at the
+ * sync point before the render, and records what it draws; draw replays it where it always went.
+ * The view's camera is the one updateViews left, which the render draws with. */
+//-------------------------------------------------------------------------------------------------
+void W3DView::recordPostDraw( void )
+{
+ Region3D axisAlignedRegion;
+ getAxisAlignedViewRegion(axisAlignedRegion);
+
+ TheGameClient->resetRenderedObjectCount();
+ // the post draw is where health bars are drawn, and each one records where it landed
+ TheGameClient->clearHealthBarPickRegions();
+#ifdef DEBUG_LOGGING
+ Int64 tIconStart = Clock_Ticks();
+#endif
+ TheDisplay->beginRecording( &m_postDraw );
+ TheGameClient->iterateDrawablesInRegion( &axisAlignedRegion, drawablePostDraw, this );
+ TheGameClient->flushTextBearingDrawables();
+ TheDisplay->endRecording();
+#ifdef DEBUG_LOGGING
+ TheIconDrawMS = viewElapsedMS( tIconStart, Clock_Ticks() );
+#endif
+}
+
void W3DView::draw( void )
{
USE_PERF_TIMER(W3DView_drawView)
@@ -2649,13 +2675,6 @@ void W3DView::draw( void )
}
#endif // DEBUG or INTERNAL
- Region3D axisAlignedRegion;
- getAxisAlignedViewRegion(axisAlignedRegion);
-
- //
- // there are several things we might want to do as a post pass on the objects after
- // they are all drawn
- /// @todo we might want to consider wiping this iterate out if there is nothing to post draw
//
// The world is finished here and everything below this line is drawn over it: health bars,
// veterancy chevrons, unit names, the 2D scene. So this is where -dx11post's chain runs, and
@@ -2667,7 +2686,7 @@ void W3DView::draw( void )
//
// Nothing happens here unless a chain was asked for, and only the first view of a frame runs it.
#ifdef DEBUG_LOGGING
- Int64 tPostChainStart, tPostChainEnd, tIconStart, tIconEnd;
+ Int64 tPostChainStart, tPostChainEnd;
tPostChainStart = Clock_Ticks();
#endif
updateScreenDistortions();
@@ -2677,19 +2696,8 @@ void W3DView::draw( void )
ThePostChainMS = viewElapsedMS( tPostChainStart, tPostChainEnd );
#endif
- TheGameClient->resetRenderedObjectCount();
- // the post draw is where health bars are drawn, and each one records where it landed
- TheGameClient->clearHealthBarPickRegions();
-#ifdef DEBUG_LOGGING
- tIconStart = Clock_Ticks();
-#endif
- TheGameClient->iterateDrawablesInRegion( &axisAlignedRegion, drawablePostDraw, this );
-#ifdef DEBUG_LOGGING
- tIconEnd = Clock_Ticks();
- TheIconDrawMS = viewElapsedMS( tIconStart, tIconEnd );
-#endif
-
- TheGameClient->flushTextBearingDrawables();
+ // the health bars and the rest of the post draw, recorded at the sync point by recordPostDraw
+ Display::replay( m_postDraw );
// Render 2D scene
W3DDisplay::m_2DScene->doRender( m_2DCamera );
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
index c3b81f1fe..420f8bc2f 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
@@ -1561,7 +1561,8 @@ void WaterRenderObjClass::updateRenderTargetTextures(CameraClass *cam)
continue;
Coord3D center;
- pTrig->getCenterPoint(&center);
+ pTrig->getCenterXY(&center);
+ center.z = TheTerrainRenderObject->getDrawHeight(center.x, center.y);
if (cam->Cull_Sphere(SphereClass(Vector3(center.x, center.y, center.z), pTrig->getRadius())))
continue;