changeset 14294:7718a19fd027 draft

(svn r18846) -Codechange: Merge DrawTileSeq into DrawCommonTileSeq.
author frosch <frosch@openttd.org>
date Sun, 17 Jan 2010 15:05:25 +0000
parents 1d93646afcfa
children 9372a6489733
files src/newgrf_commons.cpp src/newgrf_commons.h src/newgrf_house.cpp src/newgrf_industrytiles.cpp src/newgrf_station.cpp src/rail_cmd.cpp src/road_cmd.cpp src/sprite.cpp src/sprite.h src/spritecache.h src/station_cmd.cpp
diffstat 11 files changed, 76 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 	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));
-		}
-	}
-}
--- 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 @@
 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 */
--- 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 @@
 		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)
--- 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 @@
 		}
 	}
 
-	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)
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -909,7 +909,7 @@
 
 	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;
 }
--- 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 @@
 		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 @@
 	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)
--- 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 @@
 			}
 
 			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 @@
 	y += 17;
 
 	DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
-	DrawCommonTileSeqInGUI(x, y, dts, 0, 0, palette);
+	DrawOrigTileSeqInGUI(x, y, dts, palette);
 }
 
 /**
--- 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 @@
 				!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 @@
  * @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 @@
 			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);
 		}
 	}
 }
--- a/src/sprite.h
+++ b/src/sprite.h
@@ -59,10 +59,53 @@
 /** 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);
+
+/**
+ * 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);
+}
 
-bool SkipSpriteData(byte type, uint16 num);
+/**
+ * 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
--- a/src/spritecache.h
+++ b/src/spritecache.h
@@ -44,6 +44,7 @@
 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 */
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2455,7 +2455,7 @@
 		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 @@
 	}
 
 	/* 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)