Skip to content

Commit 2aef67e

Browse files
committed
chore(heightmap): Implement HeightMapRenderObjClass::setTerrainDrawSize() to set custom draw sizes (#2677)
1 parent edadb56 commit 2aef67e

8 files changed

Lines changed: 56 additions & 19 deletions

File tree

Core/GameEngineDevice/Include/W3DDevice/GameClient/BaseHeightMap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class BaseHeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHoo
123123
virtual void adjustTerrainLOD(Int adj);
124124
virtual void doPartialUpdate(const IRegion2D &partialRange, WorldHeightMap *htMap, RefRenderObjListIterator *pLightsIterator) = 0;
125125
virtual void staticLightingChanged();
126-
virtual void oversizeTerrain(Int tilesToOversize);
126+
virtual void oversizeTerrain(Int tilesToOversize) = 0; ///< Oversize the visible terrain area.
127+
virtual void setTerrainDrawSize(Int width, Int height) = 0; ///< Resize the visible terrain area. Always defaults to oversize dimensions when oversize is set.
127128
virtual void reset();
128129

129130
void redirectToHeightmap( WorldHeightMap *pMap )

Core/GameEngineDevice/Include/W3DDevice/GameClient/FlatHeightMap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class FlatHeightMapRenderObjClass : public BaseHeightMapRenderObjClass
6969
virtual void updateCenter(CameraClass *camera, RefRenderObjListIterator *pLightsIterator) override;
7070
virtual void adjustTerrainLOD(Int adj) override;
7171
virtual void reset() override;
72-
virtual void oversizeTerrain(Int tilesToOversize) override;
72+
virtual void oversizeTerrain(Int tilesToOversize) override; ///< Oversize the visible terrain area.
73+
virtual void setTerrainDrawSize(Int width, Int height) override; ///< Resize the visible terrain area. Always defaults to oversize dimensions when oversize is set.
7374
virtual void staticLightingChanged() override;
7475
virtual void doPartialUpdate(const IRegion2D &partialRange, WorldHeightMap *htMap, RefRenderObjListIterator *pLightsIterator) override;
7576
virtual int updateBlock(Int x0, Int y0, Int x1, Int y1, WorldHeightMap *pMap, RefRenderObjListIterator *pLightsIterator) override {return 0;};

Core/GameEngineDevice/Include/W3DDevice/GameClient/HeightMap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class HeightMapRenderObjClass : public BaseHeightMapRenderObjClass
8080
virtual void reset() override;
8181
virtual void doPartialUpdate(const IRegion2D &partialRange, WorldHeightMap *htMap, RefRenderObjListIterator *pLightsIterator) override;
8282

83-
virtual void oversizeTerrain(Int tilesToOversize) override;
83+
virtual void oversizeTerrain(Int tilesToOversize) override; ///< Oversize the visible terrain area.
84+
virtual void setTerrainDrawSize(Int width, Int height) override; ///< Resize the visible terrain area. Always defaults to oversize dimensions when oversize is set.
8485

8586
virtual int updateBlock(Int x0, Int y0, Int x1, Int y1, WorldHeightMap *pMap, RefRenderObjListIterator *pLightsIterator) override;
8687

@@ -93,6 +94,8 @@ class HeightMapRenderObjClass : public BaseHeightMapRenderObjClass
9394
VERTEX_FORMAT *m_vertexBufferBackup; ///< In memory copy of the vertex buffer data for quick update of dynamic lighting.
9495
Int m_originX; ///< Origin point in the grid. Slides around.
9596
Int m_originY; ///< Origin point in the grid. Slides around.
97+
Int m_oversizeDrawWidth; // Oversize draw width required by mission scripts for cinematic sequences.
98+
Int m_oversizeDrawHeight; // Oversize draw height required by mission scripts for cinematic sequences.
9699
DX8IndexBufferClass *m_indexBuffer; ///<indices defining triangles in a VB tile.
97100
Int m_numVBTilesX; ///<dimensions of array containing all the vertex buffers
98101
Int m_numVBTilesY; ///<dimensions of array containing all the vertex buffers

Core/GameEngineDevice/Include/W3DDevice/GameClient/WorldHeightMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ class WorldHeightMap : public RefCountClass,
250250

251251
Int getDrawWidth() {return m_drawWidthX;}
252252
Int getDrawHeight() {return m_drawHeightY;}
253-
void setDrawWidth(Int width) {m_drawWidthX = width; if (m_drawWidthX>m_width) m_drawWidthX = m_width;}
254-
void setDrawHeight(Int height) {m_drawHeightY = height; if (m_drawHeightY>m_height) m_drawHeightY = m_height;}
253+
void setDrawWidth(Int width) {DEBUG_ASSERTCRASH(width <= m_width, ("Draw width must not exceed map width")); m_drawWidthX = width;}
254+
void setDrawHeight(Int height) {DEBUG_ASSERTCRASH(height <= m_height, ("Draw height must not exceed map height")); m_drawHeightY = height;}
255255
virtual Int getBorderSize() override {return m_borderSize;}
256256
Int getBorderSizeInline() const { return m_borderSize; }
257257
/// Get height with the offset that HeightMapRenderObjClass uses built in.

Core/GameEngineDevice/Source/W3DDevice/GameClient/FlatHeightMap.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ void FlatHeightMapRenderObjClass::oversizeTerrain(Int tilesToOversize)
243243
// Not needed with flat version. [3/20/2003]
244244
}
245245

246-
246+
void FlatHeightMapRenderObjClass::setTerrainDrawSize(Int width, Int height)
247+
{
248+
// Not needed with flat version.
249+
}
247250

