Skip to content

Commit bcedd55

Browse files
committed
chore(heightmap): Implement HeightMapRenderObjClass::setTerrainDrawSize() to set custom draw sizes (#2677)
1 parent 81d8d5d commit bcedd55

5 files changed

Lines changed: 45 additions & 5 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_oversizeWidth;
98+
Int m_oversizeHeight;
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/Source/W3DDevice/GameClient/FlatHeightMap.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ 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+
}
247249

248250
//=============================================================================
249251
// HeightMapRenderObjClass::doPartialUpdate

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

Lines changed: 34 additions & 1 deletion
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_oversizeWidth(0),
1052+
m_oversizeHeight(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_oversizeWidth = 0;
1167+
m_oversizeHeight = 0;
11641168
}
11651169

11661170
//=============================================================================
@@ -1170,17 +1174,46 @@ void HeightMapRenderObjClass::reset()
11701174
//=============================================================================
11711175
void HeightMapRenderObjClass::oversizeTerrain(Int tilesToOversize)
11721176
{
1177+
if (m_map == nullptr)
1178+
return;
1179+
11731180
Int width = WorldHeightMap::NORMAL_DRAW_WIDTH;
11741181
Int height = WorldHeightMap::NORMAL_DRAW_HEIGHT;
1175-
if (tilesToOversize>0 && tilesToOversize<5)
1182+
1183+
if (tilesToOversize>0)
11761184
{
11771185
width += VERTEX_BUFFER_TILE_LENGTH * tilesToOversize;
11781186
height += VERTEX_BUFFER_TILE_LENGTH * tilesToOversize;
11791187
if (width>m_map->getXExtent())
11801188
width = m_map->getXExtent();
11811189
if (height>m_map->getYExtent())
11821190
height = m_map->getYExtent();
1191+
1192+
m_oversizeWidth = width;
1193+
m_oversizeHeight = height;
11831194
}
1195+
else
1196+
{
1197+
m_oversizeWidth = 0;
1198+
m_oversizeHeight = 0;
1199+
}
1200+
1201+
setTerrainDrawSize(width, height);
1202+
}
1203+
1204+
void HeightMapRenderObjClass::setTerrainDrawSize(Int width, Int height)
1205+
{
1206+
if (m_map == nullptr)
1207+
return;
1208+
1209+
if (m_oversizeWidth != 0)
1210+
width = m_oversizeWidth;
1211+
if (m_oversizeHeight != 0)
1212+
height = m_oversizeHeight;
1213+
1214+
if (width == m_map->getDrawWidth() && height == m_map->getDrawHeight())
1215+
return;
1216+
11841217
Int dx = width-m_map->getDrawWidth();
11851218
Int dy = height-m_map->getDrawHeight();
11861219
m_map->setDrawWidth(width);

0 commit comments

Comments
 (0)