Skip to content

Commit 792d17d

Browse files
committed
tweak(heightmap): Decouple cloud render update from logic step (#1579)
1 parent 26c5a9b commit 792d17d

File tree

11 files changed

+89
-76
lines changed

11 files changed

+89
-76
lines changed

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/HeightMap.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ class HeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHook
180180

181181
void renderTerrainPass(CameraClass *pCamera); ///< renders additional terrain pass.
182182
W3DShroud *getShroud() {return m_shroud;}
183-
void renderExtraBlendTiles(void); ///< render 3-way blend tiles that have blend of 3 textures.
184183
void updateShorelineTiles(Int minX, Int minY, Int maxX, Int maxY, WorldHeightMap *pMap); ///<figure out which tiles on this map cross water plane
185184
void updateViewImpassableAreas(Bool partial = FALSE, Int minX = 0, Int maxX = 0, Int minY = 0, Int maxY = 0);
186185
void clearAllScorches(void);
@@ -320,6 +319,9 @@ class HeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHook
320319
AABoxClass & getTileBoundingBox(AABoxClass *aabox, Int x, Int y); ///<Vertex buffer bounding box
321320
void initDestAlphaLUT(void); ///<initialize water depth LUT stored in m_destAlphaTexture
322321
void renderShoreLines(CameraClass *pCamera); ///<re-render parts of terrain that need custom blending into water edge
322+
void renderExtraBlendTiles(void); ///< render 3-way blend tiles that have blend of 3 textures.
323+
324+
static Bool useCloud();
323325
};
324326

325327
extern HeightMapRenderObjClass *TheTerrainRenderObject;

Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DShaderManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class W3DShaderManager
7575
W3DShaderManager(void); ///<constructor
7676
static void init( void ); ///<determine optimal shaders for current device.
7777
static void shutdown(void); ///<release resources used by shaders
78+
static void updateCloud(); ///<update the cloud position once every render frame.
79+
7880
static ChipsetType getChipset(void); ///<return current device chipset.
7981
static Int getShaderPasses(ShaderTypes shader); ///<rendering passes required for shader
8082
static Int setShader(ShaderTypes shader, Int pass); ///<enable specific shader pass.

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,14 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
38153815

38163816
Int i,j,devicePasses;
38173817
W3DShaderManager::ShaderTypes st;
3818-
Bool doCloud = TheGlobalData->m_useCloudMap;
3818+
const Bool doCloud = useCloud();
3819+
3820+
if (doCloud)
3821+
{
3822+
// TheSuperHackers @tweak Updates the cloud movement before applying it to the world.
3823+
// Is now decoupled from logic step.
3824+
W3DShaderManager::updateCloud();
3825+
}
38193826

38203827
Matrix3D tm(Transform);
38213828
#if 0 // There is some weirdness sometimes with the dx8 static buffers.
@@ -3906,10 +3913,6 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
39063913
DX8Wrapper::Set_Material(m_vertexMaterialClass);
39073914
DX8Wrapper::Set_Shader(m_shaderClass);
39083915

3909-
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT) {
3910-
doCloud = false;
3911-
}
3912-
39133916
st=W3DShaderManager::ST_TERRAIN_BASE; //set default shader
39143917

39153918
//set correct shader based on current settings
@@ -4454,10 +4457,7 @@ void HeightMapRenderObjClass::renderExtraBlendTiles(void)
44544457

44554458
W3DShaderManager::ShaderTypes st = W3DShaderManager::ST_ROAD_BASE;
44564459

4457-
Bool doCloud = TheGlobalData->m_useCloudMap;
4458-
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT) {
4459-
doCloud = false;
4460-
}
4460+
const Bool doCloud = useCloud();
44614461

44624462
if (TheGlobalData->m_useLightMap && doCloud)
44634463
{
@@ -4486,3 +4486,9 @@ void HeightMapRenderObjClass::renderExtraBlendTiles(void)
44864486
}
44874487
}
44884488
}
4489+
4490+
//=============================================================================
4491+
Bool HeightMapRenderObjClass::useCloud()
4492+
{
4493+
return TheGlobalData->m_useCloudMap && TheGlobalData->m_timeOfDay != TIME_OF_DAY_NIGHT;
4494+
}

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShaderManager.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,14 @@ class TerrainShader2Stage : public W3DShaderInterface
12481248
public:
12491249
float m_xSlidePerSecond ; ///< How far the clouds move per second.
12501250
float m_ySlidePerSecond ; ///< How far the clouds move per second.
1251-
int m_curTick;
12521251
float m_xOffset;
12531252
float m_yOffset;
1253+
12541254
virtual Int set(Int pass); ///<setup shader for the specified rendering pass.
12551255
virtual Int init(void); ///<perform any one time initialization and validation
12561256
virtual void reset(void); ///<do any custom resetting necessary to bring W3D in sync.
1257+
1258+
void updateCloud();
12571259
void updateNoise1 (D3DXMATRIX *destMatrix,D3DXMATRIX *curViewInverse, Bool doUpdate=true); ///<generate the uv coordinates for Noise1 (i.e clouds)
12581260
void updateNoise2 (D3DXMATRIX *destMatrix,D3DXMATRIX *curViewInverse, Bool doUpdate=true); ///<generate the uv coordinates for Noise2 (i.e lightmap)
12591261
} terrainShader2Stage;
@@ -1296,8 +1298,6 @@ Int TerrainShader2Stage::init( void )
12961298
//initialize settings for uv animated clouds
12971299
m_xSlidePerSecond = -0.02f;
12981300
m_ySlidePerSecond = 1.50f * m_xSlidePerSecond;
1299-
m_curTick = 0;
1300-
m_curTick = WW3D::Get_Sync_Time();//::GetTickCount();
13011301
m_xOffset = 0;
13021302
m_yOffset = 0;
13031303

