Codechange: Don't mark animated tiles dirty if frame is not changed.

If animation is continued but the animation frame has not changed then there is no need to mark the tile for refresh.

Loosely backport from JGRPP.
This commit is contained in:
Peter Nelson 2024-08-01 21:14:41 +01:00 committed by Peter Nelson
parent 8754846901
commit 1ff35cb6f9
4 changed files with 21 additions and 15 deletions

View File

@ -196,11 +196,11 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
}
private:
void SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation);
bool SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation);
public:
inline void SetRoadStopRandomBits(TileIndex tile, uint8_t random_bits) { this->SetRoadStopTileData(tile, random_bits, false); }
inline void SetRoadStopAnimationFrame(TileIndex tile, uint8_t frame) { this->SetRoadStopTileData(tile, frame, true); }
inline bool SetRoadStopAnimationFrame(TileIndex tile, uint8_t frame) { return this->SetRoadStopTileData(tile, frame, true); }
void RemoveRoadStopTileData(TileIndex tile);
static void PostDestructor(size_t index);

View File

@ -20,7 +20,14 @@
template <typename Tobj>
struct TileAnimationFrameAnimationHelper {
static uint8_t Get(Tobj *, TileIndex tile) { return GetAnimationFrame(tile); }
static void Set(Tobj *, TileIndex tile, uint8_t frame) { SetAnimationFrame(tile, frame); }
static bool Set(Tobj *, TileIndex tile, uint8_t frame)
{
uint8_t prev_frame = GetAnimationFrame(tile);
if (prev_frame == frame) return false;
SetAnimationFrame(tile, frame);
return true;
}
};
/**
@ -105,8 +112,8 @@ struct AnimationBase {
}
}
Tframehelper::Set(obj, tile, frame);
MarkTileDirtyByTile(tile);
bool changed = Tframehelper::Set(obj, tile, frame);
if (changed) MarkTileDirtyByTile(tile);
}
/**
@ -131,8 +138,8 @@ struct AnimationBase {
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;
}

View File

@ -344,7 +344,7 @@ uint16_t GetAnimRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t
struct RoadStopAnimationFrameAnimationHelper {
static uint8_t Get(BaseStation *st, TileIndex tile) { return st->GetRoadStopAnimationFrame(tile); }
static void Set(BaseStation *st, TileIndex tile, uint8_t frame) { st->SetRoadStopAnimationFrame(tile, frame); }
static bool Set(BaseStation *st, TileIndex tile, uint8_t frame) { return st->SetRoadStopAnimationFrame(tile, frame); }
};
/** Helper class for animation control. */

View File

@ -168,16 +168,14 @@ void BaseStation::PostDestructor(size_t)
InvalidateWindowData(WC_SELECT_STATION, 0, 0);
}
void BaseStation::SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation)
bool BaseStation::SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation)
{
for (RoadStopTileData &tile_data : this->custom_roadstop_tile_data) {
if (tile_data.tile == tile) {
if (animation) {
tile_data.animation_frame = data;
} else {
tile_data.random_bits = data;
}
return;
uint8_t &v = animation ? tile_data.animation_frame : tile_data.random_bits;
if (v == data) return false;
v = data;
return true;
}
}
RoadStopTileData tile_data;
@ -185,6 +183,7 @@ void BaseStation::SetRoadStopTileData(TileIndex tile, uint8_t data, bool animati
tile_data.animation_frame = animation ? data : 0;
tile_data.random_bits = animation ? 0 : data;
this->custom_roadstop_tile_data.push_back(tile_data);
return data != 0;
}
void BaseStation::RemoveRoadStopTileData(TileIndex tile)