Change: Only resort town directory window on population change if necessary
[openttd-github.git] / src / spritecache.h
blob3b3e1c9de57ecb1af22c9c1f26bfe073b89916d8
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"
15 /** Data structure describing a sprite. */
16 struct Sprite {
17 uint16 height; ///< Height of the sprite.
18 uint16 width; ///< Width of the sprite.
19 int16 x_offs; ///< Number of pixels to shift the sprite to the right.
20 int16 y_offs; ///< Number of pixels to shift the sprite downwards.
21 byte data[]; ///< Sprite data.
24 extern uint _sprite_cache_size;
26 typedef void *AllocatorProc(size_t size);
28 void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = nullptr);
29 bool SpriteExists(SpriteID sprite);
31 SpriteType GetSpriteType(SpriteID sprite);
32 uint GetOriginFileSlot(SpriteID sprite);
33 uint GetSpriteCountForSlot(uint file_slot, SpriteID begin, SpriteID end);
34 uint GetMaxSpriteID();
37 static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
39 assert(type != ST_RECOLOUR);
40 return (Sprite*)GetRawSprite(sprite, type);
43 static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
45 assert(type == ST_RECOLOUR);
46 return (byte*)GetRawSprite(sprite, type);
49 void GfxInitSpriteMem();
50 void GfxClearSpriteCache();
51 void IncreaseSpriteLRU();
53 void ReadGRFSpriteOffsets(byte container_version);
54 size_t GetGRFSpriteOffset(uint32 id);
55 bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id, byte container_version);
56 bool SkipSpriteData(byte type, uint16 num);
57 void DupSprite(SpriteID old_spr, SpriteID new_spr);
59 #endif /* SPRITECACHE_H */