@@ -1330,6 +1330,18 @@ void TerrainShader2Stage::reset(void)
13301330
DX8Wrapper::Set_DX8_Texture_Stage_State( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU|1);
13311331
}
13321332

1333+
void TerrainShader2Stage::updateCloud()
1334+
{
1335+
const float frame_time = WW3D::Get_Logic_Frame_Time_Seconds();
1336+
m_xOffset += m_xSlidePerSecond * frame_time;
1337+
m_yOffset += m_ySlidePerSecond * frame_time;
1338+
1339+
while (m_xOffset > 1) m_xOffset -= 1;
1340+
while (m_yOffset > 1) m_yOffset -= 1;
1341+
while (m_xOffset < -1) m_xOffset += 1;
1342+
while (m_yOffset < -1) m_yOffset += 1;
1343+
}
1344+
13331345
void TerrainShader2Stage::updateNoise1(D3DXMATRIX *destMatrix,D3DXMATRIX *curViewInverse, Bool doUpdate)
13341346
{
13351347
#define STRETCH_FACTOR ((float)(1/(63.0*MAP_XY_FACTOR/2))) /* covers 63/2 tiles */
@@ -1340,26 +1352,6 @@ void TerrainShader2Stage::updateNoise1(D3DXMATRIX *destMatrix,D3DXMATRIX *curVie
13401352
*destMatrix = *curViewInverse * scale;
13411353

13421354
D3DXMATRIX offset;
1343-
1344-
Int delta = m_curTick;
1345-
m_curTick = WW3D::Get_Sync_Time();//::GetTickCount();
1346-
delta = m_curTick-delta;
1347-
m_xOffset += m_xSlidePerSecond*delta/1000;
1348-
m_yOffset += m_ySlidePerSecond*delta/1000;
1349-
1350-
1351-
//m_xOffset += m_xSlidePerSecond*delta/500;
1352-
//m_yOffset += m_ySlidePerSecond*delta/500;
1353-
1354-
1355-
//m_yOffset = sinf( (float)m_curTick * 0.0001f );
1356-
//m_xOffset = cosf( (float)m_curTick * 0.0001f );
1357-
1358-
if (m_xOffset > 1) m_xOffset -= 1;
1359-
if (m_yOffset > 1) m_yOffset -= 1;
1360-
if (m_xOffset < -1) m_xOffset += 1;
1361-
if (m_yOffset < -1) m_yOffset += 1;
1362-
13631355
D3DXMatrixTranslation(&offset, m_xOffset, m_yOffset,0);
13641356
*destMatrix *= offset;
13651357
}
@@ -2447,6 +2439,12 @@ void W3DShaderManager::shutdown(void)
24472439
}
24482440
}
24492441

