summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-01-08 22:42:00 +0000
committeryexo <yexo@openttd.org>2010-01-08 22:42:00 +0000
commit7f6016031e8367c8ce53a4017e5dadd47dc1974e (patch)
tree7bfa956802d29dfff7b4491928f7d363ddc3c444 /src
parent5b422d0c64f67101ed85ebf8934dc381817e1a7b (diff)
downloadopenttd-7f6016031e8367c8ce53a4017e5dadd47dc1974e.tar.xz
(svn r18762) -Codechange: unduplicate sprite layout drawing between industries and houses
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_commons.cpp40
-rw-r--r--src/newgrf_commons.h5
-rw-r--r--src/newgrf_house.cpp28
-rw-r--r--src/newgrf_industrytiles.cpp28
-rw-r--r--src/transparency.h1
5 files changed, 48 insertions, 54 deletions
diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp
index cf8683498..f5be80d3b 100644
--- a/src/newgrf_commons.cpp
+++ b/src/newgrf_commons.cpp
@@ -19,6 +19,7 @@
#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
@@ -322,3 +323,42 @@ 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;
+ SpriteID pal = dtss->image.pal;
+
+ /* 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 (IS_CUSTOM_SPRITE(image)) image += stage;
+
+ pal = SpriteLayoutPaletteTransform(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 c2bf9acd6..8126dd8bc 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -15,6 +15,9 @@
#define NEWGRF_COMMONS_H
#include "core/bitmath_func.hpp"
+#include "tile_cmd.h"
+#include "transparency.h"
+#include "sprite.h"
#include "table/sprites.h"
@@ -146,4 +149,6 @@ static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal
}
}
+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 a9d7a697d..2a425192a 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -403,7 +403,6 @@ uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, House
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte stage, HouseID house_id)
{
const DrawTileSprites *dts = group->dts;
- const DrawTileSeqStruct *dtss;
const HouseSpec *hs = HouseSpec::Get(house_id);
SpriteID palette = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOUR_START;
@@ -424,32 +423,7 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou
DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
}
- foreach_draw_tile_seq(dtss, dts->seq) {
- if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue;
-
- image = dtss->image.sprite;
- pal = dtss->image.pal;
-
- /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
- if (IsInvisibilitySet(TO_HOUSES) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
-
- if (IS_CUSTOM_SPRITE(image)) image += stage;
-
- pal = SpriteLayoutPaletteTransform(image, pal, 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_HOUSES)
- );
- } 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_HOUSES));
- }
- }
+ DrawTileSeq(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 5abd98f4d..e455888e5 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -173,7 +173,6 @@ static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIn
static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx)
{
const DrawTileSprites *dts = group->dts;
- const DrawTileSeqStruct *dtss;
SpriteID image = dts->ground.sprite;
SpriteID pal = dts->ground.pal;
@@ -190,32 +189,7 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGro
}
}
- foreach_draw_tile_seq(dtss, dts->seq) {
- if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue;
-
- image = dtss->image.sprite;
- pal = dtss->image.pal;
-
- /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
- if (IsInvisibilitySet(TO_INDUSTRIES) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
-
- if (IS_CUSTOM_SPRITE(image)) image += stage;
-
- pal = SpriteLayoutPaletteTransform(image, pal, GENERAL_SPRITE_COLOUR(rnd_colour));
-
- 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_INDUSTRIES)
- );
- } 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_INDUSTRIES));
- }
- }
+ DrawTileSeq(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/transparency.h b/src/transparency.h
index f2945682e..3b5cd5ebe 100644
--- a/src/transparency.h
+++ b/src/transparency.h
@@ -13,6 +13,7 @@
#define TRANSPARENCY_H
#include "gfx_func.h"
+#include "openttd.h"
/**
* Transparency option bits: which position in _transparency_opt stands for which transparency.