b746578bc8
Sustituye en bloque las cabeceras de los archivos por una sola línea de copyright. Cero rastro de "Visente", "Sergi" o "1999" en el árbol del proyecto. Se eliminan también las variantes "© 2025 Port a C++20", "© 2025 Port a C++20 con SDL3" y "© 2025 Orni Attack" (con todas sus colas descriptivas como "Arquitectura de entidades" o "Sistema de física"), que en este punto eran ruido histórico. Aplicado con un par de sed (find -type f, excluyendo source/external y source/legacy): 1. \|^// © 1999 Visente i Sergi (versión Pascal)$|d 2. s|^// © 2025 (Port a C++20.*|Orni Attack.*)$|// © 2026 JailDesigner| Verificado: la única variante de cabecera tras el sweep es "// © 2026 JailDesigner". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
// shape_loader.cpp - Implementació del carregador con caché
|
|
// © 2026 JailDesigner
|
|
|
|
#include "core/graphics/shape_loader.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include "core/resources/resource_helper.hpp"
|
|
|
|
namespace Graphics {
|
|
|
|
// Inicialización de variables estàtiques
|
|
std::unordered_map<std::string, std::shared_ptr<Shape>> ShapeLoader::cache_;
|
|
std::string ShapeLoader::base_path_ = "data/shapes/";
|
|
|
|
std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
|
// Check cache first
|
|
auto it = cache_.find(filename);
|
|
if (it != cache_.end()) {
|
|
std::cout << "[ShapeLoader] Cache hit: " << filename << '\n';
|
|
return it->second; // Cache hit
|
|
}
|
|
|
|
// Normalize path: "ship.shp" → "shapes/ship.shp"
|
|
// "logo/letra_j.shp" → "shapes/logo/letra_j.shp"
|
|
std::string normalized = filename;
|
|
if (!normalized.starts_with("shapes/")) {
|
|
// Doesn't start with "shapes/", so add it
|
|
normalized = "shapes/" + normalized;
|
|
}
|
|
|
|
// Load from resource system
|
|
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
|
if (data.empty()) {
|
|
std::cerr << "[ShapeLoader] Error: no s'ha pogut load " << normalized
|
|
<< '\n';
|
|
return nullptr;
|
|
}
|
|
|
|
// Convert bytes to string and parse
|
|
std::string file_content(data.begin(), data.end());
|
|
auto shape = std::make_shared<Shape>();
|
|
if (!shape->parseFile(file_content)) {
|
|
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
|
<< '\n';
|
|
return nullptr;
|
|
}
|
|
|
|
// Verify shape is valid
|
|
if (!shape->isValid()) {
|
|
std::cerr << "[ShapeLoader] Error: shape invàlida " << normalized << '\n';
|
|
return nullptr;
|
|
}
|
|
|
|
// Cache and return
|
|
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
|
|
<< ", " << shape->get_num_primitives() << " primitives)" << '\n';
|
|
|
|
cache_[filename] = shape;
|
|
return shape;
|
|
}
|
|
|
|
void ShapeLoader::clear_cache() {
|
|
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
|
|
<< '\n';
|
|
cache_.clear();
|
|
}
|
|
|
|
size_t ShapeLoader::get_cache_size() { return cache_.size(); }
|
|
|
|
std::string ShapeLoader::resolve_path(const std::string& filename) {
|
|
// Si es un path absolut (comença con '/'), usar-lo directament
|
|
if (!filename.empty() && filename[0] == '/') {
|
|
return filename;
|
|
}
|
|
|
|
// Si ya conté el prefix base_path, usar-lo directament
|
|
if (filename.starts_with(base_path_)) {
|
|
return filename;
|
|
}
|
|
|
|
// Altrament, añadir base_path (ara suporta subdirectoris)
|
|
return base_path_ + filename;
|
|
}
|
|
|
|
} // namespace Graphics
|