OpenTTD Source 20260311-master-g511d3794ce
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
44 inline bool IsParentSprite() const
45 {
46 return static_cast<uint8_t>(this->origin.z) != 0x80;
47 }
48};
49
55struct DrawTileSprites {
57
59 DrawTileSprites() = default;
60
62 virtual ~DrawTileSprites() = default;
63
68 virtual std::span<const DrawTileSeqStruct> GetSequence() const = 0;
69};
70
76struct DrawTileSpriteSpan : DrawTileSprites {
77 std::span<const DrawTileSeqStruct> seq;
78
79 DrawTileSpriteSpan(PalSpriteID ground, std::span<const DrawTileSeqStruct> seq) : DrawTileSprites(ground), seq(seq) {}
81 DrawTileSpriteSpan() = default;
82
83 std::span<const DrawTileSeqStruct> GetSequence() const override { return this->seq; }
84};
85
90struct DrawBuildingsTileStruct : SpriteBounds {
91 PalSpriteID ground;
92 PalSpriteID building;
93 uint8_t draw_proc;
94};
95
96void 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);
97void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
98
108inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
109{
110 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
111}
112
122inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
123{
124 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
125}
126
134inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
135{
136 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
137}
138
146inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
147{
148 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
149}
150
159inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
160{
161 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
162}
163
172inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
173{
174 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
175}
176
189{
191 return (pal != 0 ? pal : default_pal);
192 } else {
193 return PAL_NONE;
194 }
195}
196
208{
209 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
210 return (pal != 0 ? pal : default_pal);
211 } else {
212 return PAL_NONE;
213 }
214}
215
221static inline PaletteID GetColourPalette(Colours colour) { return PALETTE_RECOLOUR_START + colour; }
222
223#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:122
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:221
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:146
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:159
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:134
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:188
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:172
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:108
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:207
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:90
uint8_t draw_proc
This allows to specify a special drawing procedure.
Definition sprite.h:93
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition sprite.h:44
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:76
std::span< const DrawTileSeqStruct > GetSequence() const override
The child sprites to draw.
Definition sprite.h:83
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:77
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:55
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:56
virtual std::span< const DrawTileSeqStruct > GetSequence() const =0
The child sprites to draw.
virtual ~DrawTileSprites()=default
Ensure the destructor of the sub classes are called as well.
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.