Refactor TexturePool class for improved readability and maintainability; reorganize method definitions and formatting for consistency.

This commit is contained in:
scawful
2025-04-29 08:20:59 -04:00
parent 718a14ca62
commit 0b9002e455

View File

@@ -2,11 +2,10 @@
#define YAZE_APP_GFX_TEXTURE_POOL_H #define YAZE_APP_GFX_TEXTURE_POOL_H
#include <SDL.h> #include <SDL.h>
#include <memory>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <string>
#include "app/core/platform/sdl_deleter.h"
namespace yaze { namespace yaze {
namespace gfx { namespace gfx {
@@ -18,7 +17,8 @@ public:
return instance; return instance;
} }
SDL_Texture* GetTexture(SDL_Renderer* renderer, int width, int height, Uint32 format) { SDL_Texture* GetTexture(SDL_Renderer* renderer, int width, int height,
Uint32 format) {
std::string key = GenerateKey(width, height, format); std::string key = GenerateKey(width, height, format);
// Check if we have a suitable texture in the pool // Check if we have a suitable texture in the pool
@@ -30,10 +30,12 @@ public:
} }
// Create a new texture // Create a new texture
return SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height); return SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING,
width, height);
} }
void ReturnTexture(SDL_Texture* texture, int width, int height, Uint32 format) { void ReturnTexture(SDL_Texture* texture, int width, int height,
Uint32 format) {
if (!texture) return; if (!texture) return;
std::string key = GenerateKey(width, height, format); std::string key = GenerateKey(width, height, format);
@@ -53,10 +55,12 @@ private:
TexturePool() = default; TexturePool() = default;
std::string GenerateKey(int width, int height, Uint32 format) { std::string GenerateKey(int width, int height, Uint32 format) {
return std::to_string(width) + "x" + std::to_string(height) + "_" + std::to_string(format); return std::to_string(width) + "x" + std::to_string(height) + "_" +
std::to_string(format);
} }
std::unordered_map<std::string, std::vector<SDL_Texture*>> available_textures_; std::unordered_map<std::string, std::vector<SDL_Texture*>>
available_textures_;
}; };
} // namespace gfx } // namespace gfx