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.

fix(gamelogic): keep the water grid's frame gate in the grid

Olcay Seygan4c7d8bff8348
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h
index 818baad6f..841255d3b 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/WaterGridMotion.h
@@ -76,8 +76,9 @@ public:
/** Moves every point in motion one step, the first time it is called for a given logic frame; a
* second call for the same frame does nothing. meshData holds (gridCellsX+1+2)*(gridCellsY+1+2)
- * points, a border of one around the grid. */
- static void updateForLogicFrame( UnsignedInt currLogicFrame, Bool doWaterGrid, Bool &meshInMotion,
+ * points, a border of one around the grid. lastLogicFrame is the gate, EA's function static: the
+ * caller owns it, so a new game or a load starts from a gate of its own. */
+ static void updateForLogicFrame( UnsignedInt currLogicFrame, UnsignedInt &lastLogicFrame, Bool doWaterGrid, Bool &meshInMotion,
MeshPoint *meshData, Int gridCellsX, Int gridCellsY );
};
@@ -137,6 +138,7 @@ private:
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
+ UnsignedInt m_lastStepFrame; ///< the logic frame the motion last stepped on; 0 after a reset
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
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp
index dd3d66711..bb0819a89 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/WaterGridMotion.cpp
@@ -32,10 +32,9 @@
#include "GameLogic/WaterGridMotion.h"
// ------------------------------------------------------------------------------------------------
-void WaterGridMotion::updateForLogicFrame( UnsignedInt currLogicFrame, Bool doWaterGrid, Bool &meshInMotion,
+void WaterGridMotion::updateForLogicFrame( UnsignedInt currLogicFrame, UnsignedInt &lastLogicFrame, Bool doWaterGrid, Bool &meshInMotion,
MeshPoint *meshData, Int gridCellsX, Int gridCellsY )
{
- static UnsignedInt lastLogicFrame = 0;
if( lastLogicFrame != currLogicFrame )
{
// for vertex animated water we need to update the vector field
@@ -133,6 +132,7 @@ WaterGrid::WaterGrid( void )
m_meshData = NULL;
m_meshDataSize = 0;
m_meshGeneration = 0;
+ m_lastStepFrame = 0;
m_meshInMotion = FALSE;
m_doWaterGrid = FALSE;
m_heightsEnabled = FALSE;
@@ -169,6 +169,9 @@ WaterGrid::~WaterGrid( void )
void WaterGrid::reset( void )
{
+ // a new game, or a load, steps on its first frame whatever frame the last game stopped on
+ m_lastStepFrame = 0;
+
// for vertex animated water mesh reset the values
if( m_meshData)
{
@@ -237,7 +240,7 @@ void WaterGrid::disableMotion( void )
// ------------------------------------------------------------------------------------------------
void WaterGrid::update( UnsignedInt logicFrame )
{
- WaterGridMotion::updateForLogicFrame( logicFrame, m_doWaterGrid, m_meshInMotion, m_meshData, m_gridCellsX, m_gridCellsY );
+ WaterGridMotion::updateForLogicFrame( logicFrame, m_lastStepFrame, m_doWaterGrid, m_meshInMotion, m_meshData, m_gridCellsX, m_gridCellsY );
}
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tests/test_water_grid.cpp b/GeneralsMD/Code/Tests/test_water_grid.cpp
index c00d3665f..ec8df6019 100644
--- a/GeneralsMD/Code/Tests/test_water_grid.cpp
+++ b/GeneralsMD/Code/Tests/test_water_grid.cpp
@@ -84,14 +84,15 @@ struct MovedEngine
std::vector<Point> points;
Bool moving;
int callsPerFrame;
- MovedEngine( int calls = 1 ) : points( water_grid::POINTS_X * water_grid::POINTS_Y ), moving( FALSE ), callsPerFrame( calls ) {}
+ UnsignedInt lastFrame;
+ MovedEngine( int calls = 1 ) : points( water_grid::POINTS_X * water_grid::POINTS_Y ), moving( FALSE ), callsPerFrame( calls ), lastFrame( 0 ) {}
Point *mesh( void ) { return &points[0]; }
Bool &inMotion( void ) { return moving; }
void clientPass( UnsignedInt ) {}
void logicFrameTop( UnsignedInt frame )
{
for (int i = 0; i < callsPerFrame; ++i)
- WaterGridMotion::updateForLogicFrame( frame, TRUE, moving, &points[0], water_grid::CELLS_X, water_grid::CELLS_Y );
+ WaterGridMotion::updateForLogicFrame( frame, lastFrame, TRUE, moving, &points[0], water_grid::CELLS_X, water_grid::CELLS_Y );
}
};