OpenTTD
spritecache.h
Go to the documentation of this file.
1 /* $Id: spritecache.h 27732 2017-01-14 18:30:26Z frosch $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef SPRITECACHE_H
13 #define SPRITECACHE_H
14 
15 #include "gfx_type.h"
16 
18 struct Sprite {
19  uint16 height;
20  uint16 width;
21  int16 x_offs;
22  int16 y_offs;
23  byte data[];
24 };
25 
26 extern uint _sprite_cache_size;
27 
28 typedef void *AllocatorProc(size_t size);
29 
30 void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = NULL);
31 bool SpriteExists(SpriteID sprite);
32 
34 uint GetOriginFileSlot(SpriteID sprite);
35 uint GetSpriteCountForSlot(uint file_slot, SpriteID begin, SpriteID end);
36 uint GetMaxSpriteID();
37 
38 
39 static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
40 {
41  assert(type != ST_RECOLOUR);
42  return (Sprite*)GetRawSprite(sprite, type);
43 }
44 
45 static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
46 {
47  assert(type == ST_RECOLOUR);
48  return (byte*)GetRawSprite(sprite, type);
49 }
50 
51 void GfxInitSpriteMem();
52 void GfxClearSpriteCache();
53 void IncreaseSpriteLRU();
54 
55 void ReadGRFSpriteOffsets(byte container_version);
56 size_t GetGRFSpriteOffset(uint32 id);
57 bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id, byte container_version);
58 bool SkipSpriteData(byte type, uint16 num);
59 void DupSprite(SpriteID old_spr, SpriteID new_spr);
60 
61 #endif /* SPRITECACHE_H */
SpriteType GetSpriteType(SpriteID sprite)
Get the sprite type of a given sprite.
uint GetSpriteCountForSlot(uint file_slot, SpriteID begin, SpriteID end)
Count the sprites which originate from a specific file slot in a range of SpriteIDs.
Data structure describing a sprite.
Definition: spritecache.h:18
uint GetMaxSpriteID()
Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no spr...
bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id, byte container_version)
Load a real or recolour sprite.
int16 y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:22
void ReadGRFSpriteOffsets(byte container_version)
Parse the sprite section of GRFs.
SpriteType
Types of sprites that might be loaded.
Definition: gfx_type.h:297
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information...
byte data[]
Sprite data.
Definition: spritecache.h:23
size_t GetGRFSpriteOffset(uint32 id)
Get the file offset for a specific sprite in the sprite section of a GRF.
uint16 height
Height of the sprite.
Definition: spritecache.h:19
uint16 width
Width of the sprite.
Definition: spritecache.h:20
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
int16 x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:21
void * GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator=NULL)
Reads a sprite (from disk or sprite cache).
uint GetOriginFileSlot(SpriteID sprite)
Get the (FIOS) file slot of a given sprite.
Recolour sprite.
Definition: gfx_type.h:301
bool SkipSpriteData(byte type, uint16 num)
Skip the given amount of sprite graphics data.
Definition: spritecache.cpp:98
Types related to the graphics and/or input devices.