perf: aplicar checks performance-* (91 fixes)

Cambios aplicados:
- Reemplazar std::endl con '\n' (91 casos)
  * std::endl hace flush del buffer (más lento)
  * '\n' solo inserta newline (más rápido)
  * Mejora rendimiento de logging/debug

Check excluido:
- performance-enum-size: Tamaño de enum no es crítico para rendimiento
This commit is contained in:
2025-12-18 21:24:07 +01:00
parent 7f6af6dd00
commit 364cf36183
17 changed files with 94 additions and 92 deletions

View File

@@ -26,7 +26,7 @@ Bala::Bala(SDL_Renderer* renderer)
forma_ = Graphics::ShapeLoader::load("bullet.shp");
if (!forma_ || !forma_->es_valida()) {
std::cerr << "[Bala] Error: no s'ha pogut carregar bullet.shp" << std::endl;
std::cerr << "[Bala] Error: no s'ha pogut carregar bullet.shp" << '\n';
}
}

View File

@@ -68,7 +68,7 @@ void Enemic::inicialitzar(TipusEnemic tipus, const Punt* ship_pos) {
// Carregar forma
forma_ = Graphics::ShapeLoader::load(shape_file);
if (!forma_ || !forma_->es_valida()) {
std::cerr << "[Enemic] Error: no s'ha pogut carregar " << shape_file << std::endl;
std::cerr << "[Enemic] Error: no s'ha pogut carregar " << shape_file << '\n';
}
// [MODIFIED] Posició aleatòria amb comprovació de seguretat
@@ -106,7 +106,7 @@ void Enemic::inicialitzar(TipusEnemic tipus, const Punt* ship_pos) {
centre_.y = static_cast<float>((std::rand() % range_y) + static_cast<int>(min_y));
std::cout << "[Enemic] Advertència: spawn sense zona segura després de "
<< Defaults::Enemies::Spawn::MAX_SPAWN_ATTEMPTS << " intents" << std::endl;
<< Defaults::Enemies::Spawn::MAX_SPAWN_ATTEMPTS << " intents" << '\n';
}
} else {
// [EXISTING] No ship position: spawn anywhere (backward compatibility)

View File

@@ -28,7 +28,7 @@ Nau::Nau(SDL_Renderer* renderer, const char* shape_file)
forma_ = Graphics::ShapeLoader::load(shape_file);
if (!forma_ || !forma_->es_valida()) {
std::cerr << "[Nau] Error: no s'ha pogut carregar " << shape_file << std::endl;
std::cerr << "[Nau] Error: no s'ha pogut carregar " << shape_file << '\n';
}
}

View File

