From b434e1bc35860603446adf97b408f257adfa83c2 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 10 Sep 2024 14:13:31 +0200 Subject: [PATCH] Clarify height map parameters and integrate into MapGenSettings --- data/language/en-GB.txt | 4 +-- src/openrct2-ui/windows/MapGen.cpp | 47 ++++++++++++++---------------- src/openrct2/world/MapGen.cpp | 12 ++++---- src/openrct2/world/MapGen.h | 4 ++- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 3e8b732765..0c86bd81f2 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3166,9 +3166,9 @@ STR_6041 :{BLACK}No mechanics are hired! STR_6042 :Load height map STR_6043 :Select height map STR_6044 :Smooth height map -STR_6045 :Strength +STR_6045 :Strength: STR_6046 :Normalise height map -STR_6047 :Smooth tiles +STR_6047 :Smooth tile edges STR_6048 :Height map error STR_6049 :Error reading PNG STR_6050 :Error reading bitmap diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp index 090f54adfa..ef568a4519 100644 --- a/src/openrct2-ui/windows/MapGen.cpp +++ b/src/openrct2-ui/windows/MapGen.cpp @@ -87,7 +87,7 @@ namespace OpenRCT2::Ui::Windows WIDX_HEIGHTMAP_STRENGTH_UP, WIDX_HEIGHTMAP_STRENGTH_DOWN, WIDX_HEIGHTMAP_NORMALIZE, - WIDX_HEIGHTMAP_SMOOTH_TILES, + WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES, WIDX_HEIGHTMAP_LOW, WIDX_HEIGHTMAP_LOW_UP, WIDX_HEIGHTMAP_LOW_DOWN, @@ -157,7 +157,7 @@ namespace OpenRCT2::Ui::Windows MakeWidget ({ 4, 52}, {100, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_MAPGEN_SMOOTH_HEIGHTMAP), // WIDX_HEIGHTMAP_SMOOTH_HEIGHTMAP MakeSpinnerWidgets({104, 70}, { 95, 12}, WindowWidgetType::Spinner, WindowColour::Secondary ), // WIDX_HEIGHTMAP_STRENGTH{,_UP,_DOWN} MakeWidget ({ 4, 88}, {100, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_MAPGEN_NORMALIZE ), // WIDX_HEIGHTMAP_NORMALIZE - MakeWidget ({ 4, 106}, {100, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_MAPGEN_SMOOTH_TILE ), // WIDX_HEIGHTMAP_SMOOTH_TILES + MakeWidget ({ 4, 106}, {100, 12}, WindowWidgetType::Checkbox, WindowColour::Secondary, STR_MAPGEN_SMOOTH_TILE ), // WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES MakeSpinnerWidgets({104, 124}, { 95, 12}, WindowWidgetType::Spinner, WindowColour::Secondary ), // WIDX_HEIGHTMAP_LOW{,_UP,_DOWN} MakeSpinnerWidgets({104, 142}, { 95, 12}, WindowWidgetType::Spinner, WindowColour::Secondary ), // WIDX_HEIGHTMAP_HIGH{,_UP,_DOWN} kWidgetsEnd, @@ -206,7 +206,7 @@ namespace OpenRCT2::Ui::Windows (1uLL << WIDX_HEIGHTMAP_STRENGTH_UP) | (1uLL << WIDX_HEIGHTMAP_STRENGTH_DOWN) | (1uLL << WIDX_HEIGHTMAP_NORMALIZE) | - (1uLL << WIDX_HEIGHTMAP_SMOOTH_TILES) | + (1uLL << WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES) | (1uLL << WIDX_HEIGHTMAP_HIGH) | (1uLL << WIDX_HEIGHTMAP_HIGH_UP) | (1uLL << WIDX_HEIGHTMAP_HIGH_DOWN) | @@ -250,7 +250,7 @@ namespace OpenRCT2::Ui::Windows 0, 0, 0, - (1uLL << WIDX_HEIGHTMAP_SMOOTH_TILES), + (1uLL << WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES), 0, 0, }; @@ -326,16 +326,16 @@ namespace OpenRCT2::Ui::Windows .simplex_octaves = 4, // Height map _settings - .smooth = true, .smooth_height_map = false, .smooth_strength = 1, .normalize_height = false, + .smoothTileEdges = true, + .heightmapLow = 2, + .heightmapHigh = 70, }; bool _randomTerrain = true; bool _heightmapLoaded = false; - int32_t _heightmapLow = 2; - int32_t _heightmapHigh = 70; void SetPage(int32_t newPage) { @@ -356,7 +356,7 @@ namespace OpenRCT2::Ui::Windows SetWidgetEnabled(WIDX_HEIGHTMAP_STRENGTH_UP, _settings.smooth_height_map); SetWidgetEnabled(WIDX_HEIGHTMAP_STRENGTH_DOWN, _settings.smooth_height_map); SetWidgetEnabled(WIDX_HEIGHTMAP_NORMALIZE, true); - SetWidgetEnabled(WIDX_HEIGHTMAP_SMOOTH_TILES, true); + SetWidgetEnabled(WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES, true); SetWidgetEnabled(WIDX_HEIGHTMAP_HIGH, true); SetWidgetEnabled(WIDX_HEIGHTMAP_HIGH_UP, true); SetWidgetEnabled(WIDX_HEIGHTMAP_HIGH_DOWN, true); @@ -493,9 +493,6 @@ namespace OpenRCT2::Ui::Windows case MapGenAlgorithm::heightmapImage: if (!_heightmapLoaded) return; - - mapgenSettings.simplex_low = _heightmapLow; - mapgenSettings.simplex_high = _heightmapHigh; break; } @@ -852,21 +849,21 @@ namespace OpenRCT2::Ui::Windows InvalidateWidget(WIDX_HEIGHTMAP_STRENGTH); break; case WIDX_HEIGHTMAP_LOW_UP: - _heightmapLow = std::min(_heightmapLow + 1, kMaximumWaterHeight - 1); - _heightmapHigh = std::max(_heightmapHigh, _heightmapLow + 1); + _settings.heightmapLow = std::min(_settings.heightmapLow + 1, kMaximumWaterHeight - 1); + _settings.heightmapHigh = std::max(_settings.heightmapHigh, _settings.heightmapLow + 1); InvalidateWidget(WIDX_HEIGHTMAP_LOW); break; case WIDX_HEIGHTMAP_LOW_DOWN: - _heightmapLow = std::max(_heightmapLow - 1, 2); + _settings.heightmapLow = std::max(_settings.heightmapLow - 1, 2); InvalidateWidget(WIDX_HEIGHTMAP_LOW); break; case WIDX_HEIGHTMAP_HIGH_UP: - _heightmapHigh = std::min(_heightmapHigh + 1, kMaximumWaterHeight); + _settings.heightmapHigh = std::min(_settings.heightmapHigh + 1, kMaximumWaterHeight); InvalidateWidget(WIDX_HEIGHTMAP_HIGH); break; case WIDX_HEIGHTMAP_HIGH_DOWN: - _heightmapHigh = std::max(_heightmapHigh - 1, 2 + 1); - _heightmapLow = std::min(_heightmapLow, _heightmapHigh - 1); + _settings.heightmapHigh = std::max(_settings.heightmapHigh - 1, 2 + 1); + _settings.heightmapLow = std::min(_settings.heightmapLow, _settings.heightmapHigh - 1); InvalidateWidget(WIDX_HEIGHTMAP_HIGH); break; } @@ -911,10 +908,10 @@ namespace OpenRCT2::Ui::Windows SetCheckboxValue(WIDX_HEIGHTMAP_NORMALIZE, _settings.normalize_height); InvalidateWidget(WIDX_HEIGHTMAP_NORMALIZE); break; - case WIDX_HEIGHTMAP_SMOOTH_TILES: - _settings.smooth = !_settings.smooth; - SetCheckboxValue(WIDX_HEIGHTMAP_SMOOTH_TILES, _settings.smooth); - InvalidateWidget(WIDX_HEIGHTMAP_SMOOTH_TILES); + case WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES: + _settings.smoothTileEdges = !_settings.smoothTileEdges; + SetCheckboxValue(WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES, _settings.smoothTileEdges); + InvalidateWidget(WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES); break; } @@ -932,7 +929,7 @@ namespace OpenRCT2::Ui::Windows SetCheckboxValue(WIDX_HEIGHTMAP_SMOOTH_HEIGHTMAP, _settings.smooth_height_map); SetCheckboxValue(WIDX_HEIGHTMAP_NORMALIZE, _settings.normalize_height); - SetCheckboxValue(WIDX_HEIGHTMAP_SMOOTH_TILES, _settings.smooth); + SetCheckboxValue(WIDX_HEIGHTMAP_SMOOTH_TILE_EDGES, _settings.smoothTileEdges); SetPressedTab(); } @@ -948,7 +945,7 @@ namespace OpenRCT2::Ui::Windows // Smooth strength label and value const auto strengthColour = _settings.smooth_height_map ? enabledColour : disabledColour; DrawTextBasic( - dpi, windowPos + ScreenCoordsXY{ 5, widgets[WIDX_HEIGHTMAP_STRENGTH].top + 1 }, STR_MAPGEN_SMOOTH_STRENGTH, {}, + dpi, windowPos + ScreenCoordsXY{ 18, widgets[WIDX_HEIGHTMAP_STRENGTH].top + 1 }, STR_MAPGEN_SMOOTH_STRENGTH, {}, { strengthColour }); auto ft = Formatter(); @@ -966,7 +963,7 @@ namespace OpenRCT2::Ui::Windows { labelColour }); ft = Formatter(); - ft.Add(_heightmapLow); + ft.Add(_settings.heightmapLow); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_HEIGHTMAP_LOW].left + 1, widgets[WIDX_HEIGHTMAP_LOW].top + 1 }, STR_COMMA16, ft, { labelColour }); @@ -977,7 +974,7 @@ namespace OpenRCT2::Ui::Windows { labelColour }); ft = Formatter(); - ft.Add(_heightmapHigh); + ft.Add(_settings.heightmapHigh); DrawTextBasic( dpi, windowPos + ScreenCoordsXY{ widgets[WIDX_HEIGHTMAP_HIGH].left + 1, widgets[WIDX_HEIGHTMAP_HIGH].top + 1 }, STR_COMMA16, ft, { labelColour }); diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index ba0e984425..1b1c62f418 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -835,7 +835,7 @@ static void MapGenSmoothHeightmap(std::vector& src, int32_t strength) static void MapGenGenerateFromHeightmapImage(MapGenSettings* settings) { Guard::Assert(!_heightMapData.mono_bitmap.empty(), "No height map loaded"); - Guard::Assert(settings->simplex_high != settings->simplex_low, "Low and high setting cannot be the same"); + Guard::Assert(settings->heightmapHigh != settings->heightmapLow, "Low and high setting cannot be the same"); // Make a copy of the original height map that we can edit auto dest = _heightMapData.mono_bitmap; @@ -876,10 +876,10 @@ static void MapGenGenerateFromHeightmapImage(MapGenSettings* settings) } Guard::Assert(maxValue > minValue, "Input range is invalid"); - Guard::Assert(settings->simplex_high > settings->simplex_low, "Output range is invalid"); + Guard::Assert(settings->heightmapHigh > settings->heightmapLow, "Output range is invalid"); const uint8_t rangeIn = maxValue - minValue; - const uint8_t rangeOut = settings->simplex_high - settings->simplex_low; + const uint8_t rangeOut = settings->heightmapHigh - settings->heightmapLow; for (uint32_t y = 0; y < _heightMapData.height; y++) { @@ -893,7 +893,7 @@ static void MapGenGenerateFromHeightmapImage(MapGenSettings* settings) // Read value from bitmap, and convert its range uint8_t value = dest[x + y * _heightMapData.width]; - value = static_cast(static_cast(value - minValue) / rangeIn * rangeOut) + settings->simplex_low; + value = static_cast(static_cast(value - minValue) / rangeIn * rangeOut) + settings->heightmapLow; surfaceElement->BaseHeight = value; // Floor to even number @@ -909,8 +909,8 @@ static void MapGenGenerateFromHeightmapImage(MapGenSettings* settings) } } - // Smooth map - if (settings->smooth) + // Smooth tile edges + if (settings->smoothTileEdges) { // Keep smoothing the entire map until no tiles are changed anymore while (true) diff --git a/src/openrct2/world/MapGen.h b/src/openrct2/world/MapGen.h index 9f8b1dc2d1..72493e8291 100644 --- a/src/openrct2/world/MapGen.h +++ b/src/openrct2/world/MapGen.h @@ -41,10 +41,12 @@ struct MapGenSettings int32_t simplex_octaves; // Height map settings - bool smooth; bool smooth_height_map; uint32_t smooth_strength; bool normalize_height; + bool smoothTileEdges; + int32_t heightmapLow; + int32_t heightmapHigh; }; void MapGenGenerate(MapGenSettings* settings);