20 template <
typename Tobj>
23 static bool Set(Tobj *,
TileIndex tile, uint8_t frame)
26 if (prev_frame == frame)
return false;
42 template <
typename Tbase,
typename Tspec,
typename Tobj,
typename Textra, u
int16_t (*GetCallback)(CallbackID callback, u
int32_t param1, u
int32_t param2, const Tspec *statspec, Tobj *st, TileIndex tile, Textra extra_data),
typename Tframehelper>
52 static void AnimateTile(
const Tspec *spec, Tobj *obj,
TileIndex tile,
bool random_animation, Textra extra_data = 0)
54 assert(spec !=
nullptr);
57 uint8_t animation_speed = spec->animation.speed;
58 if (
HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) {
59 uint16_t callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data);
61 if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8)
ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, Tbase::cb_animation_speed, callback);
62 animation_speed =
Clamp(callback & 0xFF, 0, 16);
72 uint8_t frame = Tframehelper::Get(obj, tile);
73 uint8_t num_frames = spec->animation.frames;
75 bool frame_set_by_callback =
false;
77 if (
HasBit(spec->callback_mask, Tbase::cbm_animation_next_frame)) {
78 uint16_t callback = GetCallback(Tbase::cb_animation_next_frame, random_animation ? Random() : 0, 0, spec, obj, tile, extra_data);
81 frame_set_by_callback =
true;
83 switch (callback & 0xFF) {
89 frame_set_by_callback =
false;
93 frame = callback & 0xFF;
103 if (!frame_set_by_callback) {
104 if (frame < num_frames) {
115 bool changed = Tframehelper::Set(obj, tile, frame);
133 uint16_t callback = GetCallback(cb, random_bits, trigger, spec, obj, tile, extra_data);
136 switch (callback & 0xFF) {
141 bool changed = Tframehelper::Set(obj, tile, callback);
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
void AddAnimatedTile(TileIndex tile, bool mark_dirty)
Add the given tile to the animated tile table (if it does not exist yet).
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definitions related to NewGRF animation.
static const uint8_t ANIM_STATUS_LOOPING
Animation is looping.
Callbacks that NewGRFs could implement.
CallbackID
List of implemented NewGRF callbacks.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
Pseudo random number generator.
ClientSettings _settings_client
The current settings for this game.
Helper class for a unified approach to NewGRF animation.
static void AnimateTile(const Tspec *spec, Tobj *obj, TileIndex tile, bool random_animation, Textra extra_data=0)
Animate a single tile.
static void ChangeAnimationFrame(CallbackID cb, const Tspec *spec, Tobj *obj, TileIndex tile, uint32_t random_bits, uint32_t trigger, Textra extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
SoundSettings sound
sound effect settings
bool ambient
Play ambient, industry and town sounds.
Map writing/reading functions for tiles.
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
void SetAnimationFrame(Tile t, uint8_t frame)
Set a new animation frame.
Definition of the tick-based game-timer.
Functions related to (drawing on) viewports.