summaryrefslogtreecommitdiffstats
path: root/src/view/SpriteCache.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/SpriteCache.hpp')
-rw-r--r--src/view/SpriteCache.hpp26
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();