OpenTTD Source: src/sprite.h Source File

OpenTTD Source 15.0-RC2

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
10#ifndef SPRITE_H
11#define SPRITE_H
12
13#include "core/geometry_type.hpp"
14#include "transparency.h"
15
16#include "table/sprites.h"
17
18 struct SpriteBounds {
19 Coord3D<int8_t> origin;
20 Coord3D<uint8_t> extent;
21 Coord3D<int8_t> offset;
22
23 constexpr SpriteBounds() = default;
24 constexpr SpriteBounds(const Coord3D<int8_t> &origin, const Coord3D<uint8_t> &extent, const Coord3D<int8_t> &offset) :
25 origin(origin), extent(extent), offset(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
33 struct 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
52 struct DrawTileSprites {
53 PalSpriteID ground{};
54
55 DrawTileSprites(PalSpriteID ground) : ground(ground) {}
56 DrawTileSprites() = default;
57
58 virtual ~DrawTileSprites() = default;
59 virtual std::span<const DrawTileSeqStruct> GetSequence() const = 0;
60};
61
67 struct DrawTileSpriteSpan : DrawTileSprites {
68 std::span<const DrawTileSeqStruct> seq;
69
70 DrawTileSpriteSpan(PalSpriteID ground, std::span<const DrawTileSeqStruct> seq) : DrawTileSprites(ground), seq(seq) {}
71 DrawTileSpriteSpan(PalSpriteID ground) : DrawTileSprites(ground) {};
72 DrawTileSpriteSpan() = default;
73
74 std::span<const DrawTileSeqStruct> GetSequence() const override { return this->seq; }
75};
76
81 struct 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
95 inline 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
105 inline 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
113 inline 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
121 inline 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
130 inline 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
139 inline 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
155 inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
156{
157 if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
158 return (pal != 0 ? pal : default_pal);
159 } else {
160 return PAL_NONE;
161 }
162}
163
174 inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
175{
176 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
177 return (pal != 0 ? pal : default_pal);
178 } else {
179 return PAL_NONE;
180 }
181}
182
188 static inline PaletteID GetColourPalette(Colours colour) { return PALETTE_RECOLOUR_START + colour; }
189
190#endif /* SPRITE_H */
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
geometry_type.hpp
All geometry types in OpenTTD.
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
DrawCommonTileSeq
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
DrawRailTileSeqInGUI
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
GetColourPalette
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:188
DrawOrigTileSeqInGUI
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition sprite.h:121
DrawNewGRFTileSeq
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
DrawCommonTileSeqInGUI
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
DrawOrigTileSeq
void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
Draw TTD sprite sequence on tile.
Definition sprite.h:113
SpriteLayoutPaletteTransform
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
DrawNewGRFTileSeqInGUI
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:139
DrawRailTileSeq
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
GroundSpritePaletteTransform
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
sprites.h
This file contains all sprite-related enums and defines.
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition sprites.h:1588
PALETTE_MODIFIER_TRANSPARENT
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
PALETTE_MODIFIER_COLOUR
static constexpr uint8_t PALETTE_MODIFIER_COLOUR
this bit is set when a recolouring process is in action
Definition sprites.h:1562
Coord3D
A coordinate with three dimensions.
Definition geometry_type.hpp:43
Coord3D::z
T z
Z coordinate.
Definition geometry_type.hpp:46
DrawBuildingsTileStruct
This structure is the same for both Industries and Houses.
Definition sprite.h:81
DrawTileSeqStruct
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:33
DrawTileSeqStruct::IsParentSprite
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition sprite.h:41
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSpriteSpan::seq
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:68
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
PalSpriteID
Combination of a palette sprite and a 'real' sprite.
Definition gfx_type.h:22
SpriteBounds
Definition sprite.h:18
SpriteBounds::offset
Coord3D< int8_t > offset
Relative position of sprite from bounding box.
Definition sprite.h:21
SpriteBounds::origin
Coord3D< int8_t > origin
Position of northern corner within tile.
Definition sprite.h:19
SpriteBounds::extent
Coord3D< uint8_t > extent
Size of bounding box.
Definition sprite.h:20
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
transparency.h
Functions related to transparency.
TransparencyOption
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition transparency.h:23