OpenTTD Source 20241224-master-gf74b0cf984
|
Functions to cache sprites in memory. More...
Go to the source code of this file.
Data Structures | |
struct | Sprite |
Data structure describing a sprite. More... | |
class | SimpleSpriteAllocator |
SpriteAllocate that uses malloc to allocate memory. More... | |
class | UniquePtrSpriteAllocator |
SpriteAllocator that allocates memory via a unique_ptr array. More... | |
Enumerations | |
enum | SpriteCacheCtrlFlags { SCCF_ALLOW_ZOOM_MIN_1X_PAL = 0 , SCCF_ALLOW_ZOOM_MIN_1X_32BPP = 1 , SCCF_ALLOW_ZOOM_MIN_2X_PAL = 2 , SCCF_ALLOW_ZOOM_MIN_2X_32BPP = 3 } |
Functions | |
void * | GetRawSprite (SpriteID sprite, SpriteType type, SpriteAllocator *allocator=nullptr, SpriteEncoder *encoder=nullptr) |
Reads a sprite (from disk or sprite cache). | |
bool | SpriteExists (SpriteID sprite) |
SpriteType | GetSpriteType (SpriteID sprite) |
Get the sprite type of a given sprite. | |
SpriteFile * | GetOriginFile (SpriteID sprite) |
Get the SpriteFile of a given sprite. | |
uint32_t | GetSpriteLocalID (SpriteID sprite) |
Get the GRF-local sprite id of a given sprite. | |
uint | GetSpriteCountForFile (const std::string &filename, SpriteID begin, SpriteID end) |
Count the sprites which originate from a specific file in a range of SpriteIDs. | |
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. | |
const Sprite * | GetSprite (SpriteID sprite, SpriteType type) |
const uint8_t * | GetNonSprite (SpriteID sprite, SpriteType type) |
void | GfxInitSpriteMem () |
void | GfxClearSpriteCache () |
Remove all encoded sprites from the sprite cache without discarding sprite location information. | |
void | GfxClearFontSpriteCache () |
Remove all encoded font sprites from the sprite cache without discarding sprite location information. | |
void | IncreaseSpriteLRU () |
SpriteFile & | OpenCachedSpriteFile (const std::string &filename, Subdirectory subdir, bool palette_remap) |
Open/get the SpriteFile that is cached for use in the sprite cache. | |
std::span< const std::unique_ptr< SpriteFile > > | GetCachedSpriteFiles () |
Get the list of cached SpriteFiles. | |
void | ReadGRFSpriteOffsets (SpriteFile &file) |
Parse the sprite section of GRFs. | |
size_t | GetGRFSpriteOffset (uint32_t id) |
Get the file offset for a specific sprite in the sprite section of a GRF. | |
bool | LoadNextSprite (SpriteID load_index, SpriteFile &file, uint file_sprite_id) |
Load a real or recolour sprite. | |
bool | SkipSpriteData (SpriteFile &file, uint8_t type, uint16_t num) |
Skip the given amount of sprite graphics data. | |
void | DupSprite (SpriteID old_spr, SpriteID new_spr) |
Variables | |
uint | _sprite_cache_size |
Functions to cache sprites in memory.
Definition in file spritecache.h.
enum SpriteCacheCtrlFlags |
Definition at line 25 of file spritecache.h.
Definition at line 693 of file spritecache.cpp.
std::span< const std::unique_ptr< SpriteFile > > GetCachedSpriteFiles | ( | ) |
Get the list of cached SpriteFiles.
Definition at line 81 of file spritecache.cpp.
Referenced by SpriteAlignerWindow::UpdateWidgetSize().
size_t GetGRFSpriteOffset | ( | uint32_t | id | ) |
Get the file offset for a specific sprite in the sprite section of a GRF.
id | ID of the sprite to look up. |
Definition at line 556 of file spritecache.cpp.
References _grf_sprite_offsets.
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.
Definition at line 220 of file spritecache.cpp.
Referenced by SpriteAlignerWindow::OnClick(), SpriteAlignerWindow::OnQueryTextFinished(), and UpdateCursorSize().
|
inline |
Definition at line 64 of file spritecache.h.
SpriteFile * GetOriginFile | ( | SpriteID | sprite | ) |
Get the SpriteFile of a given sprite.
sprite | The sprite to look at. |
Definition at line 170 of file spritecache.cpp.
References SpriteCache::file.
Referenced by SpriteAlignerWindow::DrawWidget(), and SpriteAlignerWindow::SetStringParameters().
void * GetRawSprite | ( | SpriteID | sprite, |
SpriteType | type, | ||
SpriteAllocator * | 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.
sprite | Sprite to read. |
type | Expected sprite type. |
allocator | Allocator function to use. Set to nullptr to use the usual sprite cache. |
encoder | Sprite encoder to use. Set to nullptr to use the currently active blitter. |
Definition at line 960 of file spritecache.cpp.
References Debug, SpriteCache::file, HandleInvalidSpriteRequest(), Invalid, SpriteCache::length, MapGen, ReadRecolourSprite(), ReadSprite(), Recolour, and SpriteCache::type.
Referenced by HandleInvalidSpriteRequest(), and ReadSprite().
|
inline |
Definition at line 58 of file spritecache.h.
Count the sprites which originate from a specific file in a range of SpriteIDs.
file | The loaded SpriteFile. |
begin | First sprite in range. |
end | First sprite not in range. |
Definition at line 194 of file spritecache.cpp.
References Debug, SpriteCache::file, and GetCachedSpriteFileByName().
uint32_t GetSpriteLocalID | ( | SpriteID | sprite | ) |
Get the GRF-local sprite id of a given sprite.
sprite | The sprite to look at. |
Definition at line 181 of file spritecache.cpp.
Referenced by SpriteAlignerWindow::DrawWidget(), NewGRFProfiler::EndResolve(), and SpriteAlignerWindow::SetStringParameters().
SpriteType GetSpriteType | ( | SpriteID | sprite | ) |
Get the sprite type of a given sprite.
sprite | The sprite to look at. |
Definition at line 159 of file spritecache.cpp.
References Invalid, and SpriteCache::type.
Referenced by SpriteAlignerWindow::OnClick(), and SpriteAlignerWindow::OnQueryTextFinished().
void GfxClearFontSpriteCache | ( | ) |
Remove all encoded font sprites from the sprite cache without discarding sprite location information.
Definition at line 1079 of file spritecache.cpp.
References DeleteEntryFromSpriteCache(), Font, and SpriteCache::type.
Referenced by AdjustGUIZoom().
void GfxClearSpriteCache | ( | ) |
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition at line 1064 of file spritecache.cpp.
References VideoDriver::ClearSystemSprites(), DeleteEntryFromSpriteCache(), and VideoDriver::GetInstance().
Referenced by CheckBlitter().
void GfxInitSpriteMem | ( | ) |
Definition at line 1047 of file spritecache.cpp.
void IncreaseSpriteLRU | ( | ) |
Definition at line 738 of file spritecache.cpp.
bool LoadNextSprite | ( | SpriteID | load_index, |
SpriteFile & | file, | ||
uint | file_sprite_id | ||
) |
Load a real or recolour sprite.
load_index | Global sprite index. |
file | GRF to load from. |
file_sprite_id | Sprite number in the GRF. |
container_version | Container version of the GRF. |
Definition at line 621 of file spritecache.cpp.
References _grf_sprite_offsets, SpriteCache::control_flags, SpriteCache::file, SpriteFile::GetContainerVersion(), RandomAccessFile::GetPos(), Invalid, SpriteCache::length, MapGen, MAX_SPRITES, Normal, RandomAccessFile::ReadByte(), RandomAccessFile::ReadDword(), RandomAccessFile::ReadWord(), Recolour, RandomAccessFile::SkipBytes(), SkipSpriteData(), SpriteCache::type, and SpriteCache::warned.
Referenced by LoadFontGlyph(), LoadGrfFile(), and LoadGrfFileIndexed().
SpriteFile & OpenCachedSpriteFile | ( | const std::string & | filename, |
Subdirectory | subdir, | ||
bool | palette_remap | ||
) |
Open/get the SpriteFile that is cached for use in the sprite cache.
filename | Name of the file at the disk. |
subdir | The sub directory to search this file in. |
palette_remap | Whether a palette remap needs to be performed for this file. |
Definition at line 93 of file spritecache.cpp.
References GetCachedSpriteFileByName(), and SpriteFile::SeekToBegin().
Referenced by LoadGrfFile(), LoadGrfFileIndexed(), and LoadNewGRFFile().
void ReadGRFSpriteOffsets | ( | SpriteFile & | file | ) |
Parse the sprite section of GRFs.
container_version | Container version of the GRF we're currently processing. |
Definition at line 565 of file spritecache.cpp.
References _grf_sprite_offsets, SpriteFile::GetContainerVersion(), RandomAccessFile::GetPos(), RandomAccessFile::ReadByte(), RandomAccessFile::ReadDword(), SCC_MASK, SCC_PAL, SCCF_ALLOW_ZOOM_MIN_1X_32BPP, SCCF_ALLOW_ZOOM_MIN_1X_PAL, SCCF_ALLOW_ZOOM_MIN_2X_32BPP, SCCF_ALLOW_ZOOM_MIN_2X_PAL, RandomAccessFile::SeekTo(), SetBit(), and RandomAccessFile::SkipBytes().
Referenced by LoadGrfFile(), LoadGrfFileIndexed(), and LoadNewGRFFileFromFile().
bool SkipSpriteData | ( | SpriteFile & | file, |
uint8_t | type, | ||
uint16_t | num | ||
) |
Skip the given amount of sprite graphics data.
type | the type of sprite (compressed etc) |
num | the amount of sprites to skip |
Definition at line 122 of file spritecache.cpp.
References RandomAccessFile::ReadByte(), and RandomAccessFile::SkipBytes().
Referenced by LoadNewGRFFileFromFile(), and LoadNextSprite().
bool SpriteExists | ( | SpriteID | sprite | ) |
Definition at line 145 of file spritecache.cpp.
|
extern |
Definition at line 32 of file spritecache.cpp.