OpenTTD Source: src/spritecache.h Source File

OpenTTD Source 13.2.1

spritecache.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 SPRITECACHE_H
11 #define SPRITECACHE_H
12
13 #include "gfx_type.h"
14 #include "spriteloader/spriteloader.hpp"
15
17 struct Sprite {
18 uint16 height;
19 uint16 width;
20 int16 x_offs;
21 int16 y_offs;
22 byte data[];
23 };
24
25 enum SpriteCacheCtrlFlags {
26 SCCF_ALLOW_ZOOM_MIN_1X_PAL = 0,
27 SCCF_ALLOW_ZOOM_MIN_1X_32BPP = 1,
28 SCCF_ALLOW_ZOOM_MIN_2X_PAL = 2,
29 SCCF_ALLOW_ZOOM_MIN_2X_32BPP = 3,
30 };
31
32 extern uint _sprite_cache_size;
33
34 typedef void *AllocatorProc(size_t size);
35
36 void *SimpleSpriteAlloc(size_t size);
37 void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = nullptr, SpriteEncoder *encoder = nullptr);
38 bool SpriteExists(SpriteID sprite);
39
40 SpriteType GetSpriteType(SpriteID sprite);
41 SpriteFile *GetOriginFile(SpriteID sprite);
42 uint32 GetSpriteLocalID(SpriteID sprite);
43 uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end);
44 uint GetMaxSpriteID();
45
46
47 static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
48 {
49 assert(type != ST_RECOLOUR);
50 return (Sprite*)GetRawSprite(sprite, type);
51 }
52
53 static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
54 {
55 assert(type == ST_RECOLOUR);
56 return (byte*)GetRawSprite(sprite, type);
57 }
58
59 void GfxInitSpriteMem();
60 void GfxClearSpriteCache();
61 void IncreaseSpriteLRU();
62
63 SpriteFile &OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap);
64
65 void ReadGRFSpriteOffsets(SpriteFile &file);
66 size_t GetGRFSpriteOffset(uint32 id);
67 bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id);
68 bool SkipSpriteData(SpriteFile &file, byte type, uint16 num);
69 void DupSprite(SpriteID old_spr, SpriteID new_spr);
70
71 #endif /* SPRITECACHE_H */
Sprite::data
byte data[]
Sprite data.
Definition: spritecache.h:22
GetSpriteType
SpriteType GetSpriteType(SpriteID sprite)
Get the sprite type of a given sprite.
Definition: spritecache.cpp:163
GetGRFSpriteOffset
size_t GetGRFSpriteOffset(uint32 id)
Get the file offset for a specific sprite in the sprite section of a GRF.
Definition: spritecache.cpp:546
Sprite::height
uint16 height
Height of the sprite.
Definition: spritecache.h:18
spriteloader.hpp
Sprite::x_offs
int16 x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:20
SkipSpriteData
bool SkipSpriteData(SpriteFile &file, byte type, uint16 num)
Skip the given amount of sprite graphics data.
Definition: spritecache.cpp:126
SCCF_ALLOW_ZOOM_MIN_2X_32BPP
@ SCCF_ALLOW_ZOOM_MIN_2X_32BPP
Allow use of sprite min zoom setting at 2x in 32bpp mode.
Definition: spritecache.h:29
GetOriginFile
SpriteFile * GetOriginFile(SpriteID sprite)
Get the SpriteFile of a given sprite.
Definition: spritecache.cpp:174
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
GetRawSprite
void * GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator=nullptr, SpriteEncoder *encoder=nullptr)
Reads a sprite (from disk or sprite cache).
Definition: spritecache.cpp:941
GetSpriteCountForFile
uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end)
Count the sprites which originate from a specific file in a range of SpriteIDs.
Definition: spritecache.cpp:198
GetSpriteLocalID
uint32 GetSpriteLocalID(SpriteID sprite)
Get the GRF-local sprite id of a given sprite.
Definition: spritecache.cpp:185
LoadNextSprite
bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
Load a real or recolour sprite.
Definition: spritecache.cpp:611
SCCF_ALLOW_ZOOM_MIN_1X_PAL
@ SCCF_ALLOW_ZOOM_MIN_1X_PAL
Allow use of sprite min zoom setting at 1x in palette mode.
Definition: spritecache.h:26
Sprite::width
uint16 width
Width of the sprite.
Definition: spritecache.h:19
SpriteEncoder
Interface for something that can encode a sprite.
Definition: spriteloader.hpp:84
ReadGRFSpriteOffsets
void ReadGRFSpriteOffsets(SpriteFile &file)
Parse the sprite section of GRFs.
Definition: spritecache.cpp:555
SimpleSpriteAlloc
void * SimpleSpriteAlloc(size_t size)
Sprite allocator simply using malloc.
Definition: spritecache.cpp:882
SpriteFile
RandomAccessFile with some extra information specific for sprite files.
Definition: sprite_file_type.hpp:19
SpriteType
SpriteType
Types of sprites that might be loaded.
Definition: gfx_type.h:307
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
Sprite::y_offs
int16 y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:21
SCCF_ALLOW_ZOOM_MIN_2X_PAL
@ SCCF_ALLOW_ZOOM_MIN_2X_PAL
Allow use of sprite min zoom setting at 2x in palette mode.
Definition: spritecache.h:28
GetMaxSpriteID
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
Definition: spritecache.cpp:221
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:311
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition: spritecache.cpp:1042
OpenCachedSpriteFile
SpriteFile & OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap)
Open/get the SpriteFile that is cached for use in the sprite cache.
Definition: spritecache.cpp:96
gfx_type.h
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
SpriteCacheCtrlFlags
SpriteCacheCtrlFlags
Definition: spritecache.h:25
SCCF_ALLOW_ZOOM_MIN_1X_32BPP
@ SCCF_ALLOW_ZOOM_MIN_1X_32BPP
Allow use of sprite min zoom setting at 1x in 32bpp mode.
Definition: spritecache.h:27