Spread tile loop iterations over all ticks when using day length > 1
See: #545
This commit is contained in:
@@ -818,18 +818,41 @@ static uint32 GetTileLoopFeedback()
|
|||||||
return feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];
|
return feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<uint> _tile_loop_counts;
|
||||||
|
|
||||||
|
void SetupTileLoopCounts()
|
||||||
|
{
|
||||||
|
_tile_loop_counts.resize(_settings_game.economy.day_length_factor);
|
||||||
|
if (_settings_game.economy.day_length_factor == 0) return;
|
||||||
|
|
||||||
|
uint64 count_per_tick_fp16 = (static_cast<uint64>(1) << (MapLogX() + MapLogY() + 8)) / _settings_game.economy.day_length_factor;
|
||||||
|
uint64 accumulator = 0;
|
||||||
|
for (uint &count : _tile_loop_counts) {
|
||||||
|
accumulator += count_per_tick_fp16;
|
||||||
|
count = static_cast<uint32>(accumulator >> 16);
|
||||||
|
accumulator &= 0xFFFF;
|
||||||
|
}
|
||||||
|
if (accumulator > 0) _tile_loop_counts[0]++;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
|
* Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
|
||||||
*/
|
*/
|
||||||
void RunTileLoop()
|
void RunTileLoop(bool apply_day_length)
|
||||||
{
|
{
|
||||||
|
/* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */
|
||||||
|
uint count;
|
||||||
|
if (apply_day_length && _settings_game.economy.day_length_factor > 1) {
|
||||||
|
count = _tile_loop_counts[_tick_skip_counter];
|
||||||
|
if (count == 0) return;
|
||||||
|
} else {
|
||||||
|
count = 1 << (MapLogX() + MapLogY() - 8);
|
||||||
|
}
|
||||||
|
|
||||||
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
|
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
|
||||||
|
|
||||||
const uint32 feedback = GetTileLoopFeedback();
|
const uint32 feedback = GetTileLoopFeedback();
|
||||||
|
|
||||||
/* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */
|
|
||||||
uint count = 1 << (MapLogX() + MapLogY() - 8);
|
|
||||||
|
|
||||||
TileIndex tile = _cur_tileloop_tile;
|
TileIndex tile = _cur_tileloop_tile;
|
||||||
/* The LFSR cannot have a zeroed state. */
|
/* The LFSR cannot have a zeroed state. */
|
||||||
dbg_assert(tile != 0);
|
dbg_assert(tile != 0);
|
||||||
|
@@ -166,7 +166,8 @@ bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
|
|||||||
bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
|
bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
|
||||||
|
|
||||||
void DoClearSquare(TileIndex tile);
|
void DoClearSquare(TileIndex tile);
|
||||||
void RunTileLoop();
|
void SetupTileLoopCounts();
|
||||||
|
void RunTileLoop(bool apply_day_length = false);
|
||||||
void RunAuxiliaryTileLoop();
|
void RunAuxiliaryTileLoop();
|
||||||
|
|
||||||
void InitializeLandscape();
|
void InitializeLandscape();
|
||||||
|
@@ -116,6 +116,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
|||||||
} else {
|
} else {
|
||||||
SetScaledTickVariables();
|
SetScaledTickVariables();
|
||||||
}
|
}
|
||||||
|
SetupTileLoopCounts();
|
||||||
UpdateCachedSnowLine();
|
UpdateCachedSnowLine();
|
||||||
UpdateCachedSnowLineBounds();
|
UpdateCachedSnowLineBounds();
|
||||||
|
|
||||||
|
@@ -2050,13 +2050,14 @@ void StateGameLoop()
|
|||||||
RunAuxiliaryTileLoop();
|
RunAuxiliaryTileLoop();
|
||||||
if (_tick_skip_counter < _settings_game.economy.day_length_factor) {
|
if (_tick_skip_counter < _settings_game.economy.day_length_factor) {
|
||||||
AnimateAnimatedTiles();
|
AnimateAnimatedTiles();
|
||||||
|
RunTileLoop(true);
|
||||||
CallVehicleTicks();
|
CallVehicleTicks();
|
||||||
OnTick_Companies(false);
|
OnTick_Companies(false);
|
||||||
} else {
|
} else {
|
||||||
_tick_skip_counter = 0;
|
_tick_skip_counter = 0;
|
||||||
IncreaseDate();
|
IncreaseDate();
|
||||||
AnimateAnimatedTiles();
|
AnimateAnimatedTiles();
|
||||||
RunTileLoop();
|
RunTileLoop(true);
|
||||||
CallVehicleTicks();
|
CallVehicleTicks();
|
||||||
CallLandscapeTick();
|
CallLandscapeTick();
|
||||||
OnTick_Companies(true);
|
OnTick_Companies(true);
|
||||||
|
@@ -859,6 +859,7 @@ bool AfterLoadGame()
|
|||||||
/* Update current year
|
/* Update current year
|
||||||
* must be done before loading sprites as some newgrfs check it */
|
* must be done before loading sprites as some newgrfs check it */
|
||||||
SetDate(_date, _date_fract, false);
|
SetDate(_date, _date_fract, false);
|
||||||
|
SetupTileLoopCounts();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Force the old behaviour for compatibility reasons with old savegames. As new
|
* Force the old behaviour for compatibility reasons with old savegames. As new
|
||||||
|
@@ -1743,6 +1743,8 @@ static void DayLengthChanged(int32 new_value)
|
|||||||
extern void VehicleDayLengthChanged(DateTicksScaled old_scaled_date_ticks, DateTicksScaled old_scaled_date_ticks_offset, uint8 old_day_length_factor);
|
extern void VehicleDayLengthChanged(DateTicksScaled old_scaled_date_ticks, DateTicksScaled old_scaled_date_ticks_offset, uint8 old_day_length_factor);
|
||||||
VehicleDayLengthChanged(old_scaled_date_ticks, old_scaled_date_ticks_offset, _pre_change_day_length_factor);
|
VehicleDayLengthChanged(old_scaled_date_ticks, old_scaled_date_ticks_offset, _pre_change_day_length_factor);
|
||||||
|
|
||||||
|
SetupTileLoopCounts();
|
||||||
|
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user