VEGO-Engine  0.1
Loading...
Searching...
No Matches
TextureManager.h
1#pragma once
2
3#include "ECS.h"
4#include "SDL3/SDL_surface.h"
5#include <SDL3/SDL_render.h>
6#include <map>
7#include <memory>
8#include <string>
9#include <vector>
10#include "Textures.h"
11
23
24class TextureManager
25{
26 public:
27 TextureManager(Manager* manager) : manager(manager) {}
28 ~TextureManager() {
29 for (auto& it : this->texture_cache) {
30 SDL_DestroyTexture(it.second);
31 }
32 for (auto& it : this->mapTile_texture_cache) {
33 SDL_DestroyTexture(it.second);
34 }
35 }
36
46 void addSingleTexture(Textures texture, const char* filePath);
47
56 void addTextures(const std::map<Textures, const char*>& textures);
57
67 SDL_Texture* loadTexture(Textures texture);
68 static std::vector<SDL_Rect> splitSpriteSheet(SDL_Texture* spriteSheet, int width, int height, int spritesOnSheet);
69 static void draw(SDL_Renderer* renderer, SDL_Texture* texture, SDL_FRect src, SDL_FRect dest, bool flipped = false);
70
71 void setScaleMode(SDL_ScaleMode scaleMode) { this->scaleMode = scaleMode; }
72
84 SDL_Texture* loadMapTileTexture(const char* path);
85
86 std::string getTexturePath(Textures texture) {
87 return this->texture_references.at(texture);
88 }
89
90 private:
91 SDL_ScaleMode scaleMode = SDL_SCALEMODE_NEAREST;
92 Manager* manager;
93 std::map<Textures, SDL_Texture*> texture_cache;
94 std::map<std::string, SDL_Texture*> mapTile_texture_cache;
95
96 std::map<Textures, std::string> texture_references;
97};
Is responsible for managing all entities.
Definition Manager.h:23
SDL_Texture * loadTexture(Textures texture)
Loads a texture from the cache.
Definition TextureManager.cpp:31
void addTextures(const std::map< Textures, const char * > &textures)
Adds multiple textures to the cache.
Definition TextureManager.cpp:24
void addSingleTexture(Textures texture, const char *filePath)
Adds a single texture to the cache.
Definition TextureManager.cpp:10
SDL_Texture * loadMapTileTexture(const char *path)
Loads a map tile texture from the file system and caches it.
Definition TextureManager.cpp:47
Forward declaration of the Textures enum class.