Fix: eliminar carga doble de texturas en inicialización
Problema: Cada textura se cargaba DOS veces: 1. Primera carga temporal para obtener dimensiones (width) 2. Segunda carga real para almacenar en textures_ Solución: Reutilizar la textura cargada en lugar de crear nueva. - TextureInfo ahora guarda shared_ptr<Texture> en lugar de solo path - Se ordena por tamaño usando la textura ya cargada - Se almacena directamente en textures_ sin recargar Resultado: 4 cargas → 4 cargas (sin duplicados) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
BIN
resources.pack
BIN
resources.pack
Binary file not shown.
@@ -147,22 +147,22 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
if (fs::exists(balls_dir) && fs::is_directory(balls_dir)) {
|
||||
struct TextureInfo {
|
||||
std::string name;
|
||||
std::string path;
|
||||
std::shared_ptr<Texture> texture;
|
||||
int width;
|
||||
};
|
||||
std::vector<TextureInfo> texture_files;
|
||||
|
||||
// Cargar información de todas las texturas (incluyendo dimensiones)
|
||||
// Cargar todas las texturas (solo una vez)
|
||||
for (const auto& entry : fs::directory_iterator(balls_dir)) {
|
||||
if (entry.is_regular_file() && entry.path().extension() == ".png") {
|
||||
std::string filename = entry.path().stem().string();
|
||||
std::string fullpath = entry.path().string();
|
||||
|
||||
// Cargar temporalmente para obtener dimensiones
|
||||
auto temp_texture = std::make_shared<Texture>(renderer_, fullpath);
|
||||
int width = temp_texture->getWidth();
|
||||
// Cargar textura y obtener dimensiones
|
||||
auto texture = std::make_shared<Texture>(renderer_, fullpath);
|
||||
int width = texture->getWidth();
|
||||
|
||||
texture_files.push_back({filename, fullpath, width});
|
||||
texture_files.push_back({filename, texture, width});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,9 +172,9 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
return a.width > b.width; // Descendente por tamaño
|
||||
});
|
||||
|
||||
// Cargar todas las texturas en orden de tamaño (0=big, 1=normal, 2=small, 3=tiny)
|
||||
// Guardar texturas ya cargadas en orden (0=big, 1=normal, 2=small, 3=tiny)
|
||||
for (const auto& info : texture_files) {
|
||||
textures_.push_back(std::make_shared<Texture>(renderer_, info.path));
|
||||
textures_.push_back(info.texture);
|
||||
texture_names_.push_back(info.name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user