OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
28 template <
typename Tbase,
typename Tspec,
typename Tobj,
typename Textra, u
int16 (*GetCallback)(CallbackID callback, u
int32 param1, u
int32 param2, const Tspec *statspec, Tobj *st, TileIndex tile, Textra extra_data)>
38 static void AnimateTile(
const Tspec *spec, Tobj *obj,
TileIndex tile,
bool random_animation, Textra extra_data = 0)
40 assert(spec !=
nullptr);
43 uint8 animation_speed = spec->animation.speed;
44 if (
HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) {
45 uint16 callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data);
47 if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8)
ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, Tbase::cb_animation_speed, callback);
48 animation_speed =
Clamp(callback & 0xFF, 0, 16);
59 uint8 num_frames = spec->animation.frames;
61 bool frame_set_by_callback =
false;
63 if (
HasBit(spec->callback_mask, Tbase::cbm_animation_next_frame)) {
64 uint16 callback = GetCallback(Tbase::cb_animation_next_frame, random_animation ? Random() : 0, 0, spec, obj, tile, extra_data);
67 frame_set_by_callback =
true;
69 switch (callback & 0xFF) {
75 frame_set_by_callback =
false;
79 frame = callback & 0xFF;
89 if (!frame_set_by_callback) {
90 if (frame < num_frames) {
119 uint16 callback = GetCallback(cb, random_bits, trigger, spec, obj, tile, extra_data);
122 switch (callback & 0xFF) {
uint32 TileIndex
The index/ID of a Tile.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static void ChangeAnimationFrame(CallbackID cb, const Tspec *spec, Tobj *obj, TileIndex tile, uint32 random_bits, uint32 trigger, Textra extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
ClientSettings _settings_client
The current settings for this game.
static void AnimateTile(const Tspec *spec, Tobj *obj, TileIndex tile, bool random_animation, Textra extra_data=0)
Animate a single tile.
CallbackID
List of implemented NewGRF callbacks.
bool ambient
Play ambient, industry and town sounds.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
SoundSettings sound
sound effect settings
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Helper class for a unified approach to NewGRF animation.
static const uint8 ANIM_STATUS_LOOPING
Animation is looping.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet).