ASAPCabinetFE
 
Loading...
Searching...
No Matches
texture_cache.h
1#ifndef TEXTURE_CACHE_H
2#define TEXTURE_CACHE_H
3
4#include <SDL.h>
5#include <unordered_map>
6#include <list>
7#include <string>
8#include <memory>
9
11public:
14
15 SDL_Texture* getTexture(SDL_Renderer* renderer, const std::string& path);
16 void clearCache();
17
18private:
19 struct TextureDeleter {
20 void operator()(SDL_Texture* texture) const {
21 SDL_DestroyTexture(texture);
22 }
23 };
24
25 struct CacheEntry {
26 SDL_Renderer* renderer;
27 std::unique_ptr<SDL_Texture, TextureDeleter> texture;
28 CacheEntry(SDL_Renderer* r, SDL_Texture* t) : renderer(r), texture(t) {}
29 };
30
31 std::unordered_map<std::string, CacheEntry> cache_;
32 std::list<std::string> lruKeys_;
33 static const size_t MAX_CACHE_SIZE = 100;
34
35 void evictOldest();
36};
37
38#endif // TEXTURE_CACHE_H
Definition texture_cache.h:10