Skip to content

Commit 8112ded

Browse files
authored
refactor(heightmap): Remove HALF_RES_MESH because it was never used and is broken (#2076)
1 parent 3e8c472 commit 8112ded

File tree

10 files changed

+57
-131
lines changed

10 files changed

+57
-131
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ class WorldHeightMap : public RefCountClass,
188188
TileData *getSourceTile(UnsignedInt ndx) { if (ndx<NUM_SOURCE_TILES) return(m_sourceTiles[ndx]); return(NULL); };
189189
TileData *getEdgeTile(UnsignedInt ndx) { if (ndx<NUM_SOURCE_TILES) return(m_edgeTiles[ndx]); return(NULL); };
190190
/// UV mapping data for a cell to map into the terrain texture.
191-
void getUVForNdx(Int ndx, float *minU, float *minV, float *maxU, float*maxV, Bool fullTile);
192-
Bool getUVForTileIndex(Int ndx, Short tileNdx, float U[4], float V[4], Bool fullTile);
191+
void getUVForNdx(Int ndx, float *minU, float *minV, float *maxU, float*maxV);
192+
Bool getUVForTileIndex(Int ndx, Short tileNdx, float U[4], float V[4]);
193193
Int getTextureClassFromNdx(Int tileNdx);
194194
void readTexClass(TXTextureClass *texClass, TileData **tileData);
195195
Int updateTileTexturePositions(Int *edgeHeight); ///< Places each tile in the texture.
@@ -267,7 +267,7 @@ class WorldHeightMap : public RefCountClass,
267267
TextureClass *getAlphaTerrainTexture(void); //< generates if needed and returns alpha terrain texture
268268
TextureClass *getEdgeTerrainTexture(void); //< generates if needed and returns blend edge texture
269269
/// UV mapping data for a cell to map into the terrain texture. Returns true if the textures had to be stretched for cliffs.
270-
Bool getUVData(Int xIndex, Int yIndex, float U[4], float V[4], Bool fullTile);
270+
Bool getUVData(Int xIndex, Int yIndex, float U[4], float V[4]);
271271
Bool getFlipState(Int xIndex, Int yIndex) const;
272272
///Faster version of above function without all the safety checks - For people that do checks externally.
273273
Bool getQuickFlipState(Int xIndex, Int yIndex) const
@@ -280,7 +280,7 @@ class WorldHeightMap : public RefCountClass,
280280
Bool getCliffState(Int xIndex, Int yIndex) const;
281281
Bool getExtraAlphaUVData(Int xIndex, Int yIndex, float U[4], float V[4], UnsignedByte alpha[4], Bool *flip, Bool *cliff);
282282
/// UV mapping data for a cell to map into the alpha terrain texture.
283-
void getAlphaUVData(Int xIndex, Int yIndex, float U[4], float V[4], UnsignedByte alpha[4], Bool *flip, Bool fullTile);
283+
void getAlphaUVData(Int xIndex, Int yIndex, float U[4], float V[4], UnsignedByte alpha[4], Bool *flip);
284284
void getTerrainColorAt(Real x, Real y, RGBColor *pColor);
285285
AsciiString getTerrainNameAt(Real x, Real y);
286286
Bool isCliffMappedTexture(Int xIndex, Int yIndex);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ void BaseHeightMapRenderObjClass::updateScorches(void)
19911991
#if 0
19921992
UnsignedByte alpha[4];
19931993
float UA[4], VA[4];
1994-
m_map->getAlphaUVData(xNdx, yNdx, UA, VA, alpha, &flipForBlend, false);
1994+
m_map->getAlphaUVData(xNdx, yNdx, UA, VA, alpha, &flipForBlend);
19951995
#endif
19961996
if (flipForBlend) {
19971997
*curIb++ = startVertex + j*yOffset + i+1;
@@ -2089,7 +2089,7 @@ Int BaseHeightMapRenderObjClass::getStaticDiffuse(Int x, Int y)
20892089

20902090
Vector3 l2r,n2f,normalAtTexel;
20912091
Int vn0,un0,vp1,up1;
2092-
const Int cellOffset = 1;
2092+
constexpr const Int cellOffset = 1;
20932093

20942094
vn0 = y-cellOffset;
20952095
vp1 = y+cellOffset;

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

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@
9595
#define no_OPTIMIZED_HEIGHTMAP_LIGHTING 01
9696
// Doesn't work well. jba.
9797

98-
const Bool HALF_RES_MESH = false;
99-
10098
HeightMapRenderObjClass *TheHeightMap = NULL;
10199
//-----------------------------------------------------------------------------
102100
// Private Data
@@ -308,12 +306,8 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, char *data, Int
308306
Int xCoord, yCoord;
309307
Int vn0,un0,vp1,up1;
310308
Vector3 l2r,n2f,normalAtTexel;
311-
Int vertsPerRow=(VERTEX_BUFFER_TILE_LENGTH)*4; //vertices per row of VB
312-
313-
Int cellOffset = 1;
314-
if (HALF_RES_MESH) {
315-
cellOffset = 2;
316-
}
309+
constexpr const Int vertsPerRow=(VERTEX_BUFFER_TILE_LENGTH)*4; //vertices per row of VB
310+
constexpr const Int cellOffset = 1;
317311

318312
REF_PTR_SET(m_map, pMap); //update our heightmap pointer in case it changed since last call.
319313
if (m_vertexBufferTiles && pMap)
@@ -332,14 +326,9 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, char *data, Int
332326
for (j=y0; j<y1; j++)
333327
{
334328
VERTEX_FORMAT *vb = vBase;
335-
if (HALF_RES_MESH) {
336-
if (j&1) continue;
337-
vb += ((j-originY)/2)*vertsPerRow/2; //skip to correct row in vertex buffer
338-
vb += ((x0-originX)/2)*4; //skip to correct vertex in row.
339-
} else {
340-
vb += (j-originY)*vertsPerRow; //skip to correct row in vertex buffer
341-
vb += (x0-originX)*4; //skip to correct vertex in row.
342-
}
329+
vb += (j-originY)*vertsPerRow; //skip to correct row in vertex buffer
330+
vb += (x0-originX)*4; //skip to correct vertex in row.
331+
343332
vn0 = getYWithOrigin(j)-cellOffset;
344333
if (vn0 < -pMap->getDrawOrgY())
345334
vn0=-pMap->getDrawOrgY();
@@ -350,9 +339,6 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, char *data, Int
350339
yCoord = getYWithOrigin(j)+pMap->getDrawOrgY();
351340
for (i=x0; i<x1; i++)
352341
{
353-
if (HALF_RES_MESH) {
354-
if (i&1) continue;
355-
}
356342
un0 = getXWithOrigin(i)-cellOffset;
357343
if (un0 < -pMap->getDrawOrgX())
358344
un0=-pMap->getDrawOrgX();
@@ -368,8 +354,8 @@ Int HeightMapRenderObjClass::updateVB(DX8VertexBufferClass *pVB, char *data, Int
368354
Bool flipForBlend = false; // True if the blend needs the triangles flipped.
369355

370356
if (pMap) {
371-
pMap->getUVData(getXWithOrigin(i),getYWithOrigin(j),U, V, HALF_RES_MESH);
372-
pMap->getAlphaUVData(getXWithOrigin(i),getYWithOrigin(j), UA, VA, alpha, &flipForBlend, HALF_RES_MESH);
357+
pMap->getUVData(getXWithOrigin(i),getYWithOrigin(j),U, V);
358+
pMap->getAlphaUVData(getXWithOrigin(i),getYWithOrigin(j), UA, VA, alpha, &flipForBlend);
373359
}
374360

375361

@@ -569,7 +555,7 @@ Int HeightMapRenderObjClass::updateVBForLight(DX8VertexBufferClass *pVB, char *d
569555
Int i,j,k;
570556
Int vn0,un0,vp1,up1;
571557
Vector3 l2r,n2f,normalAtTexel;
572-
Int vertsPerRow=(VERTEX_BUFFER_TILE_LENGTH)*4; //vertices per row of VB
558+
constexpr const Int vertsPerRow=(VERTEX_BUFFER_TILE_LENGTH)*4; //vertices per row of VB
573559

574560
if (m_vertexBufferTiles && m_map)
575561
{
@@ -583,9 +569,6 @@ Int HeightMapRenderObjClass::updateVBForLight(DX8VertexBufferClass *pVB, char *d
583569

584570
for (j=y0; j<y1; j++)
585571
{
586-
if (HALF_RES_MESH) {
587-
if (j&1) continue;
588-
}
589572
Int yCoord = getYWithOrigin(j)+m_map->getDrawOrgY()-m_map->getBorderSizeInline();
590573
Bool intersect = false;
591574
for (k=0; k<numLights; k++) {
@@ -610,9 +593,6 @@ Int HeightMapRenderObjClass::updateVBForLight(DX8VertexBufferClass *pVB, char *d
610593

611594
for (i=x0; i<x1; i++)
612595
{
613-
if (HALF_RES_MESH) {
614-
if (i&1) continue;
615-
}
616596
Int xCoord = getXWithOrigin(i)+m_map->getDrawOrgX()-m_map->getBorderSizeInline();
617597
Bool intersect = false;
618598
for (k=0; k<numLights; k++) {
@@ -634,9 +614,6 @@ Int HeightMapRenderObjClass::updateVBForLight(DX8VertexBufferClass *pVB, char *d
634614
}
635615
// vb is the pointer to the vertex in the hardware dx8 vertex buffer.
636616
Int offset = (j-originY)*vertsPerRow+4*(i-originX);
637-
if (HALF_RES_MESH) {
638-
offset = (j-originY)*vertsPerRow/4+2*(i-originX);
639-
}
640617
vb = vBase + offset; //skip to correct row in vertex buffer
641618
// vbMirror is the pointer to the vertex in our memory based copy.
642619
// The important point is that we can read out of our copy to get the original
@@ -716,7 +693,7 @@ Int HeightMapRenderObjClass::updateVBForLightOptimized(DX8VertexBufferClass *pVB
716693
Int i,j,k;
717694
Int vn0,un0,vp1,up1;
718695
Vector3 l2r,n2f,normalAtTexel;
719-
Int vertsPerRow=(VERTEX_BUFFER_TILE_LENGTH)*4; //vertices per row of VB
696+
constexpr const Int vertsPerRow=(VERTEX_BUFFER_TILE_LENGTH)*4; //vertices per row of VB
720697

721698
if (m_vertexBufferTiles && m_map)
722699
{
@@ -735,32 +712,16 @@ Int HeightMapRenderObjClass::updateVBForLightOptimized(DX8VertexBufferClass *pVB
735712
// the formula's that Generals is using but in the case of the "half-res-mesh" I'm not
736713
// sure things are correct...
737714
//
738-
Int quad_right_offset;
739-
Int quad_below_offset;
740-
Int quad_below_right_offset;
741-
742-
if (HALF_RES_MESH == false) {
743-
// offset = (j-originY)*vertsPerRow+4*(i-originX);
744-
quad_right_offset = 4;
745-
quad_below_offset = vertsPerRow;
746-
quad_below_right_offset = vertsPerRow + 4;
747-
748-
} else {
749-
// offset = (j-originY)*vertsPerRow/4+2*(i-originX);
750-
quad_right_offset = 2;
751-
quad_below_offset = vertsPerRow/4;
752-
quad_below_right_offset = vertsPerRow/4 + 2;
753-
}
715+
constexpr const Int quad_right_offset = 4;
716+
constexpr const Int quad_below_offset = vertsPerRow;
717+
//constexpr const Int quad_below_right_offset = vertsPerRow + 4;
754718

755719
//
756720
// i,j loop over the quads affected by the light. Each quad has its *own* 4 vertices. This
757721
// means that for any vertex position on the map, there are actually 4 copies of the vertex.
758722
//
759723
for (j=y0; j<y1; j++)
760724
{
761-
if (HALF_RES_MESH) {
762-
if (j&1) continue;
763-
}
764725
Int yCoord = getYWithOrigin(j)+m_map->getDrawOrgY()-m_map->getBorderSizeInline();
765726
Bool intersect = false;
766727
for (k=0; k<numLights; k++) {
@@ -785,9 +746,6 @@ Int HeightMapRenderObjClass::updateVBForLightOptimized(DX8VertexBufferClass *pVB
785746

786747
for (i=x0; i<x1; i++)
787748
{
788-
if (HALF_RES_MESH) {
789-
if (i&1) continue;
790-
}
791749
Int xCoord = getXWithOrigin(i)+m_map->getDrawOrgX()-m_map->getBorderSizeInline();
792750
Bool intersect = false;
793751
for (k=0; k<numLights; k++) {
@@ -809,9 +767,6 @@ Int HeightMapRenderObjClass::updateVBForLightOptimized(DX8VertexBufferClass *pVB
809767
}
810768
// vb is the pointer to the vertex in the hardware dx8 vertex buffer.
811769
Int offset = (j-originY)*vertsPerRow+4*(i-originX);
812-
if (HALF_RES_MESH) {
813-
offset = (j-originY)*vertsPerRow/4+2*(i-originX);
814-
}
815770
vb = vBase + offset; //skip to correct row in vertex buffer
816771
// vbMirror is the pointer to the vertex in our memory based copy.
817772
// The important point is that we can read out of our copy to get the original
@@ -1704,10 +1659,8 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera , RefRenderObjLis
17041659
return; // no need to center.
17051660
}
17061661

1707-
Int cellOffset = 1;
1708-
if (HALF_RES_MESH) {
1709-
cellOffset = 2;
1710-
}
1662+
constexpr const Int cellOffset = 1;
1663+
17111664
// determine the ray corresponding to the camera and distance to projection plane
17121665
Matrix3D camera_matrix = camera->Get_Transform();
17131666

@@ -1813,10 +1766,6 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera , RefRenderObjLis
18131766
newOrgX = (visMaxX+visMinX)/2-m_x/2.0;
18141767
newOrgY = (visMaxY+visMinY)/2-m_y/2.0;
18151768
}
1816-
if (HALF_RES_MESH) {
1817-
newOrgX &= 0xFFFFFFFE;
1818-
newOrgY &= 0xFFFFFFFE;
1819-
}
18201769
Int deltaX = newOrgX - m_map->getDrawOrgX();
18211770
Int deltaY = newOrgY - m_map->getDrawOrgY();
18221771
if (IABS(deltaX) > m_x/2 || IABS(deltaY)>m_x/2) {
@@ -2069,10 +2018,6 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
20692018
count++;
20702019
Int numPolys = VERTEX_BUFFER_TILE_LENGTH*VERTEX_BUFFER_TILE_LENGTH*2;
20712020
Int numVertex = (VERTEX_BUFFER_TILE_LENGTH*2)*(VERTEX_BUFFER_TILE_LENGTH*2);
2072-
if (HALF_RES_MESH) {
2073-
numPolys /= 4;
2074-
numVertex /= 4;
2075-
}
20762021
DX8Wrapper::Set_Vertex_Buffer(m_vertexBufferTiles[j*m_numVBTilesX+i]);
20772022
#ifdef PRE_TRANSFORM_VERTEX
20782023
if (m_xformedVertexBuffer && pass==0) {
@@ -2207,10 +2152,6 @@ void HeightMapRenderObjClass::renderTerrainPass(CameraClass *pCamera)
22072152
count++;
22082153
Int numPolys = VERTEX_BUFFER_TILE_LENGTH*VERTEX_BUFFER_TILE_LENGTH*2;
22092154
Int numVertex = (VERTEX_BUFFER_TILE_LENGTH*2)*(VERTEX_BUFFER_TILE_LENGTH*2);
2210-
if (HALF_RES_MESH) {
2211-
numPolys /= 4;
2212-
numVertex /= 4;
2213-
}
22142155
DX8Wrapper::Set_Vertex_Buffer(m_vertexBufferTiles[j*m_numVBTilesX+i]);
22152156
#ifdef PRE_TRANSFORM_VERTEX
22162157
if (m_xformedVertexBuffer && pass==0) {

0 commit comments

Comments
 (0)