Change: Improve "local authority rating" setting name and helptext
[openttd-github.git] / src / spritecache.h
blob367d690951196f2927abfed49cb39702896dd1ba
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 */
8 /** @file spritecache.h Functions to cache sprites in memory. */
10 #ifndef SPRITECACHE_H
11 #define SPRITECACHE_H
13 #include "gfx_type.h"
14 #include "spriteloader/spriteloader.hpp"
16 /** Data structure describing a sprite. */
17 struct Sprite {
18 uint16 height; ///< Height of the sprite.
19 uint16 width; ///< Width of the sprite.
20 int16 x_offs; ///< Number of pixels to shift the sprite to the right.
21 int16 y_offs; ///< Number of pixels to shift the sprite downwards.
22 byte data[]; ///< Sprite data.
25 extern uint _sprite_cache_size;
27 typedef void *AllocatorProc(size_t size);
29 void *SimpleSpriteAlloc(size_t size);
30 void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = nullptr, SpriteEncoder *encoder = nullptr);
31 bool SpriteExists(SpriteID sprite);
33 SpriteType GetSpriteType(SpriteID sprite);
34 SpriteFile *GetOriginFile(SpriteID sprite);
35 uint32 GetSpriteLocalID(SpriteID sprite);
36 uint GetSpriteCountForFile(const std::string &filename, SpriteID begin, SpriteID end);
37 uint GetMaxSpriteID();
40 static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
42 assert(type != ST_RECOLOUR);
43 return (Sprite*)GetRawSprite(sprite, type);
46 static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
48 assert(type == ST_RECOLOUR);
49 return (byte*)GetRawSprite(sprite, type);
52 void GfxInitSpriteMem();
53 void GfxClearSpriteCache();
54 void IncreaseSpriteLRU();
56 SpriteFile &OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap);
58 void ReadGRFSpriteOffsets(SpriteFile &file);
59 size_t GetGRFSpriteOffset(uint32 id);
60 bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id);
61 bool SkipSpriteData(SpriteFile &file, byte type, uint16 num);
62 void DupSprite(SpriteID old_spr, SpriteID new_spr);
64 #endif /* SPRITECACHE_H */