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:
@@ -19,7 +19,9 @@ Checks:
|
|||||||
- modernize-*
|
- modernize-*
|
||||||
- -modernize-use-trailing-return-type # Excluido (estilo controversial)
|
- -modernize-use-trailing-return-type # Excluido (estilo controversial)
|
||||||
- -modernize-avoid-c-arrays # Excluido (arrays C son OK en algunos contextos)
|
- -modernize-avoid-c-arrays # Excluido (arrays C son OK en algunos contextos)
|
||||||
# - performance-*
|
# ✅ Check 9: performance-* (91 fixes aplicados)
|
||||||
|
- performance-*
|
||||||
|
- -performance-enum-size # Excluido (tamaño de enum no crítico)
|
||||||
# - bugprone-unchecked-optional-access
|
# - bugprone-unchecked-optional-access
|
||||||
# - bugprone-sizeof-expression
|
# - bugprone-sizeof-expression
|
||||||
# - bugprone-suspicious-missing-comma
|
# - bugprone-suspicious-missing-comma
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ bool Shape::carregar(const std::string& filepath) {
|
|||||||
// Llegir fitxer
|
// Llegir fitxer
|
||||||
std::ifstream file(filepath);
|
std::ifstream file(filepath);
|
||||||
if (!file.is_open()) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
|||||||
try {
|
try {
|
||||||
escala_defecte_ = std::stof(extract_value(line));
|
escala_defecte_ = std::stof(extract_value(line));
|
||||||
} catch (...) {
|
} 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;
|
escala_defecte_ = 1.0F;
|
||||||
}
|
}
|
||||||
} else if (starts_with(line, "center:")) {
|
} else if (starts_with(line, "center:")) {
|
||||||
@@ -66,7 +66,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
|||||||
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
|
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
} else if (starts_with(line, "line:")) {
|
} else if (starts_with(line, "line:")) {
|
||||||
auto points = parse_points(extract_value(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});
|
primitives_.push_back({PrimitiveType::LINE, points});
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
|
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Comandes desconegudes ignorades silenciosament
|
// Comandes desconegudes ignorades silenciosament
|
||||||
}
|
}
|
||||||
|
|
||||||
if (primitives_.empty()) {
|
if (primitives_.empty()) {
|
||||||
std::cerr << "[Shape] Error: cap primitiva carregada" << std::endl;
|
std::cerr << "[Shape] Error: cap primitiva carregada" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ void Shape::parse_center(const std::string& value) {
|
|||||||
centre_.x = std::stof(trim(val.substr(0, comma)));
|
centre_.x = std::stof(trim(val.substr(0, comma)));
|
||||||
centre_.y = std::stof(trim(val.substr(comma + 1)));
|
centre_.y = std::stof(trim(val.substr(comma + 1)));
|
||||||
} catch (...) {
|
} 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};
|
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});
|
points.push_back({x, y});
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
|
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
|||||||
// Check cache first
|
// Check cache first
|
||||||
auto it = cache_.find(filename);
|
auto it = cache_.find(filename);
|
||||||
if (it != cache_.end()) {
|
if (it != cache_.end()) {
|
||||||
std::cout << "[ShapeLoader] Cache hit: " << filename << std::endl;
|
std::cout << "[ShapeLoader] Cache hit: " << filename << '\n';
|
||||||
return it->second; // Cache hit
|
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);
|
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
|
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,19 +42,19 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
|||||||
auto shape = std::make_shared<Shape>();
|
auto shape = std::make_shared<Shape>();
|
||||||
if (!shape->parsejar_fitxer(file_content)) {
|
if (!shape->parsejar_fitxer(file_content)) {
|
||||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify shape is valid
|
// Verify shape is valid
|
||||||
if (!shape->es_valida()) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache and return
|
// Cache and return
|
||||||
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
|
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
|
||||||
<< ", " << shape->get_num_primitives() << " primitives)" << std::endl;
|
<< ", " << shape->get_num_primitives() << " primitives)" << '\n';
|
||||||
|
|
||||||
cache_[filename] = shape;
|
cache_[filename] = shape;
|
||||||
return shape;
|
return shape;
|
||||||
@@ -62,7 +62,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
|||||||
|
|
||||||
void ShapeLoader::clear_cache() {
|
void ShapeLoader::clear_cache() {
|
||||||
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
|
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
cache_.clear();
|
cache_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
|||||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||||
|
|
||||||
if (!shape_estrella_ || !shape_estrella_->es_valida()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void VectorText::load_charset() {
|
|||||||
chars_[c] = shape;
|
chars_[c] = shape;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ void VectorText::load_charset() {
|
|||||||
chars_[c] = shape;
|
chars_[c] = shape;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ void VectorText::load_charset() {
|
|||||||
chars_[c] = shape;
|
chars_[c] = shape;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,12 +72,12 @@ void VectorText::load_charset() {
|
|||||||
chars_[c] = shape;
|
chars_[c] = shape;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[VectorText] Carregats " << chars_.size() << " caràcters"
|
std::cout << "[VectorText] Carregats " << chars_.size() << " caràcters"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string VectorText::get_shape_filename(char c) const {
|
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 {
|
} else {
|
||||||
// Carácter no soportado: saltar (o renderizar '?' en el futuro)
|
// Carácter no soportado: saltar (o renderizar '?' en el futuro)
|
||||||
std::cerr << "[VectorText] Warning: caràcter no suportat '" << c << "'"
|
std::cerr << "[VectorText] Warning: caràcter no suportat '" << c << "'"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
current_x += char_width_scaled + spacing_scaled;
|
current_x += char_width_scaled + spacing_scaled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ constexpr Uint32 IGNORE_MOTION_DURATION = 1000; // Ignorar primers 1000ms
|
|||||||
void forceHide() {
|
void forceHide() {
|
||||||
// Forçar ocultació sincronitzant estat SDL i estat intern
|
// Forçar ocultació sincronitzant estat SDL i estat intern
|
||||||
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible
|
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible
|
||||||
<< " -> false" << std::endl;
|
<< " -> false" << '\n';
|
||||||
SDL_HideCursor();
|
SDL_HideCursor();
|
||||||
cursor_visible = false;
|
cursor_visible = false;
|
||||||
last_mouse_move_time = 0;
|
last_mouse_move_time = 0;
|
||||||
initialization_time = SDL_GetTicks(); // Marcar temps per ignorar esdeveniments inicials
|
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) {
|
void setForceHidden(bool force) {
|
||||||
@@ -59,13 +59,13 @@ void handleEvent(const SDL_Event& event) {
|
|||||||
// Ignorar esdeveniments fantasma de SDL durant el període inicial
|
// Ignorar esdeveniments fantasma de SDL durant el període inicial
|
||||||
if (initialization_time > 0 && (current_time - initialization_time < IGNORE_MOTION_DURATION)) {
|
if (initialization_time > 0 && (current_time - initialization_time < IGNORE_MOTION_DURATION)) {
|
||||||
std::cout << "[Mouse::handleEvent] Ignorant moviment fantasma de SDL. time=" << current_time
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_mouse_move_time = current_time;
|
last_mouse_move_time = current_time;
|
||||||
if (!cursor_visible) {
|
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();
|
SDL_ShowCursor();
|
||||||
cursor_visible = true;
|
cursor_visible = true;
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ void updateCursorVisibility() {
|
|||||||
Uint32 current_time = SDL_GetTicks();
|
Uint32 current_time = SDL_GetTicks();
|
||||||
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time)) {
|
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time)) {
|
||||||
std::cout << "[Mouse::updateCursorVisibility] Ocultant cursor per timeout. current=" << current_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();
|
SDL_HideCursor();
|
||||||
cursor_visible = false;
|
cursor_visible = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ SDLManager::SDLManager()
|
|||||||
max_zoom_(1.0F) {
|
max_zoom_(1.0F) {
|
||||||
// Inicialitzar SDL3
|
// Inicialitzar SDL3
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << std::endl;
|
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << '\n';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ SDLManager::SDLManager()
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (finestra_ == nullptr) {
|
if (finestra_ == nullptr) {
|
||||||
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
|
std::cerr << "Error creant finestra: " << SDL_GetError() << '\n';
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ SDLManager::SDLManager()
|
|||||||
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
|
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
|
||||||
|
|
||||||
if (renderer_ == 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_DestroyWindow(finestra_);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return;
|
return;
|
||||||
@@ -74,7 +74,7 @@ SDLManager::SDLManager()
|
|||||||
|
|
||||||
std::cout << "SDL3 inicialitzat: " << current_width_ << "x" << current_height_
|
std::cout << "SDL3 inicialitzat: " << current_width_ << "x" << current_height_
|
||||||
<< " (logic: " << Defaults::Game::WIDTH << "x"
|
<< " (logic: " << Defaults::Game::WIDTH << "x"
|
||||||
<< Defaults::Game::HEIGHT << ")" << std::endl;
|
<< Defaults::Game::HEIGHT << ")" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor amb configuració
|
// Constructor amb configuració
|
||||||
@@ -95,7 +95,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
|
|||||||
max_zoom_(1.0F) {
|
max_zoom_(1.0F) {
|
||||||
// Inicialitzar SDL3
|
// Inicialitzar SDL3
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << std::endl;
|
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << '\n';
|
||||||
return;
|
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);
|
finestra_ = SDL_CreateWindow(window_title.c_str(), current_width_, current_height_, flags);
|
||||||
|
|
||||||
if (finestra_ == nullptr) {
|
if (finestra_ == nullptr) {
|
||||||
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
|
std::cerr << "Error creant finestra: " << SDL_GetError() << '\n';
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
|
|||||||
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
|
renderer_ = SDL_CreateRenderer(finestra_, nullptr);
|
||||||
|
|
||||||
if (renderer_ == 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_DestroyWindow(finestra_);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return;
|
return;
|
||||||
@@ -153,7 +153,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
|
|||||||
if (is_fullscreen_) {
|
if (is_fullscreen_) {
|
||||||
std::cout << " [FULLSCREEN]";
|
std::cout << " [FULLSCREEN]";
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLManager::~SDLManager() {
|
SDLManager::~SDLManager() {
|
||||||
@@ -168,7 +168,7 @@ SDLManager::~SDLManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
std::cout << "SDL3 netejat correctament" << std::endl;
|
std::cout << "SDL3 netejat correctament" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::calculateMaxWindowSize() {
|
void SDLManager::calculateMaxWindowSize() {
|
||||||
@@ -181,13 +181,13 @@ void SDLManager::calculateMaxWindowSize() {
|
|||||||
max_height_ = mode->h - 100;
|
max_height_ = mode->h - 100;
|
||||||
std::cout << "Display detectat: " << mode->w << "x" << mode->h
|
std::cout << "Display detectat: " << mode->w << "x" << mode->h
|
||||||
<< " (max finestra: " << max_width_ << "x" << max_height_ << ")"
|
<< " (max finestra: " << max_width_ << "x" << max_height_ << ")"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
} else {
|
} else {
|
||||||
// Fallback conservador
|
// Fallback conservador
|
||||||
max_width_ = 1920;
|
max_width_ = 1920;
|
||||||
max_height_ = 1080;
|
max_height_ = 1080;
|
||||||
std::cerr << "No s'ha pogut detectar el display, usant fallback: "
|
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
|
// 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);
|
max_zoom_ = std::max(max_zoom_, Defaults::Window::MIN_ZOOM);
|
||||||
|
|
||||||
std::cout << "Max zoom: " << max_zoom_ << "x (display: "
|
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) {
|
void SDLManager::applyZoom(float new_zoom) {
|
||||||
@@ -249,7 +249,7 @@ void SDLManager::applyZoom(float new_zoom) {
|
|||||||
Options::window.zoom_factor = zoom_factor_;
|
Options::window.zoom_factor = zoom_factor_;
|
||||||
|
|
||||||
std::cout << "Zoom: " << zoom_factor_ << "x ("
|
std::cout << "Zoom: " << zoom_factor_ << "x ("
|
||||||
<< new_width << "x" << new_height << ")" << std::endl;
|
<< new_width << "x" << new_height << ")" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::updateLogicalPresentation() {
|
void SDLManager::updateLogicalPresentation() {
|
||||||
@@ -279,7 +279,7 @@ void SDLManager::updateViewport() {
|
|||||||
|
|
||||||
std::cout << "Viewport: " << scaled_width << "x" << scaled_height
|
std::cout << "Viewport: " << scaled_width << "x" << scaled_height
|
||||||
<< " @ (" << offset_x << "," << offset_y << ") [scale=" << scale << "]"
|
<< " @ (" << offset_x << "," << offset_y << ") [scale=" << scale << "]"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::updateRenderingContext() const {
|
void SDLManager::updateRenderingContext() const {
|
||||||
@@ -295,7 +295,7 @@ void SDLManager::increaseWindowSize() {
|
|||||||
float new_zoom = zoom_factor_ + Defaults::Window::ZOOM_INCREMENT;
|
float new_zoom = zoom_factor_ + Defaults::Window::ZOOM_INCREMENT;
|
||||||
applyZoom(new_zoom);
|
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() {
|
void SDLManager::decreaseWindowSize() {
|
||||||
@@ -306,7 +306,7 @@ void SDLManager::decreaseWindowSize() {
|
|||||||
float new_zoom = zoom_factor_ - Defaults::Window::ZOOM_INCREMENT;
|
float new_zoom = zoom_factor_ - Defaults::Window::ZOOM_INCREMENT;
|
||||||
applyZoom(new_zoom);
|
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) {
|
void SDLManager::applyWindowSize(int new_width, int new_height) {
|
||||||
@@ -352,7 +352,7 @@ void SDLManager::toggleFullscreen() {
|
|||||||
SDL_SetWindowFullscreen(finestra_, true);
|
SDL_SetWindowFullscreen(finestra_, true);
|
||||||
|
|
||||||
std::cout << "F3: Fullscreen activat (guardada: "
|
std::cout << "F3: Fullscreen activat (guardada: "
|
||||||
<< windowed_width_ << "x" << windowed_height_ << ")" << std::endl;
|
<< windowed_width_ << "x" << windowed_height_ << ")" << '\n';
|
||||||
} else {
|
} else {
|
||||||
// EXITING FULLSCREEN
|
// EXITING FULLSCREEN
|
||||||
is_fullscreen_ = false;
|
is_fullscreen_ = false;
|
||||||
@@ -362,7 +362,7 @@ void SDLManager::toggleFullscreen() {
|
|||||||
applyWindowSize(windowed_width_, windowed_height_);
|
applyWindowSize(windowed_width_, windowed_height_);
|
||||||
|
|
||||||
std::cout << "F3: Fullscreen desactivat (restaurada: "
|
std::cout << "F3: Fullscreen desactivat (restaurada: "
|
||||||
<< windowed_width_ << "x" << windowed_height_ << ")" << std::endl;
|
<< windowed_width_ << "x" << windowed_height_ << ")" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
Options::window.fullscreen = is_fullscreen_;
|
Options::window.fullscreen = is_fullscreen_;
|
||||||
@@ -392,7 +392,7 @@ bool SDLManager::handleWindowEvent(const SDL_Event& event) {
|
|||||||
|
|
||||||
std::cout << "Finestra redimensionada: " << current_width_
|
std::cout << "Finestra redimensionada: " << current_width_
|
||||||
<< "x" << current_height_ << " (zoom ≈" << zoom_factor_ << "x)"
|
<< "x" << current_height_ << " (zoom ≈" << zoom_factor_ << "x)"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -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)
|
// 1. Permitir que Input procese el evento (para hotplug de gamepads)
|
||||||
auto event_msg = Input::get()->handleEvent(event);
|
auto event_msg = Input::get()->handleEvent(event);
|
||||||
if (!event_msg.empty()) {
|
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)
|
// 2. Procesar SDL_EVENT_QUIT directamente (no es input de juego)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Bala::Bala(SDL_Renderer* renderer)
|
|||||||
forma_ = Graphics::ShapeLoader::load("bullet.shp");
|
forma_ = Graphics::ShapeLoader::load("bullet.shp");
|
||||||
|
|
||||||
if (!forma_ || !forma_->es_valida()) {
|
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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ void Enemic::inicialitzar(TipusEnemic tipus, const Punt* ship_pos) {
|
|||||||
// Carregar forma
|
// Carregar forma
|
||||||
forma_ = Graphics::ShapeLoader::load(shape_file);
|
forma_ = Graphics::ShapeLoader::load(shape_file);
|
||||||
if (!forma_ || !forma_->es_valida()) {
|
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
|
// [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));
|
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 "
|
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 {
|
} else {
|
||||||
// [EXISTING] No ship position: spawn anywhere (backward compatibility)
|
// [EXISTING] No ship position: spawn anywhere (backward compatibility)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Nau::Nau(SDL_Renderer* renderer, const char* shape_file)
|
|||||||
forma_ = Graphics::ShapeLoader::load(shape_file);
|
forma_ = Graphics::ShapeLoader::load(shape_file);
|
||||||
|
|
||||||
if (!forma_ || !forma_->es_valida()) {
|
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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ EscenaJoc::EscenaJoc(SDLManager& sdl, ContextEscenes& context)
|
|||||||
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
|
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
|
||||||
<< ", P2: "
|
<< ", P2: "
|
||||||
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
|
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
|
|
||||||
// Consumir opcions (preparació per MODE_DEMO futur)
|
// Consumir opcions (preparació per MODE_DEMO futur)
|
||||||
auto opcio = context_.consumir_opcio();
|
auto opcio = context_.consumir_opcio();
|
||||||
@@ -133,7 +133,7 @@ void EscenaJoc::inicialitzar() {
|
|||||||
if (!stage_config_) {
|
if (!stage_config_) {
|
||||||
stage_config_ = StageSystem::StageLoader::carregar("data/stages/stages.yaml");
|
stage_config_ = StageSystem::StageLoader::carregar("data/stages/stages.yaml");
|
||||||
if (!stage_config_) {
|
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)
|
// 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
|
// [DEBUG] Log entrada a LEVEL_START
|
||||||
static bool first_entry = true;
|
static bool first_entry = true;
|
||||||
if (first_entry) {
|
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;
|
first_entry = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1442,5 +1442,5 @@ void EscenaJoc::unir_jugador(uint8_t player_id) {
|
|||||||
|
|
||||||
// No visual message, just spawn (per user requirement)
|
// 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';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ void EscenaLogo::inicialitzar_lletres() {
|
|||||||
for (const auto& fitxer : fitxers) {
|
for (const auto& fitxer : fitxers) {
|
||||||
auto forma = ShapeLoader::load(fitxer);
|
auto forma = ShapeLoader::load(fitxer);
|
||||||
if (!forma || !forma->es_valida()) {
|
if (!forma || !forma->es_valida()) {
|
||||||
std::cerr << "[EscenaLogo] Error carregant " << fitxer << std::endl;
|
std::cerr << "[EscenaLogo] Error carregant " << fitxer << '\n';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ void EscenaTitol::inicialitzar_titol() {
|
|||||||
for (const auto& fitxer : fitxers_orni) {
|
for (const auto& fitxer : fitxers_orni) {
|
||||||
auto forma = ShapeLoader::load(fitxer);
|
auto forma = ShapeLoader::load(fitxer);
|
||||||
if (!forma || !forma->es_valida()) {
|
if (!forma || !forma->es_valida()) {
|
||||||
std::cerr << "[EscenaTitol] Error carregant " << fitxer << std::endl;
|
std::cerr << "[EscenaTitol] Error carregant " << fitxer << '\n';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ void EscenaTitol::inicialitzar_titol() {
|
|||||||
for (const auto& fitxer : fitxers_attack) {
|
for (const auto& fitxer : fitxers_attack) {
|
||||||
auto forma = ShapeLoader::load(fitxer);
|
auto forma = ShapeLoader::load(fitxer);
|
||||||
if (!forma || !forma->es_valida()) {
|
if (!forma || !forma->es_valida()) {
|
||||||
std::cerr << "[EscenaTitol] Error carregant " << fitxer << std::endl;
|
std::cerr << "[EscenaTitol] Error carregant " << fitxer << '\n';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +487,7 @@ void EscenaTitol::actualitzar(float delta_time) {
|
|||||||
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
|
<< (config_partida_.jugador1_actiu ? "ACTIU" : "INACTIU")
|
||||||
<< ", P2: "
|
<< ", P2: "
|
||||||
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
|
<< (config_partida_.jugador2_actiu ? "ACTIU" : "INACTIU")
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
|
|
||||||
context_.canviar_escena(Escena::JOC);
|
context_.canviar_escena(Escena::JOC);
|
||||||
estat_actual_ = EstatTitol::PLAYER_JOIN_PHASE;
|
estat_actual_ = EstatTitol::PLAYER_JOIN_PHASE;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void SpawnController::configurar(const ConfigStage* config) {
|
|||||||
|
|
||||||
void SpawnController::iniciar() {
|
void SpawnController::iniciar() {
|
||||||
if (config_ == nullptr) {
|
if (config_ == nullptr) {
|
||||||
std::cerr << "[SpawnController] Error: config_ és null" << std::endl;
|
std::cerr << "[SpawnController] Error: config_ és null" << '\n';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ void SpawnController::iniciar() {
|
|||||||
generar_spawn_events();
|
generar_spawn_events();
|
||||||
|
|
||||||
std::cout << "[SpawnController] Stage " << static_cast<int>(config_->stage_id)
|
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() {
|
void SpawnController::reset() {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
|||||||
// Load from resource system
|
// Load from resource system
|
||||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||||
if (data.empty()) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
|||||||
|
|
||||||
// Parse metadata
|
// Parse metadata
|
||||||
if (!yaml.contains("metadata")) {
|
if (!yaml.contains("metadata")) {
|
||||||
std::cerr << "[StageLoader] Error: falta camp 'metadata'" << std::endl;
|
std::cerr << "[StageLoader] Error: falta camp 'metadata'" << '\n';
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!parse_metadata(yaml["metadata"], config->metadata)) {
|
if (!parse_metadata(yaml["metadata"], config->metadata)) {
|
||||||
@@ -46,12 +46,12 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
|||||||
|
|
||||||
// Parse stages
|
// Parse stages
|
||||||
if (!yaml.contains("stages")) {
|
if (!yaml.contains("stages")) {
|
||||||
std::cerr << "[StageLoader] Error: falta camp 'stages'" << std::endl;
|
std::cerr << "[StageLoader] Error: falta camp 'stages'" << '\n';
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!yaml["stages"].is_sequence()) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,11 +69,11 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[StageLoader] Carregats " << config->stages.size()
|
std::cout << "[StageLoader] Carregats " << config->stages.size()
|
||||||
<< " stages correctament" << std::endl;
|
<< " stages correctament" << '\n';
|
||||||
return config;
|
return config;
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "[StageLoader] Excepció: " << e.what() << std::endl;
|
std::cerr << "[StageLoader] Excepció: " << e.what() << '\n';
|
||||||
return nullptr;
|
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) {
|
bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta) {
|
||||||
try {
|
try {
|
||||||
if (!yaml.contains("version") || !yaml.contains("total_stages")) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::exception& e) {
|
} 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;
|
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") ||
|
if (!yaml.contains("stage_id") || !yaml.contains("total_enemies") ||
|
||||||
!yaml.contains("spawn_config") || !yaml.contains("enemy_distribution") ||
|
!yaml.contains("spawn_config") || !yaml.contains("enemy_distribution") ||
|
||||||
!yaml.contains("difficulty_multipliers")) {
|
!yaml.contains("difficulty_multipliers")) {
|
||||||
std::cerr << "[StageLoader] Error: stage incompleta" << std::endl;
|
std::cerr << "[StageLoader] Error: stage incompleta" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,13 +122,13 @@ bool StageLoader::parse_stage(const fkyaml::node& yaml, ConfigStage& stage) {
|
|||||||
|
|
||||||
if (!stage.es_valid()) {
|
if (!stage.es_valid()) {
|
||||||
std::cerr << "[StageLoader] Error: stage " << static_cast<int>(stage.stage_id)
|
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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& conf
|
|||||||
try {
|
try {
|
||||||
if (!yaml.contains("mode") || !yaml.contains("initial_delay") ||
|
if (!yaml.contains("mode") || !yaml.contains("initial_delay") ||
|
||||||
!yaml.contains("spawn_interval")) {
|
!yaml.contains("spawn_interval")) {
|
||||||
std::cerr << "[StageLoader] Error: spawn_config incompleta" << std::endl;
|
std::cerr << "[StageLoader] Error: spawn_config incompleta" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& conf
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ bool StageLoader::parse_distribution(const fkyaml::node& yaml, DistribucioEnemic
|
|||||||
try {
|
try {
|
||||||
if (!yaml.contains("pentagon") || !yaml.contains("quadrat") ||
|
if (!yaml.contains("pentagon") || !yaml.contains("quadrat") ||
|
||||||
!yaml.contains("molinillo")) {
|
!yaml.contains("molinillo")) {
|
||||||
std::cerr << "[StageLoader] Error: enemy_distribution incompleta" << std::endl;
|
std::cerr << "[StageLoader] Error: enemy_distribution incompleta" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,13 +168,13 @@ bool StageLoader::parse_distribution(const fkyaml::node& yaml, DistribucioEnemic
|
|||||||
// Validar que suma 100
|
// Validar que suma 100
|
||||||
int sum = dist.pentagon + dist.quadrat + dist.molinillo;
|
int sum = dist.pentagon + dist.quadrat + dist.molinillo;
|
||||||
if (sum != 100) {
|
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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi
|
|||||||
try {
|
try {
|
||||||
if (!yaml.contains("speed_multiplier") || !yaml.contains("rotation_multiplier") ||
|
if (!yaml.contains("speed_multiplier") || !yaml.contains("rotation_multiplier") ||
|
||||||
!yaml.contains("tracking_strength")) {
|
!yaml.contains("tracking_strength")) {
|
||||||
std::cerr << "[StageLoader] Error: difficulty_multipliers incompleta" << std::endl;
|
std::cerr << "[StageLoader] Error: difficulty_multipliers incompleta" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,18 +193,18 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi
|
|||||||
|
|
||||||
// Validar rangs raonables
|
// Validar rangs raonables
|
||||||
if (mult.velocitat < 0.1F || mult.velocitat > 5.0F) {
|
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) {
|
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) {
|
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;
|
return true;
|
||||||
} catch (const std::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,20 +220,20 @@ ModeSpawn StageLoader::parse_spawn_mode(const std::string& mode_str) {
|
|||||||
return ModeSpawn::WAVE;
|
return ModeSpawn::WAVE;
|
||||||
}
|
}
|
||||||
std::cerr << "[StageLoader] Warning: mode de spawn desconegut '" << mode_str
|
std::cerr << "[StageLoader] Warning: mode de spawn desconegut '" << mode_str
|
||||||
<< "', usant PROGRESSIVE" << std::endl;
|
<< "', usant PROGRESSIVE" << '\n';
|
||||||
return ModeSpawn::PROGRESSIVE;
|
return ModeSpawn::PROGRESSIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StageLoader::validar_config(const ConfigSistemaStages& config) {
|
bool StageLoader::validar_config(const ConfigSistemaStages& config) {
|
||||||
if (config.stages.empty()) {
|
if (config.stages.empty()) {
|
||||||
std::cerr << "[StageLoader] Error: cap stage carregat" << std::endl;
|
std::cerr << "[StageLoader] Error: cap stage carregat" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.stages.size() != config.metadata.total_stages) {
|
if (config.stages.size() != config.metadata.total_stages) {
|
||||||
std::cerr << "[StageLoader] Warning: nombre de stages (" << config.stages.size()
|
std::cerr << "[StageLoader] Warning: nombre de stages (" << config.stages.size()
|
||||||
<< ") no coincideix amb metadata.total_stages ("
|
<< ") 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
|
// Validar stage_id consecutius
|
||||||
@@ -241,7 +241,7 @@ bool StageLoader::validar_config(const ConfigSistemaStages& config) {
|
|||||||
if (config.stages[i].stage_id != i + 1) {
|
if (config.stages[i].stage_id != i + 1) {
|
||||||
std::cerr << "[StageLoader] Error: stage_id no consecutius (esperat "
|
std::cerr << "[StageLoader] Error: stage_id no consecutius (esperat "
|
||||||
<< i + 1 << ", trobat " << static_cast<int>(config.stages[i].stage_id)
|
<< i + 1 << ", trobat " << static_cast<int>(config.stages[i].stage_id)
|
||||||
<< ")" << std::endl;
|
<< ")" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ StageManager::StageManager(const ConfigSistemaStages* config)
|
|||||||
stage_actual_(1),
|
stage_actual_(1),
|
||||||
timer_transicio_(0.0F) {
|
timer_transicio_(0.0F) {
|
||||||
if (config_ == nullptr) {
|
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);
|
canviar_estat(EstatStage::INIT_HUD);
|
||||||
|
|
||||||
std::cout << "[StageManager] Inicialitzat a stage " << static_cast<int>(stage_actual_)
|
std::cout << "[StageManager] Inicialitzat a stage " << static_cast<int>(stage_actual_)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void StageManager::actualitzar(float delta_time, bool pausar_spawn) {
|
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() {
|
void StageManager::stage_completat() {
|
||||||
std::cout << "[StageManager] Stage " << static_cast<int>(stage_actual_) << " completat!"
|
std::cout << "[StageManager] Stage " << static_cast<int>(stage_actual_) << " completat!"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
canviar_estat(EstatStage::LEVEL_COMPLETED);
|
canviar_estat(EstatStage::LEVEL_COMPLETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ void StageManager::canviar_estat(EstatStage nou_estat) {
|
|||||||
std::cout << "LEVEL_COMPLETED";
|
std::cout << "LEVEL_COMPLETED";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
void StageManager::processar_init_hud(float delta_time) {
|
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) {
|
if (stage_actual_ > config_->metadata.total_stages) {
|
||||||
stage_actual_ = 1;
|
stage_actual_ = 1;
|
||||||
std::cout << "[StageManager] Totes les stages completades! Tornant a stage 1"
|
std::cout << "[StageManager] Totes les stages completades! Tornant a stage 1"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load next stage
|
// Load next stage
|
||||||
@@ -155,7 +155,7 @@ void StageManager::carregar_stage(uint8_t stage_id) {
|
|||||||
const ConfigStage* stage_config = config_->obte_stage(stage_id);
|
const ConfigStage* stage_config = config_->obte_stage(stage_id);
|
||||||
if (stage_config == nullptr) {
|
if (stage_config == nullptr) {
|
||||||
std::cerr << "[StageManager] Error: no es pot trobar stage " << static_cast<int>(stage_id)
|
std::cerr << "[StageManager] Error: no es pot trobar stage " << static_cast<int>(stage_id)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ void StageManager::carregar_stage(uint8_t stage_id) {
|
|||||||
spawn_controller_.iniciar();
|
spawn_controller_.iniciar();
|
||||||
|
|
||||||
std::cout << "[StageManager] Carregat stage " << static_cast<int>(stage_id) << ": "
|
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
|
} // namespace StageSystem
|
||||||
|
|||||||
Reference in New Issue
Block a user