6d0df85e5e
Tanda grande de identifier-naming: 47 métodos privados pasan de snake_case (en su mayoría catalán/spanish) a camelBack inglés. Solo afecta a sus archivos hpp+cpp; ningún símbolo cruza fichero (los públicos quedan para una pasada manual con VS Code). Renames por clase: - ShapeLoader: resolve_path → resolvePath. - VectorText: load_charset → loadCharset, get_shape_filename → getShapeFilename. - Shape: starts_with → startsWith (cuidado de no tocar std::string::starts_with que también usaba), extract_value → extractValue, parse_center → parseCenter, parse_points → parsePoints. - Starfield: inicialitzar_estrella → initStar, fora_area → isOutsideArea, calcular_escala → computeScale, calcular_brightness → computeBrightness. - TitleScene: actualitzar_animacio_logo → updateLogoAnimation, inicialitzar_titol → initTitle. - LogoScene: inicialitzar_lletres → initLetters, actualitzar_explosions → updateExplosions, canviar_estat → changeState, totes_lletres_completes → allLettersComplete. - SpawnController: generar_spawn_events → generateSpawnEvents, seleccionar_tipus_aleatori → selectRandomType, spawn_enemic → spawnEnemy, aplicar_multiplicadors → applyMultipliers. - ShipAnimator: actualitzar_entering/floating/exiting → updateEntering/Floating/Exiting, configurar_nau_p1/p2 → configureShipP1/P2, calcular_posicio_fora_pantalla → computeOffscreenPosition. - GameScene: dibuixar_marges → drawMargins, dibuixar_marcador → drawScoreboard, disparar_bala → fireBullet, obtenir_punt_spawn → getSpawnPoint, unir_jugador → joinPlayer, dibuixar_continue → drawContinue, dibuixar_missatge_stage → drawStageMessage. - StageLoader: parse_metadata/stage/spawn_config/distribution/multipliers/ spawn_mode → parseMetadata/Stage/SpawnConfig/Distribution/Multipliers/ SpawnMode, validar_config → validateConfig. - StageManager: canviar_estat → changeState, processar_init_hud/level_start/playing/level_completed → processInitHud/LevelStart/Playing/LevelCompleted, carregar_stage → loadStage. Métodos públicos y funciones libres (cross-file) quedan a propósito sin tocar — los renombrará el usuario con la herramienta de rename de VS Code. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
87 lines
2.7 KiB
C++
87 lines
2.7 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/";
|
|
|
|
auto ShapeLoader::load(const std::string& filename) -> std::shared_ptr<Shape> {
|
|
// 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->getName()
|
|
<< ", " << shape->getNumPrimitives() << " primitives)" << '\n';
|
|
|
|
cache_[filename] = shape;
|
|
return shape;
|
|
}
|
|
|
|
void ShapeLoader::clear_cache() {
|
|
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
|
|
<< '\n';
|
|
cache_.clear();
|
|
}
|
|
|
|
auto ShapeLoader::get_cache_size() -> 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
|
|
if (filename.starts_with(base_path_)) {
|
|
return filename;
|
|
}
|
|
|
|
// Altrament, añadir base_path (ara suporta subdirectoris)
|
|
return base_path_ + filename;
|
|
}
|
|
|
|
} // namespace Graphics
|