OpenTTD Source 15.0-beta2
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
26 int8_t delta_x = 0;
27 int8_t delta_y = 0;
28 int8_t delta_z = 0;
29 uint8_t size_x = 0;
30 uint8_t size_y = 0;
31 uint8_t size_z = 0;
32 PalSpriteID image{};
33
35 bool IsParentSprite() const
36 {
37 return (uint8_t)this->delta_z != 0x80;
38 }
39};
40
48
50 DrawTileSprites() = default;
51
52 virtual ~DrawTileSprites() = default;
53 virtual std::span<const DrawTileSeqStruct> GetSequence() const = 0;
54};
55
62 std::span<const DrawTileSeqStruct> seq;
63
64 template <size_t N>
65 DrawTileSpriteSpan(PalSpriteID ground, const DrawTileSeqStruct (&seq)[N]) : DrawTileSprites(ground), seq(std::begin(seq), std::end(seq)) {}
67 DrawTileSpriteSpan() = default;
68
69 std::span<const DrawTileSeqStruct> GetSequence() const override { return this->seq; }
70};
71
77 PalSpriteID ground;
78 PalSpriteID building;
79 uint8_t subtile_x;
80 uint8_t subtile_y;
81 uint8_t width;
82 uint8_t height;
83 uint8_t dz;
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
95inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
96{
97 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
98}
99
105inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
106{
107 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
108}
109
113inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
114{
115 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
116}
117
121inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
122{
123 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
124}
125
130inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
131{
132 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
133}
134
139inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
140{
141 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
142}
143
156{
158 return (pal != 0 ? pal : default_pal);
159 } else {
160 return PAL_NONE;
161 }
162}
163
175{
176 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
177 return (pal != 0 ? pal : default_pal);
178 } else {
179 return PAL_NONE;
180 }
181}
182
183#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:105
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:121
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:130
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:113
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:155
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:139
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:95
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:174
This file contains all sprite-related enums and defines.
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:76
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:25
int8_t delta_z
0x80 identifies child sprites
Definition sprite.h:28
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition sprite.h:35
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:61
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:62
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:46
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:47
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:43
Functions related to transparency.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.