MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetRawSprite

Function GetRawSprite

src/spritecache.cpp:855–895  ·  view source on GitHub ↗

* Reads a sprite (from disk or sprite cache). * If the sprite is not available or of wrong type, a fallback sprite is returned. * @param sprite Sprite to read. * @param type Expected sprite type. * @param allocator Allocator function to use. Set to nullptr to use the usual sprite cache. * @param encoder Sprite encoder to use. Set to nullptr to use the currently active blitter. * @return Spri

Source from the content-addressed store, hash-verified

853 * @return Sprite raw data
854 */
855void *GetRawSprite(SpriteID sprite, SpriteType type, SpriteAllocator *allocator, SpriteEncoder *encoder)
856{
857 assert(type != SpriteType::MapGen || IsMapgenSpriteID(sprite));
858 assert(type < SpriteType::Invalid);
859
860 if (!SpriteExists(sprite)) {
861 Debug(sprite, 1, "Tried to load non-existing sprite #{}. Probable cause: Wrong/missing NewGRFs", sprite);
862
863 /* SPR_IMG_QUERY is a BIG FAT RED ? */
864 sprite = SPR_IMG_QUERY;
865 }
866
867 SpriteCache *sc = GetSpriteCache(sprite);
868
869 if (sc->type != type) return HandleInvalidSpriteRequest(sprite, type, sc, allocator, encoder);
870
871 if (allocator == nullptr && encoder == nullptr) {
872 /* Load sprite into/from spritecache */
873
874 /* Update LRU */
875 sc->lru = ++_sprite_lru_counter;
876
877 /* Load the sprite, if it is not loaded, yet */
878 if (sc->ptr == nullptr) {
879 UniquePtrSpriteAllocator cache_allocator;
880 if (sc->type == SpriteType::Recolour) {
881 ReadRecolourSprite(*sc->file, sc->file_pos, sc->length, cache_allocator);
882 } else {
883 ReadSprite(sc, sprite, type, cache_allocator, nullptr);
884 }
885 sc->ptr = std::move(cache_allocator.data);
886 sc->length = static_cast<uint32_t>(cache_allocator.size);
887 _spritecache_bytes_used += sc->length;
888 }
889
890 return static_cast<void *>(sc->ptr.get());
891 } else {
892 /* Do not use the spritecache, but a different allocator. */
893 return ReadSprite(sc, sprite, type, *allocator, encoder);
894 }
895}
896
897void GfxInitSpriteMem()
898{

Callers 5

ReadSpriteFunction · 0.85
GetSpriteFunction · 0.85
GetNonSpriteFunction · 0.85
PopulateCursorCacheMethod · 0.85

Calls 7

IsMapgenSpriteIDFunction · 0.85
SpriteExistsFunction · 0.85
GetSpriteCacheFunction · 0.85
ReadRecolourSpriteFunction · 0.85
ReadSpriteFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected