diff options
author | frosch <frosch@openttd.org> | 2010-01-17 15:05:25 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-01-17 15:05:25 +0000 |
commit | 24e0945bc462ea0687689880caf0d830455934e2 (patch) | |
tree | 489fd14a952047f356b8258eb6f5f799d23d5c47 | |
parent | 830af8ee77bbbedb23f4caa53c8b47c20235f1b2 (diff) | |
download | openttd-24e0945bc462ea0687689880caf0d830455934e2.tar.xz |
(svn r18846) -Codechange: Merge DrawTileSeq into DrawCommonTileSeq.
-rw-r--r-- | src/newgrf_commons.cpp | 41 | ||||
-rw-r--r-- | src/newgrf_commons.h | 4 | ||||
-rw-r--r-- | src/newgrf_house.cpp | 3 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 3 | ||||
-rw-r--r-- | src/newgrf_station.cpp | 2 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 5 | ||||
-rw-r--r-- | src/road_cmd.cpp | 5 | ||||
-rw-r--r-- | src/sprite.cpp | 23 | ||||
-rw-r--r-- | src/sprite.h | 49 | ||||
-rw-r--r-- | src/spritecache.h | 1 | ||||
-rw-r--r-- | src/station_cmd.cpp | 4 |
11 files changed, 76 insertions, 64 deletions
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 5d6abd15a..cf8683498 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -19,7 +19,6 @@ #include "newgrf_commons.h" #include "station_map.h" #include "tree_map.h" -#include "viewport_func.h" #include "core/mem_func.hpp" /** Constructor of generic class @@ -323,43 +322,3 @@ uint32 GetNearbyTileInformation(TileIndex tile) byte terrain_type = GetTerrainType(tile) << 2 | (tile_type == MP_WATER ? 1 : 0) << 1; return tile_type << 24 | z << 16 | terrain_type << 8 | tileh; } - -/** - * Draws a building including all subsprites on a tile. - * @param ti The tile to draw on - * @param dts Sprite and subsprites to draw - * @param to The transparancy bit that toggles drawing of these sprites - * @param stage The construction stage (0-3) - * @param default_palette The default recolour sprite to use (typically company colour resp. random industry/house colour) - */ -void DrawTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, byte stage, SpriteID default_palette) -{ - const DrawTileSeqStruct *dtss; - foreach_draw_tile_seq(dtss, dts->seq) { - if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue; - - SpriteID image = dtss->image.sprite; - - /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */ - if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; - - if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) { - image += stage; - } - - SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette); - - if ((byte)dtss->delta_z != 0x80) { - AddSortableSpriteToDraw( - image, pal, - ti->x + dtss->delta_x, ti->y + dtss->delta_y, - dtss->size_x, dtss->size_y, - dtss->size_z, ti->z + dtss->delta_z, - !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to) - ); - } else { - /* For industries and houses delta_x and delta_y are unsigned */ - AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)); - } - } -} diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index 92546d7e8..56a16aaeb 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -15,8 +15,6 @@ #define NEWGRF_COMMONS_H #include "tile_cmd.h" -#include "transparency.h" -#include "sprite.h" /** * Maps an entity id stored on the map to a GRF file. @@ -107,6 +105,4 @@ uint32 GetTerrainType(TileIndex tile); TileIndex GetNearbyTile(byte parameter, TileIndex tile); uint32 GetNearbyTileInformation(TileIndex tile); -void DrawTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, byte stage, SpriteID default_palette); - #endif /* NEWGRF_COMMONS_H */ diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index ab28d5093..2a2e4cd3f 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -26,6 +26,7 @@ #include "company_base.h" #include "town.h" #include "core/random_func.hpp" +#include "sprite.h" static BuildingCounts<uint32> _building_counts; static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX]; @@ -421,7 +422,7 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette)); } - DrawTileSeq(ti, dts, TO_HOUSES, stage, palette); + DrawNewGRFTileSeq(ti, dts, TO_HOUSES, stage, palette); } void DrawNewHouseTile(TileInfo *ti, HouseID house_id) diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index ac1d3be8e..4afc810ee 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -26,6 +26,7 @@ #include "command_func.h" #include "animated_tile_func.h" #include "water.h" +#include "sprite.h" #include "table/strings.h" @@ -185,7 +186,7 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGro } } - DrawTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour)); + DrawNewGRFTileSeq(ti, dts, TO_INDUSTRIES, stage, GENERAL_SPRITE_COLOUR(rnd_colour)); } uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile) diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 94adbe869..f1301ea72 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -909,7 +909,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y); - DrawCommonTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette); + DrawRailTileSeqInGUI(x, y, sprites, rti->total_offset, relocation, palette); return true; } diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index d7622d831..205cd2ce2 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -35,6 +35,7 @@ #include "company_base.h" #include "table/strings.h" +#include "table/sprites.h" #include "table/railtypes.h" #include "table/track_land.h" @@ -1981,7 +1982,7 @@ static void DrawTile_Track(TileInfo *ti) if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti); /* No NewGRF depots, so no relocation */ - DrawCommonTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette); + DrawRailTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette); } DrawBridgeMiddle(ti); } @@ -1999,7 +2000,7 @@ void DrawTrainDepotSprite(int x, int y, int dir, RailType railtype) SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company); DrawSprite(image, PAL_NONE, x, y); - DrawCommonTileSeqInGUI(x, y, dts, offset, 0, palette); + DrawRailTileSeqInGUI(x, y, dts, offset, 0, palette); } static uint GetSlopeZ_Track(TileIndex tile, uint x, uint y) diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index ed9192319..56ae78847 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -36,7 +36,6 @@ #include "company_base.h" #include "core/random_func.hpp" -#include "table/sprites.h" #include "table/strings.h" /** @@ -1223,7 +1222,7 @@ static void DrawTile_Road(TileInfo *ti) } DrawGroundSprite(dts->ground.sprite, PAL_NONE); - DrawCommonTileSeq(ti, dts, TO_BUILDINGS, 0, 0, palette); + DrawOrigTileSeq(ti, dts, TO_BUILDINGS, palette); break; } } @@ -1239,7 +1238,7 @@ void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt) y += 17; DrawSprite(dts->ground.sprite, PAL_NONE, x, y); - DrawCommonTileSeqInGUI(x, y, dts, 0, 0, palette); + DrawOrigTileSeqInGUI(x, y, dts, palette); } /** diff --git a/src/sprite.cpp b/src/sprite.cpp index 719fe0550..bfb0acff5 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -26,13 +26,17 @@ * @param orig_offset Sprite-Offset for original sprites * @param newgrf_offset Sprite-Offset for NewGRF defined sprites * @param default_palette The default recolour sprite to use (typically company colour) + * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned */ -void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette) +void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned) { const DrawTileSeqStruct *dtss; foreach_draw_tile_seq(dtss, dts->seq) { SpriteID image = dtss->image.sprite; + /* TTD sprite 0 means no sprite */ + if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue; + /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */ if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; @@ -49,8 +53,9 @@ void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, Transpare !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to) ); } else { - /* For stations and original spritelayouts delta_x and delta_y are signed */ - AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)); + int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x; + int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y; + AddChildSpriteScreen(image, pal, offs_x, offs_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)); } } } @@ -63,14 +68,19 @@ void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, Transpare * @param orig_offset Sprite-Offset for original sprites * @param newgrf_offset Sprite-Offset for NewGRF defined sprites * @param default_palette The default recolour sprite to use (typically company colour) + * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned */ -void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette) +void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned) { const DrawTileSeqStruct *dtss; Point child_offset = {0, 0}; foreach_draw_tile_seq(dtss, dts->seq) { SpriteID image = dtss->image.sprite; + + /* TTD sprite 0 means no sprite */ + if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue; + image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset); SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette); @@ -83,8 +93,9 @@ void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig child_offset.x = pt.x + spr->x_offs; child_offset.y = pt.y + spr->y_offs; } else { - /* For stations and original spritelayouts delta_x and delta_y are signed */ - DrawSprite(image, pal, x + child_offset.x + dtss->delta_x, y + child_offset.y + dtss->delta_y); + int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x; + int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y; + DrawSprite(image, pal, x + child_offset.x + offs_x, y + child_offset.y + offs_y); } } } diff --git a/src/sprite.h b/src/sprite.h index 9144fe979..d831e31c4 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -59,10 +59,53 @@ struct DrawBuildingsTileStruct { /** Iterate through all DrawTileSeqStructs in DrawTileSprites. */ #define foreach_draw_tile_seq(idx, list) for (idx = list; ((byte) idx->delta_x) != 0x80; idx++) -void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette); -void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette); +void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned); +void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned); -bool SkipSpriteData(byte type, uint16 num); +/** + * Draw tile sprite sequence on tile with railroad specifics. + * @param total_offset Spriteoffset from normal rail to current railtype. + * @param newgrf_offset Startsprite of the Action1 to use. + */ +static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, SpriteID default_palette) +{ + DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false); +} + +/** + * Draw tile sprite sequence in GUI with railroad specifics. + * @param total_offset Spriteoffset from normal rail to current railtype. + * @param newgrf_offset Startsprite of the Action1 to use. + */ +static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, SpriteID default_palette) +{ + DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false); +} + +/** + * Draw TTD sprite sequence on tile. + */ +static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, SpriteID default_palette) +{ + DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false); +} + +/** + * Draw TTD sprite sequence in GUI. + */ +static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, SpriteID default_palette) +{ + DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false); +} + +/** + * Draw NewGRF industrytile or house sprite layout + * @param stage Sprite inside the Action1 spritesets to use, i.e. construction stage. + */ +static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, SpriteID default_palette) +{ + DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true); +} /** * Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layout entry diff --git a/src/spritecache.h b/src/spritecache.h index 42a9904e4..172702500 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -44,6 +44,7 @@ void GfxInitSpriteMem(); void IncreaseSpriteLRU(); bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id); +bool SkipSpriteData(byte type, uint16 num); void DupSprite(SpriteID old_spr, SpriteID new_spr); #endif /* SPRITECACHE_H */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index ff3fd4b12..2ed623ea6 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2455,7 +2455,7 @@ static void DrawTile_Station(TileInfo *ti) total_offset = 0; } - DrawCommonTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette); + DrawRailTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette); } void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image) @@ -2477,7 +2477,7 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro } /* Default waypoint has no railtype specific sprites */ - DrawCommonTileSeqInGUI(x, y, t, st == STATION_WAYPOINT ? 0 : total_offset, 0, pal); + DrawRailTileSeqInGUI(x, y, t, st == STATION_WAYPOINT ? 0 : total_offset, 0, pal); } static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y) |