Skip to content

Commit

Permalink
Update progress bar during simplex map smoothing operations
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronVanGeffen committed Apr 10, 2024
1 parent 630dbf8 commit 3455f8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/OpenLoco/src/Map/MapGenerator/MapGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,23 +834,23 @@ namespace OpenLoco::World::MapGenerator
HeightMap heightMap(512, 512, 512);

generateHeightMap(options, heightMap);
updateProgress(17);
updateProgress(25);

generateLand(heightMap);
updateProgress(17);
updateProgress(35);

generateWater(heightMap);
updateProgress(25);
updateProgress(45);

generateTerrain(heightMap);
updateProgress(35);
updateProgress(55);
}

generateSurfaceVariation();
updateProgress(40);
updateProgress(65);

generateTrees();
updateProgress(45);
updateProgress(75);

generateTowns();
updateProgress(225);
Expand Down
12 changes: 12 additions & 0 deletions src/OpenLoco/src/Map/MapGenerator/SimplexTerrainGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SimplexTerrainGenerator.h"
#include "S5/S5.h"
#include "Ui/ProgressBar.h"
#include <algorithm>

using namespace OpenLoco::S5;
Expand Down Expand Up @@ -60,6 +61,8 @@ namespace OpenLoco::World::MapGenerator
void SimplexTerrainGenerator::generate(const SimplexSettings& settings, HeightMapRange heightMap)
{
generateSimplex(settings, heightMap);
Ui::ProgressBar::setProgress(15);

smooth(settings.smooth, heightMap);
}

Expand All @@ -82,6 +85,12 @@ namespace OpenLoco::World::MapGenerator

void SimplexTerrainGenerator::smooth(int32_t iterations, HeightMapRange heightMap)
{
if (iterations == 0)
return;

const auto progressSteps = (25 - 15) / iterations;
auto currentProgress = 15;

for (int32_t i = 0; i < iterations; i++)
{
auto copyHeight = heightMap;
Expand All @@ -100,6 +109,9 @@ namespace OpenLoco::World::MapGenerator
heightMap[{ x, y }] = total / 9;
}
}

currentProgress += progressSteps;
Ui::ProgressBar::setProgress(currentProgress);
}
}

Expand Down

0 comments on commit 3455f8c

Please sign in to comment.