diff --git a/src/animated_tile.cpp b/src/animated_tile.cpp index 67aba4c364..a0c9a5e8c2 100644 --- a/src/animated_tile.cpp +++ b/src/animated_tile.cpp @@ -70,9 +70,9 @@ static void UpdateAnimatedTileSpeed(TileIndex tile, AnimatedTileInfo &info) * on that table yet). Also increases the size of the table if necessary. * @param tile the tile to make animated */ -void AddAnimatedTile(TileIndex tile) +void AddAnimatedTile(TileIndex tile, bool mark_dirty) { - MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE); + if (mark_dirty) MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE); AnimatedTileInfo &info = _animated_tiles[tile]; UpdateAnimatedTileSpeed(tile, info); info.pending_deletion = false; diff --git a/src/animated_tile_func.h b/src/animated_tile_func.h index 0066f8a082..b00c815c27 100644 --- a/src/animated_tile_func.h +++ b/src/animated_tile_func.h @@ -12,7 +12,7 @@ #include "tile_type.h" -void AddAnimatedTile(TileIndex tile); +void AddAnimatedTile(TileIndex tile, bool mark_dirty = true); void DeleteAnimatedTile(TileIndex tile); void AnimateAnimatedTiles(); void UpdateAllAnimatedTileSpeeds(); diff --git a/src/base_station_base.h b/src/base_station_base.h index f6653b4973..c2d3cee6cf 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -211,11 +211,11 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { } private: - void SetRoadStopTileData(TileIndex tile, byte data, byte offset); + bool SetRoadStopTileData(TileIndex tile, byte data, byte offset); public: inline void SetRoadStopRandomBits(TileIndex tile, byte random_bits) { this->SetRoadStopTileData(tile, random_bits, 0); } - inline void SetRoadStopAnimationFrame(TileIndex tile, byte frame) { this->SetRoadStopTileData(tile, frame, 8); } + inline bool SetRoadStopAnimationFrame(TileIndex tile, byte frame) { return this->SetRoadStopTileData(tile, frame, 8); } void RemoveRoadStopTileData(TileIndex tile); static void PostDestructor(size_t index); diff --git a/src/newgrf_animation_base.h b/src/newgrf_animation_base.h index 95787c9c8c..1bc69cef7c 100644 --- a/src/newgrf_animation_base.h +++ b/src/newgrf_animation_base.h @@ -20,7 +20,16 @@ template struct TileAnimationFrameAnimationHelper { static byte Get(Tobj *obj, TileIndex tile) { return GetAnimationFrame(tile); } - static void Set(Tobj *obj, TileIndex tile, byte frame) { SetAnimationFrame(tile, frame); } + static bool Set(Tobj *obj, TileIndex tile, byte frame) + { + byte prev = GetAnimationFrame(tile); + if (frame != prev) { + SetAnimationFrame(tile, frame); + return true; + } else { + return false; + } + } }; /** @@ -105,8 +114,9 @@ struct AnimationBase { } } - Tframehelper::Set(obj, tile, frame); - MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE); + if (Tframehelper::Set(obj, tile, frame)) { + MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE); + } } /** @@ -127,12 +137,12 @@ struct AnimationBase { if (callback == CALLBACK_FAILED) return; switch (callback & 0xFF) { - case 0xFD: /* Do nothing. */ break; - case 0xFE: AddAnimatedTile(tile); break; - case 0xFF: DeleteAnimatedTile(tile); break; + case 0xFD: /* Do nothing. */ break; + case 0xFE: AddAnimatedTile(tile, false); break; + case 0xFF: DeleteAnimatedTile(tile); break; default: - Tframehelper::Set(obj, tile, callback); - AddAnimatedTile(tile); + bool changed = Tframehelper::Set(obj, tile, callback); + AddAnimatedTile(tile, changed); break; } diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index b07832f12d..702dda2cd6 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -333,7 +333,7 @@ uint16 GetAnimRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2 struct RoadStopAnimationFrameAnimationHelper { static byte Get(BaseStation *st, TileIndex tile) { return st->GetRoadStopAnimationFrame(tile); } - static void Set(BaseStation *st, TileIndex tile, byte frame) { st->SetRoadStopAnimationFrame(tile, frame); } + static bool Set(BaseStation *st, TileIndex tile, byte frame) { return st->SetRoadStopAnimationFrame(tile, frame); } }; /** Helper class for animation control. */ diff --git a/src/station.cpp b/src/station.cpp index 6f73e6db49..4f23a4d3f5 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -183,16 +183,18 @@ void BaseStation::PostDestructor(size_t index) InvalidateWindowData(WC_SELECT_STATION, 0, 0); } -void BaseStation::SetRoadStopTileData(TileIndex tile, byte data, byte offset) +bool BaseStation::SetRoadStopTileData(TileIndex tile, byte data, byte offset) { for (size_t i = 0; i < this->custom_road_stop_tiles.size(); i++) { if (this->custom_road_stop_tiles[i] == tile) { + if (GB(this->custom_road_stop_data[i], offset, 8) == data) return false; SB(this->custom_road_stop_data[i], offset, 8, data); - return; + return true; } } this->custom_road_stop_tiles.push_back(tile); this->custom_road_stop_data.push_back(((uint)data) << offset); + return data != 0; } void BaseStation::RemoveRoadStopTileData(TileIndex tile) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index a157947299..3aed46a97c 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2631,7 +2631,7 @@ static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byt IncreaseBuildingCount(t, type); MakeHouseTile(tile, t->index, counter, stage, type, random_bits); - if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile); + if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile, false); MarkTileDirtyByTile(tile); }