682c27c07c
Cap caller invocava resolvePath fora de la seua pròpia definició. A més, BASE_PATH apuntava a "data/shapes/" mentre que load() ja construeix el path amb el prefix "shapes/" directament — el helper mai s'hauria activat encara que es cridara. Hallazgo #18 de CODE_REVIEW.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
36 lines
941 B
C++
36 lines
941 B
C++
// shape_loader.hpp - Carregador estàtic de formes con caché
|
|
// © 2026 JailDesigner
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include "core/graphics/shape.hpp"
|
|
|
|
namespace Graphics {
|
|
|
|
// Carregador estàtic de formes con caché
|
|
class ShapeLoader {
|
|
public:
|
|
// No instanciable (tot estàtic)
|
|
ShapeLoader() = delete;
|
|
|
|
// Carregar shape desde file (con caché)
|
|
// Retorna punter compartit (nullptr si error)
|
|
// Exemple: load("ship.shp") → busca a "data/shapes/ship.shp"
|
|
static auto load(const std::string& filename) -> std::shared_ptr<Shape>;
|
|
|
|
// Netejar caché (útil per debug/recàrrega)
|
|
static void clearCache();
|
|
|
|
// Estadístiques (debug)
|
|
static auto getCacheSize() -> size_t;
|
|
|
|
private:
|
|
static std::unordered_map<std::string, std::shared_ptr<Shape>> cache;
|
|
};
|
|
|
|
} // namespace Graphics
|