From b331d3f7870bc4e56ebf22d5bb2ac192008dc5dd Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Sun, 5 Jan 2025 21:05:34 +0000 Subject: [PATCH] Codechange: Speed up ground density transition during river generation This in turn avoids running the tile loop. --- src/clear_cmd.cpp | 2 +- src/clear_func.h | 2 ++ src/landscape.cpp | 8 +------- src/water_cmd.cpp | 19 ++++++++++++++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index c40904e0fd..00e67d7640 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -202,7 +202,7 @@ static inline bool NeighbourIsNormal(TileIndex tile) return false; } -static void TileLoopClearDesert(TileIndex tile) +void TileLoopClearDesert(TileIndex tile) { /* Current desert level - 0 if it is not desert */ uint current = 0; diff --git a/src/clear_func.h b/src/clear_func.h index 28fd7d4a85..cdc6c9b74a 100644 --- a/src/clear_func.h +++ b/src/clear_func.h @@ -15,4 +15,6 @@ void DrawHillyLandTile(const TileInfo *ti); void DrawClearLandTile(const TileInfo *ti, uint8_t set); +void TileLoopClearDesert(TileIndex tile); + #endif /* CLEAR_FUNC_H */ diff --git a/src/landscape.cpp b/src/landscape.cpp index 544a41876b..056a939c6c 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1400,7 +1400,7 @@ static void CreateRivers() uint wells = Map::ScaleBySize(4 << _settings_game.game_creation.amount_of_rivers); const uint num_short_rivers = wells - std::max(1u, wells / 10); - SetGeneratingWorldProgress(GWP_RIVER, wells + TILE_UPDATE_FREQUENCY / 64); // Include the tile loop calls below. + SetGeneratingWorldProgress(GWP_RIVER, wells); /* Try to create long rivers. */ for (; wells > num_short_rivers; wells--) { @@ -1424,12 +1424,6 @@ static void CreateRivers() /* Widening rivers may have left some tiles requiring to be watered. */ ConvertGroundTilesIntoWaterTiles(); - - /* Run tile loop to update the ground density. */ - for (uint i = 0; i != TILE_UPDATE_FREQUENCY; i++) { - if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER); - RunTileLoop(); - } } /** diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index f15c15666b..fe60bca1e5 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -40,6 +40,7 @@ #include "water_cmd.h" #include "landscape_cmd.h" #include "pathfinder/water_regions.h" +#include "clear_func.h" #include "table/strings.h" @@ -443,7 +444,23 @@ CommandCost CmdBuildLock(DoCommandFlag flags, TileIndex tile) /** Callback to create non-desert around a river tile. */ static bool RiverModifyDesertZone(TileIndex tile, void *) { - if (GetTropicZone(tile) == TROPICZONE_DESERT) SetTropicZone(tile, TROPICZONE_NORMAL); + if (GetTropicZone(tile) == TROPICZONE_DESERT) { + SetTropicZone(tile, TROPICZONE_NORMAL); + + /* Speed up the transition from desert to grass. */ + if (IsTileType(tile, MP_CLEAR)) TileLoopClearDesert(tile); + + for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { + const TileIndex t = tile + TileOffsByDiagDir(dir); + + if (!IsValidTile(t)) continue; + if (!IsTileType(t, MP_CLEAR)) continue; + + /* Speed up the transition of adjacent desert tile density. */ + TileLoopClearDesert(t); + } + } + return false; }