From 9b91d6f3d0187e0daf29a262cf19ad08ba2b7cf5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 26 Sep 2014 03:08:15 +0200 Subject: Add support for rotated sprites --- src/view/SpriteCache.hpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/view/SpriteCache.hpp') diff --git a/src/view/SpriteCache.hpp b/src/view/SpriteCache.hpp index c08ba6f..ae01887 100644 --- a/src/view/SpriteCache.hpp +++ b/src/view/SpriteCache.hpp @@ -27,6 +27,7 @@ #pragma once #include +#include #include #include @@ -38,19 +39,32 @@ namespace View { class SpriteCache { private: - class SDL_Surface_deleter { - public: - void operator()(SDL_Surface *surface) { + struct SDL_Surface_deleter { + void operator()(SDL_Surface *surface) const { SDL_FreeSurface(surface); } }; - std::unordered_map> sprites; + typedef std::pair sprite_key; + typedef std::unique_ptr sprite_value; - std::unique_ptr load(const std::string &name); + struct sprite_key_hash { + size_t operator()(const sprite_key &k) const { + std::hash string_hash; + std::hash int_hash; + + return string_hash(k.first) ^ int_hash(k.second); + } + }; + + std::unordered_map sprites; + + sprite_value load(const std::string &id); + sprite_value load(const std::string &id, unsigned rotation); + sprite_value & get(const std::string &id, unsigned rotation); public: - SDL_Surface * get(const std::string &type, const std::string &name); + SDL_Surface * get(const std::string &type, const std::string &name, unsigned rotation = 0); void clear() { sprites.clear(); -- cgit v1.2.3