OpenTTD Source: src/sprite.h Source File

OpenTTD Source 13.2.1

sprite.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef SPRITE_H
11 #define SPRITE_H
12
13 #include "transparency.h"
14
15 #include "table/sprites.h"
16
17 #define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
18 #define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
19
20 /* The following describes bunch of sprites to be drawn together in a single 3D
21 * bounding box. Used especially for various multi-sprite buildings (like
22 * depots or stations): */
23
25 struct DrawTileSeqStruct {
26 int8 delta_x;
27 int8 delta_y;
28 int8 delta_z;
29 byte size_x;
30 byte size_y;
31 byte size_z;
32 PalSpriteID image;
33
35 void MakeTerminator()
36 {
37 this->delta_x = (int8)0x80;
38 }
39
41 bool IsTerminator() const
42 {
43 return (byte)this->delta_x == 0x80;
44 }
45
47 bool IsParentSprite() const
48 {
49 return (byte)this->delta_z != 0x80;
50 }
51 };
52
58 struct DrawTileSprites {
59 PalSpriteID ground;
60 const DrawTileSeqStruct *seq;
61 };
62
67 struct DrawBuildingsTileStruct {
68 PalSpriteID ground;
69 PalSpriteID building;
70 byte subtile_x;
71 byte subtile_y;
72 byte width;
73 byte height;
74 byte dz;
75 byte draw_proc; // this allows to specify a special drawing procedure.
76 };
77
79 #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
80
81 void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
82 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
83
89 static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
90 {
91 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
92 }
93
99 static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
100 {
101 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
102 }
103
107 static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
108 {
109 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
110 }
111
115 static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
116 {
117 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
118 }
119
124 static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
125 {
126 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
127 }
128
133 static inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
134 {
135 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
136 }
137
149 static inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
150 {
151 if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
152 return (pal != 0 ? pal : default_pal);
153 } else {
154 return PAL_NONE;
155 }
156 }
157
168 static inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
169 {
170 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
171 return (pal != 0 ? pal : default_pal);
172 } else {
173 return PAL_NONE;
174 }
175 }
176
177 #endif /* SPRITE_H */
DrawCommonTileSeq
void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence.
Definition: sprite.cpp:30
DrawRailTileSeqInGUI
static void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition: sprite.h:99
DrawOrigTileSeqInGUI
static void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition: sprite.h:115
DrawTileSeqStruct::IsParentSprite
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition: sprite.h:47
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
SpriteLayoutPaletteTransform
static PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layou...
Definition: sprite.h:149
PALETTE_MODIFIER_COLOUR
@ PALETTE_MODIFIER_COLOUR
this bit is set when a recolouring process is in action
Definition: sprites.h:1538
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
DrawCommonTileSeqInGUI
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence in the GUI.
Definition: sprite.cpp:92
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
DrawTileSeqStruct::delta_x
int8 delta_x
0x80 is sequence terminator
Definition: sprite.h:26
DrawRailTileSeq
static void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
Definition: sprite.h:89
DrawNewGRFTileSeq
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition: sprite.h:124
DrawTileSeqStruct::delta_z
int8 delta_z
0x80 identifies child sprites
Definition: sprite.h:28
DrawTileSeqStruct::IsTerminator
bool IsTerminator() const
Check whether this is a sequence terminator.
Definition: sprite.h:41
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
DrawNewGRFTileSeqInGUI
static void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition: sprite.h:133
sprites.h
PALETTE_MODIFIER_TRANSPARENT
@ PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
Definition: sprites.h:1537
GroundSpritePaletteTransform
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition: sprite.h:168
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:22
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
DrawBuildingsTileStruct
This structure is the same for both Industries and Houses.
Definition: sprite.h:67
transparency.h
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:22
DrawOrigTileSeq
static void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
Draw TTD sprite sequence on tile.
Definition: sprite.h:107
DrawTileSprites::seq
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Definition: sprite.h:60
DrawTileSeqStruct::MakeTerminator
void MakeTerminator()
Make this struct a sequence terminator.
Definition: sprite.h:35
DrawTileSeqStruct
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition: sprite.h:25