Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

refactor(gameengine): read the client from a block captured before the tick

Olcay Seygan10dfaa039678
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/AudioEventRTS.h b/GeneralsMD/Code/GameEngine/Include/Common/AudioEventRTS.h
index 1481f9bb5..8cfbb8393 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/AudioEventRTS.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/AudioEventRTS.h
@@ -82,12 +82,14 @@ public:
// generateFilename is separate from generatePlayInfo because generatePlayInfo should only be called once
// per triggered event. generateFilename will be called once per loop, or once to get each filename if 'all' is
// specified.
- void generateFilename( void );
+ // forPlaying FALSE: only the file names, as AudioManager::getAudioLengthMS measures them from the tick,
+ // with no draw from the audio stream for the delay, pitch and volume it does not need (LOGIC-THREAD.md M7)
+ void generateFilename( Bool forPlaying = TRUE );
AsciiString getFilename( void );
// The attack and decay sounds are generated in generatePlayInfo, because they will never be played more
// than once during a given sound event.
- void generatePlayInfo( void );
+ void generatePlayInfo( Bool forPlaying = TRUE );
Real getPitchShift( void ) const;
Real getVolumeShift( void ) const;
AsciiString getAttackFilename( void ) const;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h b/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
index a6a1ce7cb..9ae0602f5 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
@@ -81,6 +81,10 @@ public:
constructor touches none of that. madeInTick is the second case. */
virtual void buildRenderObjects( Bool madeInTick ) { }
+ /** M7: a module the player's "extra animations" option leaves out below its MinLODRequired, one
+ above STATIC_GAME_LOD_LOW (0); the reads logic makes of the draw modules skip it everywhere. */
+ Bool isLODOptional() const { return (Int)getModuleData()->getMinimumRequiredGameLOD() > 0; }
+
virtual void setShadowsEnabled(Bool enable) = 0;
virtual void releaseShadows(void) = 0; ///< frees all shadow resources used by this module - used by Options screen.
virtual void allocateShadows(void) = 0; ///< create shadow resources if not already present. Used by Options screen.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GameAudio.h b/GeneralsMD/Code/GameEngine/Include/Common/GameAudio.h
index 6a0603806..db094e19e 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GameAudio.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GameAudio.h
@@ -190,6 +190,13 @@ class AudioManager : public SubsystemInterface
///< NOTE NOTE NOTE !!DO NOT USE THIS IN FOR GAMELOGIC PURPOSES!! NOTE NOTE NOTE
virtual Bool isCurrentlyPlaying( AudioHandle handle );
+ /** LOGIC-THREAD.md M7. At the sync point, before every tick: which sounds play and how many loops
+ * each music track has finished, so isCurrentlyPlaying and hasMusicTrackCompleted asked from the
+ * tick answer from that and never touch the device. A sound ends on this machine's clock, so
+ * the copy differs from a read in the middle of the tick only by the milliseconds the tick took;
+ * the tick's own adds and removes reach the device after it either way. */
+ virtual void captureForLogic( void ) { }
+
// Device Dependent open and close functions
virtual void openDevice( void ) = 0;
virtual void closeDevice( void ) = 0;
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
index afa15787a..f6ac23f76 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h
@@ -28,8 +28,12 @@
#define __LOGICTHREAD_H__
#include "Lib/BaseType.h"
+#include "Common/GameType.h"
#include <functional>
+#include <vector>
+
+class Player;
/**
* `-logicthread 0` (the default) runs the tick on the main thread, as it always ran.
@@ -69,7 +73,8 @@ namespace LogicThread
CENSUS_DRAWABLE_PUSH, ///< Drawable::doClientWork run inside the tick: hidden, colour, decal, shadows, sub-objects, ambient sound, caption
CENSUS_DESTROY_DRAWABLE, ///< a drawable deleted: draw modules, render objects, shadows (M4: after the tick for one logic destroyed)
CENSUS_AUDIO_READ, ///< a logic read of the audio device: sound lengths, a track done, a handle still playing (hazard 4, M7)
- CENSUS_CLIENT_READ, ///< a logic read of other client state: selection, input enabled, camera, the water grid (hazard 4, M7)
+ CENSUS_CLIENT_READ, ///< a logic read of other client state: selection, input enabled, camera (hazard 4, M7)
+ CENSUS_ASSET_LOAD, ///< the W3D asset manager loading a model or an animation for a cache logic reads (hazards 5 and 22, M7)
CENSUS_COUNT
};
@@ -125,6 +130,49 @@ namespace LogicThread
/** The tick cleared the game: what it queued has no game left to play in. GameEngine::reset. */
void discardEffects( void );
+ /** LOGIC-THREAD.md phase 2, M7. What logic reads of the client, copied by runTick on the main
+ * thread before every tick (the sync point), so the tick reads this block and never the client.
+ * Between ticks only the player changes these, so the copy holds what a live read in the tick
+ * gave. Inside the tick logic changes some of them itself through calls that now wait for the
+ * tick's end: a script selects a unit, starts a camera move. Those calls write the block too,
+ * at the call, so a read later in the same tick sees them as it saw the immediate call. */
+ struct SelectedEntry
+ {
+ DrawableID drawable;
+ ObjectID object;
+ };
+ struct ClientBlock
+ {
+ std::vector<SelectedEntry> selection; ///< the local selection (InGameUI::m_selectedDrawables)
+ UnsignedInt frameSelectionChanged; ///< InGameUI::getFrameSelectionChanged
+ Player *observerLookAt; ///< ControlBar::getObserverLookAtPlayer
+ Bool cameraFrozen; ///< View::isTimeFrozen
+ Bool cameraMoving; ///< View::isCameraMoving
+ Bool cameraBlurring; ///< View::isCameraMotionBlurring
+ };
+ const ClientBlock &clientBlock( void );
+
+ /** A select or deselect the tick queued (InGameUI), written to the block at the call. */
+ void noteSelected( DrawableID drawable, ObjectID object, Bool selected );
+ void noteSelectionCleared( void );
+
+ /** What a queued camera call does to the two answers logic reads (time frozen, movement finished),
+ * written to the block at the call. This is the camera's state machine in four words, not the
+ * camera: a move whose path collapses to one point, or a motion blur the device refuses, leaves the
+ * real camera finished where the block says moving. So -logicthread 0 keeps asking the camera
+ * (readViewFromTick), exact as it always was, and counts every read where the block would have
+ * answered otherwise; -logicthread 1 answers from the block. */
+ enum ViewEffect
+ {
+ VIEW_MOVES, ///< a move, zoom, pitch or rotation starts
+ VIEW_FREEZES_TIME, ///< cameraModFreezeTime
+ VIEW_BLUR_STARTS, ///< an in or out motion blur, which counts as a finished movement
+ VIEW_BLUR_ENDS ///< a filter mode that replaces it
+ };
+ void noteViewEffect( ViewEffect effect );
+ Bool isCameraMovementFinishedForTick( void );
+ Bool isTimeFrozenForTick( void );
+
} // namespace LogicThread
#define LOGIC_CENSUS( channel ) LogicThread::census( LogicThread::channel )
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 6e45bc7c7..bd8ee428f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -40,6 +40,7 @@
#include "Common/GameType.h"
#include "Common/MessageStream.h" // for GameMessageTranslator
#include "Common/KindOf.h"
+#include "Common/LogicThread.h"
#include "Common/SpecialPowerType.h"
#include "Common/Snapshot.h"
#include "Common/STLTypedefs.h"
@@ -981,9 +982,9 @@ public: // ********************************************************************
virtual void deselectAllDrawables( void ); ///< Clear the "select" flag from all drawables
void holdSelectionThroughTunnel( Drawable *draw ); ///< a selected unit going down a tunnel on its own is selected again when it comes up
void restoreSelectionAfterTunnel( Drawable *draw ); ///< reselect a unit held by holdSelectionThroughTunnel
- virtual Int getSelectCount( void ) { return m_selectCount; } ///< Get count of currently selected drawables
+ virtual Int getSelectCount( void ) { LOGIC_CENSUS( CENSUS_CLIENT_READ ); return m_selectCount; } ///< Get count of currently selected drawables
virtual Int getMaxSelectCount( void ) { return m_maxSelectCount; } ///< Get the max number of selected drawables
- virtual UnsignedInt getFrameSelectionChanged( void ) { return m_frameSelectionChanged; } ///< Get the max number of selected drawables
+ virtual UnsignedInt getFrameSelectionChanged( void ) { LOGIC_CENSUS( CENSUS_CLIENT_READ ); return m_frameSelectionChanged; } ///< Get the max number of selected drawables
virtual const DrawableList *getAllSelectedDrawables( void ) const; ///< Return the list of all the currently selected Drawable IDs.
virtual const DrawableList *getAllSelectedLocalDrawables( void ); ///< Return the list of all the currently selected Drawable IDs owned by the current player.
virtual Drawable *getFirstSelectedDrawable( void ); ///< get the first selected drawable (if any)
@@ -997,7 +998,7 @@ public: // ********************************************************************
virtual void setInputEnabled( Bool enable ); ///< Set the input enabled or disabled
virtual void clearModifierModes( void ); ///< forget every mode a held key puts us in (see the definition)
- virtual Bool getInputEnabled( void ) { return m_inputEnabled; } ///< Get the current input status
+ virtual Bool getInputEnabled( void ) { LOGIC_CENSUS( CENSUS_CLIENT_READ ); return m_inputEnabled; } ///< Get the current input status
virtual void disregardDrawable( Drawable *draw ); ///< Drawable is being destroyed, clean up any UI elements associated with it
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/TerrainVisual.h b/GeneralsMD/Code/GameEngine/Include/GameClient/TerrainVisual.h
index feb254b16..6e8a504e9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/TerrainVisual.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/TerrainVisual.h
@@ -240,28 +240,9 @@ public:
//
// water methods
//
+ /** the water grid was enabled or disabled; the grid itself (mesh, settings, motion, heights) is
+ TerrainLogic's WaterGrid, and this only builds what the visual draws it with */
virtual void enableWaterGrid( Bool enable ) = 0;
- /// set min/max height values allowed in water grid pointed to by waterTable
- virtual void setWaterGridHeightClamps( const WaterHandle *waterTable, Real minZ, Real maxZ ) = 0;
- /// adjust fallof parameters for grid change method
- virtual void setWaterAttenuationFactors( const WaterHandle *waterTable, Real a, Real b, Real c, Real range ) = 0;
- /// set the water table position and orientation in world space
- virtual void setWaterTransform( const WaterHandle *waterTable, Real angle, Real x, Real y, Real z ) = 0;
- virtual void setWaterTransform( const Matrix3D *transform ) = 0;
- /// get water transform parameters
- virtual void getWaterTransform( const WaterHandle *waterTable, Matrix3D *transform ) = 0;
- /// water grid resolution spacing
- virtual void setWaterGridResolution( const WaterHandle *waterTable, Real gridCellsX, Real gridCellsY, Real cellSize ) = 0;
- virtual void getWaterGridResolution( const WaterHandle *waterTable, Real *gridCellsX, Real *gridCellsY, Real *cellSize ) = 0;
- /// adjust the water grid in world coords by the delta
- virtual void changeWaterHeight( Real x, Real y, Real delta ) = 0;
- /// adjust the velocity at a water grid point corresponding to the world x,y
- virtual void addWaterVelocity( Real worldX, Real worldY, Real velocity, Real preferredHeight ) = 0;
- /// get height of water grid at specified position
- virtual Bool getWaterGridHeight( Real worldX, Real worldY, Real *height) = 0;
- /** move the water grid's mesh one step for this logic frame; a second call for the same frame does
- nothing. GameLogic::update calls it at the top of every logic frame (T1c, defect 17). */
- virtual void updateWaterGrid( UnsignedInt logicFrame ) = 0;
/// set detail of terrain tracks.
virtual void setTerrainTracksDetail(void)=0;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
index c30de1caa..afd06b346 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h
@@ -155,6 +155,8 @@ public:
virtual void moveCameraTo(const Coord3D *o, Int frames, Int shutter, Bool orient, Real easeIn, Real easeOut) { lookAt( o ); }
virtual void moveCameraAlongWaypointPath(Waypoint *way, Int frames, Int shutter, Bool orient, Real easeIn, Real easeOut) { }
virtual Bool isCameraMovementFinished( void ) { return TRUE; }
+ virtual Bool isCameraMoving( void ) { return FALSE; } ///< a scripted move, zoom, pitch or rotation under way (LogicThread::ClientBlock)
+ virtual Bool isCameraMotionBlurring( void ) { return FALSE; } ///< an in or out motion blur, which isCameraMovementFinished counts as finished
virtual void cameraModFinalZoom(Real finalZoom, Real easeIn, Real easeOut){}; ///< Final zoom for current camera movement.
virtual void cameraModRollingAverage(Int framesToAverage){}; ///< Number of frames to average movement for current camera movement.
virtual void cameraModFinalTimeMultiplier(Int finalMultiplier){}; ///< Final time multiplier for current camera movement.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
index 8d2deacc0..73415225d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
@@ -160,6 +160,7 @@ public:
Bool isInGameLogicUpdate( void ) const { return m_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
+ 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
void setObjectIDCounter( ObjectID nextObjID ) { m_nextObjID = nextObjID; }
@@ -358,6 +359,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
// CRC cache system -----------------------------------------------------------------------------
UnsignedInt m_CRC; ///< Cache of previous CRC value
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/TerrainLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/TerrainLogic.h
index 14d398f3a..f8944ba9f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/TerrainLogic.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/TerrainLogic.h
@@ -38,6 +38,7 @@
#include "Common/Snapshot.h"
#include "Common/STLTypedefs.h"
#include "GameClient/TerrainRoads.h"
+#include "GameLogic/WaterGridMotion.h"
typedef std::vector<ICoord2D> VecICoord2D;
@@ -311,6 +312,7 @@ public:
PathfindLayerEnum getHighestLayerForDestination(const Coord3D *pos, Bool onlyHealthyBridges = false);
void enableWaterGrid( Bool enable ); ///< enable/disable the water grid
+ WaterGrid *getWaterGrid( void ) { return &m_waterGrid; } ///< the vertex animated water grid, logic's (WaveGuideUpdate pushes it, the renderer draws it)
// This is stuff to get the currently active boundary information
Int getActiveBoundary(void) { return m_activeBoundary; }
@@ -378,6 +380,7 @@ protected:
AsciiString m_filenameString; ///< filename for terrain data
Bool m_waterGridEnabled; ///< TRUE when water grid is enabled
+ WaterGrid m_waterGrid; ///< the grid itself, mesh and settings (was in the water render object)
static WaterHandle m_gridWaterHandle; ///< water handle for the grid water (we only presently have one)
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h
index 2e0745e95..818baad6f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h
@@ -33,14 +33,18 @@
frame-rate history (defect 17).
GameLogic::update now steps it, at its top, before anything in the frame reads or writes the grid -
- where EA's client pass stood, just ahead of the logic frame - through TerrainVisual::updateWaterGrid.
+ where EA's client pass stood, just ahead of the logic frame - through WaterGrid::update.
The step is W3DWater.cpp's text unchanged, frame gate and all, but for these substitutions:
- currLogicFrame is a parameter where the original read TheGameLogic->getFrame() (0 without one);
- the render object's m_doWaterGrid, m_meshInMotion, m_meshData, m_gridCellsX and m_gridCellsY are
parameters of the same names without the m_;
- WaterRenderObjClass::IN_MOTION and WaterMeshData are this class's IN_MOTION and MeshPoint, which
WaterRenderObjClass now uses under its old names (the same members in the same order).
- Tests/test_water_grid.cpp holds it to the original's own output, and shows the count per frame. */
+ Tests/test_water_grid.cpp holds it to the original's own output, and shows the count per frame.
+
+ The rest of the grid followed the step out of the render object (LOGIC-THREAD M7): WaterGrid below
+ is the mesh, its size, its transform, its clamps and falloff and its two enable flags, owned by
+ TerrainLogic. Logic reads and writes nothing else; WaterRenderObjClass draws from it. */
#pragma once
@@ -48,6 +52,9 @@
#define WATERGRIDMOTION_H
#include "Lib/BaseType.h"
+#include "Common/Snapshot.h"
+#include "WWMath/matrix3d.h"
+#include "WWMath/vector2.h"
class WaterGridMotion
{
@@ -75,4 +82,80 @@ public:
};
+/** The vertex animated water grid, as simulation state. This was WaterRenderObjClass's mesh and
+ * settings and W3DTerrainVisual's m_isWaterGridRenderingEnabled; every body is the original text with
+ * the render object's members renamed to these. The two flags stay two, as they were:
+ * m_heightsEnabled is the one getHeight answers to (W3DTerrainVisual's), m_doWaterGrid the one the
+ * motion and the pushes answer to (the render object's), and a new map's load clears only the second.
+ * The renderer reads this at draw time, outside the tick for now; making that read safe against a
+ * tick running beside the draw is a later phase. */
+class WaterGrid : public Snapshot
+{
+public:
+
+ typedef WaterGridMotion::MeshPoint MeshPoint;
+
+ WaterGrid( void );
+ virtual ~WaterGrid( void );
+
+ void reset( void ); ///< zero the mesh, as a game's reset did
+ void enable( Bool state ); ///< what TerrainVisual::enableWaterGrid did to the grid
+ void disableMotion( void ); ///< what a new map's load did: the render object's enableWaterGrid(false)
+ void update( UnsignedInt logicFrame ); ///< one step of motion, once per logic frame (WaterGridMotion)
+ void setHeightClamps( Real minz, Real maxz ); ///< min/max height values allowed in grid
+ void setChangeAttenuationFactors( Real a, Real b, Real c, Real range ); ///< falloff for changeHeight
+ void setTransform( Real angle, Real x, Real y, Real z ); ///< position/orientation of grid in space
+ void setTransform( const Matrix3D *transform ); ///< set transform by matrix (leaves the grid axes alone)
+ void getTransform( Matrix3D *transform ) const; ///< get grid transform matrix
+ void setResolution( Real gridCellsX, Real gridCellsY, Real cellSize ); ///< grid resolution and spacing
+ void getResolution( Real *gridCellsX, Real *gridCellsY, Real *cellSize ) const;
+ void addVelocity( Real worldX, Real worldY, Real zVelocity, Real preferredHeight );
+ void changeHeight( Real x, Real y, Real delta ); ///< change height of grid at world point including neighbors within falloff
+ Bool getHeight( Real worldX, Real worldY, Real *height ) const; ///< TRUE inside an enabled grid; height untouched without a mesh
+
+ // for the renderer
+ Bool isMotionEnabled( void ) const { return m_doWaterGrid; }
+ Bool isHeightEnabled( void ) const { return m_heightsEnabled; }
+ Bool wasPushed( void ) const { return m_pushed; } ///< a push landed since the last enable (EA's m_disableRiver)
+ MeshPoint *getMeshData( void ) { return m_meshData; }
+ Int getCellsX( void ) const { return m_gridCellsX; }
+ Int getCellsY( void ) const { return m_gridCellsY; }
+ Real getCellSize( void ) const { return m_gridCellSize; }
+ UnsignedInt getMeshGeneration( void ) const { return m_meshGeneration; } ///< bumps each time the mesh is (re)allocated
+
+protected:
+
+ virtual void crc( Xfer *xfer );
+ virtual void xfer( Xfer *xfer );
+ virtual void loadPostProcess( void );
+
+private:
+
+ void allocateMesh( void );
+ Bool worldToGridSpace( Real worldX, Real worldY, Real &gridX, Real &gridY ) const;
+
+ MeshPoint *m_meshData; ///< heightmap data for 3D Mesh based water
+ UnsignedInt m_meshDataSize; ///< size of m_meshData
+ UnsignedInt m_meshGeneration; ///< count of allocations, so the renderer knows to rebuild its buffers
+ Bool m_meshInMotion; ///< TRUE once we've messed with velocities and are in motion
+ Bool m_doWaterGrid; ///< the render object's flag: motion and pushes
+ Bool m_heightsEnabled; ///< W3DTerrainVisual's m_isWaterGridRenderingEnabled: heights
+ Bool m_pushed; ///< the render object's m_disableRiver; drawing only, not saved
+
+ Matrix3D m_transform; ///< the render object's Transform: the grid's place in the world
+ Vector2 m_gridDirectionX; ///< vector along water grid's x-axis (scaled to world-space)
+ Vector2 m_gridDirectionY; ///< vector along water grid's y-axis (scaled to world-space)
+ Vector2 m_gridOrigin; ///< unit vector along water grid's x-axis
+ Real m_minGridHeight; ///< minimum height value allowed for water mesh
+ Real m_maxGridHeight; ///< maximum height value allowed for water mesh
+ Real m_gridChangeMaxRange; ///< maximum range of changeHeight() method
+ Real m_gridChangeAtt0;
+ Real m_gridChangeAtt1;
+ Real m_gridChangeAtt2;
+ Real m_gridCellSize; ///< world-space width/height of each cell.
+ Int m_gridCellsX; ///< number of cells along width
+ Int m_gridCellsY; ///< number of cells along height
+
+};
+
#endif // WATERGRIDMOTION_H
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Audio/AudioEventRTS.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Audio/AudioEventRTS.cpp
index 288f3739b..09455b4e2 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Audio/AudioEventRTS.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Audio/AudioEventRTS.cpp
@@ -358,7 +358,7 @@ void AudioEventRTS::setEventName( AsciiString name )
}
//-------------------------------------------------------------------------------------------------
-void AudioEventRTS::generateFilename( void )
+void AudioEventRTS::generateFilename( Bool forPlaying )
{
// A Logic Random Value is used because we may ask "How long will it take to play this sound?"
// In that case, we need the same answer across all pcs.
@@ -413,9 +413,10 @@ void AudioEventRTS::generateFilename( void )
m_filenameToLoad.concat(generateFilenameExtension(m_eventInfo->m_soundType));
adjustForLocalization(m_filenameToLoad);
- // Note: Also generate Delay when generating a filename, cause
+ // Note: Also generate Delay when generating a filename, cause
// we want delay to apply between every loop of a sound.
- m_delay = GameAudioRandomValueReal(m_eventInfo->m_delayMin, m_eventInfo->m_delayMax);
+ if (forPlaying)
+ m_delay = GameAudioRandomValueReal(m_eventInfo->m_delayMin, m_eventInfo->m_delayMax);
}
//-------------------------------------------------------------------------------------------------
@@ -425,10 +426,13 @@ AsciiString AudioEventRTS::getFilename( void )
}
//-------------------------------------------------------------------------------------------------
-void AudioEventRTS::generatePlayInfo( void )
+void AudioEventRTS::generatePlayInfo( Bool forPlaying )
{
- m_pitchShift = GameAudioRandomValueReal(m_eventInfo->m_pitchShiftMin, m_eventInfo->m_pitchShiftMax);
- m_volumeShift = GameAudioRandomValueReal(1.0f + m_eventInfo->m_volumeShift, 1.0f); // volume shifts are between 0 and 1
+ if (forPlaying)
+ {
+ m_pitchShift = GameAudioRandomValueReal(m_eventInfo->m_pitchShiftMin, m_eventInfo->m_pitchShiftMax);
+ m_volumeShift = GameAudioRandomValueReal(1.0f + m_eventInfo->m_volumeShift, 1.0f); // volume shifts are between 0 and 1
+ }
m_loopCount = m_eventInfo->m_loopCount;
m_portionToPlayNext = PP_Attack;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
index e09a225e3..44240ce56 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
@@ -1179,9 +1179,11 @@ Real AudioManager::getWaveFileLengthMS( AsciiString strToLoad ) const
}
//-------------------------------------------------------------------------------------------------
+/* Logic's, not the device's (LOGIC-THREAD.md M7): the event table, the file headers and the logic
+ stream's Unchanged reads, with no draw from the audio stream. Only a file that is not a .wav goes
+ to the device, in getFileLengthMS, which counts it. */
Real AudioManager::getAudioLengthMS( const AudioEventRTS *event )
{
- LOGIC_CENSUS( CENSUS_AUDIO_READ );
if (!event->getAudioEventInfo()) {
getInfoForAudioEvent(event);
if (!event->getAudioEventInfo()) {
@@ -1191,8 +1193,8 @@ Real AudioManager::getAudioLengthMS( const AudioEventRTS *event )
AudioEventRTS tmpEvent = *event;
- tmpEvent.generateFilename();
- tmpEvent.generatePlayInfo();
+ tmpEvent.generateFilename( FALSE );
+ tmpEvent.generatePlayInfo( FALSE );
AsciiString attack = tmpEvent.getAttackFilename();
AsciiString sound = tmpEvent.getFilename();
AsciiString decay = tmpEvent.getDecayFilename();
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
index 895ec9f3b..7c3c12605 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp
@@ -25,13 +25,18 @@
#include "Common/LogicThread.h"
#include "Common/AudioEventRTS.h"
#include "Common/EarlyCommandLine.h"
+#include "Common/GameAudio.h"
#include "Common/MessageStream.h"
#include "GameClient/ControlBar.h"
#include "GameClient/Drawable.h"
#include "GameClient/GameClient.h"
+#include "GameClient/InGameUI.h"
+#include "GameClient/View.h"
+#include "GameLogic/Object.h"
#include "GameLogic/FPUControl.h"
#include "GameLogic/GameLogic.h"
+#include <algorithm>
#include <chrono>
#include <condition_variable>
#include <exception>
@@ -83,7 +88,7 @@ namespace
"drawable", "modelcondition", "audio", "ingameui", "controlbar", "tacticalview", "radar",
"fxlist", "terrainvisual", "particles", "gameclient", "eva", "newdrawable", "clientrandom",
"ghost", "messagestream", "display", "jobs", "ondemandflush", "observerlookat",
- "drawablepush", "destroydrawable", "audioread", "clientread"
+ "drawablepush", "destroydrawable", "audioread", "clientread", "assetload"
};
// M5: what the tick asked of the audio, the FX lists and the particle systems, in call order.
@@ -93,6 +98,35 @@ namespace
// M6: the camera calls of the tick, see callViewAfterTick
std::vector< std::function<void()> > s_viewCalls;
+ // M7: what the tick reads of the client, see LogicThread::ClientBlock
+ LogicThread::ClientBlock s_block;
+ Int64 s_viewReads = 0; ///< camera answers the tick asked the camera for, at -logicthread 0
+ Int64 s_viewMispredicted = 0; ///< of those, the ones the block would have answered otherwise
+
+ /* The sync point: the main thread, before the tick, with every call the last tick queued already
+ run. So the block holds what the tick's first read of the client would have returned. */
+ void captureClientBlock( void )
+ {
+ s_block.selection.clear();
+ const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
+ for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )
+ {
+ LogicThread::SelectedEntry entry = { (*it)->getID(), (*it)->getObject()->getID() };
+ s_block.selection.push_back( entry );
+ }
+ s_block.frameSelectionChanged = TheInGameUI->getFrameSelectionChanged();
+ s_block.observerLookAt = TheControlBar->getObserverLookAtPlayer();
+ s_block.cameraFrozen = TheTacticalView->isTimeFrozen();
+ s_block.cameraMoving = TheTacticalView->isCameraMoving();
+ s_block.cameraBlurring = TheTacticalView->isCameraMotionBlurring();
+ TheAudio->captureForLogic();
+ }
+
+ Bool blockSaysCameraFinished( void )
+ {
+ return s_block.cameraBlurring || !s_block.cameraMoving;
+ }
+
void runViewCalls( void )
{
// swapped out first: a call that queues another (none does today) waits for the next run
@@ -109,6 +143,9 @@ namespace
bones a death effect may still have read, then the control bar (M2). */
void flushAfterTick( void )
{
+ // M7: the frame the tick ran, which it used to hand the client itself; a tick that started a map
+ // ran frame 0 after the load, one that cleared the game left 0
+ TheGameClient->setFrame( TheGameLogic->getFrameForClient() );
Drawable::flushPendingClientWork();
runViewCalls();
// an effect queues nothing more: none of them runs inside a tick
@@ -241,6 +278,10 @@ void LogicThread::shutdown( void )
//-------------------------------------------------------------------------------------------------
void LogicThread::runTick( void )
{
+ captureClientBlock();
+ // the client's clock reads the frame the tick runs, as GameLogic::update set it at its top
+ TheGameClient->setFrame( TheGameLogic->getFrame() );
+
if( !s_enabled || tickNeedsMainThread() )
{
++s_inlineTicks;
@@ -341,6 +382,77 @@ void LogicThread::readViewFromTick( void )
t_isLogicThread = onLogicThread;
}
+//-------------------------------------------------------------------------------------------------
+const LogicThread::ClientBlock &LogicThread::clientBlock( void )
+{
+ return s_block;
+}
+
+//-------------------------------------------------------------------------------------------------
+void LogicThread::noteSelected( DrawableID drawable, ObjectID object, Bool selected )
+{
+ std::vector<SelectedEntry>::iterator it = s_block.selection.begin();
+ while( it != s_block.selection.end() && it->drawable != drawable )
+ ++it;
+ if( selected == ( it != s_block.selection.end() ) )
+ return;
+ if( selected )
+ {
+ SelectedEntry entry = { drawable, object };
+ s_block.selection.push_back( entry );
+ }
+ else
+ s_block.selection.erase( it );
+ s_block.frameSelectionChanged = TheGameLogic->getFrame();
+}
+
+//-------------------------------------------------------------------------------------------------
+void LogicThread::noteSelectionCleared( void )
+{
+ if( s_block.selection.empty() )
+ return;
+ s_block.selection.clear();
+ s_block.frameSelectionChanged = TheGameLogic->getFrame();
+}
+
+//-------------------------------------------------------------------------------------------------
+void LogicThread::noteViewEffect( ViewEffect effect )
+{
+ switch( effect )
+ {
+ case VIEW_MOVES: s_block.cameraMoving = TRUE; break;
+ case VIEW_FREEZES_TIME: s_block.cameraFrozen = TRUE; break;
+ case VIEW_BLUR_STARTS: s_block.cameraBlurring = TRUE; break;
+ case VIEW_BLUR_ENDS: s_block.cameraBlurring = FALSE; break;
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool LogicThread::isCameraMovementFinishedForTick( void )
+{
+ if( s_enabled )
+ return blockSaysCameraFinished();
+ readViewFromTick();
+ const Bool finished = TheTacticalView->isCameraMovementFinished();
+ ++s_viewReads;
+ if( finished != blockSaysCameraFinished() )
+ ++s_viewMispredicted;
+ return finished;
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool LogicThread::isTimeFrozenForTick( void )
+{
+ if( s_enabled )
+ return s_block.cameraFrozen;
+ readViewFromTick();
+ const Bool frozen = TheTacticalView->isTimeFrozen();
+ ++s_viewReads;
+ if( frozen != s_block.cameraFrozen )
+ ++s_viewMispredicted;
+ return frozen;
+}
+
//-------------------------------------------------------------------------------------------------
void LogicThread::discardEffects( void )
{
@@ -362,4 +474,6 @@ void LogicThread::report( void )
for( Int i = 0; i < CENSUS_COUNT; ++i )
used += snprintf( line + used, sizeof(line) - used, "%s%s %lld", i ? " | " : "", CHANNEL_NAMES[ i ], (long long)s_census[ i ] );
DEBUG_LOG(( "HEADLESS LOGICTHREAD CENSUS: %s\n", line ));
+ DEBUG_LOG(( "HEADLESS LOGICTHREAD VIEW: %lld camera reads asked of the camera, %lld the block would have answered otherwise\n",
+ (long long)s_viewReads, (long long)s_viewMispredicted ));
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 2869e693e..5f22746bd 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -912,10 +912,15 @@ Bool Drawable::clientOnly_getFirstRenderObjInfo(Coord3D* pos, Real* boundingSphe
}
//-------------------------------------------------------------------------------------------------
+/** The bones, launch offsets and barrel counts logic reads skip a draw module the player's "extra
+ * animations" option (m_useDrawModuleLOD) can leave out, on every machine, so one player's option
+ * cannot change where another machine's shot leaves from. */
Bool Drawable::getProjectileLaunchOffset(WeaponSlotType wslot, Int specificBarrelToUse, Matrix3D* launchPos, WhichTurretType tur, Coord3D* turretRotPos, Coord3D* turretPitchPos) const
{
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
+ if ((*dm)->isLODOptional())
+ continue;
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di && di->getProjectileLaunchOffset(m_conditionState, wslot, specificBarrelToUse, launchPos, tur, turretRotPos, turretPitchPos))
return true;
@@ -1021,10 +1026,13 @@ Int Drawable::getPristineBonePositions(const char* boneNamePrefix, Int startInde
if (maxBones <= 0)
break;
+ if ((*dm)->isLODOptional())
+ continue;
+
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
{
- Int subcount =
+ Int subcount =
di->getPristineBonePositionsForConditionState(m_conditionState, boneNamePrefix, startIndex, positions, transforms, maxBones);
if (subcount > 0)
@@ -1051,6 +1059,8 @@ Int Drawable::getCurrentClientBonePositions(const char* boneNamePrefix, Int star
{
if (maxBones <= 0)
break;
+ if ((*dm)->isLODOptional())
+ continue;
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
@@ -1078,6 +1088,8 @@ Bool Drawable::getCurrentWorldspaceClientBonePositions(const char* boneName, Mat
// LaserUpdate asks from the tick; the bones have to be where the tick left the drawable
for (DrawModule** dm = const_cast<Drawable*>(this)->getDrawModulesFlushed(); *dm; ++dm)
{
+ if ((*dm)->isLODOptional())
+ continue;
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di && di->getCurrentWorldspaceClientBonePositions(boneName, transform))
return true;
@@ -5670,6 +5682,8 @@ Int Drawable::getBarrelCount(WeaponSlotType wslot) const
{
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
+ if ((*dm)->isLODOptional())
+ continue;
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
Int count = di ? di->getBarrelCount(wslot) : 0;
if (count != 0)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 684c6df43..adc9a73f9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -6032,6 +6032,8 @@ Bool InGameUI::rotatePendingPlacement( Int steps )
void InGameUI::selectDrawable( Drawable *draw )
{
// a drawable the tick destroys leaves the selection in this queue too, before it is deleted
+ if( LogicThread::defersEffects() )
+ LogicThread::noteSelected( draw->getID(), draw->getObject()->getID(), TRUE ); // what the tick reads back (M7)
LOGIC_AFTER_TICK( [=]() { selectDrawable( draw ); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
@@ -6073,6 +6075,8 @@ void InGameUI::setDisplayedMaxWarning( Bool selected )
//-------------------------------------------------------------------------------------------------
void InGameUI::deselectDrawable( Drawable *draw )
{
+ if( LogicThread::defersEffects() )
+ LogicThread::noteSelected( draw->getID(), INVALID_ID, FALSE ); // what the tick reads back (M7)
LOGIC_AFTER_TICK( [=]() { deselectDrawable( draw ); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
@@ -6113,6 +6117,8 @@ void InGameUI::deselectDrawable( Drawable *draw )
//-------------------------------------------------------------------------------------------------
void InGameUI::deselectAllDrawables( void )
{
+ if( LogicThread::defersEffects() )
+ LogicThread::noteSelectionCleared(); // what the tick reads back (M7)
LOGIC_AFTER_TICK( [=]() { deselectAllDrawables(); } );
LOGIC_CENSUS( CENSUS_INGAMEUI );
const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
index 82280438a..d6582767d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
@@ -1010,6 +1010,23 @@ TerrainLogic::~TerrainLogic()
void TerrainLogic::init( void )
{
+ // the vertex animated water's index 0 settings, which W3DTerrainVisual::init gave the grid when
+ // the grid lived in the render object; they stand until a WaveGuide1 map picks its own
+ Int waterSettingIndex = 0;
+ m_waterGrid.setHeightClamps( TheGlobalData->m_vertexWaterHeightClampLow[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterHeightClampHi[ waterSettingIndex ] );
+ m_waterGrid.setTransform( TheGlobalData->m_vertexWaterAngle[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterXPosition[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterYPosition[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterZPosition[ waterSettingIndex ] );
+ m_waterGrid.setResolution( TheGlobalData->m_vertexWaterXGridCells[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterYGridCells[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterGridSize[ waterSettingIndex ] );
+ m_waterGrid.setChangeAttenuationFactors( TheGlobalData->m_vertexWaterAttenuationA[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterAttenuationB[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterAttenuationC[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterAttenuationRange[ waterSettingIndex ] );
+
} // end init
//-------------------------------------------------------------------------------------------------
@@ -1022,6 +1039,7 @@ void TerrainLogic::reset( void )
deleteBridges();
PolygonTrigger::deleteTriggers();
m_numWaterToUpdate = 0;
+ m_waterGrid.reset(); // zero the mesh; the flags and settings carry over, as they did in the render object
} // end reset
@@ -1226,27 +1244,24 @@ void TerrainLogic::enableWaterGrid( Bool enable )
} // end if
- TheTerrainVisual->setWaterGridHeightClamps( NULL,
- TheGlobalData->m_vertexWaterHeightClampLow[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterHeightClampHi[ waterSettingIndex ] );
- TheTerrainVisual->setWaterTransform( NULL,
- TheGlobalData->m_vertexWaterAngle[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterXPosition[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterYPosition[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterZPosition[ waterSettingIndex ] );
- TheTerrainVisual->setWaterGridResolution( NULL,
- TheGlobalData->m_vertexWaterXGridCells[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterYGridCells[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterGridSize[ waterSettingIndex ] );
- TheTerrainVisual->setWaterAttenuationFactors( NULL,
- TheGlobalData->m_vertexWaterAttenuationA[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterAttenuationB[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterAttenuationC[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterAttenuationRange[ waterSettingIndex ] );
+ m_waterGrid.setHeightClamps( TheGlobalData->m_vertexWaterHeightClampLow[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterHeightClampHi[ waterSettingIndex ] );
+ m_waterGrid.setTransform( TheGlobalData->m_vertexWaterAngle[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterXPosition[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterYPosition[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterZPosition[ waterSettingIndex ] );
+ m_waterGrid.setResolution( TheGlobalData->m_vertexWaterXGridCells[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterYGridCells[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterGridSize[ waterSettingIndex ] );
+ m_waterGrid.setChangeAttenuationFactors( TheGlobalData->m_vertexWaterAttenuationA[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterAttenuationB[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterAttenuationC[ waterSettingIndex ],
+ TheGlobalData->m_vertexWaterAttenuationRange[ waterSettingIndex ] );
} // end if
- // notify the terrain visual of the change
+ // the grid itself, then the terrain visual, which only builds what it draws the grid with
+ m_waterGrid.enable( enable );
TheTerrainVisual->enableWaterGrid( enable );
} // end enableWaterGrid
@@ -1319,6 +1334,8 @@ Bool TerrainLogic::loadMap( AsciiString filename, Bool query )
#endif
if (!query) {
+ // W3DTerrainVisual::load turned the render object's grid flag off; newMap turns it back on
+ m_waterGrid.disableMotion();
// tell the game interface a new terrain file has been loaded up
TheTerrainVisual->load( getSourceFilename() );
}
@@ -2217,7 +2234,7 @@ Bool TerrainLogic::isUnderwater( Real x, Real y, Real *waterZ, Real *terrainZ )
//
Real wZ = 0.0f;
if( waterHandle == &m_gridWaterHandle )
- TheTerrainVisual->getWaterGridHeight( x, y, &wZ );
+ m_waterGrid.getHeight( x, y, &wZ );
else
wZ = getWaterHeight( waterHandle );
@@ -2275,7 +2292,7 @@ const WaterHandle* TerrainLogic::getWaterHandle( Real x, Real y )
/**@todo: Remove this after we have all water types included
in water triggers. For now do special check for water grid mesh. */
Real meshZ;
- if( TheTerrainVisual->getWaterGridHeight( x, y, &meshZ ) )
+ if( m_waterGrid.getHeight( x, y, &meshZ ) )
{
//
@@ -2369,14 +2386,14 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d
// get transform information
Matrix3D transform;
- TheTerrainVisual->getWaterTransform( water, &transform );
+ m_waterGrid.getTransform( &transform );
// save the old height
previousHeight = transform.Get_Z_Translation();
// set the new height
transform.Set_Z_Translation( height );
- TheTerrainVisual->setWaterTransform( &transform );
+ m_waterGrid.setTransform( &transform );
} // end if
else
@@ -2556,7 +2573,7 @@ void TerrainLogic::findAxisAlignedBoundingRect( const WaterHandle *water, Region
// compute the 4 corners of the table according to the grids and grid spacing
Real gridX, gridY, cellSize;
- TheTerrainVisual->getWaterGridResolution( water, &gridX, &gridY, &cellSize );
+ m_waterGrid.getResolution( &gridX, &gridY, &cellSize );
p[ 0 ].x = 0;
p[ 0 ].y = 0;
p[ 1 ].x = gridX * cellSize;
@@ -2569,7 +2586,7 @@ void TerrainLogic::findAxisAlignedBoundingRect( const WaterHandle *water, Region
// transform the 4 points using the transform matrix of the water
Vector3 v;
Matrix3D transform;
- TheTerrainVisual->getWaterTransform( water, &transform );
+ m_waterGrid.getTransform( &transform );
for( i = 0; i < 4; i++ )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp
index c56d73812..c7182289c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp
@@ -25,7 +25,10 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
+#include "Common/GameState.h"
#include "Common/GlobalData.h"
+#include "Common/MapObject.h"
+#include "Common/Xfer.h"
#include "GameLogic/WaterGridMotion.h"
// ------------------------------------------------------------------------------------------------
@@ -114,3 +117,451 @@ void WaterGridMotion::updateForLogicFrame( UnsignedInt currLogicFrame, Bool doWa
} // end if, a logic frame has passed
} // end updateForLogicFrame
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// WaterGrid: WaterRenderObjClass's grid methods, moved with their members (LOGIC-THREAD M7)
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+// 3D Grid Mesh Water defaults, W3DWater.cpp's
+#define WATER_MESH_X_VERTICES 128
+#define WATER_MESH_Y_VERTICES 128
+#define WATER_MESH_SPACING MAP_XY_FACTOR //same as terrain
+
+// ------------------------------------------------------------------------------------------------
+WaterGrid::WaterGrid( void )
+{
+ m_meshData = NULL;
+ m_meshDataSize = 0;
+ m_meshGeneration = 0;
+ m_meshInMotion = FALSE;
+ m_doWaterGrid = FALSE;
+ m_heightsEnabled = FALSE;
+ m_pushed = FALSE;
+
+ m_transform.Make_Identity();
+ m_gridOrigin=Vector2(0,0);
+ m_gridDirectionX=Vector2(1.0f,0.0f);
+ m_gridDirectionY=Vector2(1.0f,0.0f);
+
+ // set by TerrainLogic::init before anything reads them, as W3DTerrainVisual::init set them
+ m_minGridHeight = 0.0f;
+ m_maxGridHeight = 0.0f;
+ m_gridChangeMaxRange = 0.0f;
+ m_gridChangeAtt0 = 0.0f;
+ m_gridChangeAtt1 = 0.0f;
+ m_gridChangeAtt2 = 0.0f;
+
+ m_gridCellSize=WATER_MESH_SPACING;
+ m_gridCellsX=WATER_MESH_X_VERTICES;
+ m_gridCellsY=WATER_MESH_Y_VERTICES;
+}
+
+// ------------------------------------------------------------------------------------------------
+WaterGrid::~WaterGrid( void )
+{
+ if (m_meshData)
+ delete [] m_meshData;
+ m_meshData = NULL;
+ m_meshDataSize = 0;
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::reset( void )
+{
+
+ // for vertex animated water mesh reset the values
+ if( m_meshData)
+ {
+ Int i, j;
+ MeshPoint *pData;
+ Int mx = m_gridCellsX + 1;
+ Int my = m_gridCellsY + 1;
+
+ // go through each mesh point and adjust the height according to the velocity
+ for( j = 0, pData = m_meshData; j < (my + 2); j++ )
+ {
+
+ for( i = 0; i < (mx + 2); i++ )
+ {
+
+ // areset grid values for this cell
+ pData->velocity = 0.0f;
+ pData->height = 0.0f;
+ pData->preferredHeight = 0.0f;
+ pData->status = 0; // AT_REST
+
+ // on to the next one
+ pData++;
+
+ } // end for i
+
+ } // end for j
+
+ // mesh data is no longer in motion
+ m_meshInMotion = FALSE;
+
+ } // end if, water type 3
+
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::allocateMesh( void )
+{
+ //contains the current deformed water surface z(height) values. With 1 vertex invisible border
+ //around surface to speed up normal calculations.
+ m_meshDataSize = (m_gridCellsX+1+2)*(m_gridCellsY+1+2);
+ m_meshData=NEW MeshPoint[ m_meshDataSize ];
+ memset(m_meshData,0,sizeof(MeshPoint)*(m_gridCellsX+1+2)*(m_gridCellsY+1+2));
+ reset();
+ ++m_meshGeneration;
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::enable( Bool state )
+{
+ m_heightsEnabled = state;
+ m_doWaterGrid = state;
+ m_pushed = FALSE;
+
+ if (state && m_meshData == NULL)
+ allocateMesh();
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::disableMotion( void )
+{
+ m_doWaterGrid = FALSE;
+ m_pushed = FALSE;
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::update( UnsignedInt logicFrame )
+{
+ WaterGridMotion::updateForLogicFrame( logicFrame, m_doWaterGrid, m_meshInMotion, m_meshData, m_gridCellsX, m_gridCellsY );
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::setHeightClamps(Real minz, Real maxz)
+{
+ m_minGridHeight = minz;
+ m_maxGridHeight = maxz;
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::addVelocity( Real worldX, Real worldY,
+ Real zVelocity, Real preferredHeight )
+{
+
+ if( m_doWaterGrid)
+ {
+ Real gx,gy;
+ Real minX,maxX,minY,maxY;
+ Int x,y;
+ MeshPoint *meshPoint;
+ m_pushed = TRUE;
+
+ //check if center falls within grid bounds
+ if (worldToGridSpace(worldX, worldY, gx, gy))
+ {
+
+ //find extents of influence
+ minX = floorf(gx - m_gridChangeMaxRange);
+ if (minX < 0 )
+ minX = 0; //clamp extent to fall within box
+ maxX = ceilf(gx + m_gridChangeMaxRange);
+ if (maxX > m_gridCellsX)
+ maxX = m_gridCellsX; //clamp extent to fall within box
+
+ minY = floorf(gy - m_gridChangeMaxRange);
+ if (minY < 0 )
+ minY = 0; //clamp extent to fall within box
+ maxY = ceilf(gy + m_gridChangeMaxRange);
+ if (maxY > m_gridCellsY)
+ maxY = m_gridCellsY; //clamp extent to fall within box
+
+ for (y=minY; y<=maxY; y++)
+ {
+ for (x=minX; x<=maxX; x++)
+ {
+
+ // get the mesh point that we're concerned with
+ meshPoint = &m_meshData[ (y + 1) * (m_gridCellsX + 1 + 2) + x + 1 ];
+
+ // we now have a new preferred height
+ meshPoint->preferredHeight = preferredHeight;
+
+ //
+ // set the velocity of this point based on the distance from the center of the
+ // "core" point for this call
+ //
+ // The one caller, WaveGuideUpdate, pushes every logic frame, so the push is an
+ // acceleration: per frame squared, a quarter of the 30 Hz amount. WaterVelocity's
+ // parse (per second to per frame) took one half, this is the other.
+ meshPoint->velocity = meshPoint->velocity + ConvertRetailPerFrameRate( zVelocity );
+
+ // this point is now "in motion"
+ BitSet( meshPoint->status, WaterGridMotion::IN_MOTION );
+
+ }
+ }
+
+ //
+ // the mesh data is now dirty, we need to pass through the velocity field
+ // during an update phase to update the positions
+ //
+ m_meshInMotion = TRUE;
+
+ }
+
+ } // end if, water type is 3
+
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::changeHeight(Real wx, Real wy, Real delta)
+{
+ Real gx,gy;
+ Real *oldData;
+ Real newData;
+ Real distance;
+ Real minX,maxX,minY,maxY;
+ Int x,y;
+
+ //check if center falls within grid bounds
+ if (worldToGridSpace(wx, wy, gx, gy))
+ { //find extents of influence
+ minX = floorf(gx - m_gridChangeMaxRange);
+ if (minX < 0 )
+ minX = 0; //clamp extent to fall within box
+ maxX = ceilf(gx + m_gridChangeMaxRange);
+ if (maxX > m_gridCellsX)
+ maxX = m_gridCellsX; //clamp extent to fall within box
+
+ minY = floorf(gy - m_gridChangeMaxRange);
+ if (minY < 0 )
+ minY = 0; //clamp extent to fall within box
+ maxY = ceilf(gy + m_gridChangeMaxRange);
+ if (maxY > m_gridCellsY)
+ maxY = m_gridCellsY; //clamp extent to fall within box
+
+ for (y=minY; y<=maxY; y++)
+ {
+ for (x=minX; x<=maxX; x++)
+ { oldData = &m_meshData[(y+1)*(m_gridCellsX+1+2)+x+1].height;
+ distance = (gx - (Real)x)*(gx - (Real)x) + (gy - (Real)y)*(gy - (Real)y);
+ distance = sqrt(distance);
+ newData = *oldData + 1.0f/(m_gridChangeAtt0+m_gridChangeAtt1*distance+distance*distance*m_gridChangeAtt2)*delta;
+ //Clamp to min/max values
+ if (newData < m_minGridHeight)
+ newData = m_minGridHeight;
+ if (newData > m_maxGridHeight)
+ newData = m_maxGridHeight;
+ *oldData = newData;
+ }
+ }
+ }
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::setChangeAttenuationFactors(Real a, Real b, Real c, Real range)
+{
+ m_gridChangeAtt0 = a;
+ m_gridChangeAtt1 = b;
+ m_gridChangeAtt2 = c;
+ m_gridChangeMaxRange = range/m_gridCellSize; //convert range to grid space
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::setTransform(Real angle, Real x, Real y, Real z)
+{
+ m_gridDirectionX = Vector2(1.0f,0.0f);
+
+ m_gridOrigin.X = x;
+ m_gridOrigin.Y = y;
+
+ Matrix3D xform(1);
+ xform.Rotate_Z(angle);
+
+ m_gridDirectionX.X = xform.Get_X_Vector().X;
+ m_gridDirectionX.Y = xform.Get_X_Vector().Y;
+
+ m_gridDirectionY.X = xform.Get_Y_Vector().X;
+ m_gridDirectionY.Y = xform.Get_Y_Vector().Y;
+
+ xform.Set_Translation(Vector3(x,y,z));
+ m_transform = xform;
+}
+
+// ------------------------------------------------------------------------------------------------
+/** As EA's: only the matrix moves. The origin and axes worldToGridSpace uses stay where the angle
+ * version put them; the scripts that raise and lower the grid change only the Z, which getHeight
+ * adds. */
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::setTransform(const Matrix3D *transform )
+{
+
+ if( transform )
+ m_transform = *transform;
+
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::getTransform(Matrix3D *transform ) const
+{
+
+ if( transform )
+ *transform = m_transform;
+
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::setResolution(Real gridCellsX, Real gridCellsY, Real cellSize)
+{
+ m_gridCellSize=cellSize;
+
+ // EA compared m_gridCellsY with itself: a change in Y alone is not a change, and is kept
+ if (m_gridCellsX != gridCellsX || m_gridCellsY != m_gridCellsY)
+ { //resolutoin has changed
+ m_gridCellsX=gridCellsX;
+ m_gridCellsY=gridCellsY;
+
+ if (m_meshData)
+ {
+
+ delete [] m_meshData;//free previously allocated grid and allocate new size
+ m_meshData = NULL; // must set to NULL so that we properly re-allocate
+ m_meshDataSize = 0;
+
+ // the render object called its own enableWaterGrid(true) here and put m_doWaterGrid back,
+ // which left only the allocation and the cleared m_disableRiver
+ m_pushed = FALSE;
+ allocateMesh();
+
+ }
+ }
+}
+
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::getResolution( Real *gridCellsX, Real *gridCellsY, Real *cellSize ) const
+{
+
+ if( gridCellsX )
+ *gridCellsX = m_gridCellsX;
+ if( gridCellsY )
+ *gridCellsY = m_gridCellsY;
+ if( cellSize )
+ *cellSize = m_gridCellSize;
+
+}
+
+// ------------------------------------------------------------------------------------------------
+/** W3DTerrainVisual::getWaterGridHeight and the render object's getGridVertexHeight together: the
+ * answer is TRUE for a point inside an enabled grid, and the height is only written when there is
+ * a mesh to read it from. Get_Position().Z was the transform's Z translation. */
+// ------------------------------------------------------------------------------------------------
+Bool WaterGrid::getHeight( Real worldX, Real worldY, Real *height ) const
+{
+ Real gridX, gridY;
+
+ if (m_heightsEnabled && worldToGridSpace(worldX, worldY, gridX, gridY))
+ { //point falls within grid, return correct height
+ if (m_meshData)
+ *height=m_meshData[(REAL_TO_INT(gridY)+1)*(m_gridCellsX+1+2)+REAL_TO_INT(gridX)+1].height+ m_transform.Get_Z_Translation();
+ return TRUE;
+ }
+ return FALSE;
+}
+
+// ------------------------------------------------------------------------------------------------
+Bool WaterGrid::worldToGridSpace(Real worldX, Real worldY, Real &gridX, Real &gridY) const
+{
+ Real dx,dy;
+ Real ooGridCellSize = 1.0f/m_gridCellSize;
+
+ dx=worldX - m_gridOrigin.X;
+ dy=worldY - m_gridOrigin.Y;
+ gridX = ooGridCellSize * (dx * m_gridDirectionX.X + dy * m_gridDirectionX.Y);
+ gridY = ooGridCellSize * (dx * m_gridDirectionY.X + dy * m_gridDirectionY.Y);
+
+ if (gridX < 0)
+ return FALSE;
+ if (gridX > m_gridCellsX-1 )
+ return FALSE;
+ if (gridY < 0)
+ return FALSE;
+ if (gridY > m_gridCellsY-1 )
+ return FALSE;
+
+ return TRUE;
+}
+
+// ------------------------------------------------------------------------------------------------
+/** CRC */
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::crc( Xfer *xfer )
+{
+
+} // end crc
+
+// ------------------------------------------------------------------------------------------------
+/** Xfer, WaterRenderObjClass's bytes, which W3DTerrainVisual::xfer still writes in its block
+ * Version Info:
+ * 1: Initial version */
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::xfer( Xfer *xfer )
+{
+
+ // version
+ XferVersion currentVersion = 1;
+ XferVersion version = currentVersion;
+ xfer->xferVersion( &version, currentVersion );
+
+ // grid cells x
+ Int cellsX = m_gridCellsX;
+ xfer->xferInt( &cellsX );
+ if( cellsX != m_gridCellsX )
+ {
+
+ DEBUG_CRASH(( "WaterGrid::xfer - cells X mismatch\n" ));
+ throw SC_INVALID_DATA;
+
+ } // end if
+
+ // grid cells Y
+ Int cellsY = m_gridCellsY;
+ xfer->xferInt( &cellsY );
+ if( cellsY != m_gridCellsY )
+ {
+
+ DEBUG_CRASH(( "WaterGrid::xfer - cells Y mismatch\n" ));
+ throw SC_INVALID_DATA;
+
+ } // end if
+
+ // xfer each of the mesh data points
+ for( Int i = 0; i < m_meshDataSize; ++i )
+ {
+
+ // height
+ xfer->xferReal( &m_meshData[ i ].height );
+
+ // velocity
+ xfer->xferReal( &m_meshData[ i ].velocity );
+
+ // status
+ xfer->xferUnsignedByte( &m_meshData[ i ].status );
+
+ // preferred height
+ xfer->xferUnsignedByte( &m_meshData[ i ].preferredHeight );
+
+ } // end for, i
+
+} // end xfer
+
+// ------------------------------------------------------------------------------------------------
+/** Load post process */
+// ------------------------------------------------------------------------------------------------
+void WaterGrid::loadPostProcess( void )
+{
+
+} // end loadPostProcess
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp
index c932bad97..5c2427dbf 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp
@@ -1548,31 +1548,23 @@ void ActiveBody::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLeve
TheAudio->addAudioEvent(&veterancyChanged);
}
- //Also mark the UI dirty -- incase the object is selected or contained.
- Object *obj = getObject();
- Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
- if( draw )
+ //Also mark the UI dirty -- incase the object is selected or contained. The selection is the
+ //client's, so the client asks it after the tick (LOGIC-THREAD.md M7), of the object and its
+ //container as they stand now.
+ const Object *obj = getObject();
+ const ObjectID objID = obj->getID();
+ const ObjectID containerID = obj->getContainedBy() ? obj->getContainedBy()->getID() : INVALID_ID;
+ LogicThread::callAfterTick( [objID, containerID]()
{
- Object *checkOwner = draw->getObject();
- if( checkOwner == obj )
- {
- //Our selected object has been promoted!
+ Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
+ if( draw == NULL )
+ return;
+ const ObjectID selectedID = draw->getObject() ? draw->getObject()->getID() : INVALID_ID;
+ //Our selected object has been promoted, or the contained by object is containing me!
+ if( selectedID == objID
+ || ( containerID != INVALID_ID && TheInGameUI->getSelectCount() == 1 && selectedID == containerID ) )
TheControlBar->markUIDirty();
- }
- else
- {
- const Object *containedBy = obj->getContainedBy();
- if( containedBy && TheInGameUI->getSelectCount() == 1 )
- {
- Object *checkOwner = draw->getObject();
- if( checkOwner == containedBy )
- {
- //But only if the contained by object is containing me!
- TheControlBar->markUIDirty();
- }
- }
- }
- }
+ } );
}
Real oldBonus = TheGlobalData->m_healthBonus[oldLevel];
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
index 38ce1cb62..4d1a4fbbe 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp
@@ -585,7 +585,7 @@ void SpecialPowerModule::aboutToDoSpecialPower( const Coord3D *location )
Player *localPlayer = ThePlayerList->getLocalPlayer();
if( localPlayer && !localPlayer->isPlayerActive() )
{
- Player *observed = TheControlBar ? TheControlBar->getObserverLookAtPlayer() : NULL;
+ Player *observed = LogicThread::clientBlock().observerLookAt; // as the sync point saw it (M7)
if( observed )
localPlayer = observed;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
index b69698360..827632902 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
@@ -1086,24 +1086,29 @@ UpdateSleepTime ProductionUpdate::update( void )
player->getAcademyStats()->recordUpgrade( upgrade, FALSE );
- //Also mark the UI dirty -- incase object with upgrade cameo is selected.
- Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
- Object *selectedObject = draw ? draw->getObject() : NULL;
- if( selectedObject )
+ //Also mark the UI dirty -- incase object with upgrade cameo is selected. The selection is
+ //the client's, so the client asks it after the tick (LOGIC-THREAD.md M7).
+ const UpgradeTemplate *finished = upgrade;
+ LogicThread::callAfterTick( [finished]()
{
- const ThingTemplate *thing = selectedObject->getTemplate();
- for( Int i = 0; i < MAX_UPGRADE_CAMEO_UPGRADES; i++ )
+ Drawable *draw = TheInGameUI->getFirstSelectedDrawable();
+ Object *selectedObject = draw ? draw->getObject() : NULL;
+ if( selectedObject )
{
- AsciiString upgradeName = thing->getUpgradeCameoName( i );
- const UpgradeTemplate *testUpgrade = TheUpgradeCenter->findUpgrade( upgradeName );
- if( testUpgrade == upgrade )
+ const ThingTemplate *thing = selectedObject->getTemplate();
+ for( Int i = 0; i < MAX_UPGRADE_CAMEO_UPGRADES; i++ )
{
- //Our selected object has the upgrade
- TheControlBar->markUIDirty();
- break;
+ AsciiString upgradeName = thing->getUpgradeCameoName( i );
+ const UpgradeTemplate *testUpgrade = TheUpgradeCenter->findUpgrade( upgradeName );
+ if( testUpgrade == finished )
+ {
+ //Our selected object has the upgrade
+ TheControlBar->markUIDirty();
+ break;
+ }
}
}
- }
+ } );
// remove this production entry so we can go on to the next
removeFromProductionQueue( production );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp
index d5556d218..bcd48e674 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp
@@ -429,10 +429,10 @@ void WaveGuideUpdate::doWaterMotion( void )
{
// push up the water here
- TheTerrainVisual->addWaterVelocity( m_transformedShapePoints[ i ].x,
- m_transformedShapePoints[ i ].y,
- modData->m_waterVelocity,
- modData->m_preferredHeight );
+ TheTerrainLogic->getWaterGrid()->addVelocity( m_transformedShapePoints[ i ].x,
+ m_transformedShapePoints[ i ].y,
+ modData->m_waterVelocity,
+ modData->m_preferredHeight );
} // end for i
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
index e790d94d2..b031397a9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
@@ -137,6 +137,15 @@ static void updateTeamAndPlayerStuff( Object *obj, void *userData )
#define VIEW_AFTER_TICK( ... ) \
if( LogicThread::defersView() ) { LogicThread::callViewAfterTick( __VA_ARGS__ ); return; }
+/** M7. What a camera action about to wait in that queue does to the two camera answers the tick
+ * reads back, written to LogicThread::ClientBlock at the call. Only when it waits: run from the
+ * queue it was noted when it was queued. */
+static void noteView( Bool applies, LogicThread::ViewEffect effect )
+{
+ if( applies && LogicThread::defersView() )
+ LogicThread::noteViewEffect( effect );
+}
+
// GLOBALS ////////////////////////////////////////////////////////////////////////////////////////
ScriptActionsInterface *TheScriptActions = NULL;
GameWindow *ScriptActions::m_messageWindow = NULL;
@@ -813,6 +822,7 @@ void ScriptActions::doCreateReinforcements(const AsciiString& team, const AsciiS
//-------------------------------------------------------------------------------------------------
void ScriptActions::doMoveCameraTo(const AsciiString& waypoint, Real sec, Real cameraStutterSec, Real easeIn, Real easeOut)
{
+ noteView( TheTerrainLogic->getWaypointByName( waypoint ) != NULL, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doMoveCameraTo( waypoint, sec, cameraStutterSec, easeIn, easeOut ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
@@ -828,6 +838,7 @@ void ScriptActions::doMoveCameraTo(const AsciiString& waypoint, Real sec, Real c
//-------------------------------------------------------------------------------------------------
void ScriptActions::doZoomCamera(Real zoom, Real sec, Real easeIn, Real easeOut)
{
+ noteView( TRUE, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doZoomCamera( zoom, sec, easeIn, easeOut ); } );
TheTacticalView->zoomCamera(zoom, sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f);
}
@@ -837,6 +848,7 @@ void ScriptActions::doZoomCamera(Real zoom, Real sec, Real easeIn, Real easeOut)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doPitchCamera(Real pitch, Real sec, Real easeIn, Real easeOut)
{
+ noteView( TRUE, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doPitchCamera( pitch, sec, easeIn, easeOut ); } );
TheTacticalView->pitchCamera(pitch, sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f);
}
@@ -857,6 +869,8 @@ void ScriptActions::doOversizeTheTerrain(Int amount)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doSetupCamera(const AsciiString& waypoint, Real zoom, Real pitch, const AsciiString& lookAtWaypoint)
{
+ noteView( TheTerrainLogic->getWaypointByName( waypoint ) && TheTerrainLogic->getWaypointByName( lookAtWaypoint ),
+ LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doSetupCamera( waypoint, zoom, pitch, lookAtWaypoint ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
if (way==NULL) return;
@@ -937,6 +951,7 @@ void ScriptActions::doModCameraMoveToSelection(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doResetCamera(const AsciiString& waypoint, Real sec, Real easeIn, Real easeOut)
{
+ noteView( TheTerrainLogic->getWaypointByName( waypoint ) != NULL, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doResetCamera( waypoint, sec, easeIn, easeOut ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
@@ -952,6 +967,7 @@ void ScriptActions::doResetCamera(const AsciiString& waypoint, Real sec, Real ea
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRotateCamera(Real rotations, Real sec, Real easeIn, Real easeOut)
{
+ noteView( TRUE, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doRotateCamera( rotations, sec, easeIn, easeOut ); } );
TheTacticalView->rotateCamera(rotations, sec*1000.0f, easeIn*1000.0f, easeOut*1000.0f);
}
@@ -961,6 +977,7 @@ void ScriptActions::doRotateCamera(Real rotations, Real sec, Real easeIn, Real e
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRotateCameraTowardObject(const AsciiString& unitName, Real sec, Real holdSec, Real easeIn, Real easeOut)
{
+ noteView( TheScriptEngine->getUnitNamed( unitName ) != NULL, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doRotateCameraTowardObject( unitName, sec, holdSec, easeIn, easeOut ); } );
const Object *unit = TheScriptEngine->getUnitNamed(unitName);
if (!unit)
@@ -973,6 +990,7 @@ void ScriptActions::doRotateCameraTowardObject(const AsciiString& unitName, Real
//-------------------------------------------------------------------------------------------------
void ScriptActions::doRotateCameraTowardWaypoint(const AsciiString& waypointName, Real sec, Real easeIn, Real easeOut, Bool reverseRotation)
{
+ noteView( TheTerrainLogic->getWaypointByName( waypointName ) != NULL, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doRotateCameraTowardWaypoint( waypointName, sec, easeIn, easeOut, reverseRotation ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
if (way==NULL) return;
@@ -984,6 +1002,7 @@ void ScriptActions::doRotateCameraTowardWaypoint(const AsciiString& waypointName
//-------------------------------------------------------------------------------------------------
void ScriptActions::doMoveCameraAlongWaypointPath(const AsciiString& waypoint, Real sec, Real cameraStutterSec, Real easeIn, Real easeOut)
{
+ noteView( TheTerrainLogic->getWaypointByName( waypoint ) != NULL, LogicThread::VIEW_MOVES );
VIEW_AFTER_TICK( [=]() { doMoveCameraAlongWaypointPath( waypoint, sec, cameraStutterSec, easeIn, easeOut ); } );
for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
if (way->getName() == waypoint) {
@@ -3003,6 +3022,7 @@ void ScriptActions::doRadarEnable(void)
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraMotionBlurJump(const AsciiString& waypointName, Bool saturate)
{
+ noteView( TheTerrainLogic->getWaypointByName( waypointName ) != NULL, LogicThread::VIEW_BLUR_STARTS );
VIEW_AFTER_TICK( [=]() { doCameraMotionBlurJump( waypointName, saturate ); } );
Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
if (!way) {
@@ -3042,6 +3062,7 @@ void ScriptActions::doCameraMotionBlurJump(const AsciiString& waypointName, Bool
//-------------------------------------------------------------------------------------------------
void ScriptActions::doCameraMotionBlur(Bool zoomIn, Bool saturate)
{
+ noteView( TRUE, LogicThread::VIEW_BLUR_STARTS );
VIEW_AFTER_TICK( [=]() { doCameraMotionBlur( zoomIn, saturate ); } );
if (TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER))
{
@@ -3874,6 +3895,7 @@ void ScriptActions::doLetterBoxMode(Bool startLetterbox)
void ScriptActions::doBlackWhiteMode(Bool startBWMode, Int frames)
{
// which filter is on is the client's to read, after the tick
+ noteView( startBWMode, LogicThread::VIEW_BLUR_ENDS ); // its filter mode replaces a motion blur's
VIEW_AFTER_TICK( [=]() { doBlackWhiteMode( startBWMode, frames ); } );
if (startBWMode)
{
@@ -5088,6 +5110,7 @@ void ScriptActions::doForceObjectSelection(const AsciiString& teamName, const As
if (centerInView) {
Coord3D pos = *bestGuess->getPosition();
+ noteView( TRUE, LogicThread::VIEW_MOVES );
LogicThread::callViewAfterTick( [pos]() mutable { TheTacticalView->moveCameraTo(&pos, 0, 0, FALSE, 0.0f, 0.0f); } );
}
}
@@ -6630,6 +6653,7 @@ void ScriptActions::executeAction( ScriptAction *pAction )
return;
// the camera's own calls go to its queue (VIEW_AFTER_TICK), the parameters read now
case ScriptAction::CAMERA_MOD_FREEZE_TIME:
+ noteView( TRUE, LogicThread::VIEW_FREEZES_TIME );
LogicThread::callViewAfterTick( []{ TheTacticalView->cameraModFreezeTime(); } );
return;
case ScriptAction::CAMERA_MOD_FREEZE_ANGLE:
@@ -7087,6 +7111,7 @@ void ScriptActions::executeAction( ScriptAction *pAction )
case ScriptAction::CAMERA_MOTION_BLUR_FOLLOW:
{
const FilterModes mode = (enum FilterModes)(FM_VIEW_MB_PAN_ALPHA+pAction->getParameter(0)->getInt());
+ noteView( TRUE, LogicThread::VIEW_BLUR_ENDS );
LogicThread::callViewAfterTick( [=]{
TheTacticalView->setViewFilterMode(mode);
TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
@@ -7094,6 +7119,7 @@ void ScriptActions::executeAction( ScriptAction *pAction )
return;
}
case ScriptAction::CAMERA_MOTION_BLUR_END_FOLLOW:
+ noteView( TRUE, LogicThread::VIEW_BLUR_ENDS );
LogicThread::callViewAfterTick( []{
TheTacticalView->setViewFilterMode(FM_VIEW_MB_END_PAN_ALPHA);
TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
index 9e9172a67..13947f3d0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
@@ -1405,11 +1405,15 @@ Bool ScriptConditions::evaluateNamedSelected(Condition *pCondition, Parameter *p
}
+ // the selection as it stood at the sync point, with what this tick's scripts selected since
+ // (LogicThread::ClientBlock, LOGIC-THREAD.md M7)
+ const LogicThread::ClientBlock &client = LogicThread::clientBlock();
+
Bool anyChanges = false;
if (pCondition->getCustomData() == 0) anyChanges = true;
- if (TheInGameUI->getFrameSelectionChanged() != pCondition->getCustomFrame()) {
+ if (client.frameSelectionChanged != pCondition->getCustomFrame()) {
anyChanges = true; // Selection changed since we cached the value. jba.
}
if (!anyChanges) {
@@ -1418,15 +1422,12 @@ Bool ScriptConditions::evaluateNamedSelected(Condition *pCondition, Parameter *p
}
Bool isSelected = false;
- const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
- // loop through all the selected drawables
- Drawable *draw;
- for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )
+ // loop through all the selected objects
+ for( size_t i = 0; i < client.selection.size(); ++i )
{
- draw = *it;
-
- if (draw->getObject()->getName() == (pUnitParm->getString())) {
+ const Object *obj = TheGameLogic->findObjectByID( client.selection[ i ].object );
+ if (obj->getName() == (pUnitParm->getString())) {
isSelected = true;
break;
}
@@ -1437,7 +1438,7 @@ Bool ScriptConditions::evaluateNamedSelected(Condition *pCondition, Parameter *p
if (isSelected) {
pCondition->setCustomData(1); // true.
}
- pCondition->setCustomFrame(TheInGameUI->getFrameSelectionChanged());
+ pCondition->setCustomFrame(client.frameSelectionChanged);
return isSelected;
}
@@ -2764,8 +2765,7 @@ Bool ScriptConditions::evaluateCondition( Condition *pCondition )
// multiplayer or skirmish session it counts as finished at once on every machine.
if (TheGameEngine->isMultiplayerSession())
return TRUE;
- LogicThread::readViewFromTick();
- return TheTacticalView->isCameraMovementFinished();
+ return LogicThread::isCameraMovementFinishedForTick();
case Condition::TEAM_STATE_IS:
return evaluateTeamStateIs(pCondition->getParameter(0), pCondition->getParameter(1));
case Condition::TEAM_STATE_IS_NOT:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 6dcf3ca34..2287e849a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -247,6 +247,7 @@ GameLogic::GameLogic( void )
//
m_frame = 0;
+ m_frameForClient = 0;
m_frameObjectsChangedTriggerAreas = 0;
m_width = 0;
m_height = 0;
@@ -461,6 +462,7 @@ void GameLogic::reset( void )
// m_objHash.resize(OBJ_HASH_SIZE);
m_objVector.clear();
m_objVector.resize(OBJ_HASH_SIZE, NULL);
+ m_frameForClient = 0;
/* Unpause properly rather than just clearing the flag. Loading a save from the in-game menu
resets while the game is paused, and setGamePaused is where the mouse comes back, the audio
@@ -4617,10 +4619,10 @@ void GameLogic::update( void )
this stands - before a new game starts, before the scripts, before anything in the frame reads
or writes the grid. The logic catch-up runs frames with no client pass in front of them, and
there the grid fell a step behind for each: grid heights depended on the machine's frame rate.
- The gate stays: a frozen or held frame, which does not advance, does not step twice. */
- if (TheTerrainVisual)
- TheTerrainVisual->updateWaterGrid( m_frame );
-
+ The gate stays: a frozen or held frame, which does not advance, does not step twice. The grid is
+ TerrainLogic's now (M7); the render object only draws it. */
+ TheTerrainLogic->getWaterGrid()->update( m_frame );
+
/// @todo remove this hack
if ( m_startNewGame && !TheDisplay->isMoviePlaying())
{
@@ -4676,10 +4678,10 @@ void GameLogic::update( void )
if (isIntroMoviePlaying())
return;
- // send the current time to the GameClient
+ // the current time for the GameClient, which LogicThread::runTick hands it (LOGIC-THREAD.md M7)
DEBUG_ASSERTCRASH(TheGameLogic == this, ("hmm, TheGameLogic is not right"));
UnsignedInt now = TheGameLogic->getFrame();
- TheGameClient->setFrame(now);
+ m_frameForClient = now;
/* A logic frame that runs long is a hitch the player feels, and a release build has no
profiler to ask about it. Time the frame's own phases and, when the frame runs over
@@ -4709,10 +4711,8 @@ void GameLogic::update( void )
once per frozen pass: in a multiplayer or skirmish session a machine whose camera took longer
counted its script timers down further. There the camera freezes nothing, as the camera
condition in ScriptConditions already reports every move finished. */
- if( !TheGameEngine->isMultiplayerSession() )
- LogicThread::readViewFromTick();
Bool freezeTime = !TheGameEngine->isMultiplayerSession()
- && TheTacticalView->isTimeFrozen() && !TheTacticalView->isCameraMovementFinished();
+ && LogicThread::isTimeFrozenForTick() && !LogicThread::isCameraMovementFinishedForTick();
freezeTime = freezeTime || TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript();
if (freezeTime)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index e0b80766b..f21653452 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -2708,7 +2708,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup
currentlySelectedGroup = NULL;
/**/ /// @todo: multiplayer semantics
- if (currentlySelectedGroup && orderedGroup == NULL && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer /*&& !TheRecorder->isMultiplayer()*/)
+ if (currentlySelectedGroup && orderedGroup == NULL && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && LogicThread::clientBlock().observerLookAt == thisPlayer /*&& !TheRecorder->isMultiplayer()*/)
{
const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
TheInGameUI->deselectAllDrawables();
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
index 9ffdd5a9b..45a15c916 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
@@ -198,10 +198,12 @@ class MilesAudioManager : public AudioManager
virtual void killAudioEventImmediately( AudioHandle audioEvent );
- ///< Return whether the current audio is playing or not.
+ ///< Return whether the current audio is playing or not.
///< NOTE NOTE NOTE !!DO NOT USE THIS IN FOR GAMELOGIC PURPOSES!! NOTE NOTE NOTE
virtual Bool isCurrentlyPlaying( AudioHandle handle );
+ virtual void captureForLogic( void );
+
virtual void notifyOfAudioCompletion( UnsignedIntPtr audioCompleted, UnsignedInt flags );
virtual PlayingAudio *findPlayingAudioFrom( UnsignedIntPtr audioCompleted, UnsignedInt flags );
@@ -323,6 +325,10 @@ class MilesAudioManager : public AudioManager
H3DPOBJECT m_listener;
HPROVIDER m_delayFilter;
+ // LOGIC-THREAD.md M7: what the tick asks, as captureForLogic found it at the sync point
+ std::vector<AudioHandle> m_playingAtSync; ///< every handle isCurrentlyPlaying said yes to, sorted
+ std::vector< std::pair<AsciiString, Int> > m_musicLoopsAtSync; ///< each music stream and the loops it has finished
+
// This is a list of all handles that are forcibly played. They always play as UI sounds.
std::list<HAUDIO> m_audioForcePlayed;
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTerrainVisual.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTerrainVisual.h
index 5c57213ad..ea94ff88c 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTerrainVisual.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTerrainVisual.h
@@ -77,30 +77,8 @@ public:
//
// water methods
//
- /// enable/disable the water grid
+ /// the water grid was enabled/disabled (TerrainLogic's WaterGrid holds it)
virtual void enableWaterGrid( Bool enable );
- /// set min/max height values allowed in water grid pointed to by waterTable
- virtual void setWaterGridHeightClamps( const WaterHandle *waterTable, Real minZ, Real maxZ );
- /// adjust fallof parameters for grid change method
- virtual void setWaterAttenuationFactors( const WaterHandle *waterTable,
- Real a, Real b, Real c, Real range );
- /// set the water table position and orientation in world space
- virtual void setWaterTransform( const WaterHandle *waterTable,
- Real angle, Real x, Real y, Real z );
- virtual void setWaterTransform( const Matrix3D *transform );
- virtual void getWaterTransform( const WaterHandle *waterTable, Matrix3D *transform );
- /// water grid resolution spacing
- virtual void setWaterGridResolution( const WaterHandle *waterTable,
- Real gridCellsX, Real gridCellsY, Real cellSize );
- virtual void getWaterGridResolution( const WaterHandle *waterTable,
- Real *gridCellsX, Real *gridCellsY, Real *cellSize );
- /// adjust the water grid in world coords by the delta
- virtual void changeWaterHeight( Real x, Real y, Real delta );
- /// adjust the velocity at a water grid point corresponding to the world x,y
- virtual void addWaterVelocity( Real worldX, Real worldY,
- Real velocity, Real preferredHeight );
- virtual Bool getWaterGridHeight( Real worldX, Real worldY, Real *height);
- virtual void updateWaterGrid( UnsignedInt logicFrame );
virtual void setTerrainTracksDetail(void);
virtual void setShoreLineDetail(void);
@@ -190,9 +168,7 @@ protected:
#ifdef DO_SEISMIC_SIMULATIONS
WorldHeightMap *m_clientHeightMap; ///< this is a workspace for animating the terrain elevations
#endif
-
- Bool m_isWaterGridRenderingEnabled;
-
+
AsciiString m_currentSkyboxTexNames[NumSkyboxTextures]; ///<store current texture names applied to skybox.
AsciiString m_initialSkyboxTexNames[NumSkyboxTextures]; ///<store starting texture/default skybox textures.
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index 26bb0d581..cd5f387ec 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -172,6 +172,8 @@ public:
virtual void moveCameraTo(const Coord3D *o, Int miliseconds, Int shutter, Bool orient, Real easeIn, Real easeOut);
virtual void moveCameraAlongWaypointPath(Waypoint *pWay, Int frames, Int shutter, Bool orient, Real easeIn, Real easeOut);
virtual Bool isCameraMovementFinished(void);
+ virtual Bool isCameraMoving(void) { return m_doingMoveCameraOnWaypointPath || m_doingRotateCamera || m_doingPitchCamera || m_doingZoomCamera; }
+ virtual Bool isCameraMotionBlurring(void);
virtual Bool isCameraMovementAtWaypointAlongPath(void);
virtual void resetCamera(const Coord3D *location, Int frames, Real easeIn, Real easeOut); ///< Move camera to location, and reset to default angle & zoom.
virtual void rotateCamera(Real rotations, Int frames, Real easeIn, Real easeOut); ///< Rotate camera about current viewpoint.
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
index 6d8360963..9b97aece8 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h
@@ -65,9 +65,8 @@ with rectangular planar surfaces and was tuned with an emphasis on water.
Since skies are only visible in reflections, this code will also
render clouds and sky bodies.
*/
-class WaterRenderObjClass : public Snapshot,
- public RenderObjClass
-{
+class WaterRenderObjClass : public RenderObjClass
+{
public:
@@ -108,8 +107,7 @@ public:
void reset( void ); ///< reset any resources we need to
void load(void); ///< load/setup any map dependent features
void update( void ); ///< update phase of the water
- void updateMeshMotion( UnsignedInt logicFrame ); ///< the grid's motion, once per logic frame (WaterGridMotion.h)
- void enableWaterGrid(Bool state); ///< used to active custom water for special maps. (i.e DAM).
+ void enableWaterGrid(Bool state); ///< used to active custom water for special maps. (i.e DAM). The grid is TerrainLogic's WaterGrid; this builds its buffers
void updateMapOverrides(void); ///< used to update any map specific map overrides for water appearance.
void setTimeOfDay(TimeOfDay tod); ///<change sky/water for time of day
void toggleCloudLayer(Bool state) { m_useCloudLayer=state;} ///<enables/disables the cloud layer
@@ -117,19 +115,6 @@ public:
void ReleaseResources(void); ///< Release all dx8 resources so the device can be reset.
void ReAcquireResources(void); ///< Reacquire all resources after device reset.
Real getWaterHeight(Real x, Real y); ///<return water height at given point - for use by WB.
- void setGridHeightClamps(Real minz, Real maxz); ///<set min/max height values alllowed in grid
- void addVelocity( Real worldX, Real worldY, Real zVelocity, Real preferredHeight ); ///< add velocity value
- void changeGridHeight(Real x, Real y, Real delta); ///<change height of grid at world point including neighbors within falloff.
- void setGridChangeAttenuationFactors(Real a, Real b, Real c, Real range); ///<adjust falloff parameters for grid change method.
- void setGridTransform(Real angle, Real x, Real y, Real z); ///<positoin/orientation of grid in space
- void setGridTransform(const Matrix3D *transform); ///< set transform by matrix
- void getGridTransform(Matrix3D *transform); ///< get grid transform matrix
- void setGridResolution(Real gridCellsX, Real gridCellsY, Real cellSize); ///<grid resolution and spacing
- void getGridResolution(Real *gridCellsX, Real *gridCellsY, Real *cellSize); ///<get grid resolution params
- inline void setGridVertexHeight(Int x, Int y, Real value);
- inline void getGridVertexHeight(Int x, Int y, Real *value)
- { if (m_meshData) *value=m_meshData[(y+1)*(m_gridCellsX+1+2)+x+1].height+ Get_Position().Z;}
- inline Bool worldToGridSpace(Real worldX, Real worldY, Real &gridX, Real &gridY); ///<convert from world coordinates to grid's local coordinate system.
void replaceSkyboxTexture(const AsciiString& oldTexName, const AsciiString& newTextName);
@@ -187,31 +172,13 @@ protected:
RenderObjClass *m_skyBox; ///<box around level
WaterTracksRenderSystem *m_waterTrackSystem; ///<object responsible for rendering water wakes
- enum WaterMeshStatus
- {
- AT_REST = 0x00,
- IN_MOTION = WaterGridMotion::IN_MOTION ///< 0x01, as it always was
- };
+ /* The grid mesh and its settings are TerrainLogic's WaterGrid (LOGIC-THREAD M7), read here at
+ draw time: the mesh, its size and the transform, which syncGridTransform copies into this
+ object's own. Nothing keeps a tick from writing the grid while it is read; that is a later
+ phase's, with the rest of the overlap. */
typedef WaterGridMotion::MeshPoint WaterMeshData; ///< moved, unchanged, with the step that moves it (T1c)
- WaterMeshData *m_meshData; ///< heightmap data for 3D Mesh based water.
- UnsignedInt m_meshDataSize; ///< size of m_meshData
- Bool m_meshInMotion; ///< TRUE once we've messed with velocities and are in motion
- Bool m_doWaterGrid; ///< allows/prevents water grid rendering.
-
- Vector2 m_gridDirectionX; ///<vector along water grid's x-axis (scaled to world-space)
- Vector2 m_gridDirectionY; ///<vector along water grid's y-axis (scaled to world-space)
- Vector2 m_gridOrigin; ///<unit vector along water grid's x-axis
- Real m_gridWidth; ///<object-space width of water grid
- Real m_gridHeight; ///<object-space width of water grid
- Real m_minGridHeight; ///<minimum height value allowed for water mesh
- Real m_maxGridHeight; ///<maximum height value allowed for water mesh
- Real m_gridChangeMaxRange; ///<maximum range of changeGridHeight() method
- Real m_gridChangeAtt0;
- Real m_gridChangeAtt1;
- Real m_gridChangeAtt2;
- Real m_gridCellSize; ///<world-space width/height of each cell.
- Int m_gridCellsX; ///<number of cells along width
- Int m_gridCellsY; ///<number of cells along height
+ UnsignedInt m_meshGeneration; ///< the grid allocation the mesh buffers were built for
+ void syncGridTransform(void); ///< take the grid's transform, as the grid setters once set ours
Real m_riverVOrigin;
TextureClass *m_riverTexture;
@@ -225,7 +192,6 @@ protected:
Real m_riverXOffset;
Real m_riverYOffset;
Bool m_drawingRiver;
- Bool m_disableRiver;
TextureClass *m_riverAlphaEdge;
TimeOfDay m_tod; ///<time of day setting for reflected cloud layer
@@ -269,36 +235,8 @@ protected:
RenderResult generateIndexBuffer(int sizeX, int sizeY); ///<Generate static index buufer
RenderResult generateVertexBuffer( Int sizeX, Int sizeY, Int vertexSize, Bool doFill);///<Generate static vertex buffer
- // snapshot methods for save/load
- virtual void crc( Xfer *xfer );
- virtual void xfer( Xfer *xfer );
- virtual void loadPostProcess( void );
-
};
-//Public inline function declerations
-inline Bool WaterRenderObjClass::worldToGridSpace(Real worldX, Real worldY, Real &gridX, Real &gridY)
-{
- Real dx,dy;
- Real ooGridCellSize = 1.0f/m_gridCellSize;
-
- dx=worldX - m_gridOrigin.X;
- dy=worldY - m_gridOrigin.Y;
- gridX = ooGridCellSize * (dx * m_gridDirectionX.X + dy * m_gridDirectionX.Y);
- gridY = ooGridCellSize * (dx * m_gridDirectionY.X + dy * m_gridDirectionY.Y);
-
- if (gridX < 0)
- return FALSE;
- if (gridX > m_gridCellsX-1 )
- return FALSE;
- if (gridY < 0)
- return FALSE;
- if (gridY > m_gridCellsY-1 )
- return FALSE;
-
- return TRUE;
-}
-
extern WaterRenderObjClass *TheWaterRenderObj; ///<global water rendering object
#endif // end __W3DWater_H_
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
index 072d33881..99f00ed37 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
@@ -61,6 +61,8 @@
#include "Common/LogicThread.h"
#include "Common/ScopedMutex.h"
+#include <algorithm>
+
#include "GameClient/DebugDisplay.h"
#include "GameClient/Drawable.h"
#include "GameClient/GameClient.h"
@@ -1650,6 +1652,14 @@ Bool MilesAudioManager::isMusicPlaying( void ) const
//-------------------------------------------------------------------------------------------------
Bool MilesAudioManager::hasMusicTrackCompleted( const AsciiString& trackName, Int numberOfTimes ) const
{
+ if( LogicThread::defersEffects() )
+ {
+ for( size_t i = 0; i < m_musicLoopsAtSync.size(); ++i )
+ if( m_musicLoopsAtSync[ i ].first == trackName && m_musicLoopsAtSync[ i ].second >= numberOfTimes )
+ return TRUE;
+ return FALSE;
+ }
+
LOGIC_CENSUS( CENSUS_AUDIO_READ );
std::list<PlayingAudio *>::const_iterator it;
PlayingAudio *playing;
@@ -1753,6 +1763,9 @@ void MilesAudioManager::closeDevice( void )
//-------------------------------------------------------------------------------------------------
Bool MilesAudioManager::isCurrentlyPlaying( AudioHandle handle )
{
+ if( LogicThread::defersEffects() )
+ return std::binary_search( m_playingAtSync.begin(), m_playingAtSync.end(), handle ) || isQueuedFromTick( handle );
+
LOGIC_CENSUS( CENSUS_AUDIO_READ );
std::list<PlayingAudio *>::iterator it;
PlayingAudio *playing;
@@ -1792,6 +1805,41 @@ Bool MilesAudioManager::isCurrentlyPlaying( AudioHandle handle )
return isQueuedFromTick(handle);
}
+//-------------------------------------------------------------------------------------------------
+/** isCurrentlyPlaying's yes for every handle it would give one to, less the tick's own queue, which
+ * it still asks itself; and hasMusicTrackCompleted's loop count for every music stream. */
+void MilesAudioManager::captureForLogic( void )
+{
+ m_playingAtSync.clear();
+ m_musicLoopsAtSync.clear();
+
+ const std::list<PlayingAudio *> *lists[] = { &m_playingSounds, &m_playing3DSounds, &m_playingStreams };
+ for( Int i = 0; i < 3; ++i )
+ {
+ for( std::list<PlayingAudio *>::const_iterator it = lists[ i ]->begin(); it != lists[ i ]->end(); ++it )
+ {
+ PlayingAudio *playing = *it;
+ if( playing && playing->isPlaying() )
+ m_playingAtSync.push_back( playing->m_audioEventRTS->getPlayingHandle() );
+ }
+ }
+ for( std::list<AudioRequest *>::const_iterator ait = m_audioRequests.begin(); ait != m_audioRequests.end(); ++ait )
+ {
+ AudioRequest *req = *ait;
+ if( req && req->m_usePendingEvent )
+ m_playingAtSync.push_back( req->m_pendingEvent->getPlayingHandle() );
+ }
+ std::sort( m_playingAtSync.begin(), m_playingAtSync.end() );
+
+ for( std::list<PlayingAudio *>::const_iterator it = m_playingStreams.begin(); it != m_playingStreams.end(); ++it )
+ {
+ PlayingAudio *playing = *it;
+ if( playing && audioIsType( playing->m_audioEventRTS, AT_Music ) )
+ m_musicLoopsAtSync.push_back( std::make_pair( playing->m_audioEventRTS->getEventName(),
+ (Int)( INFINITE_LOOP_COUNT - AIL_stream_loop_count( playing->m_stream ) ) ) );
+ }
+}
+
//-------------------------------------------------------------------------------------------------
void MilesAudioManager::queueAudioCompletion( UnsignedIntPtr audioCompleted, UnsignedInt flags )
{
@@ -2907,6 +2955,7 @@ Real MilesAudioManager::getFileLengthMS( AsciiString strToLoad ) const
return fromHeader;
}
+ LOGIC_CENSUS( CENSUS_AUDIO_READ ); // the device, from the tick (LOGIC-THREAD.md M7)
// Load it as a stream to get the file info without actually opening the file.
HSTREAM stream = AIL_open_stream(m_digitalHandle, strToLoad.str(), 0);
if (!stream) {
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
index fa077c54b..acb9eda70 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
@@ -376,6 +376,7 @@ HAnimClass* W3DAnimationInfo::getAnimHandle() const
#ifdef RETAIN_ANIM_HANDLES
if (m_handle == NULL)
{
+ LOGIC_CENSUS( CENSUS_ASSET_LOAD );
// Get_HAnim addrefs it, so we'll have to release it in our dtor.
m_handle = W3DDisplay::m_assetManager->Get_HAnim(m_name.str());
DEBUG_ASSERTCRASH(m_handle, ("*** ASSET ERROR: animation %s not found\n",m_name.str()));
@@ -642,13 +643,16 @@ void ModelConditionInfo::validateCachedBones(RenderObjClass* robj, Real scale) c
Bool tossRobj = false;
if (robj == NULL)
{
- if (m_modelName.isEmpty())
+ // the asset manager's built-in NULL object has no bones either, so it is not worth a trip there
+ // from the tick
+ if (m_modelName.isEmpty() || m_modelName.compareNoCase("NULL") == 0)
{
//BONEPOS_LOG(("Bailing: model name is empty\n"));
return;
}
- robj = W3DDisplay::m_assetManager->Create_Render_Obj(m_modelName.str(), scale, 0);
+ LOGIC_CENSUS( CENSUS_ASSET_LOAD );
+ robj =W3DDisplay::m_assetManager->Create_Render_Obj(m_modelName.str(), scale, 0);
DEBUG_ASSERTCRASH(robj, ("*** ASSET ERROR: Model %s not found!\n",m_modelName.str()));
if (!robj)
{
@@ -1105,7 +1109,10 @@ void W3DModelDrawModuleData::validateStuffForTimeAndWeather(const Drawable* draw
ModelConditionVector::iterator c_it; // VC6 leaked it out to the transition loop below
for (c_it = m_conditionStates.begin(); c_it != m_conditionStates.end(); ++c_it)
{
- if (!c_it->matchesMode(false, false) && !c_it->matchesMode(night, snowy))
+ // a template with no state for both night and snow falls back on its night or its snow state,
+ // and logic asks that one's bones; validated here it is not loaded from inside a tick
+ if (!c_it->matchesMode(false, false) && !c_it->matchesMode(night, false) &&
+ !c_it->matchesMode(false, snowy) && !c_it->matchesMode(night, snowy))
continue;
c_it->validateStuff(NULL, draw->getScale(), m_extraPublicBones);
@@ -1821,18 +1828,26 @@ W3DModelDraw::W3DModelDraw(Thing *thing, const ModuleData* moduleData) : DrawMod
//-------------------------------------------------------------------------------------------------
/** The pristine bone, turret and barrel caches are logic's, and filling them loads every state's
- model. A drawable logic makes in a tick fills them here, after the tick, in a window where the
- caches count as logic's (isValidTimeToCalcLogicStuff), so they take the same values from the same
- unanimated models as they did in the constructor. Without that, the first fill could come from
- an on-demand setModelState inside a later tick with this machine's live render object. */
+ model. A drawable logic makes in a tick fills them here after the tick, and one the map load makes
+ fills them here too, in a window where the caches count as logic's (isValidTimeToCalcLogicStuff),
+ so they take the same values from the same unanimated models as they did in the constructor.
+ Without that, the first fill could come from an on-demand setModelState inside a later tick with
+ this machine's live render object, or from a bone query loading the model inside the tick: a
+ campaign map loads outside GameLogic::update, and its garrisons and spawn points asked on frame 1.
+ A map object can also set its own night and snow flags once it is made (Object.cpp, objectTime
+ and objectWeather), so the map load validates the night and snow states as well. */
void W3DModelDraw::buildRenderObjects( Bool madeInTick )
{
{
- LatchRestore<Bool> forLogic( s_fillingLogicCaches, s_fillingLogicCaches || madeInTick );
+ const Bool loadingMap = TheGameLogic->isLoadingMap();
+ LatchRestore<Bool> forLogic( s_fillingLogicCaches, s_fillingLogicCaches || madeInTick || loadingMap );
// only validate the current time-of-day and weather conditions by default.
getW3DModelDrawModuleData()->validateStuffForTimeAndWeather(getDrawable(),
TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT,
TheGlobalData->m_weather == WEATHER_SNOWY);
+ // ponytail: loads every map object's night and snow models once; validate per object override if memory bites
+ if (loadingMap)
+ getW3DModelDrawModuleData()->validateStuffForTimeAndWeather(getDrawable(), TRUE, TRUE);
}
ModelConditionFlags emptyFlags;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp
index b1e98da15..180033c68 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp
@@ -134,8 +134,10 @@ Drawable *W3DGameClient::friend_createDrawable( const ThingTemplate *tmplate,
//-------------------------------------------------------------------------------------------------
void W3DGameClient::addScorch(const Coord3D *pos, Real radius, Scorches type)
{
+ const Coord3D at = *pos;
+ LOGIC_AFTER_TICK( [=]() { addScorch( &at, radius, type ); } );
LOGIC_CENSUS( CENSUS_GAMECLIENT );
- if (TheTerrainRenderObject)
+ if (TheTerrainRenderObject)
{
Vector3 loc(pos->x, pos->y, pos->z);
TheTerrainRenderObject->addScorch(loc, radius, type);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
index b8193a9fa..3723ac07b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp
@@ -52,6 +52,7 @@
#include "GameLogic/Object.h"
#include "GameLogic/GameLogic.h"
+#include "GameLogic/TerrainLogic.h"
#include "W3DDevice/GameClient/W3DScene.h"
#include "W3DDevice/GameClient/W3DTerrainVisual.h"
@@ -286,26 +287,8 @@ void W3DTerrainVisual::init( void )
else
m_waterRenderObject->toggleCloudLayer(false);
- // set the vertex animated water properties
- Int waterSettingIndex = 0; // use index 0 settings by default
- TheTerrainVisual->setWaterGridHeightClamps( NULL,
- TheGlobalData->m_vertexWaterHeightClampLow[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterHeightClampHi[ waterSettingIndex ] );
- TheTerrainVisual->setWaterTransform( NULL,
- TheGlobalData->m_vertexWaterAngle[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterXPosition[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterYPosition[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterZPosition[ waterSettingIndex ] );
- TheTerrainVisual->setWaterGridResolution( NULL,
- TheGlobalData->m_vertexWaterXGridCells[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterYGridCells[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterGridSize[ waterSettingIndex ] );
- TheTerrainVisual->setWaterAttenuationFactors( NULL,
- TheGlobalData->m_vertexWaterAttenuationA[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterAttenuationB[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterAttenuationC[ waterSettingIndex ],
- TheGlobalData->m_vertexWaterAttenuationRange[ waterSettingIndex ] );
- m_isWaterGridRenderingEnabled = FALSE;
+ // the vertex animated water's index 0 settings, which were set here, are TerrainLogic::init's now:
+ // the grid is logic's, and the render object takes its transform from it when it draws
#ifdef DO_SEISMIC_SIMULATIONS
m_seismicSimulationList.clear();
@@ -730,10 +713,8 @@ Bool W3DTerrainVisual::load( AsciiString filename )
void W3DTerrainVisual::enableWaterGrid( Bool enable )
{
- //Get default water type
- m_isWaterGridRenderingEnabled = enable;
-
- // make the changes in the water render object
+ // the flag getWaterGridHeight answered to is TerrainLogic's WaterGrid's now; the render object
+ // still has buffers and river flags to see to
if( m_waterRenderObject )
m_waterRenderObject->enableWaterGrid( enable );
@@ -821,139 +802,6 @@ TerrainType *W3DTerrainVisual::getTerrainTile( Real x, Real y )
} // end getTerrainTile
-// ------------------------------------------------------------------------------------------------
-/** set min/max height values allowed in water grid pointed to by waterTable */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::setWaterGridHeightClamps( const WaterHandle *waterTable,
- Real minZ, Real maxZ )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->setGridHeightClamps( minZ, maxZ );
-
-} // end setWaterGridHeightClamps
-
-// ------------------------------------------------------------------------------------------------
-/** adjust fallof parameters for grid change method */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::setWaterAttenuationFactors( const WaterHandle *waterTable,
- Real a, Real b, Real c, Real range )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->setGridChangeAttenuationFactors( a, b, c, range );
-
-} // end setWaterAttenuationFactors
-
-// ------------------------------------------------------------------------------------------------
-/** set the water table position and orientation in world space */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::setWaterTransform( const WaterHandle *waterTable,
- Real angle, Real x, Real y, Real z )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->setGridTransform( angle, x, y, z );
-
-} // end setWaterTransform
-
-// ------------------------------------------------------------------------------------------------
-/** set water table transform by matrix */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::setWaterTransform( const Matrix3D *transform )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->setGridTransform( transform );
-
-} // end setWaterTransform
-
-// ------------------------------------------------------------------------------------------------
-/** get the water transform matrix */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::getWaterTransform( const WaterHandle *waterTable, Matrix3D *transform )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->getGridTransform( transform );
-
-} // end getWaterTransform
-
-// ------------------------------------------------------------------------------------------------
-/** water grid resolution spacing */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::setWaterGridResolution( const WaterHandle *waterTable,
- Real gridCellsX, Real gridCellsY, Real cellSize )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->setGridResolution( gridCellsX, gridCellsY, cellSize );
-
-} // end setWaterGridResolution
-
-// ------------------------------------------------------------------------------------------------
-/** get water grid resolution spacing */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::getWaterGridResolution( const WaterHandle *waterTable,
- Real *gridCellsX, Real *gridCellsY, Real *cellSize )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->getGridResolution( gridCellsX, gridCellsY, cellSize );
-
-} // end getWaterGridResolution
-
-// ------------------------------------------------------------------------------------------------
-/** adjust the water grid in world coords by the delta */
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::changeWaterHeight( Real x, Real y, Real delta )
-{
-
- if( m_waterRenderObject )
- m_waterRenderObject->changeGridHeight( x, y, delta );
-
-} // end changeWaterHeight
-
-// ------------------------------------------------------------------------------------------------
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::addWaterVelocity( Real worldX, Real worldY,
- Real velocity, Real preferredHeight )
-{
- LOGIC_CENSUS( CENSUS_CLIENT_READ ); // the water grid's motion, as updateWaterGrid
- if( m_waterRenderObject )
- m_waterRenderObject->addVelocity( worldX, worldY, velocity, preferredHeight );
-
-} // end addWaterVelocity
-
-// ------------------------------------------------------------------------------------------------
-// ------------------------------------------------------------------------------------------------
-void W3DTerrainVisual::updateWaterGrid( UnsignedInt logicFrame )
-{
- /* The water grid's motion is simulation: logic steps it here and reads it back through
- getWaterGridHeight, so it cannot wait for the tick's end. It lives in the render object,
- which makes it client state logic reads (M7 moves the grid into TerrainLogic). */
- LOGIC_CENSUS( CENSUS_CLIENT_READ );
- // whether or not the grid is drawn: the simulation reads it either way, as update() stepped it
- if( m_waterRenderObject )
- m_waterRenderObject->updateMeshMotion( logicFrame );
-} // end updateWaterGrid
-
-// ------------------------------------------------------------------------------------------------
-// ------------------------------------------------------------------------------------------------
-Bool W3DTerrainVisual::getWaterGridHeight( Real worldX, Real worldY, Real *height)
-{
- LOGIC_CENSUS( CENSUS_CLIENT_READ );
- Real gridX, gridY;
-
- if (m_isWaterGridRenderingEnabled && m_waterRenderObject &&
- m_waterRenderObject->worldToGridSpace(worldX, worldY, gridX, gridY))
- { //point falls within grid, return correct height
- m_waterRenderObject->getGridVertexHeight(REAL_TO_INT(gridX),REAL_TO_INT(gridY),height);
- return TRUE;
- }
- return FALSE;
-}
-
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void W3DTerrainVisual::setRawMapHeight(const ICoord2D *gridPos, Int height)
@@ -1258,10 +1106,12 @@ void W3DTerrainVisual::xfer( Xfer *xfer )
// extend base class
TerrainVisual::xfer( xfer );
- // flag for whether or not the water grid is enabled
- Bool gridEnabled = m_isWaterGridRenderingEnabled;
+ // flag for whether or not the water grid is enabled; the flag and the grid are TerrainLogic's
+ // now, written here, in this block and in these bytes, as they were from the render object
+ WaterGrid *waterGrid = TheTerrainLogic->getWaterGrid();
+ Bool gridEnabled = waterGrid->isHeightEnabled();
xfer->xferBool( &gridEnabled );
- if( gridEnabled != m_isWaterGridRenderingEnabled )
+ if( gridEnabled != waterGrid->isHeightEnabled() )
{
DEBUG_CRASH(( "W3DTerrainVisual::xfer - m_isWaterGridRenderingEnabled mismatch\n" ));
@@ -1271,7 +1121,7 @@ void W3DTerrainVisual::xfer( Xfer *xfer )
// xfer grid data if enabled
if( gridEnabled )
- xfer->xferSnapshot( m_waterRenderObject );
+ xfer->xferSnapshot( waterGrid );
/*
{
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index eb8635dcd..799977c03 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -3818,18 +3818,21 @@ void W3DView::resetCamera(const Coord3D *location, Int milliseconds, Real easeIn
Bool W3DView::isCameraMovementFinished(void)
{
LOGIC_CENSUS( CENSUS_CLIENT_READ );
- if (m_viewFilter == FT_VIEW_MOTION_BLUR_FILTER) {
- // Several of the motion blur effects are similar to camera movements.
- if (m_viewFilterMode == FM_VIEW_MB_IN_AND_OUT_ALPHA ||
- m_viewFilterMode == FM_VIEW_MB_IN_AND_OUT_SATURATE ||
- m_viewFilterMode == FM_VIEW_MB_IN_ALPHA ||
- m_viewFilterMode == FM_VIEW_MB_OUT_ALPHA ||
- m_viewFilterMode == FM_VIEW_MB_IN_SATURATE ||
- m_viewFilterMode == FM_VIEW_MB_OUT_SATURATE ) {
- return true;
- }
- }
- return !m_doingMoveCameraOnWaypointPath && !m_doingRotateCamera && !m_doingPitchCamera && !m_doingZoomCamera;
+ return isCameraMotionBlurring() || !isCameraMoving();
+}
+
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+Bool W3DView::isCameraMotionBlurring(void)
+{
+ // Several of the motion blur effects are similar to camera movements.
+ return m_viewFilter == FT_VIEW_MOTION_BLUR_FILTER &&
+ (m_viewFilterMode == FM_VIEW_MB_IN_AND_OUT_ALPHA ||
+ m_viewFilterMode == FM_VIEW_MB_IN_AND_OUT_SATURATE ||
+ m_viewFilterMode == FM_VIEW_MB_IN_ALPHA ||
+ m_viewFilterMode == FM_VIEW_MB_OUT_ALPHA ||
+ m_viewFilterMode == FM_VIEW_MB_IN_SATURATE ||
+ m_viewFilterMode == FM_VIEW_MB_OUT_SATURATE);
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
index ed60c8985..85edab429 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp
@@ -64,6 +64,7 @@
#include "GameLogic/GameLogic.h"
#include "GameLogic/PolygonTrigger.h"
#include "GameLogic/ScriptEngine.h"
+#include "GameLogic/TerrainLogic.h"
#include "W3DDevice/GameClient/W3DShaderManager.h"
#include "W3DDevice/GameClient/W3DDisplay.h"
#include "W3DDevice/GameClient/W3DPoly.h"
@@ -362,11 +363,6 @@ WaterRenderObjClass::~WaterRenderObjClass(void)
SAFE_RELEASE( m_pBumpTexture2[i]);
}
- if (m_meshData)
- delete [] m_meshData;
- m_meshData = NULL;
- m_meshDataSize = 0;
-
//Release strings allocated inside global water settings.
for (i=0; i<TIME_OF_DAY_COUNT; i++)
{ WaterSettings[i].m_skyTextureFile.clear();
@@ -390,7 +386,6 @@ WaterRenderObjClass::WaterRenderObjClass(void)
m_dy=0;
m_indexBuffer=NULL;
m_waterTrackSystem = NULL;
- m_doWaterGrid = FALSE;
m_meshVertexMaterialClass=NULL;
m_meshLight=NULL;
m_vertexMaterialClass=NULL;
@@ -411,19 +406,8 @@ WaterRenderObjClass::WaterRenderObjClass(void)
m_dwWavePixelShader=NULL;
m_dwWaveVertexShader=NULL;
- m_meshData=NULL;
- m_meshDataSize = 0;
- m_meshInMotion = FALSE;
- m_gridOrigin=Vector2(0,0);
- m_gridDirectionX=Vector2(1.0f,0.0f);
- m_gridDirectionY=Vector2(1.0f,0.0f);
-
- m_gridCellSize=WATER_MESH_SPACING;
- m_gridCellsX=WATER_MESH_X_VERTICES;
- m_gridCellsY=WATER_MESH_Y_VERTICES;
- m_gridWidth = m_gridCellsX * m_gridCellSize;
- m_gridHeight = m_gridCellsY * m_gridCellSize;
-
+ m_meshGeneration = 0;
+
Int i=NUM_BUMP_FRAMES;
while (i--)
m_pBumpTexture[i]=NULL;
@@ -963,13 +947,16 @@ void WaterRenderObjClass::ReAcquireResources(void)
m_pDev=DX8Wrapper::_Get_D3D_Device();
//We're using the same grid for either 3D Water Mesh or Pixel/Vertex shader. Just
- //allocate the right size depending on usage
- if (m_meshData)
+ //allocate the right size depending on usage. The grid's mesh, once allocated, is never freed
+ //for good, so "buffers built for an allocation" is the old "m_meshData != NULL"; and before the
+ //first one (init's call here, ahead of TerrainLogic) there is no grid to ask.
+ if (m_meshGeneration != 0)
{
+ WaterGrid *grid = TheTerrainLogic->getWaterGrid();
//Create new grid data
- if (Render_Failed(generateIndexBuffer(m_gridCellsX+1,m_gridCellsY+1)))
+ if (Render_Failed(generateIndexBuffer(grid->getCellsX()+1,grid->getCellsY()+1)))
return;
- if (Render_Failed(generateVertexBuffer(m_gridCellsX+1,m_gridCellsY+1,sizeof(MaterMeshVertexFormat),false)))
+ if (Render_Failed(generateVertexBuffer(grid->getCellsX()+1,grid->getCellsY()+1,sizeof(MaterMeshVertexFormat),false)))
return;
}
else
@@ -1272,58 +1259,30 @@ void WaterRenderObjClass::updateMapOverrides(void)
void WaterRenderObjClass::reset( void )
{
- // for vertex animated water mesh reset the values
- if( m_meshData)
- {
- Int i, j;
- WaterMeshData *pData;
- Int mx = m_gridCellsX + 1;
- Int my = m_gridCellsY + 1;
-
- // go through each mesh point and adjust the height according to the velocity
- for( j = 0, pData = m_meshData; j < (my + 2); j++ )
- {
-
- for( i = 0; i < (mx + 2); i++ )
- {
-
- // areset grid values for this cell
- pData->velocity = 0.0f;
- pData->height = 0.0f;
- pData->preferredHeight = 0.0f;
- pData->status = WaterRenderObjClass::AT_REST;
-
- // on to the next one
- pData++;
-
- } // end for i
-
- } // end for j
-
- // mesh data is no longer in motion
- m_meshInMotion = FALSE;
-
- } // end if, water type 3
+ // the vertex animated water mesh is zeroed by TerrainLogic::reset, which owns it now
if (m_waterTrackSystem)
m_waterTrackSystem->reset();
-}
+}
+// ------------------------------------------------------------------------------------------------
+/** TerrainLogic::enableWaterGrid has enabled or disabled its WaterGrid, and W3DTerrainVisual::load
+ * calls this with FALSE for a new map. The grid's flag, mesh and m_disableRiver are the grid's;
+ * what is left is the river flag and the buffers, rebuilt when the grid has a new allocation - the
+ * old "state && m_meshData == NULL", and the reallocation setGridResolution made through here. */
+// ------------------------------------------------------------------------------------------------
void WaterRenderObjClass::enableWaterGrid(Bool state)
{
- m_doWaterGrid = state;
-
m_drawingRiver = false;
- m_disableRiver = false;
- if (state && m_meshData == NULL)
+ WaterGrid *grid = TheTerrainLogic->getWaterGrid();
+ if (grid->getMeshGeneration() != m_meshGeneration)
{ //water type has changed, must allocate necessary assets for new water.
- //contains the current deformed water surface z(height) values. With 1 vertex invisible border
- //around surface to speed up normal calculations.
- m_meshDataSize = (m_gridCellsX+1+2)*(m_gridCellsY+1+2);
- m_meshData=NEW WaterMeshData[ m_meshDataSize ];
- memset(m_meshData,0,sizeof(WaterMeshData)*(m_gridCellsX+1+2)*(m_gridCellsY+1+2));
- reset();
+ m_meshGeneration = grid->getMeshGeneration();
+
+ // the grid was zeroed as it was allocated; reset() did that and this
+ if (m_waterTrackSystem)
+ m_waterTrackSystem->reset();
//Release existing grid data
SAFE_RELEASE(m_vertexBufferD3D);
@@ -1331,13 +1290,25 @@ void WaterRenderObjClass::enableWaterGrid(Bool state)
releaseWaterTwins();
//Create new grid data
- if (Render_Failed(generateIndexBuffer(m_gridCellsX+1,m_gridCellsY+1)))
+ if (Render_Failed(generateIndexBuffer(grid->getCellsX()+1,grid->getCellsY()+1)))
return;
- if (Render_Failed(generateVertexBuffer(m_gridCellsX+1,m_gridCellsY+1,sizeof(MaterMeshVertexFormat),false)))
+ if (Render_Failed(generateVertexBuffer(grid->getCellsX()+1,grid->getCellsY()+1,sizeof(MaterMeshVertexFormat),false)))
return;
}
}
+// ------------------------------------------------------------------------------------------------
+/** The grid's transform was this object's own: the grid setters called Set_Transform. They are
+ * TerrainLogic's now, so the drawing takes it from there before it draws. */
+// ------------------------------------------------------------------------------------------------
+void WaterRenderObjClass::syncGridTransform(void)
+{
+ Matrix3D gridTransform;
+ TheTerrainLogic->getWaterGrid()->getTransform(&gridTransform);
+ if (memcmp(&gridTransform, &Transform, sizeof(Matrix3D)) != 0)
+ Set_Transform(gridTransform);
+}
+
// ------------------------------------------------------------------------------------------------
/** Update phase for water if we need it. This called once per client frame reguardless
* of how fast the logic framerate is running */
@@ -1413,21 +1384,11 @@ void WaterRenderObjClass::update( void )
}
/* The mesh motion that was here - the part of the water the simulation reads - is stepped by the
- logic now, once per logic frame: updateMeshMotion, from GameLogic::update (T1c, defect 17). */
+ logic now, once per logic frame: TerrainLogic's WaterGrid::update, from GameLogic::update (T1c,
+ defect 17; the grid moved to TerrainLogic in M7). */
} // end update
-// ------------------------------------------------------------------------------------------------
-/** The water grid's mesh motion for one logic frame. GameLogic::update calls this, through
- * TerrainVisual::updateWaterGrid, at the top of every logic frame: where EA's client pass stepped it,
- * just ahead of the frame, but once per logic frame however many frames a pass runs. The step, and
- * the gate that makes a second call for the same frame do nothing, are WaterGridMotion's. */
-// ------------------------------------------------------------------------------------------------
-void WaterRenderObjClass::updateMeshMotion( UnsignedInt logicFrame )
-{
- WaterGridMotion::updateForLogicFrame( logicFrame, m_doWaterGrid, m_meshInMotion, m_meshData, m_gridCellsX, m_gridCellsY );
-}
-
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
@@ -1731,6 +1692,8 @@ void WaterRenderObjClass::Render(RenderInfoClass & rinfo)
if (TheTerrainRenderObject && !TheTerrainRenderObject->getMap())
return; //no map has been loaded yet.
+ syncGridTransform(); // the grid's place in the world, which every water surface below is drawn at
+
if (((RTS3DScene *)rinfo.Camera.Get_User_Data())->getCustomPassMode() == SCENE_PASS_ALPHA_MASK ||
((SceneClass *)rinfo.Camera.Get_User_Data())->Get_Extra_Pass_Polygon_Mode() == SceneClass::EXTRA_PASS_CLEAR_LINE)
return; //water is not drawn in wireframe or custom scene passes
@@ -1761,7 +1724,7 @@ void WaterRenderObjClass::Render(RenderInfoClass & rinfo)
case WATER_TYPE_3_GRIDMESH:
//Draw the water surface as a bunch of alpha blended tiles covering areas where water is visible
renderWater();
- if (!m_drawingRiver || m_disableRiver) {
+ if (!m_drawingRiver || TheTerrainLogic->getWaterGrid()->wasPushed()) {
renderWaterMesh(); //Draw water surface as 3D deforming mesh if it's enabled on this map.
}
break;
@@ -2425,7 +2388,9 @@ void WaterRenderObjClass::renderSkyBody(Matrix3D *mat)
void WaterRenderObjClass::renderWaterMesh(void)
{
- if (!m_doWaterGrid)
+ // the grid is TerrainLogic's, read here as it stands (see W3DWater.h)
+ WaterGrid *grid = TheTerrainLogic->getWaterGrid();
+ if (!grid->isMotionEnabled())
return; //the water grid is disabled.
//According to Nvidia there's a D3D bug that happens if you don't start with a
@@ -2435,12 +2400,13 @@ void WaterRenderObjClass::renderWaterMesh(void)
Setting *setting=&m_settings[m_tod];
WaterMeshData *pData;
- Int mx=m_gridCellsX+1;
- Int my=m_gridCellsY+1;
+ WaterMeshData *meshData=grid->getMeshData();
+ Int mx=grid->getCellsX()+1;
+ Int my=grid->getCellsY()+1;
Int i,j;
-
- Real cellSizeX=m_gridCellSize;
- Real cellSizeY=m_gridCellSize;
+
+ Real cellSizeX=grid->getCellSize();
+ Real cellSizeY=grid->getCellSize();
// Real uScale2=5.0f*setting->waterRepeatCount/(128.0f)*cellSizeX/10.0f;
// Real vScale2=5.0f*setting->waterRepeatCount/(128.0f)*cellSizeY/10.0f;
@@ -2463,7 +2429,7 @@ void WaterRenderObjClass::renderWaterMesh(void)
static Real PhasePerFrameY=0.1f;
//update the mesh heights for this frame (update buffer is 2 samples wider/taller due to border)
- for (j=0,pData=m_meshData; j<(my+2); j++)
+ for (j=0,pData=meshData; j<(my+2); j++)
{
for (i=0; i<(mx+2); i++)
{
@@ -2514,7 +2480,7 @@ void WaterRenderObjClass::renderWaterMesh(void)
Real bumpSizeDiv2=0.3f*cellSizeY/BUMP_SIZE;
//Data has a 1 vertex padding all around it so we don't need to special-case edges. Improves performance
- for (j=0,pData=m_meshData+mx+2+1; j<my; j++,pData+=2) //skip 2 horizontal border samples after each row
+ for (j=0,pData=meshData+mx+2+1; j<my; j++,pData+=2) //skip 2 horizontal border samples after each row
{
Real y=(float)j*cellSizeY;
Real v1Offset=m_riverVOrigin+(float)j*vScale + uvCosScale*WWMath::Fast_Sin(sinOffset+y*PI/(8*MAP_XY_FACTOR));
@@ -2661,214 +2627,8 @@ void WaterRenderObjClass::renderWaterMesh(void)
}
-inline void WaterRenderObjClass::setGridVertexHeight(Int x, Int y, Real value)
-{
- DEBUG_ASSERTCRASH( x < (m_gridCellsX+1) && y < (m_gridCellsY+1), ("Invalid Water Mesh Coordinates\n") );
-
- if (m_meshData)
- {
- m_meshData[(y+1)*(m_gridCellsX+1+2)+x+1].height = value;
- }
-}
-
-void WaterRenderObjClass::setGridHeightClamps(Real minz, Real maxz)
-{
- m_minGridHeight = minz;
- m_maxGridHeight = maxz;
-}
-
-void WaterRenderObjClass::addVelocity( Real worldX, Real worldY,
- Real zVelocity, Real preferredHeight )
-{
-
- if( m_doWaterGrid)
- {
- Real gx,gy;
- Real minX,maxX,minY,maxY;
- Int x,y;
- WaterMeshData *meshPoint;
- m_disableRiver = true;
-
- //check if center falls within grid bounds
- if (worldToGridSpace(worldX, worldY, gx, gy))
- {
-
- //find extents of influence
- minX = floorf(gx - m_gridChangeMaxRange);
- if (minX < 0 )
- minX = 0; //clamp extent to fall within box
- maxX = ceilf(gx + m_gridChangeMaxRange);
- if (maxX > m_gridCellsX)
- maxX = m_gridCellsX; //clamp extent to fall within box
-
- minY = floorf(gy - m_gridChangeMaxRange);
- if (minY < 0 )
- minY = 0; //clamp extent to fall within box
- maxY = ceilf(gy + m_gridChangeMaxRange);
- if (maxY > m_gridCellsY)
- maxY = m_gridCellsY; //clamp extent to fall within box
-
- for (y=minY; y<=maxY; y++)
- {
- for (x=minX; x<=maxX; x++)
- {
-
- // get the mesh point that we're concerned with
- meshPoint = &m_meshData[ (y + 1) * (m_gridCellsX + 1 + 2) + x + 1 ];
-
- // we now have a new preferred height
- meshPoint->preferredHeight = preferredHeight;
-
- //
- // set the velocity of this point based on the distance from the center of the
- // "core" point for this call
- //
- // The one caller, WaveGuideUpdate, pushes every logic frame, so the push is an
- // acceleration: per frame squared, a quarter of the 30 Hz amount. WaterVelocity's
- // parse (per second to per frame) took one half, this is the other.
- meshPoint->velocity = meshPoint->velocity + ConvertRetailPerFrameRate( zVelocity );
-
- // this point is now "in motion"
- BitSet( meshPoint->status, WaterRenderObjClass::IN_MOTION );
-
- }
- }
-
- //
- // the mesh data is now dirty, we need to pass through the velocity field
- // during an update phase to update the positions
- //
- m_meshInMotion = TRUE;
-
- }
-
- } // end if, water type is 3
-
-}
-
-void WaterRenderObjClass::changeGridHeight(Real wx, Real wy, Real delta)
-{
- Real gx,gy;
- Real *oldData;
- Real newData;
- Real distance;
- Real minX,maxX,minY,maxY;
- Int x,y;
-
- //check if center falls within grid bounds
- if (worldToGridSpace(wx, wy, gx, gy))
- { //find extents of influence
- minX = floorf(gx - m_gridChangeMaxRange);
- if (minX < 0 )
- minX = 0; //clamp extent to fall within box
- maxX = ceilf(gx + m_gridChangeMaxRange);
- if (maxX > m_gridCellsX)
- maxX = m_gridCellsX; //clamp extent to fall within box
-
- minY = floorf(gy - m_gridChangeMaxRange);
- if (minY < 0 )
- minY = 0; //clamp extent to fall within box
- maxY = ceilf(gy + m_gridChangeMaxRange);
- if (maxY > m_gridCellsY)
- maxY = m_gridCellsY; //clamp extent to fall within box
-
- for (y=minY; y<=maxY; y++)
- {
- for (x=minX; x<=maxX; x++)
- { oldData = &m_meshData[(y+1)*(m_gridCellsX+1+2)+x+1].height;
- distance = (gx - (Real)x)*(gx - (Real)x) + (gy - (Real)y)*(gy - (Real)y);
- distance = sqrt(distance);
- newData = *oldData + 1.0f/(m_gridChangeAtt0+m_gridChangeAtt1*distance+distance*distance*m_gridChangeAtt2)*delta;
- //Clamp to min/max values
- if (newData < m_minGridHeight)
- newData = m_minGridHeight;
- if (newData > m_maxGridHeight)
- newData = m_maxGridHeight;
- *oldData = newData;
- }
- }
- }
-}
-
-void WaterRenderObjClass::setGridChangeAttenuationFactors(Real a, Real b, Real c, Real range)
-{
- m_gridChangeAtt0 = a;
- m_gridChangeAtt1 = b;
- m_gridChangeAtt2 = c;
- m_gridChangeMaxRange = range/m_gridCellSize; //convert range to grid space
-}
-
-void WaterRenderObjClass::setGridTransform(Real angle, Real x, Real y, Real z)
-{
- m_gridDirectionX = Vector2(1.0f,0.0f);
-
- m_gridOrigin.X = x;
- m_gridOrigin.Y = y;
-
- Matrix3D xform(1);
- xform.Rotate_Z(angle);
-
- m_gridDirectionX.X = xform.Get_X_Vector().X;
- m_gridDirectionX.Y = xform.Get_X_Vector().Y;
-
- m_gridDirectionY.X = xform.Get_Y_Vector().X;
- m_gridDirectionY.Y = xform.Get_Y_Vector().Y;
-
- xform.Set_Translation(Vector3(x,y,z));
- Set_Transform(xform);
-}
-
-void WaterRenderObjClass::setGridTransform(const Matrix3D *transform )
-{
-
- if( transform )
- Set_Transform( *transform );
-
-}
-
-void WaterRenderObjClass::getGridTransform(Matrix3D *transform )
-{
-
- if( transform )
- *transform = Get_Transform();
-
-}
-
-void WaterRenderObjClass::setGridResolution(Real gridCellsX, Real gridCellsY, Real cellSize)
-{
- m_gridCellSize=cellSize;
-
- if (m_gridCellsX != gridCellsX || m_gridCellsY != m_gridCellsY)
- { //resolutoin has changed
- m_gridCellsX=gridCellsX;
- m_gridCellsY=gridCellsY;
-
- if (m_meshData)
- {
-
- delete [] m_meshData;//free previously allocated grid and allocate new size
- m_meshData = NULL; // must set to NULL so that we properly re-allocate
- m_meshDataSize = 0;
-
- Bool enable = m_doWaterGrid;
- enableWaterGrid(true); // allocates buffers.
- m_doWaterGrid = enable;
-
- }
- }
-}
-
-void WaterRenderObjClass::getGridResolution( Real *gridCellsX, Real *gridCellsY, Real *cellSize )
-{
-
- if( gridCellsX )
- *gridCellsX = m_gridCellsX;
- if( gridCellsY )
- *gridCellsY = m_gridCellsY;
- if( cellSize )
- *cellSize = m_gridCellSize;
-
-}
+/* The grid's setters, addVelocity and changeGridHeight that stood here are TerrainLogic's WaterGrid's
+ (GameLogic/WaterGridMotion.h), moved with the members they write (LOGIC-THREAD M7). */
static Real wobble(Real baseV, Real offset, Bool wobble)
{
@@ -2928,7 +2688,7 @@ void WaterRenderObjClass::drawRiverWater(PolygonTrigger *pTrig)
Real bumpFactor = 5;
static Bool doWobble = true;
- if (m_disableRiver) return;
+ if (TheTerrainLogic->getWaterGrid()->wasPushed()) return;
m_drawingRiver = true;
//allocate 2 triangles per side with 3 indices per triangle
@@ -3706,75 +3466,7 @@ void WaterRenderObjClass::renderSkyBody(Matrix3D *mat)
}
#endif
-// ------------------------------------------------------------------------------------------------
-/** CRC */
-// ------------------------------------------------------------------------------------------------
-void WaterRenderObjClass::crc( Xfer *xfer )
-{
-
-} // end crc
-
-// ------------------------------------------------------------------------------------------------
-/** Xfer
- * Version Info:
- * 1: Initial version */
-// ------------------------------------------------------------------------------------------------
-void WaterRenderObjClass::xfer( Xfer *xfer )
-{
-
- // version
- XferVersion currentVersion = 1;
- XferVersion version = currentVersion;
- xfer->xferVersion( &version, currentVersion );
-
- // grid cells x
- Int cellsX = m_gridCellsX;
- xfer->xferInt( &cellsX );
- if( cellsX != m_gridCellsX )
- {
-
- DEBUG_CRASH(( "WaterRenderObjClass::xfer - cells X mismatch\n" ));
- throw SC_INVALID_DATA;
-
- } // end if
-
- // grid cells Y
- Int cellsY = m_gridCellsY;
- xfer->xferInt( &cellsY );
- if( cellsY != m_gridCellsY )
- {
-
- DEBUG_CRASH(( "WaterRenderObjClass::xfer - cells Y mismatch\n" ));
- throw SC_INVALID_DATA;
-
- } // end if
-
- // xfer each of the mesh data points
- for( Int i = 0; i < m_meshDataSize; ++i )
- {
-
- // height
- xfer->xferReal( &m_meshData[ i ].height );
-
- // velocity
- xfer->xferReal( &m_meshData[ i ].velocity );
-
- // status
- xfer->xferUnsignedByte( &m_meshData[ i ].status );
-
- // preferred height
- xfer->xferUnsignedByte( &m_meshData[ i ].preferredHeight );
-
- } // end for, i
-
-} // end xfer
-
-// ------------------------------------------------------------------------------------------------
-/** Load post process */
-// ------------------------------------------------------------------------------------------------
-void WaterRenderObjClass::loadPostProcess( void )
-{
-
-} // end loadPostProcess
+/* The save's grid data (the snapshot that was here) is WaterGrid::xfer's; W3DTerrainVisual::xfer
+ still writes it in the same place. */
diff --git a/GeneralsMD/Code/Tests/test_water_grid.cpp b/GeneralsMD/Code/Tests/test_water_grid.cpp
index 387da8b80..c00d3665f 100644
--- a/GeneralsMD/Code/Tests/test_water_grid.cpp
+++ b/GeneralsMD/Code/Tests/test_water_grid.cpp
@@ -19,7 +19,7 @@
* T1c, defect 17: the water grid steps once per logic frame, however many logic frames a pass runs.
*
* WaterGridMotion::updateForLogicFrame is the step moved out of WaterRenderObjClass::update; GameLogic::
- * update calls it (through TerrainVisual::updateWaterGrid) at the top of every logic frame. This plays
+ * update calls it (through TerrainLogic's WaterGrid::update) at the top of every logic frame. This plays
* Tests/water_grid_scenario.h through it that way, under EA's loop and three shapes of the fork's
* catch-up, and requires every one to print what the ORIGINAL code printed under EA's loop.
*