Skip to content

Commit b36b7f5

Browse files
committed
Replicate in Generals
1 parent f54ec02 commit b36b7f5

File tree

2 files changed

+20
-27
lines changed
  • Generals/Code/GameEngineDevice

2 files changed

+20
-27
lines changed

Generals/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

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

Lines changed: 19 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"
@@ -961,7 +962,7 @@ void WaterRenderObjClass::load(void)
961962
Int WaterRenderObjClass::init(Real waterLevel, Real dx, Real dy, SceneClass *parentScene, WaterType type)
962963
{
963964

964-
m_iBumpFrame=0;
965+
m_fBumpFrame=0;
965966
m_fBumpScale=SEA_BUMP_SCALE;
966967

967968
m_dx=dx;
@@ -1181,38 +1182,33 @@ void WaterRenderObjClass::enableWaterGrid(Bool state)
11811182
}
11821183

11831184
// ------------------------------------------------------------------------------------------------
1184-
/** Update phase for water if we need it. This called once per client frame reguardless
1185-
* of how fast the logic framerate is running */
1185+
/** Update phase for water if we need it. */
11861186
// ------------------------------------------------------------------------------------------------
11871187
void WaterRenderObjClass::update( void )
11881188
{
1189-
static UnsignedInt lastLogicFrame = 0;
1190-
UnsignedInt currLogicFrame = 0;
1189+
// TheSuperHackers @tweak The water movement time step is now decoupled from the render update.
1190+
const Real timeScale = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
11911191

1192-
if( TheGameLogic )
1193-
currLogicFrame = TheGameLogic->getFrame();
1194-
1195-
// we only process things if the logic frame has changed
1196-
if( lastLogicFrame != currLogicFrame )
11971192
{
1193+
constexpr const Real MagicOffset = 0.0125f * 33 / 5000; ///< the work of top Munkees; do not question it
11981194

1199-
m_riverVOrigin += 0.002f;
1200-
m_riverXOffset += (Real)(0.0125*33/5000);
1201-
m_riverYOffset += (Real)(2*0.0125*33/5000);
1202-
if (m_riverXOffset > 1) m_riverXOffset -= 1;
1203-
if (m_riverYOffset > 1) m_riverYOffset -= 1;
1204-
if (m_riverXOffset < -1) m_riverXOffset += 1;
1205-
if (m_riverYOffset < -1) m_riverYOffset += 1;
1206-
m_iBumpFrame++;
1207-
if (m_iBumpFrame >= NUM_BUMP_FRAMES) {
1208-
m_iBumpFrame = 0;
1209-
}
1195+
m_riverVOrigin += 0.002f * timeScale;
1196+
m_riverXOffset += (Real)(MagicOffset * timeScale);
1197+
m_riverYOffset += (Real)(2 * MagicOffset * timeScale);
1198+
1199+
// This moves offsets towards zero when smaller -1.0 or larger 1.0
1200+
m_riverXOffset -= (Int)m_riverXOffset;
1201+
m_riverYOffset -= (Int)m_riverYOffset;
1202+
1203+
m_fBumpFrame += timeScale;
1204+
if (m_fBumpFrame >= NUM_BUMP_FRAMES)
1205+
m_fBumpFrame = 0.0f;
12101206

12111207
// for vertex animated water we need to update the vector field
12121208
if( m_doWaterGrid && m_meshInMotion == TRUE )
12131209
{
12141210
const Real PREFERRED_HEIGHT_FUDGE = 1.0f; ///< this is close enough to at rest
1215-
const Real AT_REST_VELOCITY_FUDGE = 1.0f; ///< when we're close enought to at rest height and velocity we will stop
1211+
const Real AT_REST_VELOCITY_FUDGE = 1.0f; ///< when we're close enough to at rest height and velocity we will stop
12161212
const Real WATER_DAMPENING = 0.93f; ///< use with up force of 15.0
12171213
Int i, j;
12181214
Int mx = m_gridCellsX+1;
@@ -1280,9 +1276,6 @@ void WaterRenderObjClass::update( void )
12801276

12811277
}
12821278

1283-
// mark the last logic frame we processed on
1284-
lastLogicFrame = currLogicFrame;
1285-
12861279
}
12871280

12881281
}
@@ -1823,7 +1816,7 @@ void WaterRenderObjClass::drawSea(RenderInfoClass & rinfo)
18231816
m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
18241817
m_pDev->SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
18251818

1826-
m_pDev->SetTexture( 0, m_pBumpTexture[m_iBumpFrame]);
1819+
m_pDev->SetTexture( 0, m_pBumpTexture[(Int)m_fBumpFrame]);
18271820
#ifdef MIPMAP_BUMP_TEXTURE
18281821
m_pDev->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_POINT );
18291822
m_pDev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );

0 commit comments

Comments
 (0)