refactor: eliminar ShapeLoader::resolvePath i BASE_PATH (codi mort)
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>
This commit is contained in:
@@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
namespace Graphics {
|
namespace Graphics {
|
||||||
|
|
||||||
// Inicialización de variables estàtiques
|
// Inicialización de variables estàtiques
|
||||||
std::unordered_map<std::string, std::shared_ptr<Shape>> ShapeLoader::cache;
|
std::unordered_map<std::string, std::shared_ptr<Shape>> ShapeLoader::cache;
|
||||||
|
|
||||||
auto ShapeLoader::load(const std::string& filename) -> std::shared_ptr<Shape> {
|
auto ShapeLoader::load(const std::string& filename) -> std::shared_ptr<Shape> {
|
||||||
// Check cache first
|
// Check cache first
|
||||||
auto it = cache.find(filename);
|
auto it = cache.find(filename);
|
||||||
if (it != cache.end()) {
|
if (it != cache.end()) {
|
||||||
@@ -57,29 +57,14 @@ auto ShapeLoader::load(const std::string& filename) -> std::shared_ptr<Shape> {
|
|||||||
|
|
||||||
cache[filename] = shape;
|
cache[filename] = shape;
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeLoader::clearCache() {
|
void ShapeLoader::clearCache() {
|
||||||
std::cout << "[ShapeLoader] Netejant caché (" << cache.size() << " formes)"
|
std::cout << "[ShapeLoader] Netejant caché (" << cache.size() << " formes)"
|
||||||
<< '\n';
|
<< '\n';
|
||||||
cache.clear();
|
cache.clear();
|
||||||
}
|
|
||||||
|
|
||||||
auto ShapeLoader::getCacheSize() -> size_t { return cache.size(); }
|
|
||||||
|
|
||||||
auto ShapeLoader::resolvePath(const std::string& filename) -> std::string {
|
|
||||||
// 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
|
auto ShapeLoader::getCacheSize() -> size_t { return cache.size(); }
|
||||||
if (filename.starts_with(BASE_PATH)) {
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Altrament, añadir base_path (ara suporta subdirectoris)
|
|
||||||
return std::string(BASE_PATH) + filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace Graphics {
|
namespace Graphics {
|
||||||
|
|
||||||
// Carregador estàtic de formes con caché
|
// Carregador estàtic de formes con caché
|
||||||
class ShapeLoader {
|
class ShapeLoader {
|
||||||
public:
|
public:
|
||||||
// No instanciable (tot estàtic)
|
// No instanciable (tot estàtic)
|
||||||
ShapeLoader() = delete;
|
ShapeLoader() = delete;
|
||||||
@@ -30,10 +30,6 @@ class ShapeLoader {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unordered_map<std::string, std::shared_ptr<Shape>> cache;
|
static std::unordered_map<std::string, std::shared_ptr<Shape>> cache;
|
||||||
static constexpr const char* BASE_PATH = "data/shapes/";
|
};
|
||||||
|
|
||||||
// Helpers privats
|
|
||||||
static auto resolvePath(const std::string& filename) -> std::string;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
|
|||||||
Reference in New Issue
Block a user