248251
//=============================================================================
249252
// HeightMapRenderObjClass::doPartialUpdate

Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,8 @@ m_vertexBufferTiles(nullptr),
10481048
m_vertexBufferBackup(nullptr),
10491049
m_originX(0),
10501050
m_originY(0),
1051+
m_oversizeDrawWidth(0),
1052+
m_oversizeDrawHeight(0),
10511053
m_indexBuffer(nullptr),
10521054
m_numVBTilesX(0),
10531055
m_numVBTilesY(0),
@@ -1161,6 +1163,8 @@ void HeightMapRenderObjClass::ReAcquireResources()
11611163
void HeightMapRenderObjClass::reset()
11621164
{
11631165
BaseHeightMapRenderObjClass::reset();
1166+
m_oversizeDrawWidth = 0;
1167+
m_oversizeDrawHeight = 0;
11641168
}
11651169

11661170
//=============================================================================
@@ -1170,17 +1174,42 @@ void HeightMapRenderObjClass::reset()
11701174
//=============================================================================
11711175
void HeightMapRenderObjClass::oversizeTerrain(Int tilesToOversize)
11721176
{
1173-
Int width = WorldHeightMap::NORMAL_DRAW_WIDTH;
1174-
Int height = WorldHeightMap::NORMAL_DRAW_HEIGHT;
1175-
if (tilesToOversize>0 && tilesToOversize<5)
1177+
if (tilesToOversize>0)
11761178
{
1177-
width += VERTEX_BUFFER_TILE_LENGTH * tilesToOversize;
1178-
height += VERTEX_BUFFER_TILE_LENGTH * tilesToOversize;
1179-
if (width>m_map->getXExtent())
1180-
width = m_map->getXExtent();
1181-
if (height>m_map->getYExtent())
1182-
height = m_map->getYExtent();
1179+
m_oversizeDrawWidth = WorldHeightMap::NORMAL_DRAW_WIDTH + VERTEX_BUFFER_TILE_LENGTH * tilesToOversize;
1180+
m_oversizeDrawHeight = WorldHeightMap::NORMAL_DRAW_HEIGHT + VERTEX_BUFFER_TILE_LENGTH * tilesToOversize;
1181+
m_oversizeDrawWidth = std::min(m_oversizeDrawWidth, m_map->getXExtent());
1182+
m_oversizeDrawHeight = std::min(m_oversizeDrawHeight, m_map->getYExtent());
1183+
setTerrainDrawSize(m_oversizeDrawWidth, m_oversizeDrawHeight);
11831184
}
1185+
else
1186+
{
1187+
m_oversizeDrawWidth = 0;
1188+
m_oversizeDrawHeight = 0;
1189+
Int width = std::min((Int)WorldHeightMap::NORMAL_DRAW_WIDTH, m_map->getXExtent());
1190+
Int height = std::min((Int)WorldHeightMap::NORMAL_DRAW_HEIGHT, m_map->getYExtent());
1191+
setTerrainDrawSize(width, height);
1192+
}
1193+
}
1194+
1195+
void HeightMapRenderObjClass::setTerrainDrawSize(Int width, Int height)
1196+
{
1197+
if (m_map == nullptr)
1198+
return;
1199+
1200+
if (m_oversizeDrawWidth != 0)
1201+
width = m_oversizeDrawWidth;
1202+
else
1203+
width = std::min(width, m_map->getXExtent());
1204+
1205+
if (m_oversizeDrawHeight != 0)
1206+
height = m_oversizeDrawHeight;
1207+
else
1208+
height = std::min(height, m_map->getYExtent());
1209+
1210+
if (width == m_map->getDrawWidth() && height == m_map->getDrawHeight())
1211+
return;
1212+
11841213
Int dx = width-m_map->getDrawWidth();
11851214
Int dy = height-m_map->getDrawHeight();
11861215
m_map->setDrawWidth(width);

Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,8 @@ void WbView3d::updateHeightMapInView(WorldHeightMap *htMap, Bool partial, const
15121512
htMap->setDrawHeight(htMap->getYExtent());
15131513
m_heightMapRenderObj->initHeightData(htMap->getXExtent(), htMap->getYExtent(), htMap, &lightListIt);
15141514
} else {
1515-
htMap->setDrawWidth(m_partialMapSize);
1516-
htMap->setDrawHeight(m_partialMapSize);
1515+
htMap->setDrawWidth(std::min(m_partialMapSize, htMap->getXExtent()));
1516+
htMap->setDrawHeight(std::min(m_partialMapSize, htMap->getYExtent()));
15171517
m_heightMapRenderObj->initHeightData(htMap->getDrawWidth(), htMap->getDrawHeight(), htMap, &lightListIt);
15181518
}
15191519
m_heightMapRenderObj->updateViewImpassableAreas();

GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,8 @@ void WbView3d::updateHeightMapInView(WorldHeightMap *htMap, Bool partial, const
15931593
htMap->setDrawHeight(htMap->getYExtent());
15941594
m_heightMapRenderObj->initHeightData(htMap->getXExtent(), htMap->getYExtent(), htMap, &lightListIt);
15951595
} else {
1596-
htMap->setDrawWidth(m_partialMapSize);
1597-
htMap->setDrawHeight(m_partialMapSize);
1596+
htMap->setDrawWidth(std::min(m_partialMapSize, htMap->getXExtent()));
1597+
htMap->setDrawHeight(std::min(m_partialMapSize, htMap->getYExtent()));
15981598
m_heightMapRenderObj->initHeightData(htMap->getDrawWidth(), htMap->getDrawHeight(), htMap, &lightListIt);
15991599
}
16001600
m_heightMapRenderObj->updateViewImpassableAreas();

0 commit comments

Comments
 (0)