7ee359b910
Sweep final del naming a CamelCase/camelBack/lower_case:
Fitxers renombrats:
- effects/gestor_puntuacio_flotant.{hpp,cpp} -> floating_score_manager.{hpp,cpp}
- effects/puntuacio_flotant.hpp -> floating_score.hpp
Tipus (CamelCase):
- GestorPuntuacioFlotant -> FloatingScoreManager
- PuntuacioFlotant -> FloatingScore
- ConfigStage -> StageConfig
- ConfigSistemaStages -> StageSystemConfig
- NauTitol -> TitleShip
- EstatNau -> ShipState
Metodes publics (camelBack):
- obte_renderer -> getRenderer
- get_num_actius -> getActiveCount
- calcular_direccio_explosio -> computeExplosionDirection
- trobar_slot_lliure -> findFreeSlot
- explotar -> explode
- reiniciar -> reset
- es_valida -> isValid
- parsejar_fitxer -> parseFile
- carregar -> load
- crear_explosio -> createExplosion
- registrar_puntuacio -> registerScore
- construir_marcador -> buildScoreboard
- render_centered -> renderCentered
Camps struct publics (snake_case):
- actiu/actius -> active
- rotacio -> rotation, rotacio_visual -> visual_rotation
- acceleracio -> acceleration
- velocitat -> velocity
- escala/escala_inicial/objectiu/actual -> scale/initial_scale/...
- posicio/posicio_inicial/objectiu/actual -> position/initial_position/...
- fase_oscilacio -> oscillation_phase
- temps_estat -> state_time
- jugador_id -> player_id
- estat -> state
- brillantor -> brightness
- tipus -> type
Camps privats (sufix _):
- naus_ -> ships_, orni_ -> enemies_, bales_ -> bullets_
- gestor_puntuacio_ -> floating_score_manager_
- punt_mort_ -> death_position_, punt_spawn_ -> spawn_position_
- itocado_per_jugador_ -> hit_timer_per_player_
- vides_per_jugador_ -> lives_per_player_
- puntuacio_per_jugador_ -> score_per_player_
- estat_game_over_ -> game_over_state_
- continues_usados_ -> continues_used_
Constants:
- MARGE_ESQ/DRET/DALT/BAIX -> MARGIN_LEFT/RIGHT/TOP/BOTTOM
Variables locals i parametres comuns (snake_case):
- nau -> ship, enemic -> enemy, bala -> bullet
- forma -> shape, punt(s) -> point(s)
- jugador -> player, partida -> match
- temps -> time, missatge -> message
Diff: 59 fitxers, +1000/-1000 (simetric). Compila i enllaça.
Pendents per a futures fases (no bloquejants):
- Comentaris de capçalera en catala -> castella
- Variables locals/parametres minoritaris en catala
- Include guards (queden alguns #ifndef en lloc de #pragma once)
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 amb caché
|
|
// © 2025 Port a C++20 amb SDL3
|
|
|
|
#include "core/graphics/shape_loader.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include "core/resources/resource_helper.hpp"
|
|
|
|
namespace Graphics {
|
|
|
|
// Inicialització 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 és un path absolut (comença amb '/'), usar-lo directament
|
|
if (!filename.empty() && filename[0] == '/') {
|
|
return filename;
|
|
}
|
|
|
|
// Si ja conté el prefix base_path, usar-lo directament
|
|
if (filename.starts_with(base_path_)) {
|
|
return filename;
|
|
}
|
|
|
|
// Altrament, afegir base_path (ara suporta subdirectoris)
|
|
return base_path_ + filename;
|
|
}
|
|
|
|
} // namespace Graphics
|