Skip to content

Commit 99eebdc

Browse files
committed
tweak(water): Decouple water movement time step from render update
1 parent 2bbf902 commit 99eebdc

File tree

2 files changed

+22
-27
lines changed
  • GeneralsMD/Code/GameEngineDevice

2 files changed

+22
-27
lines changed

GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DWater.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class WaterRenderObjClass : public Snapshot,
168168
Int m_numIndices; ///<number of indices in D3D index buffer
169169
LPDIRECT3DTEXTURE8 m_pBumpTexture[NUM_BUMP_FRAMES]; ///<animation frames
170170
LPDIRECT3DTEXTURE8 m_pBumpTexture2[NUM_BUMP_FRAMES]; ///<animation frames
171-
Int m_iBumpFrame; ///<current animation frame
171+
Real m_fBumpFrame; ///<current animation frame
172172
Real m_fBumpScale; ///<scales bump map uv perturbation
173173
TextureClass * m_pReflectionTexture; ///<render target for reflection
174174
RenderObjClass *m_skyBox; ///<box around level

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWater.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "mesh.h"
5050
#include "matinfo.h"
5151

52+
#include "Common/GameEngine.h"
5253
#include "Common/GameState.h"
5354
#include "Common/GlobalData.h"
5455
#include "Common/PerfTimer.h"
@@ -984,7 +985,7 @@ void WaterRenderObjClass::load(void)
984985
Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *parentScene, WaterType type)
985986
{
986987

987-
m_iBumpFrame=0;
988+
m_fBumpFrame=0;
988989
m_fBumpScale=SEA_BUMP_SCALE;
989990

990991
m_dx=dx;
@@ -1204,38 +1205,35 @@ void WaterRenderObjClass::enableWaterGrid(Bool state)
12041205
}
12051206

12061207
// ------------------------------------------------------------------------------------------------
1207-
/** Update phase for water if we need it. This called once per client frame reguardless
1208-
* of how fast the logic framerate is running */
1208+
/** Update phase for water if we need it. */
12091209
// ------------------------------------------------------------------------------------------------
12101210
void WaterRenderObjClass::update( void )
12111211
{
1212-
static UnsignedInt lastLogicFrame = 0;
1213-
UnsignedInt currLogicFrame = 0;
1212+
// TheSuperHackers @tweak The water movement time step is now decoupled from the render update.
1213+
const Real timeScale = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
12141214

1215-
if( TheGameLogic )
1216-
currLogicFrame = TheGameLogic->getFrame();
1217-
1218-
// we only process things if the logic frame has changed
1219-
if( lastLogicFrame != currLogicFrame )
12201215
{
1216+
constexpr const Real MagicOffset = 0.0125 * 33 / 5000; ///< the work of top Munkees; do not question it
12211217

1222-
m_riverVOrigin += 0.002f;
1223-
m_riverXOffset += (Real)(0.0125*33/5000);
1224-
m_riverYOffset += (Real)(2*0.0125*33/5000);
1225-
if (m_riverXOffset > 1) m_riverXOffset -= 1;
1226-
if (m_riverYOffset > 1) m_riverYOffset -= 1;
1227-
if (m_riverXOffset < -1) m_riverXOffset += 1;
1228-
if (m_riverYOffset < -1) m_riverYOffset += 1;
1229-
m_iBumpFrame++;
1230-
if (m_iBumpFrame >= NUM_BUMP_FRAMES) {
1231-
m_iBumpFrame = 0;
1232-
}
1218+
m_riverVOrigin += 0.002f * timeScale;
1219+
m_riverXOffset += (Real)(MagicOffset * timeScale);
1220+
m_riverYOffset += (Real)(2 * MagicOffset * timeScale);
1221+
1222+
if (m_riverXOffset > 1.0f)
1223+
m_riverXOffset -= (Int)m_riverXOffset;
1224+
1225+
if (m_riverYOffset > 1.0f)
1226+
m_riverYOffset -= (Int)m_riverYOffset;
1227+
1228+
m_fBumpFrame += timeScale;
1229+
if (m_fBumpFrame >= NUM_BUMP_FRAMES)
1230+
m_fBumpFrame = 0.0f;
12331231

12341232
// for vertex animated water we need to update the vector field
12351233
if( m_doWaterGrid && m_meshInMotion == TRUE )
12361234
{
12371235
const Real PREFERRED_HEIGHT_FUDGE = 1.0f; ///< this is close enough to at rest
1238-
const Real AT_REST_VELOCITY_FUDGE = 1.0f; ///< when we're close enought to at rest height and velocity we will stop
1236+
const Real AT_REST_VELOCITY_FUDGE = 1.0f; ///< when we're close enough to at rest height and velocity we will stop
12391237
const Real WATER_DAMPENING = 0.93f; ///< use with up force of 15.0
12401238
Int i, j;
12411239
Int mx = m_gridCellsX+1;
@@ -1303,9 +1301,6 @@ void WaterRenderObjClass::update( void )
13031301

13041302
}
13051303

1306-
// mark the last logic frame we processed on
1307-
lastLogicFrame = currLogicFrame;
1308-
13091304
}
13101305

13111306
}
@@ -1846,7 +1841,7 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)
18461841
m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
18471842
m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
18481843

1849-
m_pDev->SetTexture( 0, m_pBumpTexture[m_iBumpFrame]);
1844+
m_pDev->SetTexture( 0, m_pBumpTexture[(Int)m_fBumpFrame]);
18501845
#ifdef MIPMAP_BUMP_TEXTURE
18511846
m_pDev->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_POINT );
18521847
m_pDev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );

0 commit comments

Comments
 (0)