-
Notifications
You must be signed in to change notification settings - Fork 221
bugfix(heightmap): Fix full terrain rebuild on every frame when DrawEntireTerrain is enabled #2846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,7 +340,7 @@ void BaseHeightMapRenderObjClass::adjustTerrainLOD(Int adj) | |
| m_shroud->reset(); //need reset here since initHeightData will load new shroud. | ||
|
|
||
| BaseHeightMapRenderObjClass *newROBJ = nullptr; | ||
| if (TheGlobalData->m_terrainLOD==7) { | ||
| if (TheGlobalData->m_terrainLOD == TERRAIN_LOD_MAX) { | ||
| newROBJ = TheHeightMap; | ||
| if (newROBJ==nullptr) { | ||
| newROBJ = NEW_REF( HeightMapRenderObjClass, () ); | ||
|
|
@@ -351,8 +351,7 @@ void BaseHeightMapRenderObjClass::adjustTerrainLOD(Int adj) | |
| newROBJ = NEW_REF( FlatHeightMapRenderObjClass, () ); | ||
| } | ||
| } | ||
| if (TheGlobalData->m_terrainLOD == 5) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5 previously referred to enum value It set |
||
| newROBJ = nullptr; | ||
|
|
||
| RTS3DScene *pMyScene = (RTS3DScene *)Scene; | ||
| if (pMyScene) { | ||
| pMyScene->Remove_Render_Object(this); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1048,6 +1048,8 @@ m_vertexBufferTiles(nullptr), | |
| m_vertexBufferBackup(nullptr), | ||
| m_originX(0), | ||
| m_originY(0), | ||
| m_desiredDrawWidth(WorldHeightMap::NORMAL_DRAW_WIDTH), | ||
| m_desiredDrawHeight(WorldHeightMap::NORMAL_DRAW_HEIGHT), | ||
| m_oversizeDrawWidth(0), | ||
| m_oversizeDrawHeight(0), | ||
| m_indexBuffer(nullptr), | ||
|
|
@@ -1081,45 +1083,19 @@ void HeightMapRenderObjClass::adjustTerrainLOD(Int adj) | |
| case TERRAIN_LOD_MIN: TheWritableGlobalData->m_useCloudMap = false; | ||
| TheWritableGlobalData->m_useLightMap = false ; | ||
| TheWritableGlobalData->m_useWaterPlane = false; | ||
| TheWritableGlobalData->m_stretchTerrain = false; | ||
| TheWritableGlobalData->m_useHalfHeightMap = true; | ||
| break; | ||
| case TERRAIN_LOD_HALF_CLOUDS: TheWritableGlobalData->m_useCloudMap = true; | ||
| TheWritableGlobalData->m_useLightMap = true; | ||
| TheWritableGlobalData->m_useWaterPlane = false; | ||
| TheWritableGlobalData->m_stretchTerrain = false; | ||
| TheWritableGlobalData->m_useHalfHeightMap = true; | ||
| break; | ||
| case TERRAIN_LOD_STRETCH_NO_CLOUDS: TheWritableGlobalData->m_useCloudMap = false; | ||
| TheWritableGlobalData->m_useLightMap = false; | ||
| TheWritableGlobalData->m_useWaterPlane = false; | ||
| TheWritableGlobalData->m_stretchTerrain = true; | ||
| TheWritableGlobalData->m_useHalfHeightMap = false; | ||
| break; | ||
| case TERRAIN_LOD_STRETCH_CLOUDS: TheWritableGlobalData->m_useCloudMap = true; | ||
| TheWritableGlobalData->m_useLightMap = true; | ||
| TheWritableGlobalData->m_useWaterPlane = false; | ||
| TheWritableGlobalData->m_stretchTerrain = true; | ||
| TheWritableGlobalData->m_useHalfHeightMap = false; | ||
| break; | ||
| case TERRAIN_LOD_NO_CLOUDS: TheWritableGlobalData->m_useCloudMap = false; | ||
| TheWritableGlobalData->m_useLightMap = false; | ||
| TheWritableGlobalData->m_useWaterPlane = false; | ||
| TheWritableGlobalData->m_stretchTerrain = false; | ||
| TheWritableGlobalData->m_useHalfHeightMap = false; | ||
| break; | ||
| default: | ||
| case TERRAIN_LOD_NO_WATER: TheWritableGlobalData->m_useCloudMap = true; | ||
| TheWritableGlobalData->m_useLightMap = true; | ||
| TheWritableGlobalData->m_useWaterPlane = false; | ||
| TheWritableGlobalData->m_stretchTerrain = false; | ||
| TheWritableGlobalData->m_useHalfHeightMap = false; | ||
| break; | ||
| case TERRAIN_LOD_MAX: TheWritableGlobalData->m_useCloudMap = true; | ||
| TheWritableGlobalData->m_useLightMap = true; | ||
| TheWritableGlobalData->m_useWaterPlane = true; | ||
| TheWritableGlobalData->m_stretchTerrain = false; | ||
| TheWritableGlobalData->m_useHalfHeightMap = false; | ||
| break; | ||
| } | ||
| if (m_map==nullptr) return; | ||
|
|
@@ -1178,17 +1154,13 @@ void HeightMapRenderObjClass::oversizeTerrain(Int tilesToOversize) | |
| { | ||
| m_oversizeDrawWidth = WorldHeightMap::NORMAL_DRAW_WIDTH + VERTEX_BUFFER_TILE_LENGTH * tilesToOversize; | ||
| m_oversizeDrawHeight = WorldHeightMap::NORMAL_DRAW_HEIGHT + VERTEX_BUFFER_TILE_LENGTH * tilesToOversize; | ||
| m_oversizeDrawWidth = std::min(m_oversizeDrawWidth, m_map->getXExtent()); | ||
| m_oversizeDrawHeight = std::min(m_oversizeDrawHeight, m_map->getYExtent()); | ||
| setTerrainDrawSize(m_oversizeDrawWidth, m_oversizeDrawHeight); | ||
| setTerrainDrawSize(0, 0); | ||
| } | ||
| else | ||
| { | ||
| m_oversizeDrawWidth = 0; | ||
| m_oversizeDrawHeight = 0; | ||
| Int width = std::min((Int)WorldHeightMap::NORMAL_DRAW_WIDTH, m_map->getXExtent()); | ||
| Int height = std::min((Int)WorldHeightMap::NORMAL_DRAW_HEIGHT, m_map->getYExtent()); | ||
| setTerrainDrawSize(width, height); | ||
| setTerrainDrawSize(m_desiredDrawWidth, m_desiredDrawHeight); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1197,15 +1169,17 @@ void HeightMapRenderObjClass::setTerrainDrawSize(Int width, Int height) | |
| if (m_map == nullptr) | ||
| return; | ||
|
|
||
| if (m_oversizeDrawWidth != 0) | ||
| width = m_oversizeDrawWidth; | ||
| else | ||
| width = std::min(width, m_map->getXExtent()); | ||
| if (width > 0) | ||
| m_desiredDrawWidth = width; | ||
|
|
||
| if (m_oversizeDrawHeight != 0) | ||
| height = m_oversizeDrawHeight; | ||
| else | ||
| height = std::min(height, m_map->getYExtent()); | ||
| if (height > 0) | ||
| m_desiredDrawHeight = height; | ||
|
|
||
| width = std::max(m_oversizeDrawWidth, m_desiredDrawWidth); | ||
| height = std::max(m_oversizeDrawHeight, m_desiredDrawHeight); | ||
|
|
||
| width = std::min(width, m_map->getXExtent()); | ||
| height = std::min(height, m_map->getYExtent()); | ||
|
|
||
| if (width == m_map->getDrawWidth() && height == m_map->getDrawHeight()) | ||
| return; | ||
|
|
@@ -1670,8 +1644,17 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera, const Vector3 *c | |
|
|
||
| BaseHeightMapRenderObjClass::updateCenter(camera, cameraPivot, pLightsIterator); | ||
|
|
||
| m_updating = true; | ||
|
|
||
| if (m_x >= m_map->getXExtent() && m_y >= m_map->getYExtent()) | ||
| { | ||
| { | ||
| if (m_needFullUpdate) | ||
| { | ||
| m_needFullUpdate = false; | ||
| updateBlock(0, 0, m_x-1, m_y-1, m_map, pLightsIterator); | ||
| } | ||
|
|
||
| m_updating = false; | ||
|
Comment on lines
+1647
to
+1657
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain what this code does & why it does what it does? |
||
| return; // no need to center. | ||
| } | ||
|
|
||
|
|
@@ -1792,7 +1775,6 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera, const Vector3 *c | |
|
|
||
| WorldHeightMap::DrawArea newDrawArea = m_map->createDrawArea(newOrgX, newOrgY); | ||
|
|
||
| m_updating = true; | ||
| if (m_needFullUpdate) | ||
| { | ||
| m_needFullUpdate = false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3717,30 +3717,58 @@ void W3DView::Add_Camera_Shake (const Coord3D & position,float radius,float dura | |
| CameraShakerSystem.Add_Camera_Shake(vpos,radius,duration,power); | ||
| } | ||
|
|
||
| bool W3DView::getDesiredTerrainDrawSize(ICoord2D &dimensions) const | ||
| { | ||
| if (TheGlobalData && TheGlobalData->m_drawEntireTerrain) | ||
| { | ||
| DEBUG_ASSERTCRASH(TheTerrainRenderObject != nullptr, ("TheTerrainRenderObject is null")); | ||
|
|
||
| if (WorldHeightMap *heightMap = TheTerrainRenderObject->getMap()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be made
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
| { | ||
| dimensions.x = heightMap->getXExtent(); | ||
| dimensions.y = heightMap->getYExtent(); | ||
| return true; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| const Real cameraPitch = asin(fabs(m_3DCamera->Get_Forward_Dir().Z)); | ||
|
|
||
| if (cameraPitch > ViewDefaultLowPitchRadians || !m_isUserControlled) | ||
| { | ||
| // TheSuperHackers @info The scripted camera always uses the regular draw sizes | ||
| // and uses terrain oversize if it needs to enlarge. | ||
| dimensions.x = WorldHeightMap::NORMAL_DRAW_WIDTH; | ||
| dimensions.y = WorldHeightMap::NORMAL_DRAW_HEIGHT; | ||
| return true; | ||
| } | ||
| else | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
| { | ||
| // TheSuperHackers @tweak xezon 31/12/2025 Increases visible terrain area when lowering the camera pitch. | ||
| // Note: The default camera pitch in Generals was 37.5, which we prefer to keep the normal draw size for. | ||
| dimensions.x = WorldHeightMap::LOW_ANGLE_DRAW_WIDTH; | ||
| dimensions.y = WorldHeightMap::LOW_ANGLE_DRAW_HEIGHT; | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| void W3DView::updateTerrain() | ||
| { | ||
| DEBUG_ASSERTCRASH(TheTerrainRenderObject != nullptr, ("TheTerrainRenderObject is null")); | ||
|
|
||
| RefRenderObjListIterator *it = W3DDisplay::m_3DScene->createLightsIterator(); | ||
| const Vector3 cameraPivot(m_pos.x, m_pos.y, m_pos.z); | ||
| const Real cameraPitch = asin(fabs(m_3DCamera->Get_Forward_Dir().Z)); | ||
| Int drawWidth; | ||
| Int drawHeight; | ||
| ICoord2D drawSize; | ||
|
|
||
| if (cameraPitch > ViewDefaultLowPitchRadians) | ||
| { | ||
| drawWidth = WorldHeightMap::NORMAL_DRAW_WIDTH; | ||
| drawHeight = WorldHeightMap::NORMAL_DRAW_HEIGHT; | ||
| } | ||
| else | ||
| if (getDesiredTerrainDrawSize(drawSize)) | ||
| { | ||
| // TheSuperHackers @tweak xezon 31/12/2025 Increases visible terrain area when lowering the camera pitch. | ||
| // Note: The default camera pitch in Generals was 37.5, which we prefer to keep the normal draw size for. | ||
| drawWidth = WorldHeightMap::LOW_ANGLE_DRAW_WIDTH; | ||
| drawHeight = WorldHeightMap::LOW_ANGLE_DRAW_HEIGHT; | ||
| TheTerrainRenderObject->setTerrainDrawSize(drawSize.x, drawSize.y); | ||
| } | ||
|
|
||
| TheTerrainRenderObject->setTerrainDrawSize(drawWidth, drawHeight); | ||
| RefRenderObjListIterator *it = W3DDisplay::m_3DScene->createLightsIterator(); | ||
|
|
||
| const Vector3 cameraPivot(m_pos.x, m_pos.y, m_pos.z); | ||
| TheTerrainRenderObject->updateCenter(m_3DCamera, &cameraPivot, it); | ||
|
|
||
| if (it) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -487,10 +487,6 @@ WorldHeightMap::WorldHeightMap(ChunkInputStream *pStrm, Bool logicalDataOnly): | |
| m_sourceTiles[i]=nullptr; | ||
| m_edgeTiles[i]=nullptr; | ||
| } | ||
| if (TheGlobalData && TheGlobalData->m_stretchTerrain) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this supposed to be part of the first commit? |
||
| m_drawWidthX=STRETCH_DRAW_WIDTH; | ||
| m_drawHeightY=STRETCH_DRAW_HEIGHT; | ||
| } | ||
|
|
||
| DataChunkInput file( pStrm ); | ||
|
|
||
|
|
@@ -529,16 +525,6 @@ WorldHeightMap::WorldHeightMap(ChunkInputStream *pStrm, Bool logicalDataOnly): | |
| } | ||
| } | ||
| } | ||
| if (TheGlobalData && TheGlobalData->m_drawEntireTerrain) { | ||
| m_drawWidthX=m_width; | ||
| m_drawHeightY=m_height; | ||
| } | ||
| if (m_drawWidthX > m_width) { | ||
| m_drawWidthX = m_width; | ||
| } | ||
| if (m_drawHeightY > m_height) { | ||
| m_drawHeightY = m_height; | ||
| } | ||
|
|
||
| TheSidesList->validateSides(); | ||
| setupAlphaTiles(); | ||
|
|
@@ -2221,19 +2207,8 @@ Region2D WorldHeightMap::getDrawRegion2D() | |
| WorldHeightMap::DrawArea WorldHeightMap::createDrawArea(Int xOrg, Int yOrg) | ||
| { | ||
| DrawArea area; | ||
| area.sizeX = m_drawWidthX; | ||
| area.sizeY = m_drawHeightY; | ||
|
|
||
| if (TheGlobalData && TheGlobalData->m_stretchTerrain) { | ||
| area.sizeX = STRETCH_DRAW_WIDTH; | ||
| area.sizeY = STRETCH_DRAW_HEIGHT; | ||
| } | ||
| if (TheGlobalData && TheGlobalData->m_drawEntireTerrain) { | ||
| area.sizeX = m_width; | ||
| area.sizeY = m_height; | ||
| } | ||
| area.sizeX = std::min(area.sizeX, m_width); | ||
| area.sizeY = std::min(area.sizeY, m_height); | ||
| area.sizeX = std::min(m_drawWidthX, m_width); | ||
| area.sizeY = std::min(m_drawHeightY, m_height); | ||
| area.originX = clamp(0, xOrg, m_width - area.sizeX); | ||
| area.originY = clamp(0, yOrg, m_height - area.sizeY); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7 previously referred to TERRAIN_LOD_MAX