bugfix(heightmap): Fix full terrain rebuild on every frame when DrawEntireTerrain is enabled#2846
bugfix(heightmap): Fix full terrain rebuild on every frame when DrawEntireTerrain is enabled#2846xezon wants to merge 2 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp | Core logic change: adds m_desiredDrawWidth/Height, reworks setTerrainDrawSize and oversizeTerrain, moves m_updating = true before the full-map early-return. reset() still does not restore m_desiredDrawWidth/Height to defaults. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp | Adds getDesiredTerrainDrawSize() to unify DrawEntireTerrain, scripted-camera, and pitch-based sizing; updateTerrain always calls setTerrainDrawSize before updateCenter. Logic is clean and correctly handles the null-map guard. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp | Removes DrawEntireTerrain/stretchTerrain overrides from the constructor and createDrawArea, simplifying draw-area creation to a pure clamp of m_drawWidthX/Y to the map extent. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp | Replaces magic number 7 with TERRAIN_LOD_MAX and removes the dead == 5 (TERRAIN_LOD_STRETCH_CLOUDS) branch; correct after the enum pruning. |
| Core/GameEngine/Include/GameClient/TerrainVisual.h | Removes TERRAIN_LOD_STRETCH_NO_CLOUDS, TERRAIN_LOD_HALF_CLOUDS, TERRAIN_LOD_STRETCH_CLOUDS from enum and name table; consistent with all other removal sites. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | Updates calculateTerrainLOD fallback chain to skip the removed TERRAIN_LOD_HALF_CLOUDS step; TERRAIN_LOD_NO_WATER now falls directly to TERRAIN_LOD_DISABLE. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp | Removes a large commented-out block of legacy panel-tree rendering code that depended on m_useHalfHeightMap/m_stretchTerrain; no logic change. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant W3DView
participant HeightMapRenderObj
participant WorldHeightMap
Note over W3DView: Each render frame
W3DView->>W3DView: getDesiredTerrainDrawSize()
alt DrawEntireTerrain on
W3DView->>WorldHeightMap: getXExtent() / getYExtent()
WorldHeightMap-->>W3DView: full map dimensions
else user-controlled + low pitch
W3DView-->>W3DView: LOW_ANGLE_DRAW_WIDTH/HEIGHT
else scripted camera or normal pitch
W3DView-->>W3DView: NORMAL_DRAW_WIDTH/HEIGHT
end
W3DView->>HeightMapRenderObj: setTerrainDrawSize(w, h)
Note over HeightMapRenderObj: stores m_desiredDrawWidth/Height<br/>applies max with m_oversizeDrawWidth<br/>clamps to map extent
W3DView->>HeightMapRenderObj: updateCenter(camera, pivot, lights)
alt "draw area == full map extent"
HeightMapRenderObj->>HeightMapRenderObj: updateBlock() if m_needFullUpdate
else partial view
HeightMapRenderObj->>WorldHeightMap: createDrawArea(newOrgX, newOrgY)
HeightMapRenderObj->>HeightMapRenderObj: updateBlock() for deltas
end
Note over HeightMapRenderObj,WorldHeightMap: oversizeTerrain (scripted camera)
HeightMapRenderObj->>HeightMapRenderObj: oversizeTerrain(N)
HeightMapRenderObj->>HeightMapRenderObj: setTerrainDrawSize(0,0) triggers max with oversize
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant W3DView
participant HeightMapRenderObj
participant WorldHeightMap
Note over W3DView: Each render frame
W3DView->>W3DView: getDesiredTerrainDrawSize()
alt DrawEntireTerrain on
W3DView->>WorldHeightMap: getXExtent() / getYExtent()
WorldHeightMap-->>W3DView: full map dimensions
else user-controlled + low pitch
W3DView-->>W3DView: LOW_ANGLE_DRAW_WIDTH/HEIGHT
else scripted camera or normal pitch
W3DView-->>W3DView: NORMAL_DRAW_WIDTH/HEIGHT
end
W3DView->>HeightMapRenderObj: setTerrainDrawSize(w, h)
Note over HeightMapRenderObj: stores m_desiredDrawWidth/Height<br/>applies max with m_oversizeDrawWidth<br/>clamps to map extent
W3DView->>HeightMapRenderObj: updateCenter(camera, pivot, lights)
alt "draw area == full map extent"
HeightMapRenderObj->>HeightMapRenderObj: updateBlock() if m_needFullUpdate
else partial view
HeightMapRenderObj->>WorldHeightMap: createDrawArea(newOrgX, newOrgY)
HeightMapRenderObj->>HeightMapRenderObj: updateBlock() for deltas
end
Note over HeightMapRenderObj,WorldHeightMap: oversizeTerrain (scripted camera)
HeightMapRenderObj->>HeightMapRenderObj: oversizeTerrain(N)
HeightMapRenderObj->>HeightMapRenderObj: setTerrainDrawSize(0,0) triggers max with oversize
Reviews (2): Last reviewed commit: "bugfix(heightmap): Prevent full terrain ..." | Re-trigger Greptile
| Bool m_stretchTerrain; | ||
| Bool m_useHalfHeightMap; | ||
| Bool m_stretchTerrain; // TheSuperHackers @info Legacy, unused | ||
| Bool m_useHalfHeightMap; // TheSuperHackers @info Legacy, unused |
There was a problem hiding this comment.
I am not sure if it should be removed or left. The settings still exist in the game INI files, and this allows to see that it does nothing if someone searched for it.
|
|
||
| BaseHeightMapRenderObjClass *newROBJ = nullptr; | ||
| if (TheGlobalData->m_terrainLOD==7) { | ||
| if (TheGlobalData->m_terrainLOD == TERRAIN_LOD_MAX) { |
There was a problem hiding this comment.
7 previously referred to TERRAIN_LOD_MAX
| newROBJ = NEW_REF( FlatHeightMapRenderObjClass, () ); | ||
| } | ||
| } | ||
| if (TheGlobalData->m_terrainLOD == 5) |
There was a problem hiding this comment.
5 previously referred to enum value TERRAIN_LOD_STRETCH_CLOUDS, which was removed.
It set newROBJ to null which meant it would have leaked here. Very strange code.
…d Half Height Map (#2846)
…rawEntireTerrain is enabled (#2846)
2b94631 to
5ce335a
Compare
|
Thanks for taking this on, @xezon - I reviewed the branch locally and I'm happy to see it land in place of #2786. The approach here is cleaner than mine: making A few things I checked while reviewing: • I also confirmed it carries over the the branch doesn't compile for the base Generals target (Zero Hour / GeneralsMD builds fine). The chore commit ( ffe9ce6 ) removes Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp:1646
case TERRAIN_LOD_HALF_CLOUDS: curLOD = TERRAIN_LOD_DISABLE; break;
case TERRAIN_LOD_NO_WATER: curLOD = TERRAIN_LOD_HALF_CLOUDS; break;So the base-game compile fails with The fix is just to mirror the GeneralsMD change — collapse those two lines to: case TERRAIN_LOD_NO_WATER: curLOD = TERRAIN_LOD_DISABLE; break;That's the only dangling reference I found - grepping the tree, the removed LGTM from my side. Thanks for the cleanup commit too — good to see the dead stretch-terrain / half-height-map paths finally gone ! |
Merge with Rebase
This change fixes the terrain update for DrawEntireTerrain.
It has 2 commits:
The first commit removes the legacy and unused code for stretched terrain and half height map.
The second commit fixes the terrain update for DrawEntireTerrain. W3DView tells the HeightMapRenderObjClass which size to use. The terrain oversize logic for the scripted camera was adapted to indirectly account for DrawEntireTerrain as well. All DrawEntireTerrain specific knowledge was removed from height map.
TODO