diff --git a/src/genworld.cpp b/src/genworld.cpp index 3677b92a81..3d8b52734d 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -128,6 +128,7 @@ static void _GenerateWorld() _settings_game.game_creation.snow_line_height = DEF_SNOWLINE_HEIGHT; UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); } else { GenerateLandscape(_gw.mode); GenerateClearTile(); diff --git a/src/landscape.cpp b/src/landscape.cpp index fe8d50ed7d..7df8195a6d 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -103,6 +103,8 @@ static TileIndex _current_estuary = INVALID_TILE; static bool _is_main_river = false; byte _cached_snowline = 0; +byte _cached_highest_snowline = 0; +byte _cached_lowest_snowline = 0; /** * Map 2D viewport or smallmap coordinate to 3D world or tile coordinate. @@ -657,6 +659,7 @@ void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]) } UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); } /** @@ -677,23 +680,13 @@ void UpdateCachedSnowLine() } /** - * Get the highest possible snow line height, either variable or static. - * @return the highest snow line height. + * Cache the lowest and highest possible snow line heights, either variable or static. * @ingroup SnowLineGroup */ -byte HighestSnowLine() +void UpdateCachedSnowLineBounds() { - return _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->highest_value; -} - -/** - * Get the lowest possible snow line height, either variable or static. - * @return the lowest snow line height. - * @ingroup SnowLineGroup - */ -byte LowestSnowLine() -{ - return _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->lowest_value; + _cached_highest_snowline = _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->highest_value; + _cached_lowest_snowline = _snow_line == nullptr ? _settings_game.game_creation.snow_line_height : _snow_line->lowest_value; } /** @@ -705,6 +698,7 @@ void ClearSnowLine() free(_snow_line); _snow_line = nullptr; UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); } /** @@ -1540,6 +1534,7 @@ static void CalculateSnowLine() _settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u); } UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); } /** diff --git a/src/landscape.h b/src/landscape.h index ca1a8bc675..99f20ff8ba 100644 --- a/src/landscape.h +++ b/src/landscape.h @@ -30,8 +30,7 @@ bool IsSnowLineSet(); void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]); byte GetSnowLineUncached(); void UpdateCachedSnowLine(); -byte HighestSnowLine(); -byte LowestSnowLine(); +void UpdateCachedSnowLineBounds(); void ClearSnowLine(); inline byte GetSnowLine() @@ -40,6 +39,18 @@ inline byte GetSnowLine() return _cached_snowline; } +inline byte HighestSnowLine() +{ + extern byte _cached_highest_snowline; + return _cached_highest_snowline; +} + +inline byte LowestSnowLine() +{ + extern byte _cached_lowest_snowline; + return _cached_lowest_snowline; +} + int GetSlopeZInCorner(Slope tileh, Corner corner); Slope GetFoundationSlope(TileIndex tile, int *z = nullptr); diff --git a/src/misc.cpp b/src/misc.cpp index a76cb2c469..c40affba07 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -111,6 +111,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin SetScaledTickVariables(); } UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); ClearTraceRestrictMapping(); ClearBridgeSimulatedSignalMapping(); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 458f894ec0..19b551d24b 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -635,6 +635,7 @@ bool AfterLoadGame() RebuildTownKdtree(); RebuildStationKdtree(); UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); _viewport_sign_kdtree_valid = false; @@ -3129,6 +3130,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_164) && _settings_game.game_creation.snow_line_height >= MIN_SNOWLINE_HEIGHT * TILE_HEIGHT && SlXvIsFeatureMissing(XSLFI_CHILLPP)) { _settings_game.game_creation.snow_line_height /= TILE_HEIGHT; UpdateCachedSnowLine(); + UpdateCachedSnowLineBounds(); } if (IsSavegameVersionBefore(SLV_164) && !IsSavegameVersionBefore(SLV_32)) {