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

@@ -21,7 +21,7 @@ bool Shape::carregar(const std::string& filepath) {
// Llegir fitxer
std::ifstream file(filepath);
if (!file.is_open()) {
std::cerr << "[Shape] Error: no es pot obrir " << filepath << std::endl;
std::cerr << "[Shape] Error: no es pot obrir " << filepath << '\n';
return false;
}
@@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
try {
escala_defecte_ = std::stof(extract_value(line));
} catch (...) {
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << std::endl;
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << '\n';
escala_defecte_ = 1.0F;
}
} else if (starts_with(line, "center:")) {
@@ -66,7 +66,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
primitives_.push_back({PrimitiveType::POLYLINE, points});
} else {
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
<< std::endl;
<< '\n';
}
} else if (starts_with(line, "line:")) {
auto points = parse_points(extract_value(line));
@@ -74,14 +74,14 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
primitives_.push_back({PrimitiveType::LINE, points});
} else {
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
<< std::endl;
<< '\n';
}
}
// Comandes desconegudes ignorades silenciosament
}
if (primitives_.empty()) {
std::cerr << "[Shape] Error: cap primitiva carregada" << std::endl;
std::cerr << "[Shape] Error: cap primitiva carregada" << '\n';
return false;
}
@@ -127,7 +127,7 @@ void Shape::parse_center(const std::string& value) {
centre_.x = std::stof(trim(val.substr(0, comma)));
centre_.y = std::stof(trim(val.substr(comma + 1)));
} catch (...) {
std::cerr << "[Shape] Warning: centre invàlid, usant (0,0)" << std::endl;
std::cerr << "[Shape] Warning: centre invàlid, usant (0,0)" << '\n';
centre_ = {.x = 0.0F, .y = 0.0F};
}
}
@@ -148,7 +148,7 @@ std::vector<Punt> Shape::parse_points(const std::string& str) const {
points.push_back({x, y});
} catch (...) {
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
<< std::endl;
<< '\n';
}
}
}

View File

@@ -17,7 +17,7 @@ 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 << std::endl;
std::cout << "[ShapeLoader] Cache hit: " << filename << '\n';
return it->second; // Cache hit
}
@@ -33,7 +33,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
if (data.empty()) {
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
<< std::endl;
<< '\n';
return nullptr;
}
@@ -42,19 +42,19 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
auto shape = std::make_shared<Shape>();
if (!shape->parsejar_fitxer(file_content)) {
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
<< std::endl;
<< '\n';
return nullptr;
}
// Verify shape is valid
if (!shape->es_valida()) {
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << std::endl;
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << '\n';
return nullptr;
}
// Cache and return
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
<< ", " << shape->get_num_primitives() << " primitives)" << std::endl;
<< ", " << shape->get_num_primitives() << " primitives)" << '\n';
cache_[filename] = shape;
return shape;
@@ -62,7 +62,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
void ShapeLoader::clear_cache() {
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
<< std::endl;
<< '\n';
cache_.clear();
}

View File

@@ -26,7 +26,7 @@ Starfield::Starfield(SDL_Renderer* renderer,
shape_estrella_ = ShapeLoader::load("star.shp");
if (!shape_estrella_ || !shape_estrella_->es_valida()) {
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << std::endl;
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << '\n';
return;
}

View File

@@ -29,7 +29,7 @@ void VectorText::load_charset() {
chars_[c] = shape;
} else {
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
<< std::endl;
<< '\n';
}
}
@@ -42,7 +42,7 @@ void VectorText::load_charset() {
chars_[c] = shape;
} else {
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
<< std::endl;
<< '\n';
}
}
@@ -57,7 +57,7 @@ void VectorText::load_charset() {
chars_[c] = shape;
} else {
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
<< std::endl;
<< '\n';
}
}
@@ -72,12 +72,12 @@ void VectorText::load_charset() {
chars_[c] = shape;
} else {
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
<< std::endl;
<< '\n';
}
}
std::cout << "[VectorText] Carregats " << chars_.size() << " caràcters"
<< std::endl;
<< '\n';
}
std::string VectorText::get_shape_filename(char c) const {
@@ -230,7 +230,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
} else {
// Carácter no soportado: saltar (o renderizar '?' en el futuro)
std::cerr << "[VectorText] Warning: caràcter no suportat '" << c << "'"
<< std::endl;
<< '\n';
current_x += char_width_scaled + spacing_scaled;
}
}

View File

