# HG changeset patch # User michi_cc # Date 1320100295 0 # Node ID 06aefc7e77d0743f9618e4090e15eff5b9046f33 # Parent 800fb3479a7e349de85c77a0779629e4b05d5bce (svn r23071) -Codechange: [NewGRF] Allow passing custom extra data through the generic NewGRF animation helper class. diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp --- a/src/newgrf_airporttiles.cpp +++ b/src/newgrf_airporttiles.cpp @@ -243,7 +243,7 @@ res->grffile = ats->grf_prop.grffile; } -uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, const AirportTileSpec *ats, Station *st, TileIndex tile) +uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2, const AirportTileSpec *ats, Station *st, TileIndex tile, int extra_data = 0) { ResolverObject object; const SpriteGroup *group; @@ -306,7 +306,7 @@ } /** Helper class for animation control. */ -struct AirportTileAnimationBase : public AnimationBase { +struct AirportTileAnimationBase : public AnimationBase { static const CallbackID cb_animation_speed = CBID_AIRPTILE_ANIMATION_SPEED; static const CallbackID cb_animation_next_frame = CBID_AIRPTILE_ANIM_NEXT_FRAME; diff --git a/src/newgrf_animation_base.h b/src/newgrf_animation_base.h --- a/src/newgrf_animation_base.h +++ b/src/newgrf_animation_base.h @@ -23,9 +23,10 @@ * @tparam Tbase Instantiation of this class. * @tparam Tspec NewGRF specification related to the animated tile. * @tparam Tobj Object related to the animated tile. + * @tparam Textra Custom extra callback data. * @tparam GetCallback The callback function pointer. */ -template +template struct AnimationBase { /** * Animate a single tile. @@ -34,15 +35,16 @@ * @param obj Object related to the tile. * @param tile Tile to animate changes for. * @param random_animation Whether to pass random bits to the "next frame" callback. + * @param extra_data Custom extra callback data. */ - static void AnimateTile(const Tspec *spec, Tobj *obj, TileIndex tile, bool random_animation) + static void AnimateTile(const Tspec *spec, Tobj *obj, TileIndex tile, bool random_animation, Textra extra_data = 0) { assert(spec != NULL); /* Acquire the animation speed from the NewGRF. */ uint8 animation_speed = spec->animation.speed; if (HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) { - uint16 callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile); + uint16 callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data); if (callback != CALLBACK_FAILED) animation_speed = Clamp(callback & 0xFF, 0, 16); } @@ -58,7 +60,7 @@ bool frame_set_by_callback = false; if (HasBit(spec->callback_mask, Tbase::cbm_animation_next_frame)) { - uint16 callback = GetCallback(Tbase::cb_animation_next_frame, random_animation ? Random() : 0, 0, spec, obj, tile); + uint16 callback = GetCallback(Tbase::cb_animation_next_frame, random_animation ? Random() : 0, 0, spec, obj, tile, extra_data); if (callback != CALLBACK_FAILED) { frame_set_by_callback = true; @@ -109,10 +111,11 @@ * @param tile Tile to consider animation changes for. * @param random_bits Random bits for this update. To be passed as parameter to the NewGRF. * @param trigger What triggered this update? To be passed as parameter to the NewGRF. + * @param extra_data Custom extra data for callback processing. */ - static void ChangeAnimationFrame(CallbackID cb, const Tspec *spec, Tobj *obj, TileIndex tile, uint32 random_bits, uint32 trigger) + static void ChangeAnimationFrame(CallbackID cb, const Tspec *spec, Tobj *obj, TileIndex tile, uint32 random_bits, uint32 trigger, Textra extra_data = 0) { - uint16 callback = GetCallback(cb, random_bits, trigger, spec, obj, tile); + uint16 callback = GetCallback(cb, random_bits, trigger, spec, obj, tile, extra_data); if (callback == CALLBACK_FAILED) return; switch (callback & 0xFF) { diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -505,13 +505,13 @@ } /* Simple wrapper for GetHouseCallback to keep the animation unified. */ -uint16 GetSimpleHouseCallback(CallbackID callback, uint32 param1, uint32 param2, const HouseSpec *spec, Town *town, TileIndex tile) +uint16 GetSimpleHouseCallback(CallbackID callback, uint32 param1, uint32 param2, const HouseSpec *spec, Town *town, TileIndex tile, uint32 extra_data) { return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile); } /** Helper class for animation control. */ -struct HouseAnimationBase : public AnimationBase { +struct HouseAnimationBase : public AnimationBase { static const CallbackID cb_animation_speed = CBID_HOUSE_ANIMATION_SPEED; static const CallbackID cb_animation_next_frame = CBID_HOUSE_ANIMATION_NEXT_FRAME; diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -307,13 +307,13 @@ } /* Simple wrapper for GetHouseCallback to keep the animation unified. */ -uint16 GetSimpleIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, const IndustryTileSpec *spec, Industry *ind, TileIndex tile) +uint16 GetSimpleIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, const IndustryTileSpec *spec, Industry *ind, TileIndex tile, int extra_data) { return GetIndustryTileCallback(callback, param1, param2, spec - GetIndustryTileSpec(0), ind, tile); } /** Helper class for animation control. */ -struct IndustryAnimationBase : public AnimationBase { +struct IndustryAnimationBase : public AnimationBase { static const CallbackID cb_animation_speed = CBID_INDTILE_ANIMATION_SPEED; static const CallbackID cb_animation_next_frame = CBID_INDTILE_ANIM_NEXT_FRAME; diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -521,15 +521,16 @@ * @param spec The specification of the object / the entry point. * @param o The object to call the callback for. * @param tile The tile the callback is called for. + * @param extra_data Ignored. * @return The result of the callback. */ -uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile) +uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data) { return GetObjectCallback(callback, param1, param2, spec, o, tile); } /** Helper class for animation control. */ -struct ObjectAnimationBase : public AnimationBase { +struct ObjectAnimationBase : public AnimationBase { static const CallbackID cb_animation_speed = CBID_OBJECT_ANIMATION_SPEED; static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME; diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -908,8 +908,14 @@ !HasBit(statspec->wires, GetStationGfx(tile)); } +/** Wrapper for animation control, see #GetStationCallback. */ +uint16 GetAnimStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int extra_data) +{ + return GetStationCallback(callback, param1, param2, statspec, st, tile); +} + /** Helper class for animation control. */ -struct StationAnimationBase : public AnimationBase { +struct StationAnimationBase : public AnimationBase { static const CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED; static const CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME;