Skip to content

Commit 83ca91b

Browse files
refactor(baseheightmap): Extract scorch rendering from BaseHeightMap into new W3DScorch (#3017)
1 parent 71a8c9e commit 83ca91b

7 files changed

Lines changed: 389 additions & 270 deletions

File tree

Core/GameEngineDevice/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ set(GAMEENGINEDEVICE_SRC
5858
Include/W3DDevice/GameClient/W3DProfilerFrameCapture.h
5959
# Include/W3DDevice/GameClient/W3DProjectedShadow.h
6060
Include/W3DDevice/GameClient/W3DPropBuffer.h
61+
Include/W3DDevice/GameClient/W3DScorch.h
6162
# Include/W3DDevice/GameClient/W3DRoadBuffer.h
6263
# Include/W3DDevice/GameClient/W3DScene.h
6364
Include/W3DDevice/GameClient/W3DShaderManager.h
@@ -161,6 +162,7 @@ set(GAMEENGINEDEVICE_SRC
161162
# Source/W3DDevice/GameClient/W3DPoly.cpp
162163
Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp
163164
Source/W3DDevice/GameClient/W3DPropBuffer.cpp
165+
Source/W3DDevice/GameClient/W3DScorch.cpp
164166
# Source/W3DDevice/GameClient/W3DRoadBuffer.cpp
165167
# Source/W3DDevice/GameClient/W3DScene.cpp
166168
Source/W3DDevice/GameClient/W3DShaderManager.cpp

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

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class W3DWaypointBuffer;
4646
class W3DTerrainLogic;
4747
class W3DAssetManager;
4848
class SimpleSceneClass;
49+
class W3DScorchInterface;
4950
class W3DShroud;
5051
class W3DPropDrawModuleData;
5152
class W3DPropBuffer;
@@ -70,14 +71,6 @@ class W3DDynamicLight;
7071

7172
#define DO_ROADS 1
7273

73-
#ifdef DO_SCORCH
74-
typedef struct {
75-
Vector3 location;
76-
Real radius;
77-
Int scorchType;
78-
} TScorch;
79-
#endif
80-
8174
#define VERTEX_FORMAT VertexFormatXYZDUV2
8275
#define DX8_VERTEX_FORMAT DX8_FVF_XYZDUV2
8376

@@ -195,6 +188,7 @@ class BaseHeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHoo
195188
void updateShorelineTile(Int X, Int Y, Int Border, WorldHeightMap *pMap); ///<figure out which tiles on this map cross water plane
196189
void recordShoreLineSortInfos();
197190
void updateViewImpassableAreas(Bool partial = FALSE, Int minX = 0, Int maxX = 0, Int minY = 0, Int maxY = 0);
191+
void drawScorches();
198192
void clearAllScorches();
199193
void setTimeOfDay( TimeOfDay tod );
200194
void loadRoadsAndBridges(W3DTerrainLogic *pTerrainLogic, Bool saveGame); ///< Load the roads from the map objects.
@@ -240,30 +234,7 @@ class BaseHeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHoo
240234
Int m_x; ///< dimensions of heightmap
241235
Int m_y; ///< dimensions of heightmap
242236

243-
#ifdef DO_SCORCH
244-
enum { MAX_SCORCH_VERTEX=8194,
245-
MAX_SCORCH_INDEX=6*8194,
246-
MAX_SCORCH_MARKS=500,
247-
SCORCH_MARKS_IN_TEXTURE=9,
248-
SCORCH_PER_ROW = 3};
249-
DX8VertexBufferClass *m_vertexScorch; ///<Scorch vertex buffer.
250-
DX8IndexBufferClass *m_indexScorch; ///<indices defining a triangles for the scorch drawing.
251-
TextureClass *m_scorchTexture; ///<Scorch mark texture
252-
Int m_curNumScorchVertices; ///<number of vertices used in m_vertexScorch.
253-
Int m_curNumScorchIndices; ///<number of indices used in m_indexScorch.
254-
TScorch m_scorches[MAX_SCORCH_MARKS];
255-
Int m_numScorches;
256-
257-
Int m_scorchesInBuffer; ///< how many are in the buffers. If less than numScorches, we need to update
258-
259-
// NOTE: This argument (contrary to most of the rest of the engine), is in degrees, not radians.
260-
Real m_curImpassableSlope;
261-
262-
void updateScorches(); ///<Update m_vertexScorch and m_indexScorch so all scorches will be drawn.
263-
void allocateScorchBuffers(); ///<allocate static buffers for drawing scorch marks.
264-
void freeScorchBuffers(); ///< frees up scorch buffers.
265-
void drawScorches(); ///< Draws the scorch mark polygons in m_vertexScorch.
266-
#endif
237+
Real m_curImpassableSlope; // NOTE: This argument (contrary to most of the rest of the engine), is in degrees, not radians.
267238
WorldHeightMap *m_map;
268239
Bool m_useDepthFade; ///<fade terrain lighting under water
269240
Bool m_updating;
@@ -296,6 +267,7 @@ class BaseHeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHoo
296267
W3DRoadBuffer *m_roadBuffer; ///< Class for drawing roads.
297268
#endif
298269
W3DBridgeBuffer *m_bridgeBuffer;
270+
W3DScorchInterface *m_scorches;
299271
W3DShroud *m_shroud; ///< Class for drawing the shroud over terrain.
300272
struct shoreLineTileInfo
301273
{ Int m_xy; //x,y position of tile
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2026 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#include "WWMath/vector3.h"
22+
#include "Common/GameType.h"
23+
#include "Lib/BaseTypeCore.h"
24+
25+
class TextureClass;
26+
class DX8IndexBufferClass;
27+
class DX8VertexBufferClass;
28+
class WorldHeightMap;
29+
30+
class W3DScorchInterface
31+
{
32+
public:
33+
virtual ~W3DScorchInterface() {}
34+
35+
virtual void allocateBuffers() = 0;
36+
virtual void freeBuffers() = 0;
37+
virtual void clearAllScorches() = 0;
38+
virtual void invalidateBuffers() = 0;
39+
virtual void addScorch(Vector3 location, Real radius, Scorches type) = 0;
40+
virtual void drawScorches(WorldHeightMap& map) = 0;
41+
};
42+
43+
class W3DScorch : public W3DScorchInterface
44+
{
45+
public:
46+
W3DScorch();
47+
virtual ~W3DScorch() override;
48+
49+
virtual void allocateBuffers() override; ///< allocate static buffers for drawing scorch marks.
50+
virtual void freeBuffers() override; ///< frees up scorch buffers.
51+
virtual void clearAllScorches() override;
52+
virtual void invalidateBuffers() override;
53+
virtual void addScorch(Vector3 location, Real radius, Scorches type) override;
54+
virtual void drawScorches(WorldHeightMap& map) override; ///< Draws the scorch mark polygons in m_vertexScorch.
55+
56+
private:
57+
typedef struct
58+
{
59+
Vector3 location;
60+
Real radius;
61+
Int scorchType;
62+
} TScorch;
63+
64+
enum
65+
{
66+
MAX_SCORCH_VERTEX = 8194,
67+
MAX_SCORCH_INDEX = 6 * 8194,
68+
MAX_SCORCH_MARKS = 500,
69+
SCORCH_MARKS_IN_TEXTURE = 9,
70+
SCORCH_PER_ROW = 3
71+
};
72+
73+
void updateScorches(WorldHeightMap& map); ///< Update m_vertexScorch and m_indexScorch so all scorches will be drawn.
74+
75+
DX8VertexBufferClass* m_vertexScorch; ///< Scorch vertex buffer.
76+
DX8IndexBufferClass* m_indexScorch; ///< indices defining a triangles for the scorch drawing.
77+
TextureClass* m_scorchTexture; ///< Scorch mark texture
78+
Int m_curNumScorchVertices; ///< number of vertices used in m_vertexScorch.
79+
Int m_curNumScorchIndices; ///< number of indices used in m_indexScorch.
80+
TScorch m_scorches[MAX_SCORCH_MARKS];
81+
Int m_numScorches;
82+
Int m_scorchesInBuffer; ///< how many are in the buffers. If less than numScorches, we need to update
83+
};
84+
85+
class W3DScorchDummy : public W3DScorchInterface
86+
{
87+
public:
88+
virtual void allocateBuffers() override {}
89+
virtual void freeBuffers() override {}
90+
virtual void clearAllScorches() override {}
91+
virtual void invalidateBuffers() override {}
92+
virtual void addScorch(Vector3, Real, Scorches) override {}
93+
virtual void drawScorches(WorldHeightMap&) override {}
94+
};

0 commit comments

Comments
 (0)