From 8d5c70cec583e897fd0197490d3e57eb07feb96e Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 7 Mar 2025 23:40:59 +0100 Subject: [PATCH] Make density a HeightMap property --- src/openrct2/world/map_generator/HeightMap.hpp | 10 ++++++++++ src/openrct2/world/map_generator/MapGen.cpp | 10 +++++----- src/openrct2/world/map_generator/MapGen.h | 2 +- src/openrct2/world/map_generator/SimplexNoise.cpp | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/openrct2/world/map_generator/HeightMap.hpp b/src/openrct2/world/map_generator/HeightMap.hpp index 93723b9a72..83bdaf62df 100644 --- a/src/openrct2/world/map_generator/HeightMap.hpp +++ b/src/openrct2/world/map_generator/HeightMap.hpp @@ -26,11 +26,21 @@ namespace OpenRCT2::World::MapGenerator public: uint16_t width{}; uint16_t height{}; + uint8_t density{}; HeightMap(int32_t targetWidth, int32_t targetHeight) : _height(targetWidth * targetHeight) , width(targetWidth) , height(targetHeight) + , density(1) + { + } + + HeightMap(int32_t baseWidth, int32_t baseHeight, uint8_t density_) + : _height((baseWidth * density_) * (baseHeight * density_)) + , width(baseWidth * density_) + , height(baseHeight * density_) + , density(density_) { } diff --git a/src/openrct2/world/map_generator/MapGen.cpp b/src/openrct2/world/map_generator/MapGen.cpp index 158ee4dc38..75dfcdd039 100644 --- a/src/openrct2/world/map_generator/MapGen.cpp +++ b/src/openrct2/world/map_generator/MapGen.cpp @@ -126,14 +126,14 @@ namespace OpenRCT2::World::MapGenerator /** * Sets the height of the actual game map tiles to the height map. */ - void setMapHeight(Settings* settings, const HeightMap& heightMap, const uint8_t density) + void setMapHeight(Settings* settings, const HeightMap& heightMap) { - for (auto y = 1; y < heightMap.height / density - 1; y++) + for (auto y = 1; y < heightMap.height / heightMap.density - 1; y++) { - for (auto x = 1; x < heightMap.width / density - 1; x++) + for (auto x = 1; x < heightMap.width / heightMap.density - 1; x++) { - auto heightX = x * density; - auto heightY = y * density; + auto heightX = x * heightMap.density; + auto heightY = y * heightMap.density; uint8_t q00 = heightMap[{ heightX + 0, heightY + 0 }]; uint8_t q01 = heightMap[{ heightX + 0, heightY + 1 }]; diff --git a/src/openrct2/world/map_generator/MapGen.h b/src/openrct2/world/map_generator/MapGen.h index 97d397755d..431a231217 100644 --- a/src/openrct2/world/map_generator/MapGen.h +++ b/src/openrct2/world/map_generator/MapGen.h @@ -54,6 +54,6 @@ namespace OpenRCT2::World::MapGenerator void generate(Settings* settings); void resetSurfaces(Settings* settings); void setWaterLevel(int32_t waterLevel); - void setMapHeight(Settings* settings, const HeightMap& heightMap, const uint8_t density); + void setMapHeight(Settings* settings, const HeightMap& heightMap); } // namespace OpenRCT2::World::MapGenerator diff --git a/src/openrct2/world/map_generator/SimplexNoise.cpp b/src/openrct2/world/map_generator/SimplexNoise.cpp index 8be7005d96..a03890130d 100644 --- a/src/openrct2/world/map_generator/SimplexNoise.cpp +++ b/src/openrct2/world/map_generator/SimplexNoise.cpp @@ -206,13 +206,13 @@ namespace OpenRCT2::World::MapGenerator // Create the temporary height map and initialise const auto& mapSize = settings->mapSize; const auto density = 2; - auto heightMap = HeightMap(mapSize.x * density, mapSize.y * density); + auto heightMap = HeightMap(mapSize.x, mapSize.y, density); generateSimplexNoise(settings, heightMap); smoothHeightMap(2 + (UtilRand() % 6), heightMap); // Set the game map to the height map - setMapHeight(settings, heightMap, density); + setMapHeight(settings, heightMap); if (settings->smoothTileEdges) {