1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-22 11:44:17 +01:00

Codechange: use unique_ptr over CallocT and avoid copying table

This commit is contained in:
Rubidium
2025-01-13 20:34:24 +01:00
committed by rubidium42
parent 41c9f2d82c
commit 3541ba4d0c
3 changed files with 18 additions and 24 deletions

View File

@@ -93,7 +93,7 @@ static const uint TILE_UPDATE_FREQUENCY = 1 << TILE_UPDATE_FREQUENCY_LOG; ///<
* @ingroup SnowLineGroup
* @see GetSnowLine() GameCreationSettings
*/
static SnowLine *_snow_line = nullptr;
static std::unique_ptr<SnowLine> _snow_line;
/**
* Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
@@ -584,21 +584,12 @@ bool IsSnowLineSet()
/**
* Set a variable snow line, as loaded from a newgrf file.
* @param table the 12 * 32 byte table containing the snowline for each day
* @param snow_line The new snow line configuration.
* @ingroup SnowLineGroup
*/
void SetSnowLine(uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
void SetSnowLine(std::unique_ptr<SnowLine> &&snow_line)
{
_snow_line = CallocT<SnowLine>(1);
_snow_line->lowest_value = 0xFF;
memcpy(_snow_line->table, table, sizeof(_snow_line->table));
for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
_snow_line->highest_value = std::max(_snow_line->highest_value, table[i][j]);
_snow_line->lowest_value = std::min(_snow_line->lowest_value, table[i][j]);
}
}
_snow_line = std::move(snow_line);
}
/**
@@ -640,7 +631,6 @@ uint8_t LowestSnowLine()
*/
void ClearSnowLine()
{
free(_snow_line);
_snow_line = nullptr;
}