41 #ifndef AGS_SHARED_AC_SPRITE_CACHE_H 42 #define AGS_SHARED_AC_SPRITE_CACHE_H 44 #include "common/std/memory.h" 45 #include "common/std/vector.h" 46 #include "common/std/list.h" 47 #include "ags/shared/ac/sprite_file.h" 48 #include "ags/shared/core/platform.h" 49 #include "ags/shared/gfx/bitmap.h" 50 #include "ags/shared/util/error.h" 51 #include "ags/shared/util/geometry.h" 64 typedef AGS::Shared::HError HAGSError;
69 #if AGS_PLATFORM_OS_ANDROID || AGS_PLATFORM_OS_IOS 70 #define DEFAULTCACHESIZE_KB (32 * 1024) 72 #define DEFAULTCACHESIZE_KB (128 * 1024) 82 static const sprkey_t MIN_SPRITE_INDEX = 1;
83 static const sprkey_t MAX_SPRITE_INDEX = INT32_MAX - 1;
84 static const size_t MAX_SPRITE_SLOTS = INT32_MAX;
86 typedef Size (*PfnAdjustSpriteSize)(
const Size &size,
const uint32_t sprite_flags);
87 typedef Bitmap *(*PfnInitSprite)(sprkey_t index,
Bitmap *image, uint32_t &sprite_flags);
88 typedef void (*PfnPostInitSprite)(sprkey_t index);
89 typedef void (*PfnPrewriteSprite)(
Bitmap *image);
92 PfnAdjustSpriteSize AdjustSize;
93 PfnInitSprite InitSprite;
94 PfnPostInitSprite PostInitSprite;
95 PfnPrewriteSprite PrewriteSprite;
104 int SaveToFile(
const String &filename,
int store_flags, SpriteCompression compress,
SpriteFileIndex &index);
108 inline int GetStoreFlags()
const {
109 return _file.GetStoreFlags();
111 inline SpriteCompression GetSpriteCompression()
const {
112 return _file.GetSpriteCompression();
117 bool DoesSpriteExist(sprkey_t index)
const;
119 Size GetSpriteResolution(sprkey_t index)
const;
122 sprkey_t EnlargeTo(sprkey_t topmost);
124 sprkey_t GetFreeIndex();
126 size_t GetCacheSize()
const;
128 size_t GetLockedSize()
const;
130 size_t GetMaxCacheSize()
const;
132 size_t GetSpriteSlotCount()
const;
134 bool HasFreeSlots()
const;
137 bool IsAssetSprite(sprkey_t index)
const;
140 void PrecacheSprite(sprkey_t index);
146 void LockSprite(sprkey_t index);
152 void UnlockSprite(sprkey_t index);
154 Bitmap *RemoveSprite(sprkey_t index);
156 void DisposeSprite(sprkey_t index);
159 void DisposeAllCached();
169 void SetEmptySprite(sprkey_t index,
bool as_asset);
171 void SetMaxCacheSize(
size_t size);
174 Bitmap *operator[](sprkey_t index);
178 size_t LoadSprite(sprkey_t index,
bool lock =
false);
180 void RemapSpriteToPlaceholder(sprkey_t index);
182 void DisposeOldest();
184 void FreeMem(
size_t space);
186 void InitNullSprite(sprkey_t index);
190 static Size DummyAdjustSize(
const Size &size,
const uint32_t) {
return size; }
191 static Bitmap *DummyInitSprite(sprkey_t,
Bitmap *image, uint32_t &) {
return image; }
192 static void DummyPostInitSprite(sprkey_t) { }
193 static void DummyPrewriteSprite(
Bitmap *) { }
204 SpriteData() =
default;
205 SpriteData(SpriteData &&other) =
default;
206 SpriteData(
Bitmap *image,
size_t size, uint32_t flags) : Size(size), Flags(flags), Image(image) {}
208 SpriteData &operator=(SpriteData &&other) =
default;
211 bool IsValid()
const {
return Flags != 0u; }
213 bool DoesSpriteExist()
const;
215 bool IsAssetSprite()
const;
217 bool IsError()
const;
219 bool IsExternalSprite()
const;
221 bool IsLocked()
const;
234 size_t _maxCacheSize;
Definition: achievements_tables.h:27
Definition: allegro_bitmap.h:44
Definition: sprite_file.h:127
Definition: sprite_cache.h:80
Definition: sprite_file.h:94
Definition: sprite_cache.h:91
Definition: geometry.h:148
Definition: movie_decoder.h:32