1 // 2 // Sprite cache. 3 // 4 5 6 #include "bstone_sprite_cache.h" 7 #include "id_pm.h" 8 9 10 namespace bstone 11 { 12 13 SpriteCache()14SpriteCache::SpriteCache() : 15 cache_{ max_sprites } 16 { 17 } 18 ~SpriteCache()19SpriteCache::~SpriteCache() 20 { 21 } 22 cache(const int sprite_id)23const Sprite* SpriteCache::cache( 24 const int sprite_id) 25 { 26 if (sprite_id <= 0 || sprite_id >= max_sprites) 27 { 28 throw "Invalid sprite id."; 29 } 30 31 const auto sprite_data = ::PM_GetSpritePage(sprite_id); 32 33 if (!sprite_data) 34 { 35 throw "No sprite data."; 36 } 37 38 auto& sprite = cache_[sprite_id]; 39 40 if (!sprite.is_initialized()) 41 { 42 sprite.initialize(sprite_data); 43 } 44 45 return &sprite; 46 } 47 48 49 } // bstone 50