21#ifndef __SPRITEPOOL_H__
22#define __SPRITEPOOL_H__
28#include <unordered_map>
30#include "sprite/sprite.h"
31#include "canvas/texturecanvas.h"
58 struct stNativeTextureSize {
59 std :: optional<int> nWidth;
60 std :: optional<int> nHeight;
70 SunLight :: Sprite :: Sprite sprite;
71 std :: map<int, SunLight :: Canvas :: TextureCanvas> textures;
84 std :: map<int, stNativeTextureSize> nativeTextureSizes;
85 std :: string strTypeTag;
90 typedef std :: deque<uint32_t> __FreeList;
96 std :: deque<stSlot> m_Slots;
97 std :: unordered_map<std :: string, __FreeList> m_FreeListsByType;
104 bool RegisterType(
const std :: string &strTypeTag, uint32_t nCapacity );
Generic, game-agnostic fixed-capacity sprite pool. Sprite types are registered up-front with a fixed ...
Definition spritepool.h:45
~SpritePool(void)
Destructor. Finalize all class data.
Definition spritepool.cpp:37
int GetOrCacheNativeWidth(SpriteHandle handle, int nSequenceId, int nCurrentWidth)
Get a sequence's cached natural (un-frame-divided) pixel width, caching nCurrentWidth as that value t...
Definition spritepool.cpp:287
SunLight::Sprite::Sprite * Resolve(SpriteHandle handle)
Resolve a handle to it's live Sprite object.
Definition spritepool.cpp:205
SunLight::Canvas::TextureCanvas * GetTexture(SpriteHandle handle, int nSequenceId)
Get a handle's texture canvas for the given sequence id, if it was previously created via GetOrCreate...
Definition spritepool.cpp:229
SpritePool(void)
Constructor. Initialize all class data.
Definition spritepool.cpp:30
int GetOrCacheNativeHeight(SpriteHandle handle, int nSequenceId, int nCurrentHeight)
Height counterpart of GetOrCacheNativeWidth - same reasoning, since a texture's own natural dimension...
Definition spritepool.cpp:315
SpriteHandle Acquire(const std ::string &strTypeTag)
Acquire a free slot for the given type tag, returning an opaque handle.
Definition spritepool.cpp:87
void UpdateAll(void)
Advance the animation frame of every in-use sprite. Called once per frame by the engine so Lua never ...
Definition spritepool.cpp:341
bool Release(SpriteHandle handle)
Release a previously acquired handle back to it's type's free list. Bumps the slot's generation so st...
Definition spritepool.cpp:176
void Clear(void)
Release every slot's textures now, while the caller still has a live rendering context....
Definition spritepool.cpp:372
bool RegisterType(const std ::string &strTypeTag, uint32_t nCapacity)
Reserve nCapacity fixed slots for the given type tag. Must be called before Acquire() is used for tha...
Definition spritepool.cpp:49
SunLight::Canvas::TextureCanvas * GetOrCreateTexture(SpriteHandle handle, int nSequenceId)
Get (creating if necessary) a handle's texture canvas for the given sequence id. The returned pointer...
Definition spritepool.cpp:257
uint32_t SpriteHandle
Opaque handle to a sprite pool slot. Packs a slot index (low 16 bits, 1-based so 0 stays reserved for...
Definition spritehandle.h:37
Definition irendererprovider.h:32