Cache highest snowline value

pull/390/head
Jonathan G Rennison 2 years ago
parent 0ec6f659c2
commit ed30542acf

@ -128,6 +128,7 @@ static void _GenerateWorld()
_settings_game.game_creation.snow_line_height = DEF_SNOWLINE_HEIGHT;
UpdateCachedSnowLine();
UpdateCachedSnowLineBounds();
} else {
GenerateLandscape(_gw.mode);
GenerateClearTile();

@ -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();
}
/**

@ -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);

@ -111,6 +111,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
SetScaledTickVariables();
}
UpdateCachedSnowLine();
UpdateCachedSnowLineBounds();
ClearTraceRestrictMapping();
ClearBridgeSimulatedSignalMapping();

@ -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)) {

Loading…
Cancel
Save