@@ -19,12 +19,12 @@ constexpr Uint32 IGNORE_MOTION_DURATION = 1000; // Ignorar primers 1000ms
void forceHide() {
// Forçar ocultació sincronitzant estat SDL i estat intern
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible
<< " -> false" << std::endl;
<< " -> false" << '\n';
SDL_HideCursor();
cursor_visible = false;
last_mouse_move_time = 0;
initialization_time = SDL_GetTicks(); // Marcar temps per ignorar esdeveniments inicials
std::cout << "[Mouse::forceHide] Ignorant moviments durant " << IGNORE_MOTION_DURATION << "ms" << std::endl;
std::cout << "[Mouse::forceHide] Ignorant moviments durant " << IGNORE_MOTION_DURATION << "ms" << '\n';
}
void setForceHidden(bool force) {
@@ -59,13 +59,13 @@ void handleEvent(const SDL_Event& event) {
// Ignorar esdeveniments fantasma de SDL durant el període inicial
if (initialization_time > 0 && (current_time - initialization_time < IGNORE_MOTION_DURATION)) {
std::cout << "[Mouse::handleEvent] Ignorant moviment fantasma de SDL. time=" << current_time
<< " (inicialització fa " << (current_time - initialization_time) << "ms)" << std::endl;
<< " (inicialització fa " << (current_time - initialization_time) << "ms)" << '\n';
return;
}
last_mouse_move_time = current_time;
if (!cursor_visible) {
std::cout << "[Mouse::handleEvent] Mostrant cursor per moviment REAL. time=" << last_mouse_move_time << std::endl;
std::cout << "[Mouse::handleEvent] Mostrant cursor per moviment REAL. time=" << last_mouse_move_time << '\n';
SDL_ShowCursor();
cursor_visible = true;
}
@@ -82,7 +82,7 @@ void updateCursorVisibility() {
Uint32 current_time = SDL_GetTicks();
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time)) {
std::cout << "[Mouse::updateCursorVisibility] Ocultant cursor per timeout. current=" << current_time
<< " last=" << last_mouse_move_time << " diff=" << (current_time - last_mouse_move_time) << std::endl;
<< " last=" << last_mouse_move_time << " diff=" << (current_time - last_mouse_move_time) << '\n';
SDL_HideCursor();
cursor_visible = false;
}

View File

@@ -31,7 +31,7 @@ SDLManager::SDLManager()
max_zoom_(1.0F) {
// Inicialitzar SDL3
if (!SDL_Init(SDL_INIT_VIDEO)) {
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << std::endl;
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << '\n';
return;
}
@@ -48,7 +48,7 @@ SDLManager::SDLManager()
);
if (finestra_ == nullptr) {
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
std::cerr << "Error creant finestra: " << SDL_GetError() << '\n';
SDL_Quit();
return;
}
@@ -60,7 +60,7 @@ SDLManager::SDLManager()
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
if (renderer_ == nullptr) {
std::cerr << "Error creant renderer: " << SDL_GetError() << std::endl;
std::cerr << "Error creant renderer: " << SDL_GetError() << '\n';
SDL_DestroyWindow(finestra_);
SDL_Quit();
return;
@@ -74,7 +74,7 @@ SDLManager::SDLManager()
std::cout << "SDL3 inicialitzat: " << current_width_ << "x" << current_height_
<< " (logic: " << Defaults::Game::WIDTH << "x"
<< Defaults::Game::HEIGHT << ")" << std::endl;
<< Defaults::Game::HEIGHT << ")" << '\n';
}
// Constructor amb configuració
@@ -95,7 +95,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
max_zoom_(1.0F) {
// Inicialitzar SDL3
if (!SDL_Init(SDL_INIT_VIDEO)) {
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << std::endl;
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << '\n';
return;
}
@@ -115,7 +115,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
finestra_ = SDL_CreateWindow(window_title.c_str(), current_width_, current_height_, flags);
if (finestra_ == nullptr) {
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
std::cerr << "Error creant finestra: " << SDL_GetError() << '\n';
SDL_Quit();
return;
}
@@ -129,7 +129,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
if (renderer_ == nullptr) {
std::cerr << "Error creant renderer: " << SDL_GetError() << std::endl;
std::cerr << "Error creant renderer: " << SDL_GetError() << '\n';
SDL_DestroyWindow(finestra_);
SDL_Quit();
return;
@@ -153,7 +153,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
if (is_fullscreen_) {
std::cout << " [FULLSCREEN]";
}
std::cout << std::endl;
std::cout << '\n';
}
SDLManager::~SDLManager() {
@@ -168,7 +168,7 @@ SDLManager::~SDLManager() {
}
SDL_Quit();
std::cout << "SDL3 netejat correctament" << std::endl;
std::cout << "SDL3 netejat correctament" << '\n';
}
void SDLManager::calculateMaxWindowSize() {
@@ -181,13 +181,13 @@ void SDLManager::calculateMaxWindowSize() {
max_height_ = mode->h - 100;
std::cout << "Display detectat: " << mode->w << "x" << mode->h
<< " (max finestra: " << max_width_ << "x" << max_height_ << ")"
<< std::endl;
<< '\n';
} else {
// Fallback conservador
max_width_ = 1920;
max_height_ = 1080;
std::cerr << "No s'ha pogut detectar el display, usant fallback: "
<< max_width_ << "x" << max_height_ << std::endl;
<< max_width_ << "x" << max_height_ << '\n';
}
// Calculate max zoom immediately after determining max size
@@ -209,7 +209,7 @@ void SDLManager::calculateMaxZoom() {
max_zoom_ = std::max(max_zoom_, Defaults::Window::MIN_ZOOM);
std::cout << "Max zoom: " << max_zoom_ << "x (display: "
<< max_width_ << "x" << max_height_ << ")" << std::endl;
<< max_width_ << "x" << max_height_ << ")" << '\n';
}
void SDLManager::applyZoom(float new_zoom) {
@@ -249,7 +249,7 @@ void SDLManager::applyZoom(float new_zoom) {
Options::window.zoom_factor = zoom_factor_;
std::cout << "Zoom: " << zoom_factor_ << "x ("
<< new_width << "x" << new_height << ")" << std::endl;
<< new_width << "x" << new_height << ")" << '\n';
}
void SDLManager::updateLogicalPresentation() {
@@ -279,7 +279,7 @@ void SDLManager::updateViewport() {
std::cout << "Viewport: " << scaled_width << "x" << scaled_height
<< " @ (" << offset_x << "," << offset_y << ") [scale=" << scale << "]"
<< std::endl;
<< '\n';
}
void SDLManager::updateRenderingContext() const {
@@ -295,7 +295,7 @@ void SDLManager::increaseWindowSize() {
float new_zoom = zoom_factor_ + Defaults::Window::ZOOM_INCREMENT;
applyZoom(new_zoom);
std::cout << "F2: Zoom aumentat a " << zoom_factor_ << "x" << std::endl;
std::cout << "F2: Zoom aumentat a " << zoom_factor_ << "x" << '\n';
}
void SDLManager::decreaseWindowSize() {
@@ -306,7 +306,7 @@ void SDLManager::decreaseWindowSize() {
float new_zoom = zoom_factor_ - Defaults::Window::ZOOM_INCREMENT;
applyZoom(new_zoom);
std::cout << "F1: Zoom reduït a " << zoom_factor_ << "x" << std::endl;
std::cout << "F1: Zoom reduït a " << zoom_factor_ << "x" << '\n';
}
void SDLManager::applyWindowSize(int new_width, int new_height) {
@@ -352,7 +352,7 @@ void SDLManager::toggleFullscreen() {
SDL_SetWindowFullscreen(finestra_, true);
std::cout << "F3: Fullscreen activat (guardada: "
<< windowed_width_ << "x" << windowed_height_ << ")" << std::endl;
<< windowed_width_ << "x" << windowed_height_ << ")" << '\n';
} else {
// EXITING FULLSCREEN
is_fullscreen_ = false;
@@ -362,7 +362,7 @@ void SDLManager::toggleFullscreen() {
applyWindowSize(windowed_width_, windowed_height_);
std::cout << "F3: Fullscreen desactivat (restaurada: "
<< windowed_width_ << "x" << windowed_height_ << ")" << std::endl;
<< windowed_width_ << "x" << windowed_height_ << ")" << '\n';
}
Options::window.fullscreen = is_fullscreen_;
@@ -392,7 +392,7 @@ bool SDLManager::handleWindowEvent(const SDL_Event& event) {
std::cout << "Finestra redimensionada: " << current_width_
<< "x" << current_height_ << " (zoom ≈" << zoom_factor_ << "x)"
<< std::endl;
<< '\n';
return true;
}
return false;

View File

@@ -20,7 +20,7 @@ bool handle(const SDL_Event& event, SDLManager& sdl, ContextEscenes& context) {
// 1. Permitir que Input procese el evento (para hotplug de gamepads)
auto event_msg = Input::get()->handleEvent(event);
if (!event_msg.empty()) {
std::cout << "[Input] " << event_msg << std::endl;
std::cout << "[Input] " << event_msg << '\n';
}
// 2. Procesar SDL_EVENT_QUIT directamente (no es input de juego)