Skip to content

Commit

Permalink
Questionable remedy to un-updated height bounds in case of pre-game t…
Browse files Browse the repository at this point in the history
…erraform
  • Loading branch information
lhog committed Jan 23, 2022
1 parent 9e7e28e commit 3f69f26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions rts/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ void CGame::Load(const std::string& mapFileName)
ENTER_SYNCED_CODE();
eventHandler.GamePreload();
eventHandler.CollectGarbage(true);
readMap->UpdateHeightBounds(); //needed in case pre-game terraform changed the map
LEAVE_SYNCED_CODE();
}

Expand Down
16 changes: 16 additions & 0 deletions rts/Map/ReadMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,22 @@ void CReadMap::UpdateHeightBounds(int syncFrame)
#endif
}

void CReadMap::UpdateHeightBounds()
{
const float* heightmap = GetCornerHeightMapSynced();

tempHeightBounds.x = std::numeric_limits<float>::max();
tempHeightBounds.y = std::numeric_limits<float>::lowest();

for (int i = 0; i < (mapDims.mapxp1 * mapDims.mapyp1); ++i) {
tempHeightBounds.x = std::min(tempHeightBounds.x, heightmap[i]);
tempHeightBounds.y = std::max(tempHeightBounds.y, heightmap[i]);
}

currHeightBounds.x = tempHeightBounds.x;
currHeightBounds.y = tempHeightBounds.y;
}

void CReadMap::UpdateCenterHeightmap(const SRectangle& rect, bool initialize)
{
const float* heightmapSynced = GetCornerHeightMapSynced();
Expand Down
1 change: 1 addition & 0 deletions rts/Map/ReadMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class CReadMap
unsigned int CalcHeightmapChecksum();
unsigned int CalcTypemapChecksum();

void UpdateHeightBounds();
private:
void InitHeightBounds();
void UpdateHeightBounds(int syncFrame);
Expand Down

0 comments on commit 3f69f26

Please sign in to comment.