OpenTTD Source 20260218-master-g2123fca5ea
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef SPRITE_H
11#define SPRITE_H
12
14#include "transparency.h"
15
16#include "table/sprites.h"
17
18struct SpriteBounds {
22
23 constexpr SpriteBounds() = default;
24 constexpr SpriteBounds(const Coord3D<int8_t> &origin, const Coord3D<uint8_t> &extent, const Coord3D<int8_t> &offset) :
26};
27
28/* The following describes bunch of sprites to be drawn together in a single 3D
29 * bounding box. Used especially for various multi-sprite buildings (like
30 * depots or stations): */
31
33struct DrawTileSeqStruct : SpriteBounds {
34 PalSpriteID image;
35
36 constexpr DrawTileSeqStruct() = default;
37 constexpr DrawTileSeqStruct(int8_t origin_x, int8_t origin_y, int8_t origin_z, uint8_t extent_x, uint8_t extent_y, uint8_t extent_z, PalSpriteID image) :
38 SpriteBounds({origin_x, origin_y, origin_z}, {extent_x, extent_y, extent_z}, {}), image(image) {}
39
41 inline bool IsParentSprite() const
42 {
43 return static_cast<uint8_t>(this->origin.z) != 0x80;
44 }
45};
46
52struct DrawTileSprites {
54
56 DrawTileSprites() = default;
57
58 virtual ~DrawTileSprites() = default;
59
64 virtual std::span<const DrawTileSeqStruct> GetSequence() const = 0;
65};
66
72struct DrawTileSpriteSpan : DrawTileSprites {
73 std::span<const DrawTileSeqStruct> seq;
74
75 DrawTileSpriteSpan(PalSpriteID ground, std::span<const DrawTileSeqStruct> seq) : DrawTileSprites(ground), seq(seq) {}
77 DrawTileSpriteSpan() = default;
78
79 std::span<const DrawTileSeqStruct> GetSequence() const override { return this->seq; }
80};
81
86struct DrawBuildingsTileStruct : SpriteBounds {
87 PalSpriteID ground;
88 PalSpriteID building;
89 uint8_t draw_proc; // this allows to specify a special drawing procedure.
90};
91
92void 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);
93void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
94
104inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
105{
106 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
107}
108
118inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
119{
120 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
121}
122
130inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
131{
132 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
133}
134
142inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
143{
144 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
145}
146
155inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
156{
157 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
158}
159
168inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
169{
170 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
171}
172
185{
187 return (pal != 0 ? pal : default_pal);
188 } else {
189 return PAL_NONE;
190 }
191}
192
204{
205 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
206 return (pal != 0 ? pal : default_pal);
207 } else {
208 return PAL_NONE;
209 }
210}
211
217static inline PaletteID GetColourPalette(Colours colour) { return PALETTE_RECOLOUR_START + colour; }
218
219#endif /* SPRITE_H */
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
All geometry types in OpenTTD.
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:118
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:217
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:142
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:155
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:86
void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
Draw TTD sprite sequence on tile.
Definition sprite.h:130
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:184
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:168
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:104
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:203
This file contains all sprite-related enums and defines.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition sprites.h:1588
static constexpr uint8_t PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
Definition sprites.h:1561
static constexpr uint8_t PALETTE_MODIFIER_COLOUR
this bit is set when a recolouring process is in action
Definition sprites.h:1562
A coordinate with three dimensions.
This structure is the same for both Industries and Houses.
Definition sprite.h:86
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition sprite.h:41
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:72
std::span< const DrawTileSeqStruct > GetSequence() const override
The child sprites to draw.
Definition sprite.h:79
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:73
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
virtual std::span< const DrawTileSeqStruct > GetSequence() const =0
The child sprites to draw.
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
Coord3D< int8_t > offset
Relative position of sprite from bounding box.
Definition sprite.h:21
Coord3D< int8_t > origin
Position of northern corner within tile.
Definition sprite.h:19
Coord3D< uint8_t > extent
Size of bounding box.
Definition sprite.h:20
Tile information, used while rendering the tile.
Definition tile_cmd.h:32
Functions related to transparency.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.