From 26fa77c5ee20f6bb3d56cb317dd01e7e1e4dcc3d Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 2 Mar 2016 18:36:53 +0000 Subject: [PATCH] Run animations at the normal rate regardless of day length factor. --- src/date_type.h | 1 + src/industry_cmd.cpp | 20 ++++++++++---------- src/newgrf_animation_base.h | 2 +- src/openttd.cpp | 1 + src/town_cmd.cpp | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/date_type.h b/src/date_type.h index c7d8d72488..6879f55411 100644 --- a/src/date_type.h +++ b/src/date_type.h @@ -34,6 +34,7 @@ static const int DAYS_IN_YEAR = 365; ///< days per year static const int DAYS_IN_LEAP_YEAR = 366; ///< sometimes, you need one day more... #define CURRENT_SCALED_TICKS (((((DateTicksScaled)_date * DAY_TICKS) + _date_fract) * _settings_game.economy.day_length_factor) + _tick_skip_counter) +#define SCALED_TICK_COUNTER ((((uint32)_tick_counter) * _settings_game.economy.day_length_factor) + _tick_skip_counter) #define DATE_UNIT_SIZE (_settings_client.gui.time_in_minutes ? _settings_client.gui.ticks_per_minute : (DAY_TICKS * _settings_game.economy.day_length_factor)) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 77c45410a7..6225710bfb 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -540,7 +540,7 @@ static void AnimateTile_Industry(TileIndex tile) switch (gfx) { case GFX_SUGAR_MINE_SIEVE: - if ((_tick_counter & 1) == 0) { + if ((SCALED_TICK_COUNTER & 1) == 0) { byte m = GetAnimationFrame(tile) + 1; if (_settings_client.sound.ambient) { @@ -561,7 +561,7 @@ static void AnimateTile_Industry(TileIndex tile) break; case GFX_TOFFEE_QUARY: - if ((_tick_counter & 3) == 0) { + if ((SCALED_TICK_COUNTER & 3) == 0) { byte m = GetAnimationFrame(tile); if (_industry_anim_offs_toffee[m] == 0xFF && _settings_client.sound.ambient) { @@ -579,7 +579,7 @@ static void AnimateTile_Industry(TileIndex tile) break; case GFX_BUBBLE_CATCHER: - if ((_tick_counter & 1) == 0) { + if ((SCALED_TICK_COUNTER & 1) == 0) { byte m = GetAnimationFrame(tile); if (++m >= 40) { @@ -594,7 +594,7 @@ static void AnimateTile_Industry(TileIndex tile) /* Sparks on a coal plant */ case GFX_POWERPLANT_SPARKS: - if ((_tick_counter & 3) == 0) { + if ((SCALED_TICK_COUNTER & 3) == 0) { byte m = GetAnimationFrame(tile); if (m == 6) { SetAnimationFrame(tile, 0); @@ -607,7 +607,7 @@ static void AnimateTile_Industry(TileIndex tile) break; case GFX_TOY_FACTORY: - if ((_tick_counter & 1) == 0) { + if ((SCALED_TICK_COUNTER & 1) == 0) { byte m = GetAnimationFrame(tile) + 1; switch (m) { @@ -635,7 +635,7 @@ static void AnimateTile_Industry(TileIndex tile) case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4: case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: - if ((_tick_counter & 3) == 0) { + if ((SCALED_TICK_COUNTER & 3) == 0) { IndustryGfx gfx = GetIndustryGfx(tile); gfx = (gfx < 155) ? gfx + 1 : 148; @@ -647,7 +647,7 @@ static void AnimateTile_Industry(TileIndex tile) case GFX_OILWELL_ANIMATED_1: case GFX_OILWELL_ANIMATED_2: case GFX_OILWELL_ANIMATED_3: - if ((_tick_counter & 7) == 0) { + if ((SCALED_TICK_COUNTER & 7) == 0) { bool b = Chance16(1, 7); IndustryGfx gfx = GetIndustryGfx(tile); @@ -667,7 +667,7 @@ static void AnimateTile_Industry(TileIndex tile) case GFX_COAL_MINE_TOWER_ANIMATED: case GFX_COPPER_MINE_TOWER_ANIMATED: case GFX_GOLD_MINE_TOWER_ANIMATED: { - int state = _tick_counter & 0x7FF; + int state = SCALED_TICK_COUNTER & 0x7FF; if ((state -= 0x400) < 0) return; @@ -827,7 +827,7 @@ static void TileLoop_Industry(TileIndex tile) case GFX_COAL_MINE_TOWER_NOT_ANIMATED: case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: - if (!(_tick_counter & 0x400) && Chance16(1, 2)) { + if (!(SCALED_TICK_COUNTER & 0x400) && Chance16(1, 2)) { switch (gfx) { case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED; break; case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break; @@ -850,7 +850,7 @@ static void TileLoop_Industry(TileIndex tile) case GFX_COAL_MINE_TOWER_ANIMATED: case GFX_COPPER_MINE_TOWER_ANIMATED: case GFX_GOLD_MINE_TOWER_ANIMATED: - if (!(_tick_counter & 0x400)) { + if (!(SCALED_TICK_COUNTER & 0x400)) { switch (gfx) { case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED; break; case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break; diff --git a/src/newgrf_animation_base.h b/src/newgrf_animation_base.h index 3ccbe93700..d706145da7 100644 --- a/src/newgrf_animation_base.h +++ b/src/newgrf_animation_base.h @@ -56,7 +56,7 @@ struct AnimationBase { * increasing this value by one doubles the wait. 0 is the minimum value * allowed for animation_speed, which corresponds to 30ms, and 16 is the * maximum, corresponding to around 33 minutes. */ - if (_tick_counter % (1 << animation_speed) != 0) return; + if (SCALED_TICK_COUNTER % (1 << animation_speed) != 0) return; uint8 frame = GetAnimationFrame(tile); uint8 num_frames = spec->animation.frames; diff --git a/src/openttd.cpp b/src/openttd.cpp index 8d8142c407..100a230a30 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1525,6 +1525,7 @@ void StateGameLoop() BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP); _tick_skip_counter++; if (_tick_skip_counter < _settings_game.economy.day_length_factor) { + AnimateAnimatedTiles(); CallVehicleTicks(); } else { _tick_skip_counter = 0; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index b3cb198572..dbc0aac001 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -399,7 +399,7 @@ static void AnimateTile_Town(TileIndex tile) return; } - if (_tick_counter & 3) return; + if (SCALED_TICK_COUNTER & 3) return; /* If the house is not one with a lift anymore, then stop this animating. * Not exactly sure when this happens, but probably when a house changes.