OpenTTD Source  1.11.0-beta2
spritecache.h File Reference

Go to the source code of this file.

Data Structures

struct  Sprite
 Data structure describing a sprite. More...
 

Typedefs

typedef void * AllocatorProc(size_t size)
 

Functions

void * SimpleSpriteAlloc (size_t size)
 Sprite allocator simply using malloc.
 
void * GetRawSprite (SpriteID sprite, SpriteType type, AllocatorProc *allocator=nullptr, SpriteEncoder *encoder=nullptr)
 Reads a sprite (from disk or sprite cache). More...
 
bool SpriteExists (SpriteID sprite)
 
SpriteType GetSpriteType (SpriteID sprite)
 Get the sprite type of a given sprite. More...
 
uint GetOriginFileSlot (SpriteID sprite)
 Get the (FIOS) file slot of a given sprite. More...
 
uint32 GetSpriteLocalID (SpriteID sprite)
 Get the GRF-local sprite id of a given sprite. More...
 
uint GetSpriteCountForSlot (uint file_slot, SpriteID begin, SpriteID end)
 Count the sprites which originate from a specific file slot in a range of SpriteIDs. More...
 
uint GetMaxSpriteID ()
 Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no sprites with a higher SpriteID, although there might be up to roughly a thousand unused SpriteIDs below this number. More...
 
static const SpriteGetSprite (SpriteID sprite, SpriteType type)
 
static const byte * GetNonSprite (SpriteID sprite, SpriteType type)
 
void GfxInitSpriteMem ()
 
void GfxClearSpriteCache ()
 Remove all encoded sprites from the sprite cache without discarding sprite location information.
 
void IncreaseSpriteLRU ()
 
void ReadGRFSpriteOffsets (byte container_version)
 Parse the sprite section of GRFs. More...
 
size_t GetGRFSpriteOffset (uint32 id)
 Get the file offset for a specific sprite in the sprite section of a GRF. More...
 
bool LoadNextSprite (int load_index, byte file_index, uint file_sprite_id, byte container_version)
 Load a real or recolour sprite. More...
 
bool SkipSpriteData (byte type, uint16 num)
 Skip the given amount of sprite graphics data. More...
 
void DupSprite (SpriteID old_spr, SpriteID new_spr)
 

Variables

uint _sprite_cache_size
 

Detailed Description

Functions to cache sprites in memory.

Definition in file spritecache.h.

Function Documentation

◆ GetGRFSpriteOffset()

size_t GetGRFSpriteOffset ( uint32  id)

Get the file offset for a specific sprite in the sprite section of a GRF.

Parameters
idID of the sprite to look up.
Returns
Position of the sprite in the sprite section or SIZE_MAX if no such sprite is present.

Definition at line 508 of file spritecache.cpp.

References _grf_sprite_offsets.

Referenced by LoadNextSprite().

◆ GetMaxSpriteID()

uint GetMaxSpriteID ( )

Get a reasonable (upper bound) estimate of the maximum SpriteID used in OpenTTD; there will be no sprites with a higher SpriteID, although there might be up to roughly a thousand unused SpriteIDs below this number.

Note
It's actually the number of spritecache items.
Returns
maximum SpriteID

Definition at line 187 of file spritecache.cpp.

Referenced by SpriteAlignerWindow::OnClick(), SpriteAlignerWindow::OnQueryTextFinished(), and UpdateCursorSize().

◆ GetOriginFileSlot()

uint GetOriginFileSlot ( SpriteID  sprite)

Get the (FIOS) file slot of a given sprite.

Parameters
spriteThe sprite to look at.
Returns
the FIOS file slot

Definition at line 143 of file spritecache.cpp.

◆ GetRawSprite()

void* GetRawSprite ( SpriteID  sprite,
SpriteType  type,
AllocatorProc *  allocator,
SpriteEncoder encoder 
)

Reads a sprite (from disk or sprite cache).

If the sprite is not available or of wrong type, a fallback sprite is returned.

Parameters
spriteSprite to read.
typeExpected sprite type.
allocatorAllocator function to use. Set to nullptr to use the usual sprite cache.
encoderSprite encoder to use. Set to nullptr to use the currently active blitter.
Returns
Sprite raw data

Definition at line 874 of file spritecache.cpp.

◆ GetSpriteCountForSlot()

uint GetSpriteCountForSlot ( uint  file_slot,
SpriteID  begin,
SpriteID  end 
)

Count the sprites which originate from a specific file slot in a range of SpriteIDs.

Parameters
file_slotFIOS file slot.
beginFirst sprite in range.
endFirst sprite not in range.
Returns
Number of sprites.

Definition at line 167 of file spritecache.cpp.

◆ GetSpriteLocalID()

uint32 GetSpriteLocalID ( SpriteID  sprite)

Get the GRF-local sprite id of a given sprite.

Parameters
spriteThe sprite to look at.
Returns
The GRF-local sprite id.

Definition at line 154 of file spritecache.cpp.

◆ GetSpriteType()

SpriteType GetSpriteType ( SpriteID  sprite)

Get the sprite type of a given sprite.

Parameters
spriteThe sprite to look at.
Returns
the type of sprite.

Definition at line 132 of file spritecache.cpp.

Referenced by SpriteAlignerWindow::OnClick(), and SpriteAlignerWindow::OnQueryTextFinished().

◆ LoadNextSprite()

bool LoadNextSprite ( int  load_index,
byte  file_slot,
uint  file_sprite_id,
byte  container_version 
)

Load a real or recolour sprite.

Parameters
load_indexGlobal sprite index.
file_slotGRF to load from.
file_sprite_idSprite number in the GRF.
container_versionContainer version of the GRF.
Returns
True if a valid sprite was loaded, false on any error.

Definition at line 550 of file spritecache.cpp.

References FioGetPos(), FioReadByte(), FioReadDword(), FioReadWord(), FioSkipBytes(), GetGRFSpriteOffset(), MAX_SPRITES, ReadRecolourSprite(), SkipSpriteData(), ST_INVALID, ST_NORMAL, ST_RECOLOUR, and usererror().

Referenced by LoadGrfFile().

◆ ReadGRFSpriteOffsets()

void ReadGRFSpriteOffsets ( byte  container_version)

Parse the sprite section of GRFs.

Parameters
container_versionContainer version of the GRF we're currently processing.

Definition at line 517 of file spritecache.cpp.

References _grf_sprite_offsets, FioGetPos(), FioReadDword(), FioSeekTo(), and FioSkipBytes().

Referenced by LoadGrfFile(), and LoadGrfFileIndexed().

◆ SkipSpriteData()

bool SkipSpriteData ( byte  type,
uint16  num 
)

Skip the given amount of sprite graphics data.

Parameters
typethe type of sprite (compressed etc)
numthe amount of sprites to skip
Returns
true if the data could be correctly skipped.

Definition at line 95 of file spritecache.cpp.

References FioReadByte(), and FioSkipBytes().

Referenced by LoadNextSprite().