0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 07:53:43 +00:00
SDL_Minigame/include/TextureManager.h
freezarite cbd1993c20 Extra map for MapTiles generated by TMX file now works like intended.
removed textures map from AssetManager as it is no longer used.
Updated SpriteComponent to now check if it is a normal Texture or a MapTileTexture.
Added if condition in TextureManager::LoadMapTileTexture to check if the texture was able to be loaded by SDL
2024-11-30 15:42:56 +01:00

36 lines
1.0 KiB
C++

#pragma once
#include "ECS.h"
#include <SDL_render.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "TextureEnumBase.h"
class TextureManager
{
public:
TextureManager(Manager* manager) : manager(manager) {}
~TextureManager() {
for (auto& it : this->texture_cache) {
SDL_DestroyTexture(it.second);
}
for (auto& it : this->mapTile_texture_cache) {
SDL_DestroyTexture(it.second);
}
}
void addSingleTexture(Textures texture, const char* filePath);
void addTextures(const std::map<Textures, const char*>& textures);
SDL_Texture* loadTexture(Textures texture);
static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Rect src, SDL_Rect dest, bool flipped = false);
SDL_Texture* loadMapTileTexture(const char* path);
private:
Manager* manager;
std::map<Textures, SDL_Texture*> texture_cache;
std::map<std::string, SDL_Texture*> mapTile_texture_cache;
};