Mercurial > hg > openttd
changeset 15934:3172190fa127 draft
(svn r20622) -Codechange: unify [GS]et[Statation|Object|Industry|House]AnimationFrame
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 26 Aug 2010 14:45:45 +0000 |
parents | 8ac5258d7680 |
children | a4fa352275f4 |
files | src/industry_cmd.cpp src/industry_map.h src/newgrf_airporttiles.cpp src/newgrf_house.cpp src/newgrf_industries.cpp src/newgrf_industrytiles.cpp src/newgrf_station.cpp src/object_cmd.cpp src/object_map.h src/saveload/afterload.cpp src/station_cmd.cpp src/station_map.h src/tile_map.h src/town_map.h |
diffstat | 14 files changed, 83 insertions(+), 154 deletions(-) [+] |
line wrap: on
line diff
--- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -224,7 +224,7 @@ { if (!IsIndustryCompleted(ti->tile)) return; - const DrawIndustryAnimationStruct *d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)]; + const DrawIndustryAnimationStruct *d = &_draw_industry_spec1[GetAnimationFrame(ti->tile)]; AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0); @@ -243,7 +243,7 @@ uint8 x = 0; if (IsIndustryCompleted(ti->tile)) { - x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)]; + x = _industry_anim_offs_toffee[GetAnimationFrame(ti->tile)]; if (x == 0xFF) { x = 0; } @@ -256,7 +256,7 @@ static void IndustryDrawBubbleGenerator( const TileInfo *ti) { if (IsIndustryCompleted(ti->tile)) { - AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]); + AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetAnimationFrame(ti->tile)]); } else { AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67); } @@ -264,7 +264,7 @@ static void IndustryDrawToyFactory(const TileInfo *ti) { - const DrawIndustryAnimationStruct *d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)]; + const DrawIndustryAnimationStruct *d = &_industry_anim_offs_toys[GetAnimationFrame(ti->tile)]; if (d->image_1 != 0xFF) { AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1); @@ -281,7 +281,7 @@ static void IndustryDrawCoalPlantSparks(const TileInfo *ti) { if (IsIndustryCompleted(ti->tile)) { - uint8 image = GetIndustryAnimationState(ti->tile); + uint8 image = GetAnimationFrame(ti->tile); if (image != 0 && image < 7) { AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, @@ -328,7 +328,7 @@ } const DrawBuildingsTileStruct *dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ? - GetIndustryAnimationState(ti->tile) & INDUSTRY_COMPLETED : + GetAnimationFrame(ti->tile) & INDUSTRY_COMPLETED : GetIndustryConstructionStage(ti->tile))]; SpriteID image = dits->ground.sprite; @@ -541,7 +541,7 @@ switch (gfx) { case GFX_SUGAR_MINE_SIEVE: if ((_tick_counter & 1) == 0) { - byte m = GetIndustryAnimationState(tile) + 1; + byte m = GetAnimationFrame(tile) + 1; switch (m & 7) { case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; @@ -552,7 +552,7 @@ m = 0; DeleteAnimatedTile(tile); } - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); MarkTileDirtyByTile(tile); } @@ -560,7 +560,7 @@ case GFX_TOFFEE_QUARY: if ((_tick_counter & 3) == 0) { - byte m = GetIndustryAnimationState(tile); + byte m = GetAnimationFrame(tile); if (_industry_anim_offs_toffee[m] == 0xFF) { SndPlayTileFx(SND_30_CARTOON_SOUND, tile); @@ -570,7 +570,7 @@ m = 0; DeleteAnimatedTile(tile); } - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); MarkTileDirtyByTile(tile); } @@ -578,13 +578,13 @@ case GFX_BUBBLE_CATCHER: if ((_tick_counter & 1) == 0) { - byte m = GetIndustryAnimationState(tile); + byte m = GetAnimationFrame(tile); if (++m >= 40) { m = 0; DeleteAnimatedTile(tile); } - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); MarkTileDirtyByTile(tile); } @@ -593,12 +593,12 @@ /* Sparks on a coal plant */ case GFX_POWERPLANT_SPARKS: if ((_tick_counter & 3) == 0) { - byte m = GetIndustryAnimationState(tile); + byte m = GetAnimationFrame(tile); if (m == 6) { - SetIndustryAnimationState(tile, 0); + SetAnimationFrame(tile, 0); DeleteAnimatedTile(tile); } else { - SetIndustryAnimationState(tile, m + 1); + SetAnimationFrame(tile, m + 1); MarkTileDirtyByTile(tile); } } @@ -606,7 +606,7 @@ case GFX_TOY_FACTORY: if ((_tick_counter & 1) == 0) { - byte m = GetIndustryAnimationState(tile) + 1; + byte m = GetAnimationFrame(tile) + 1; switch (m) { case 1: SndPlayTileFx(SND_2C_MACHINERY, tile); break; @@ -624,7 +624,7 @@ } } - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); MarkTileDirtyByTile(tile); } break; @@ -649,13 +649,13 @@ bool b = Chance16(1, 7); IndustryGfx gfx = GetIndustryGfx(tile); - byte m = GetIndustryAnimationState(tile) + 1; + byte m = GetAnimationFrame(tile) + 1; if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) { SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED); SetIndustryConstructionStage(tile, 3); DeleteAnimatedTile(tile); } else { - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); SetIndustryGfx(tile, gfx); MarkTileDirtyByTile(tile); } @@ -671,26 +671,26 @@ if (state < 0x1A0) { if (state < 0x20 || state >= 0x180) { - byte m = GetIndustryAnimationState(tile); + byte m = GetAnimationFrame(tile); if (!(m & 0x40)) { - SetIndustryAnimationState(tile, m | 0x40); + SetAnimationFrame(tile, m | 0x40); SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); } if (state & 7) return; } else { if (state & 3) return; } - byte m = (GetIndustryAnimationState(tile) + 1) | 0x40; + byte m = (GetAnimationFrame(tile) + 1) | 0x40; if (m > 0xC2) m = 0xC0; - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); MarkTileDirtyByTile(tile); } else if (state >= 0x200 && state < 0x3A0) { int i = (state < 0x220 || state >= 0x380) ? 7 : 3; if (state & i) return; - byte m = (GetIndustryAnimationState(tile) & 0xBF) - 1; + byte m = (GetAnimationFrame(tile) & 0xBF) - 1; if (m < 0x80) m = 0x82; - SetIndustryAnimationState(tile, m); + SetAnimationFrame(tile, m); MarkTileDirtyByTile(tile); } break; @@ -754,7 +754,7 @@ case GFX_TOY_FACTORY: case GFX_BUBBLE_CATCHER: case GFX_TOFFEE_QUARY: - SetIndustryAnimationState(tile, 0); + SetAnimationFrame(tile, 0); SetIndustryAnimationLoop(tile, 0); break; @@ -826,7 +826,7 @@ case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED; break; } SetIndustryGfx(tile, gfx); - SetIndustryAnimationState(tile, 0x80); + SetAnimationFrame(tile, 0x80); AddAnimatedTile(tile); } break; @@ -834,7 +834,7 @@ case GFX_OILWELL_NOT_ANIMATED: if (Chance16(1, 6)) { SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1); - SetIndustryAnimationState(tile, 0); + SetAnimationFrame(tile, 0); AddAnimatedTile(tile); } break;
--- a/src/industry_map.h +++ b/src/industry_map.h @@ -229,29 +229,6 @@ } /** - * Get the animation state - * @param tile the tile to get the animation state of - * @pre IsTileType(tile, MP_INDUSTRY) - */ -static inline byte GetIndustryAnimationState(TileIndex tile) -{ - assert(IsTileType(tile, MP_INDUSTRY)); - return _me[tile].m7; -} - -/** - * Set the animation state - * @param tile the tile to set the animation state of - * @param state the new animation state - * @pre IsTileType(tile, MP_INDUSTRY) - */ -static inline void SetIndustryAnimationState(TileIndex tile, byte state) -{ - assert(IsTileType(tile, MP_INDUSTRY)); - _me[tile].m7 = state; -} - -/** * Get the random bits for this tile. * Used for grf callbacks * @param tile TileIndex of the tile to query
--- a/src/newgrf_airporttiles.cpp +++ b/src/newgrf_airporttiles.cpp @@ -185,7 +185,7 @@ case 0x43: return GetRelativePosition(tile, st->airport.tile); /* Animation frame of tile */ - case 0x44: return GetStationAnimationFrame(tile); + case 0x44: return GetAnimationFrame(tile); /* Land info of nearby tiles */ case 0x60: return GetNearbyAirportTileInformation(parameter, tile, st->index); @@ -194,7 +194,7 @@ case 0x61: tile = GetNearbyTile(parameter, tile); if (st->TileBelongsToAirport(tile)) { - return GetStationAnimationFrame(tile); + return GetAnimationFrame(tile); } return UINT_MAX; @@ -322,7 +322,7 @@ if ((_tick_counter % (1 << animation_speed)) != 0) return; bool frame_set_by_callback = false; - uint8 frame = GetStationAnimationFrame(tile); + uint8 frame = GetAnimationFrame(tile); uint16 num_frames = GB(ats->animation_info, 0, 8); if (HasBit(ats->callback_mask, CBM_AIRT_ANIM_NEXT_FRAME)) { @@ -362,7 +362,7 @@ } } - SetStationAnimationFrame(tile, frame); + SetAnimationFrame(tile, frame); MarkTileDirtyByTile(tile); } @@ -376,7 +376,7 @@ case 0xFE: AddAnimatedTile(tile); break; case 0xFF: DeleteAnimatedTile(tile); break; default: - SetStationAnimationFrame(tile, callback_res & 0xFF); + SetAnimationFrame(tile, callback_res & 0xFF); AddAnimatedTile(tile); break; }
--- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -286,7 +286,7 @@ case 0x45: return _generating_world ? 1 : 0; /* Current animation frame. */ - case 0x46: return IsTileType(tile, MP_HOUSE) ? GetHouseAnimationFrame(tile) : 0; + case 0x46: return IsTileType(tile, MP_HOUSE) ? GetAnimationFrame(tile) : 0; /* Position of the house */ case 0x47: return TileY(tile) << 16 | TileX(tile); @@ -309,7 +309,7 @@ /* Current animation frame of nearby house tiles */ case 0x63: { TileIndex testtile = GetNearbyTile(parameter, tile); - return IsTileType(testtile, MP_HOUSE) ? GetHouseAnimationFrame(testtile) : 0; + return IsTileType(testtile, MP_HOUSE) ? GetAnimationFrame(testtile) : 0; } /* Cargo acceptance history of nearby stations */ @@ -488,7 +488,7 @@ * maximum, corresponding to around 33 minutes. */ if (_tick_counter % (1 << animation_speed) != 0) return; - byte frame = GetHouseAnimationFrame(tile); + byte frame = GetAnimationFrame(tile); byte num_frames = GB(hs->animation_frames, 0, 7); if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_NEXT_FRAME)) { @@ -529,7 +529,7 @@ } } - SetHouseAnimationFrame(tile, frame); + SetAnimationFrame(tile, frame); MarkTileDirtyByTile(tile); } @@ -540,7 +540,7 @@ case 0xFE: AddAnimatedTile(tile); break; case 0xFF: DeleteAnimatedTile(tile); break; default: - SetHouseAnimationFrame(tile, callback_result & 0xFF); + SetAnimationFrame(tile, callback_result & 0xFF); AddAnimatedTile(tile); break; }
--- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -251,7 +251,7 @@ case 0x63: tile = GetNearbyTile(parameter, tile); if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) { - return GetIndustryAnimationState(tile); + return GetAnimationFrame(tile); } return 0xFFFFFFFF;
--- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -87,7 +87,7 @@ case 0x43: return GetRelativePosition(tile, inds->location.tile); /* Animation frame. Like house variable 46 but can contain anything 0..FF. */ - case 0x44: return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryAnimationState(tile) : 0; + case 0x44: return (IsTileType(tile, MP_INDUSTRY)) ? GetAnimationFrame(tile) : 0; /* Land info of nearby tiles */ case 0x60: return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index); @@ -96,7 +96,7 @@ case 0x61: tile = GetNearbyTile(parameter, tile); if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == inds) { - return GetIndustryAnimationState(tile); + return GetAnimationFrame(tile); } return UINT_MAX; @@ -316,7 +316,7 @@ if ((_tick_counter % (1 << animation_speed)) != 0) return; bool frame_set_by_callback = false; - byte frame = GetIndustryAnimationState(tile); + byte frame = GetAnimationFrame(tile); uint16 num_frames = GB(itspec->animation_info, 0, 8); if (HasBit(itspec->callback_mask, CBM_INDT_ANIM_NEXT_FRAME)) { @@ -357,7 +357,7 @@ } } - SetIndustryAnimationState(tile, frame); + SetAnimationFrame(tile, frame); MarkTileDirtyByTile(tile); } @@ -371,7 +371,7 @@ case 0xFE: AddAnimatedTile(tile); break; case 0xFF: DeleteAnimatedTile(tile); break; default: - SetIndustryAnimationState(tile, callback_res & 0xFF); + SetAnimationFrame(tile, callback_res & 0xFF); AddAnimatedTile(tile); break; }
--- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -325,13 +325,13 @@ return _svc.v49; case 0x4A: // Animation frame of tile - return GetStationAnimationFrame(tile); + return GetAnimationFrame(tile); /* Variables which use the parameter */ /* Variables 0x60 to 0x65 are handled separately below */ case 0x66: // Animation frame of nearby tile if (parameter != 0) tile = GetNearbyTile(parameter, tile); - return st->TileBelongsToRailStation(tile) ? GetStationAnimationFrame(tile) : UINT_MAX; + return st->TileBelongsToRailStation(tile) ? GetAnimationFrame(tile) : UINT_MAX; case 0x67: { // Land info of nearby tile Axis axis = GetRailStationAxis(tile); @@ -827,7 +827,7 @@ if (_tick_counter % (1 << animation_speed) != 0) return; - uint8 frame = GetStationAnimationFrame(tile); + uint8 frame = GetAnimationFrame(tile); uint8 num_frames = ss->anim_frames; bool frame_set_by_callback = false; @@ -871,7 +871,7 @@ } } - SetStationAnimationFrame(tile, frame); + SetAnimationFrame(tile, frame); MarkTileDirtyByTile(tile); } @@ -886,7 +886,7 @@ case 0xFE: AddAnimatedTile(tile); break; case 0xFF: DeleteAnimatedTile(tile); break; default: - SetStationAnimationFrame(tile, callback); + SetAnimationFrame(tile, callback); AddAnimatedTile(tile); break; }
--- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -89,13 +89,13 @@ { TileArea ta = Object::GetByTile(tile)->location; TILE_AREA_LOOP(t, ta) { - SetObjectAnimationStage(t, GetObjectAnimationStage(t) + 1); + SetAnimationFrame(t, GetAnimationFrame(t) + 1); MarkTileDirtyByTile(t); } } /** We encode the company HQ size in the animation stage. */ -#define GetCompanyHQSize GetObjectAnimationStage +#define GetCompanyHQSize GetAnimationFrame /** We encode the company HQ size in the animation stage. */ #define IncreaseCompanyHQSize IncreaseAnimationStage
--- a/src/object_map.h +++ b/src/object_map.h @@ -106,30 +106,6 @@ return IsTileType(t, MP_OBJECT) && IsStatue(t); } -/** - * Get animation stage/counter of this tile. - * @param t The tile to query. - * @pre IsTileType(t, MP_OBJECT) - * @return The animation 'stage' of the tile. - */ -static inline byte GetObjectAnimationStage(TileIndex t) -{ - assert(IsTileType(t, MP_OBJECT)); - return _me[t].m7; -} - -/** - * Set animation stage/counter of this tile. - * @param t The tile to query. - * @param stage The stage of this tile. - * @pre IsTileType(t, MP_OBJECT) - */ -static inline void SetObjectAnimationStage(TileIndex t, uint8 stage) -{ - assert(IsTileType(t, MP_OBJECT)); - _me[t].m7 = stage; -} - /** * Make an Object tile.
--- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2176,7 +2176,7 @@ break; } if (old_gfx < atc[i].old_start + atc[i].num_frames) { - SetStationAnimationFrame(t, old_gfx - atc[i].old_start); + SetAnimationFrame(t, old_gfx - atc[i].old_start); SetStationGfx(t, atc[i].old_start - offset); break; }
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1277,7 +1277,7 @@ SetCustomStationSpecIndex(tile, specindex); SetStationTileRandomBits(tile, GB(Random(), 0, 4)); - SetStationAnimationFrame(tile, 0); + SetAnimationFrame(tile, 0); if (statspec != NULL) { /* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */ @@ -2578,19 +2578,19 @@ } switch (gfx) { case APT_RADAR_GRASS_FENCE_SW: - t = &_station_display_datas_airport_radar_grass_fence_sw[GetStationAnimationFrame(ti->tile)]; + t = &_station_display_datas_airport_radar_grass_fence_sw[GetAnimationFrame(ti->tile)]; break; case APT_GRASS_FENCE_NE_FLAG: - t = &_station_display_datas_airport_flag_grass_fence_ne[GetStationAnimationFrame(ti->tile)]; + t = &_station_display_datas_airport_flag_grass_fence_ne[GetAnimationFrame(ti->tile)]; break; case APT_RADAR_FENCE_SW: - t = &_station_display_datas_airport_radar_fence_sw[GetStationAnimationFrame(ti->tile)]; + t = &_station_display_datas_airport_radar_fence_sw[GetAnimationFrame(ti->tile)]; break; case APT_RADAR_FENCE_NE: - t = &_station_display_datas_airport_radar_fence_ne[GetStationAnimationFrame(ti->tile)]; + t = &_station_display_datas_airport_radar_fence_ne[GetAnimationFrame(ti->tile)]; break; case APT_GRASS_FENCE_NE_FLAG_2: - t = &_station_display_datas_airport_flag_grass_fence_ne_2[GetStationAnimationFrame(ti->tile)]; + t = &_station_display_datas_airport_flag_grass_fence_ne_2[GetAnimationFrame(ti->tile)]; break; } }
--- a/src/station_map.h +++ b/src/station_map.h @@ -85,30 +85,6 @@ } /** - * Get the station's animation frame of this tile - * @param t the tile to query - * @pre IsTileType(t, MP_STATION) - * @return the station's animation frame - */ -static inline uint8 GetStationAnimationFrame(TileIndex t) -{ - assert(IsTileType(t, MP_STATION)); - return _me[t].m7; -} - -/** - * Set the station's animation frame of this tile - * @param t the tile to update - * @param frame the new frame - * @pre IsTileType(t, MP_STATION) - */ -static inline void SetStationAnimationFrame(TileIndex t, uint8 frame) -{ - assert(IsTileType(t, MP_STATION)); - _me[t].m7 = frame; -} - -/** * Is this station tile a rail station? * @param t the tile to get the information from * @pre IsTileType(t, MP_STATION)
--- a/src/tile_map.h +++ b/src/tile_map.h @@ -202,6 +202,30 @@ return (TropicZone)GB(_m[tile].m6, 0, 2); } +/** + * Get the current animation frame + * @param t the tile + * @pre IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION) + * @return frame number + */ +static inline byte GetAnimationFrame(TileIndex t) +{ + assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION)); + return _me[t].m7; +} + +/** + * Set a new animation frame + * @param t the tile + * @param frame the new frame number + * @pre IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION) + */ +static inline void SetAnimationFrame(TileIndex t, byte frame) +{ + assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_OBJECT) || IsTileType(t, MP_INDUSTRY) ||IsTileType(t, MP_STATION)); + _me[t].m7 = frame; +} + Slope GetTileSlope(TileIndex tile, uint *h); uint GetTileZ(TileIndex tile); uint GetTileMaxZ(TileIndex tile);
--- a/src/town_map.h +++ b/src/town_map.h @@ -140,30 +140,6 @@ } /** - * Get the current animation frame for this house - * @param t the tile - * @pre IsTileType(t, MP_HOUSE) - * @return frame number - */ -static inline byte GetHouseAnimationFrame(TileIndex t) -{ - assert(IsTileType(t, MP_HOUSE)); - return _me[t].m7; -} - -/** - * Set a new animation frame for this house - * @param t the tile - * @param frame the new frame number - * @pre IsTileType(t, MP_HOUSE) - */ -static inline void SetHouseAnimationFrame(TileIndex t, byte frame) -{ - assert(IsTileType(t, MP_HOUSE)); - _me[t].m7 = frame; -} - -/** * Get the completion of this house * @param t the tile * @return true if it is, false if it is not @@ -386,7 +362,7 @@ SetHouseType(t, type); SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED); _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter); - SetHouseAnimationFrame(t, 0); + SetAnimationFrame(t, 0); SetHouseProcessingTime(t, HouseSpec::Get(type)->processing_time); }