diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-26 03:08:15 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-26 03:08:15 +0200 |
commit | 9b91d6f3d0187e0daf29a262cf19ad08ba2b7cf5 (patch) | |
tree | 8dfd51b02ec59bb4965305292d8d57c3ab3606b1 /src/view/SpriteCache.hpp | |
parent | 8e0395e39c52b148d5ff9ef9fdd6a6d33e7b86e9 (diff) | |
download | rpgedit-9b91d6f3d0187e0daf29a262cf19ad08ba2b7cf5.tar rpgedit-9b91d6f3d0187e0daf29a262cf19ad08ba2b7cf5.zip |
Add support for rotated sprites
Diffstat (limited to 'src/view/SpriteCache.hpp')
-rw-r--r-- | src/view/SpriteCache.hpp | 26 |
1 files changed, 20 insertions, 6 deletions
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 <memory> +#include <string> #include <unordered_map> #include <SDL.h> @@ -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<std::string, std::unique_ptr<SDL_Surface, SDL_Surface_deleter>> sprites; + typedef std::pair<std::string, int> sprite_key; + typedef std::unique_ptr<SDL_Surface, SDL_Surface_deleter> sprite_value; - std::unique_ptr<SDL_Surface, SDL_Surface_deleter> load(const std::string &name); + struct sprite_key_hash { + size_t operator()(const sprite_key &k) const { + std::hash<std::string> string_hash; + std::hash<int> int_hash; + + return string_hash(k.first) ^ int_hash(k.second); + } + }; + + std::unordered_map<sprite_key, sprite_value, sprite_key_hash> 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(); |