0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 09:03:42 +00:00
SDL_Minigame/include/TextureManager.h
Benedikt Galbavy 6a2e8289f6 fixed memory leaks
managers are no singletons anymore
2024-01-30 15:17:58 +01:00

29 lines
673 B
C++

#pragma once
#include <SDL_render.h>
#include <map>
#include <vector>
struct cmp_str
{
bool operator()(char const *a, char const *b) const {
return strcmp(a, b) < 0;
}
};
class TextureManager
{
public:
TextureManager() {}
~TextureManager() {
for (auto& it : this->texture_cache) {
SDL_DestroyTexture(it.second);
}
}
std::map<const char*, SDL_Texture*, cmp_str> texture_cache;
SDL_Texture* loadTexture(const char* fileName);
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
static void draw(SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false);
};