2442+
//=============================================================================
2443+
void W3DShaderManager::updateCloud()
2444+
{
2445+
terrainShader2Stage.updateCloud();
2446+
}
2447+
24502448
// W3DShaderManager::getShaderPasses =======================================================
24512449
/** Return number of renderig passes required in perform the desired shader on current
24522450
hardware. App will need to re-render the polygons this many times to complete the

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ class BaseHeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHoo
328328
void initDestAlphaLUT(void); ///<initialize water depth LUT stored in m_destAlphaTexture
329329
void renderShoreLines(CameraClass *pCamera); ///<re-render parts of terrain that need custom blending into water edge
330330
void renderShoreLinesSorted(CameraClass *pCamera); ///<optimized version for game usage.
331+
332+
static Bool useCloud();
331333
};
332334

333335
extern BaseHeightMapRenderObjClass *TheTerrainRenderObject;

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ class HeightMapRenderObjClass : public BaseHeightMapRenderObjClass
8181
virtual Int freeMapResources(void); ///< free resources used to render heightmap
8282
virtual void updateCenter(CameraClass *camera, RefRenderObjListIterator *pLightsIterator);
8383

84-
void renderExtraBlendTiles(void); ///< render 3-way blend tiles that have blend of 3 textures.
85-
86-
8784
virtual void staticLightingChanged(void);
8885
virtual void adjustTerrainLOD(Int adj);
8986
virtual void reset(void);
@@ -123,9 +120,7 @@ class HeightMapRenderObjClass : public BaseHeightMapRenderObjClass
123120
void renderTerrainPass(CameraClass *pCamera); ///< renders additional terrain pass.
124121
Int getNumExtraBlendTiles(Bool visible) { return visible?m_numVisibleExtraBlendTiles:m_numExtraBlendTiles;}
125122
void freeIndexVertexBuffers(void);
126-
127-
128-
123+
void renderExtraBlendTiles(void); ///< render 3-way blend tiles that have blend of 3 textures.
129124
};
130125

131126
#endif // end __HEIGHTMAP_H_

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class W3DShaderManager
8181
W3DShaderManager(void); ///<constructor
8282
static void init( void ); ///<determine optimal shaders for current device.
8383
static void shutdown(void); ///<release resources used by shaders
84+
static void updateCloud(); ///<update the cloud position once every render frame.
85+
8486
static ChipsetType getChipset(void); ///<return current device chipset.
8587
static GraphicsVenderID getCurrentVendor(void) {return m_currentVendor;} ///<return current card vendor.
8688
static __int64 getCurrentDriverVersion(void) {return m_driverVersion; } ///<return current driver version.

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,3 +3009,8 @@ void BaseHeightMapRenderObjClass::loadPostProcess( void )
30093009
// empty. jba [8/11/2003]
30103010
}
30113011

3012+
//=============================================================================
3013+
Bool BaseHeightMapRenderObjClass::useCloud()
3014+
{
3015+
return TheGlobalData->m_useCloudMap && TheGlobalData->m_timeOfDay != TIME_OF_DAY_NIGHT;
3016+
}

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/FlatHeightMap.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,14 @@ void FlatHeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
459459

460460
Int devicePasses;
461461
W3DShaderManager::ShaderTypes st;
462-
Bool doCloud = TheGlobalData->m_useCloudMap;
462+
const Bool doCloud = useCloud();
463+
464+
if (doCloud)
465+
{
466+
// TheSuperHackers @tweak Updates the cloud movement before applying it to the world.
467+
// Is now decoupled from logic step.
468+
W3DShaderManager::updateCloud();
469+
}
463470

464471
Matrix3D tm(Transform);
465472
// If there are trees, tell them to draw at the transparent time to draw.
@@ -494,10 +501,6 @@ void FlatHeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
494501
DX8Wrapper::Set_Material(m_vertexMaterialClass);
495502
DX8Wrapper::Set_Shader(m_shaderClass);
496503

497-
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT) {
498-
doCloud = false;
499-
}
500-
501504
st=W3DShaderManager::ST_FLAT_TERRAIN_BASE; //set default shader
502505

503506
//set correct shader based on current settings

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,14 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
19121912

19131913
Int i,j,devicePasses;
19141914
W3DShaderManager::ShaderTypes st;
1915-
Bool doCloud = TheGlobalData->m_useCloudMap;
1915+
const Bool doCloud = useCloud();
1916+
1917+
if (doCloud)
1918+
{
1919+
// TheSuperHackers @tweak Updates the cloud movement before applying it to the world.
1920+
// Is now decoupled from logic step.
1921+
W3DShaderManager::updateCloud();
1922+
}
19161923

19171924
Matrix3D tm(Transform);
19181925
#if 0 // There is some weirdness sometimes with the dx8 static buffers.
@@ -2003,10 +2010,6 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
20032010
DX8Wrapper::Set_Material(m_vertexMaterialClass);
20042011
DX8Wrapper::Set_Shader(m_shaderClass);
20052012

2006-
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT) {
2007-
doCloud = false;
2008-
}
2009-
20102013
st=W3DShaderManager::ST_TERRAIN_BASE; //set default shader
20112014

20122015
//set correct shader based on current settings
@@ -2415,10 +2418,7 @@ void HeightMapRenderObjClass::renderExtraBlendTiles(void)
24152418

24162419
W3DShaderManager::ShaderTypes st = W3DShaderManager::ST_ROAD_BASE;
24172420

2418-
Bool doCloud = TheGlobalData->m_useCloudMap;
2419-
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT) {
2420-
doCloud = false;
2421-
}
2421+
const Bool doCloud = useCloud();
24222422

24232423
if (TheGlobalData->m_useLightMap && doCloud)
24242424
{

0 commit comments

Comments
 (0)