OpenTTD Source 20250524-master-gc366e6a48e
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/* The following describes bunch of sprites to be drawn together in a single 3D
18 * bounding box. Used especially for various multi-sprite buildings (like
19 * depots or stations): */
20
23 int8_t delta_x = 0;
24 int8_t delta_y = 0;
25 int8_t delta_z = 0;
26 uint8_t size_x = 0;
27 uint8_t size_y = 0;
28 uint8_t size_z = 0;
29 PalSpriteID image{};
30
32 bool IsParentSprite() const
33 {
34 return (uint8_t)this->delta_z != 0x80;
35 }
36};
37
45
47 DrawTileSprites() = default;
48
49 virtual ~DrawTileSprites() = default;
50 virtual std::span<const DrawTileSeqStruct> GetSequence() const = 0;
51};
52
59 std::span<const DrawTileSeqStruct> seq;
60
61 DrawTileSpriteSpan(PalSpriteID ground, std::span<const DrawTileSeqStruct> seq) : DrawTileSprites(ground), seq(seq) {}
63 DrawTileSpriteSpan() = default;
64
65 std::span<const DrawTileSeqStruct> GetSequence() const override { return this->seq; }
66};
67
73 PalSpriteID ground;
74 PalSpriteID building;
75 uint8_t subtile_x;
76 uint8_t subtile_y;
77 uint8_t width;
78 uint8_t height;
79 uint8_t dz;
80 uint8_t draw_proc; // this allows to specify a special drawing procedure.
81};
82
83void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
84void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
85
91inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
92{
93 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
94}
95
101inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
102{
103 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
104}
105
109inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
110{
111 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
112}
113
117inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
118{
119 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
120}
121
126inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
127{
128 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
129}
130
135inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
136{
137 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
138}
139
152{
154 return (pal != 0 ? pal : default_pal);
155 } else {
156 return PAL_NONE;
157 }
158}
159
171{
172 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
173 return (pal != 0 ? pal : default_pal);
174 } else {
175 return PAL_NONE;
176 }
177}
178
184static inline PaletteID GetColourPalette(Colours colour) { return PALETTE_RECOLOUR_START + colour; }
185
186#endif /* SPRITE_H */
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence.
Definition sprite.cpp:30
void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition sprite.h:101
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:184
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:117
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition sprite.h:126
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence in the GUI.
Definition sprite.cpp:91
void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
Draw TTD sprite sequence on tile.
Definition sprite.h:109
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:151
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:135
void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
Definition sprite.h:91
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:170
This file contains all sprite-related enums and defines.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition sprites.h:1578
static constexpr uint8_t PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
Definition sprites.h:1551
static constexpr uint8_t PALETTE_MODIFIER_COLOUR
this bit is set when a recolouring process is in action
Definition sprites.h:1552
This structure is the same for both Industries and Houses.
Definition sprite.h:72
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:22
int8_t delta_z
0x80 identifies child sprites
Definition sprite.h:25
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition sprite.h:32
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:58
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:59
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:43
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:44
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
Tile information, used while rendering the tile.
Definition tile_cmd.h:29
Functions related to transparency.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.