OpenTTD Source 20260208-master-g43af8e94d0
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 virtual std::span<const DrawTileSeqStruct> GetSequence() const = 0;
60};
61
67struct DrawTileSpriteSpan : DrawTileSprites {
68 std::span<const DrawTileSeqStruct> seq;
69
70 DrawTileSpriteSpan(PalSpriteID ground, std::span<const DrawTileSeqStruct> seq) : DrawTileSprites(ground), seq(seq) {}
72 DrawTileSpriteSpan() = default;
73
74 std::span<const DrawTileSeqStruct> GetSequence() const override { return this->seq; }
75};
76
81struct DrawBuildingsTileStruct : SpriteBounds {
82 PalSpriteID ground;
83 PalSpriteID building;
84 uint8_t draw_proc; // this allows to specify a special drawing procedure.
85};
86
87void 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);
88void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
89
99inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
100{
101 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
102}
103
113inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
114{
115 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
116}
117
125inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
126{
127 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
128}
129
137inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
138{
139 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
140}
141
150inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
151{
152 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
153}
154
163inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
164{
165 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
166}
167
180{
182 return (pal != 0 ? pal : default_pal);
183 } else {
184 return PAL_NONE;
185 }
186}
187
199{
200 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
201 return (pal != 0 ? pal : default_pal);
202 } else {
203 return PAL_NONE;
204 }
205}
206
212static inline PaletteID GetColourPalette(Colours colour) { return PALETTE_RECOLOUR_START + colour; }
213
214#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:113
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:212
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:137
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:150
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:125
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:179
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:163
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:99
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:198
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:81
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:67
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:68
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
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.