Data Structures | Typedefs | Functions | Variables

# spritecache.h File Reference

Functions to cache sprites in memory. More...

`#include "gfx_type.h"`

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 * | GetRawSprite (SpriteID sprite, SpriteType type, AllocatorProc *allocator=NULL)
| Reads a sprite (from disk or sprite cache).
bool | SpriteExists (SpriteID sprite)
SpriteType | GetSpriteType (SpriteID sprite)
| Get the sprite type of a given sprite.
uint | GetOriginFileSlot (SpriteID sprite)
| Get the (FIOS) file slot of a given sprite.
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.
static const Sprite * | GetSprite (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.
size_t | GetGRFSpriteOffset (uint32 id)
| Get the file offset for a specific sprite in the sprite section of a GRF.
bool | LoadNextSprite (int load_index, byte file_index, uint file_sprite_id, byte container_version)
| Load a real or recolour sprite.
bool | SkipSpriteData (byte type, uint16 num)
| Skip the given amount of sprite graphics data.
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

size_t GetGRFSpriteOffset | ( | uint32 | id | ) |

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

Parameters:

  | id | ID 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 457 of file spritecache.cpp.

Referenced by LoadNextSprite().

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 158 of file spritecache.cpp.

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

uint GetOriginFileSlot | ( | SpriteID | sprite | ) |

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

Parameters:

  | sprite | The sprite to look at.

Returns:
  the FIOS file slot

Definition at line 144 of file spritecache.cpp.

Referenced by SpriteAlignerWindow::SetStringParameters().

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

Reads a sprite (from disk or sprite cache).

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

Parameters:

  | sprite | Sprite to read.
  | type | Expected sprite type.
  | allocator | Allocator function to use. Set to NULL to use the usual sprite cache.

Returns:
  Sprite raw data

Definition at line 814 of file spritecache.cpp.

References DEBUG, HandleInvalidSpriteRequest(), ReadSprite(), ST_INVALID, ST_MAPGEN, and SpriteCache::type.

Referenced by HandleInvalidSpriteRequest(), and ReadSprite().

SpriteType GetSpriteType | ( | SpriteID | sprite | ) |

Get the sprite type of a given sprite.

Parameters:

  | sprite | The sprite to look at.

Returns:
  the type of sprite.

Definition at line 133 of file spritecache.cpp.

References SpriteCache::type.

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

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

Load a real or recolour sprite.

Parameters:

  | load_index | Global sprite index.
  | file_slot | GRF to load from.
  | file_sprite_id | Sprite number in the GRF.
  | container_version | Container version of the GRF.

Returns:
  True if a valid sprite was loaded, false on any error.

Definition at line 499 of file spritecache.cpp.

References SpriteCache::container_ver, FioGetPos(), FioReadByte(), FioReadDword(), FioReadWord(), FioSkipBytes(), GetGRFSpriteOffset(), MAX_SPRITES, ReadRecolourSprite(), SkipSpriteData(), ST_INVALID, ST_NORMAL, SpriteCache::type, usererror(), and SpriteCache::warned.

Referenced by LoadFontGlyph(), LoadGrfFile(), and LoadGrfFileIndexed().

void ReadGRFSpriteOffsets | ( | byte | container_version | ) |

Parse the sprite section of GRFs.

Parameters:

  | container_version | Container version of the GRF we're currently processing.

Definition at line 466 of file spritecache.cpp.

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

Referenced by LoadGrfFile(), LoadGrfFileIndexed(), and LoadNewGRFFile().

bool SkipSpriteData | ( | byte | type,
|  | uint16 | num |
| ) |  |  |

Skip the given amount of sprite graphics data.

Parameters:

  | type | the type of sprite (compressed etc)
  | num | the amount of sprites to skip

Returns:
  true if the data could be correctly skipped.

Definition at line 96 of file spritecache.cpp.

References FioReadByte(), and FioSkipBytes().

Referenced by LoadNewGRFFile(), and LoadNextSprite().