@@ -40,7 +40,7 @@ EscenaJoc::EscenaJoc(SDLManager& sdl, ContextEscenes& context)
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
<< ", P2: "
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
<< std::endl;
<< '\n';
// Consumir opcions (preparació per MODE_DEMO futur)
auto opcio = context_.consumir_opcio();
@@ -133,7 +133,7 @@ void EscenaJoc::inicialitzar() {
if (!stage_config_) {
stage_config_ = StageSystem::StageLoader::carregar("data/stages/stages.yaml");
if (!stage_config_) {
std::cerr << "[EscenaJoc] Error: no s'ha pogut carregar stages.yaml" << std::endl;
std::cerr << "[EscenaJoc] Error: no s'ha pogut carregar stages.yaml" << '\n';
// Continue without stage system (will crash, but helps debugging)
}
}
@@ -414,7 +414,7 @@ void EscenaJoc::actualitzar(float delta_time) {
// [DEBUG] Log entrada a LEVEL_START
static bool first_entry = true;
if (first_entry) {
std::cout << "[LEVEL_START] ENTERED with P1 pos.y=" << naus_[0].get_centre().y << std::endl;
std::cout << "[LEVEL_START] ENTERED with P1 pos.y=" << naus_[0].get_centre().y << '\n';
first_entry = false;
}
@@ -1442,5 +1442,5 @@ void EscenaJoc::unir_jugador(uint8_t player_id) {
// No visual message, just spawn (per user requirement)
std::cout << "[EscenaJoc] Jugador " << (int)(player_id + 1) << " s'ha unit a la partida!" << std::endl;
std::cout << "[EscenaJoc] Jugador " << (int)(player_id + 1) << " s'ha unit a la partida!" << '\n';
}

View File

@@ -144,7 +144,7 @@ void EscenaLogo::inicialitzar_lletres() {
for (const auto& fitxer : fitxers) {
auto forma = ShapeLoader::load(fitxer);
if (!forma || !forma->es_valida()) {
std::cerr << "[EscenaLogo] Error carregant " << fitxer << std::endl;
std::cerr << "[EscenaLogo] Error carregant " << fitxer << '\n';
continue;
}

View File

@@ -120,7 +120,7 @@ void EscenaTitol::inicialitzar_titol() {
for (const auto& fitxer : fitxers_orni) {
auto forma = ShapeLoader::load(fitxer);
if (!forma || !forma->es_valida()) {
std::cerr << "[EscenaTitol] Error carregant " << fitxer << std::endl;
std::cerr << "[EscenaTitol] Error carregant " << fitxer << '\n';
continue;
}
@@ -194,7 +194,7 @@ void EscenaTitol::inicialitzar_titol() {
for (const auto& fitxer : fitxers_attack) {
auto forma = ShapeLoader::load(fitxer);
if (!forma || !forma->es_valida()) {
std::cerr << "[EscenaTitol] Error carregant " << fitxer << std::endl;
std::cerr << "[EscenaTitol] Error carregant " << fitxer << '\n';
continue;
}
@@ -487,7 +487,7 @@ void EscenaTitol::actualitzar(float delta_time) {
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
<< ", P2: "
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
<< std::endl;
<< '\n';
context_.canviar_escena(Escena::JOC);
estat_actual_ = EstatTitol::PLAYER_JOIN_PHASE;

View File

@@ -21,7 +21,7 @@ void SpawnController::configurar(const ConfigStage* config) {
void SpawnController::iniciar() {
if (config_ == nullptr) {
std::cerr << "[SpawnController] Error: config_ és null" << std::endl;
std::cerr << "[SpawnController] Error: config_ és null" << '\n';
return;
}
@@ -29,7 +29,7 @@ void SpawnController::iniciar() {
generar_spawn_events();
std::cout << "[SpawnController] Stage " << static_cast<int>(config_->stage_id)
<< ": generats " << spawn_queue_.size() << " spawn events" << std::endl;
<< ": generats " << spawn_queue_.size() << " spawn events" << '\n';
}
void SpawnController::reset() {

View File

@@ -23,7 +23,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
// Load from resource system
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
if (data.empty()) {
std::cerr << "[StageLoader] Error: no es pot carregar " << normalized << std::endl;
std::cerr << "[StageLoader] Error: no es pot carregar " << normalized << '\n';
return nullptr;
}
@@ -37,7 +37,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
// Parse metadata
if (!yaml.contains("metadata")) {
std::cerr << "[StageLoader] Error: falta camp 'metadata'" << std::endl;
std::cerr << "[StageLoader] Error: falta camp 'metadata'" << '\n';
return nullptr;
}
if (!parse_metadata(yaml["metadata"], config->metadata)) {
@@ -46,12 +46,12 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
// Parse stages
if (!yaml.contains("stages")) {
std::cerr << "[StageLoader] Error: falta camp 'stages'" << std::endl;
std::cerr << "[StageLoader] Error: falta camp 'stages'" << '\n';
return nullptr;
}
if (!yaml["stages"].is_sequence()) {
std::cerr << "[StageLoader] Error: 'stages' ha de ser una llista" << std::endl;
std::cerr << "[StageLoader] Error: 'stages' ha de ser una llista" << '\n';
return nullptr;
}
@@ -69,11 +69,11 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
}
std::cout << "[StageLoader] Carregats " << config->stages.size()
<< " stages correctament" << std::endl;
<< " stages correctament" << '\n';
return config;
} catch (const std::exception& e) {
std::cerr << "[StageLoader] Excepció: " << e.what() << std::endl;
std::cerr << "[StageLoader] Excepció: " << e.what() << '\n';
return nullptr;
}
}
@@ -81,7 +81,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta) {
try {
if (!yaml.contains("version") || !yaml.contains("total_stages")) {
std::cerr << "[StageLoader] Error: metadata incompleta" << std::endl;
std::cerr << "[StageLoader] Error: metadata incompleta" << '\n';
return false;
}
@@ -93,7 +93,7 @@ bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta)
return true;
} catch (const std::exception& e) {
std::cerr << "[StageLoader] Error parsing metadata: " << e.what() << std::endl;
std::cerr << "[StageLoader] Error parsing metadata: " << e.what() << '\n';
return false;
}
}
@@ -103,7 +103,7 @@ bool StageLoader::parse_stage(const fkyaml::node& yaml, ConfigStage& stage) {
if (!yaml.contains("stage_id") || !yaml.contains("total_enemies") ||
!yaml.contains("spawn_config") || !yaml.contains("enemy_distribution") ||
!yaml.contains("difficulty_multipliers")) {
std::cerr << "[StageLoader] Error: stage incompleta" << std::endl;
std::cerr << "[StageLoader] Error: stage incompleta" << '\n';
return false;
}
@@ -122,13 +122,13 @@ bool StageLoader::parse_stage(const fkyaml::node& yaml, ConfigStage& stage) {
if (!stage.es_valid()) {
std::cerr << "[StageLoader] Error: stage " << static_cast<int>(stage.stage_id)
<< " no és vàlid" << std::endl;
<< " no és vàlid" << '\n';
return false;
}
return true;
} catch (const std::exception& e) {
std::cerr << "[StageLoader] Error parsing stage: " << e.what() << std::endl;
std::cerr << "[StageLoader] Error parsing stage: " << e.what() << '\n';
return false;
}
}
@@ -137,7 +137,7 @@ bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& conf
try {
if (!yaml.contains("mode") || !yaml.contains("initial_delay") ||
!yaml.contains("spawn_interval")) {
std::cerr << "[StageLoader] Error: spawn_config incompleta" << std::endl;
std::cerr << "[StageLoader] Error: spawn_config incompleta" << '\n';
return false;
}
@@ -148,7 +148,7 @@ bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& conf
return true;
} catch (const std::exception& e) {
std::cerr << "[StageLoader] Error parsing spawn_config: " << e.what() << std::endl;
std::cerr << "[StageLoader] Error parsing spawn_config: " << e.what() << '\n';
return false;
}
}
@@ -157,7 +157,7 @@ bool StageLoader::parse_distribution(const fkyaml::node& yaml, DistribucioEnemic
try {
if (!yaml.contains("pentagon") || !yaml.contains("quadrat") ||
!yaml.contains("molinillo")) {
std::cerr << "[StageLoader] Error: enemy_distribution incompleta" << std::endl;
std::cerr << "[StageLoader] Error: enemy_distribution incompleta" << '\n';
return false;
}
@@ -168,13 +168,13 @@ bool StageLoader::parse_distribution(const fkyaml::node& yaml, DistribucioEnemic
// Validar que suma 100
int sum = dist.pentagon + dist.quadrat + dist.molinillo;
if (sum != 100) {
std::cerr << "[StageLoader] Error: distribució no suma 100 (suma=" << sum << ")" << std::endl;
std::cerr << "[StageLoader] Error: distribució no suma 100 (suma=" << sum << ")" << '\n';
return false;
}
return true;
} catch (const std::exception& e) {
std::cerr << "[StageLoader] Error parsing distribution: " << e.what() << std::endl;
std::cerr << "[StageLoader] Error parsing distribution: " << e.what() << '\n';
return false;
}
}
@@ -183,7 +183,7 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi
try {
if (!yaml.contains("speed_multiplier") || !yaml.contains("rotation_multiplier") ||
!yaml.contains("tracking_strength")) {
std::cerr << "[StageLoader] Error: difficulty_multipliers incompleta" << std::endl;
std::cerr << "[StageLoader] Error: difficulty_multipliers incompleta" << '\n';
return false;
}
@@ -193,18 +193,18 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi
// Validar rangs raonables
if (mult.velocitat < 0.1F || mult.velocitat > 5.0F) {
std::cerr << "[StageLoader] Warning: speed_multiplier fora de rang (0.1-5.0)" << std::endl;
std::cerr << "[StageLoader] Warning: speed_multiplier fora de rang (0.1-5.0)" << '\n';
}
if (mult.rotacio < 0.1F || mult.rotacio > 5.0F) {
std::cerr << "[StageLoader] Warning: rotation_multiplier fora de rang (0.1-5.0)" << std::endl;
std::cerr << "[StageLoader] Warning: rotation_multiplier fora de rang (0.1-5.0)" << '\n';
}
if (mult.tracking_strength < 0.0F || mult.tracking_strength > 2.0F) {
std::cerr << "[StageLoader] Warning: tracking_strength fora de rang (0.0-2.0)" << std::endl;
std::cerr << "[StageLoader] Warning: tracking_strength fora de rang (0.0-2.0)" << '\n';
}
return true;
} catch (const std::exception& e) {
std::cerr << "[StageLoader] Error parsing multipliers: " << e.what() << std::endl;
std::cerr << "[StageLoader] Error parsing multipliers: " << e.what() << '\n';
return false;
}
}
@@ -220,20 +220,20 @@ ModeSpawn StageLoader::parse_spawn_mode(const std::string& mode_str) {
return ModeSpawn::WAVE;
}
std::cerr << "[StageLoader] Warning: mode de spawn desconegut '" << mode_str
<< "', usant PROGRESSIVE" << std::endl;
<< "', usant PROGRESSIVE" << '\n';
return ModeSpawn::PROGRESSIVE;
}
bool StageLoader::validar_config(const ConfigSistemaStages& config) {
if (config.stages.empty()) {
std::cerr << "[StageLoader] Error: cap stage carregat" << std::endl;
std::cerr << "[StageLoader] Error: cap stage carregat" << '\n';
return false;
}
if (config.stages.size() != config.metadata.total_stages) {
std::cerr << "[StageLoader] Warning: nombre de stages (" << config.stages.size()
<< ") no coincideix amb metadata.total_stages ("
<< static_cast<int>(config.metadata.total_stages) << ")" << std::endl;
<< static_cast<int>(config.metadata.total_stages) << ")" << '\n';
}
// Validar stage_id consecutius
@@ -241,7 +241,7 @@ bool StageLoader::validar_config(const ConfigSistemaStages& config) {
if (config.stages[i].stage_id != i + 1) {
std::cerr << "[StageLoader] Error: stage_id no consecutius (esperat "
<< i + 1 << ", trobat " << static_cast<int>(config.stages[i].stage_id)
<< ")" << std::endl;
<< ")" << '\n';
return false;
}
}

View File

@@ -16,7 +16,7 @@ StageManager::StageManager(const ConfigSistemaStages* config)
stage_actual_(1),
timer_transicio_(0.0F) {
if (config_ == nullptr) {
std::cerr << "[StageManager] Error: config és null" << std::endl;
std::cerr << "[StageManager] Error: config és null" << '\n';
}
}
@@ -26,7 +26,7 @@ void StageManager::inicialitzar() {
canviar_estat(EstatStage::INIT_HUD);
std::cout << "[StageManager] Inicialitzat a stage " << static_cast<int>(stage_actual_)
<< std::endl;
<< '\n';
}
void StageManager::actualitzar(float delta_time, bool pausar_spawn) {
@@ -51,7 +51,7 @@ void StageManager::actualitzar(float delta_time, bool pausar_spawn) {
void StageManager::stage_completat() {
std::cout << "[StageManager] Stage " << static_cast<int>(stage_actual_) << " completat!"
<< std::endl;
<< '\n';
canviar_estat(EstatStage::LEVEL_COMPLETED);
}
@@ -104,7 +104,7 @@ void StageManager::canviar_estat(EstatStage nou_estat) {
std::cout << "LEVEL_COMPLETED";
break;
}
std::cout << std::endl;
std::cout << '\n';
}
void StageManager::processar_init_hud(float delta_time) {
@@ -142,7 +142,7 @@ void StageManager::processar_level_completed(float delta_time) {
if (stage_actual_ > config_->metadata.total_stages) {
stage_actual_ = 1;
std::cout << "[StageManager] Totes les stages completades! Tornant a stage 1"
<< std::endl;
<< '\n';
}
// Load next stage
@@ -155,7 +155,7 @@ void StageManager::carregar_stage(uint8_t stage_id) {
const ConfigStage* stage_config = config_->obte_stage(stage_id);
if (stage_config == nullptr) {
std::cerr << "[StageManager] Error: no es pot trobar stage " << static_cast<int>(stage_id)
<< std::endl;
<< '\n';
return;
}
@@ -164,7 +164,7 @@ void StageManager::carregar_stage(uint8_t stage_id) {
spawn_controller_.iniciar();
std::cout << "[StageManager] Carregat stage " << static_cast<int>(stage_id) << ": "
<< static_cast<int>(stage_config->total_enemics) << " enemics" << std::endl;
<< static_cast<int>(stage_config->total_enemics) << " enemics" << '\n';
}
} // namespace StageSystem