diff --git a/source/core/locale/locale.cpp b/source/core/locale/locale.cpp index 42c9647..618f132 100644 --- a/source/core/locale/locale.cpp +++ b/source/core/locale/locale.cpp @@ -1,11 +1,11 @@ #include "core/locale/locale.hpp" #include -#include #include #include "core/resources/resource_helper.hpp" #include "external/fkyaml_node.hpp" +#include "utils/log.hpp" namespace { @@ -36,7 +36,7 @@ auto Locale::get() -> Locale& { void Locale::load(const std::string& file_path) { auto bytes = Resource::Helper::loadFile(file_path); if (bytes.empty()) { - std::cerr << "Locale: no s'ha pogut obrir " << file_path << '\n'; + Log::error("Locale", "no s'ha pogut obrir {}", file_path); return; } @@ -46,15 +46,15 @@ void Locale::load(const std::string& file_path) { auto yaml = fkyaml::node::deserialize(begin, end); strings_.clear(); flatten(yaml, "", strings_); - std::cout << "Locale: " << strings_.size() << " traduccions des de " << file_path << '\n'; + Log::info("Locale", "{} traduccions des de {}", strings_.size(), file_path); } catch (const std::exception& e) { - std::cerr << "Locale: error parsejant " << file_path << ": " << e.what() << '\n'; + Log::error("Locale", "error parsejant {}: {}", file_path, e.what()); } } auto Locale::text(const std::string& key) const -> std::string { auto it = strings_.find(key); if (it != strings_.end()) { return it->second; } - std::cerr << "Locale: clau no trobada: " << key << '\n'; + Log::warn("Locale", "clau no trobada: {}", key); return key; } diff --git a/source/core/rendering/gif.cpp b/source/core/rendering/gif.cpp index b0df08a..b8094c2 100644 --- a/source/core/rendering/gif.cpp +++ b/source/core/rendering/gif.cpp @@ -1,10 +1,11 @@ #include "core/rendering/gif.hpp" #include -#include #include #include +#include "utils/log.hpp" + namespace GIF { namespace { @@ -111,7 +112,7 @@ namespace GIF { while (cur_code != -1) { out[dictionary[cur_code].len - 1] = dictionary[cur_code].byte; if (dictionary[cur_code].prev == cur_code) { - std::cerr << "Internal error; self-reference detected." << '\n'; + Log::error("GIF", "internal error; self-reference detected."); throw std::runtime_error("Internal error in decompress: self-reference"); } cur_code = dictionary[cur_code].prev; @@ -155,8 +156,7 @@ namespace GIF { if (prev > -1 && code_length < LZW_MAX_CODE_LENGTH) { if (code > dictionary_ind) { - std::cerr << "code = " << std::hex << code - << ", but dictionary_ind = " << dictionary_ind << '\n'; + Log::error("GIF", "code = {:x}, but dictionary_ind = {}", code, dictionary_ind); throw std::runtime_error("LZW error: code exceeds dictionary_ind."); } @@ -167,8 +167,7 @@ namespace GIF { // Verifica que 'code' sea un índice válido antes de usarlo. if (code < 0 || static_cast(code) >= dictionary.size()) { - std::cerr << "Invalid LZW code " << code - << ", dictionary size " << dictionary.size() << '\n'; + Log::error("GIF", "invalid LZW code {}, dictionary size {}", code, dictionary.size()); throw std::runtime_error("LZW error: invalid code encountered"); } @@ -287,7 +286,7 @@ namespace GIF { } else if (block_type == IMAGE_DESCRIPTOR) { return processImageDescriptor(buffer); } else { - std::cerr << "Unrecognized block type " << std::hex << static_cast(block_type) << '\n'; + Log::error("GIF", "unrecognized block type {:x}", static_cast(block_type)); return std::vector{}; } block_type = *buffer++; diff --git a/source/core/rendering/screen.cpp b/source/core/rendering/screen.cpp index 6953fd1..eb1c504 100644 --- a/source/core/rendering/screen.cpp +++ b/source/core/rendering/screen.cpp @@ -6,13 +6,13 @@ #include #include #include -#include #include #include #include "core/rendering/canvas.hpp" #include "core/rendering/sdl3gpu/viewport.hpp" #include "utils/defines.hpp" +#include "utils/log.hpp" namespace { @@ -112,11 +112,11 @@ void Screen::createSdl() { backend->setVSync(config_.vsync); if (backend->init(window_, canvas_width_, canvas_height_)) { gpu_driver_ = backend->getDriverName(); - std::cout << "Screen: path GPU actiu (driver: " << gpu_driver_ << ")\n"; + Log::info("Screen", "path GPU actiu (driver: {})", gpu_driver_); shader_backend_ = std::move(backend); return; } - std::cerr << "Screen: GPU no disponible, fallback a SDL_Renderer\n"; + Log::warn("Screen", "GPU no disponible, fallback a SDL_Renderer"); } gpu_driver_ = "sdl"; diff --git a/source/core/rendering/sdl3gpu/pipelines/crtpi_pipeline.cpp b/source/core/rendering/sdl3gpu/pipelines/crtpi_pipeline.cpp index bb29ed2..cd15f01 100644 --- a/source/core/rendering/sdl3gpu/pipelines/crtpi_pipeline.cpp +++ b/source/core/rendering/sdl3gpu/pipelines/crtpi_pipeline.cpp @@ -1,10 +1,10 @@ #include "core/rendering/sdl3gpu/pipelines/crtpi_pipeline.hpp" #include -#include #include "core/rendering/sdl3gpu/shader_factory.hpp" #include "core/rendering/sdl3gpu/viewport.hpp" +#include "utils/log.hpp" #ifdef __APPLE__ #include "core/rendering/sdl3gpu/msl/crtpi_frag.msl.h" @@ -29,7 +29,7 @@ namespace Rendering { SDL_GPUShader* frag = createShaderSPIRV(device_, kcrtpi_frag_spv, kcrtpi_frag_spv_size, "main", SDL_GPU_SHADERSTAGE_FRAGMENT, 1, 1); #endif if (vert == nullptr || frag == nullptr) { - std::cerr << "CrtPiPipeline: creació de shaders fallida: " << SDL_GetError() << '\n'; + Log::error("CrtPiPipeline", "creació de shaders fallida: {}", SDL_GetError()); if (vert != nullptr) { SDL_ReleaseGPUShader(device_, vert); } if (frag != nullptr) { SDL_ReleaseGPUShader(device_, frag); } return false; @@ -57,7 +57,7 @@ namespace Rendering { SDL_ReleaseGPUShader(device_, frag); if (pipeline_ == nullptr) { - std::cerr << "CrtPiPipeline: creació del pipeline ha fallat: " << SDL_GetError() << '\n'; + Log::error("CrtPiPipeline", "creació del pipeline ha fallat: {}", SDL_GetError()); return false; } diff --git a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp index 8579425..bcfc440 100644 --- a/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp +++ b/source/core/rendering/sdl3gpu/sdl3gpu_shader.cpp @@ -2,10 +2,10 @@ #include #include -#include #include "core/rendering/sdl3gpu/shader_factory.hpp" #include "core/rendering/sdl3gpu/viewport.hpp" +#include "utils/log.hpp" #ifdef __APPLE__ #include "core/rendering/sdl3gpu/msl/postfx_frag.msl.h" @@ -59,11 +59,11 @@ namespace Rendering { const char* driver = preferred_driver_.empty() ? nullptr : preferred_driver_.c_str(); device_ = SDL_CreateGPUDevice(FORMAT, false, driver); if (device_ == nullptr) { - std::cerr << "SDL3GPUShader: SDL_CreateGPUDevice ha fallat: " << SDL_GetError() << '\n'; + Log::error("SDL3GPUShader", "SDL_CreateGPUDevice ha fallat: {}", SDL_GetError()); return false; } if (!SDL_ClaimWindowForGPUDevice(device_, window_)) { - std::cerr << "SDL3GPUShader: SDL_ClaimWindowForGPUDevice ha fallat: " << SDL_GetError() << '\n'; + Log::error("SDL3GPUShader", "SDL_ClaimWindowForGPUDevice ha fallat: {}", SDL_GetError()); return false; } SDL_SetGPUSwapchainParameters(device_, window_, SDL_GPU_SWAPCHAINCOMPOSITION_SDR, bestPresentMode(vsync_)); @@ -82,7 +82,7 @@ namespace Rendering { fragment_shader_ = createShaderSPIRV(device_, kpostfx_frag_spv, kpostfx_frag_spv_size, "main", SDL_GPU_SHADERSTAGE_FRAGMENT, 1, 1); #endif if (vertex_shader_ == nullptr || fragment_shader_ == nullptr) { - std::cerr << "SDL3GPUShader: SDL_CreateGPUShader ha fallat: " << SDL_GetError() << '\n'; + Log::error("SDL3GPUShader", "SDL_CreateGPUShader ha fallat: {}", SDL_GetError()); return false; } return true; @@ -105,7 +105,7 @@ namespace Rendering { pipeline_ = SDL_CreateGPUGraphicsPipeline(device_, &info); if (pipeline_ == nullptr) { - std::cerr << "SDL3GPUShader: SDL_CreateGPUGraphicsPipeline ha fallat: " << SDL_GetError() << '\n'; + Log::error("SDL3GPUShader", "SDL_CreateGPUGraphicsPipeline ha fallat: {}", SDL_GetError()); return false; } return true; @@ -137,7 +137,7 @@ namespace Rendering { sampler_ = SDL_CreateGPUSampler(device_, &samp_info); if (scene_texture_ == nullptr || upload_buffer_ == nullptr || sampler_ == nullptr) { - std::cerr << "SDL3GPUShader: creació de recursos GPU ha fallat: " << SDL_GetError() << '\n'; + Log::error("SDL3GPUShader", "creació de recursos GPU ha fallat: {}", SDL_GetError()); return false; } return true; diff --git a/source/core/rendering/sprite/animated_sprite.cpp b/source/core/rendering/sprite/animated_sprite.cpp index 4ab8aa1..a36d444 100644 --- a/source/core/rendering/sprite/animated_sprite.cpp +++ b/source/core/rendering/sprite/animated_sprite.cpp @@ -1,12 +1,12 @@ #include "core/rendering/sprite/animated_sprite.hpp" #include -#include #include #include #include "core/rendering/surface.hpp" #include "core/resources/resource_cache.hpp" +#include "utils/log.hpp" // El parser pure de YAML d'animacions (parseAnimationsFromYaml + helpers) // viu a `animated_sprite_parser.cpp` perquè és testable sense Surface ni @@ -74,10 +74,10 @@ AnimatedSprite::AnimatedSprite(const AnimationResource& cached_data) { if (!first.frames.empty()) { setClip(first.frames[0].rect); } } } catch (const fkyaml::exception& e) { - std::cerr << "YAML parsing error in animation " << cached_data.name << ": " << e.what() << '\n'; + Log::error("AnimatedSprite", "YAML parsing error in animation {}: {}", cached_data.name, e.what()); throw; } catch (const std::exception& e) { - std::cerr << "Error loading animation " << cached_data.name << ": " << e.what() << '\n'; + Log::error("AnimatedSprite", "Error loading animation {}: {}", cached_data.name, e.what()); throw; } } @@ -140,7 +140,7 @@ void AnimatedSprite::setCurrentAnimation(const std::string& name) { if (current_animation_ == name) { return; } auto it = animations_.find(name); if (it == animations_.end()) { - std::cout << "** Warning: could not find \"" << name << "\" animation" << '\n'; + Log::warn("AnimatedSprite", "could not find \"{}\" animation", name); return; } current_animation_ = name; diff --git a/source/core/rendering/surface.cpp b/source/core/rendering/surface.cpp index ded56a8..484bf81 100644 --- a/source/core/rendering/surface.cpp +++ b/source/core/rendering/surface.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index 6d04718..13b29c9 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -11,6 +10,7 @@ #include "core/rendering/sprite/sprite.hpp" #include "core/rendering/surface.hpp" #include "core/resources/resource_helper.hpp" +#include "utils/log.hpp" #include "utils/utils.hpp" // Decodifica el pròxim codepoint UTF-8 de la cadena i avança 'pos' al byte @@ -55,7 +55,7 @@ auto Text::loadTextFile(const std::string& file_path) -> std::shared_ptr { auto file_data = Resource::Helper::loadFile(file_path); if (file_data.empty()) { - std::cerr << "Error: Fitxer no trobat " << getFileName(file_path) << '\n'; + Log::error("Text File", "fitxer no trobat: {}", getFileName(file_path)); throw std::runtime_error("Fitxer no trobat: " + getFileName(file_path)); } diff --git a/source/core/ui/ui_config.cpp b/source/core/ui/ui_config.cpp index 051e03f..e2ed476 100644 --- a/source/core/ui/ui_config.cpp +++ b/source/core/ui/ui_config.cpp @@ -1,6 +1,5 @@ #include "core/ui/ui_config.hpp" -#include #include #include #include @@ -9,6 +8,7 @@ #include "external/fkyaml_node.hpp" #include "utils/defaults.hpp" #include "utils/easing.hpp" +#include "utils/log.hpp" namespace { @@ -27,7 +27,7 @@ namespace { if (!node.contains(key)) { return; } const int VALUE = node[key].get_value(); if (VALUE < 0 || VALUE > 255) { - std::cerr << "UiConfig: índex '" << key << "'=" << VALUE << " fora de rang 0..255 — ignorat\n"; + Log::warn("UiConfig", "índex '{}'={} fora de rang 0..255 — ignorat", key, VALUE); return; } dst = static_cast(VALUE); @@ -183,7 +183,7 @@ auto UiConfig::curveByName(const std::string& name) -> CurveFn { const auto& reg = curveRegistry(); const auto IT = reg.find(name); if (IT == reg.end()) { - std::cerr << "UiConfig: corba '" << name << "' desconeguda — s'usa linear\n"; + Log::warn("UiConfig", "corba '{}' desconeguda — s'usa linear", name); return &Easing::linear; } return IT->second; @@ -192,7 +192,7 @@ auto UiConfig::curveByName(const std::string& name) -> CurveFn { void UiConfig::load(const std::string& file_path) { auto bytes = Resource::Helper::loadFile(file_path); if (bytes.empty()) { - std::cerr << "UiConfig: no s'ha pogut obrir " << file_path << " — s'usaran els defaults compilats\n"; + Log::warn("UiConfig", "no s'ha pogut obrir {} — s'usaran els defaults compilats", file_path); return; } @@ -345,8 +345,8 @@ void UiConfig::load(const std::string& file_path) { readCurve(n, "slide_out_curve", notifier_.slide_out_curve); } - std::cout << "UiConfig: carregat des de " << file_path << '\n'; + Log::info("UiConfig", "carregat des de {}", file_path); } catch (const std::exception& e) { - std::cerr << "UiConfig: error parsejant " << file_path << ": " << e.what() << '\n'; + Log::error("UiConfig", "error parsejant {}: {}", file_path, e.what()); } } diff --git a/source/game/debug_config.cpp b/source/game/debug_config.cpp index c14cf54..7c42096 100644 --- a/source/game/debug_config.cpp +++ b/source/game/debug_config.cpp @@ -3,11 +3,11 @@ #include #include #include -#include #include #include #include "external/fkyaml_node.hpp" +#include "utils/log.hpp" namespace DebugConfig { @@ -53,12 +53,12 @@ namespace DebugConfig { if (!yaml.contains("start_scene")) { return StartScene::GAME; } const auto RAW = yaml["start_scene"].get_value(); if (!isKnown(RAW)) { - std::cerr << "debug.yaml: start_scene \"" << RAW << "\" invàlid, arrancant a GAME\n"; + Log::warn("debug.yaml", "start_scene \"{}\" invàlid, arrancant a GAME", RAW); return StartScene::GAME; } return fromName(RAW); } catch (const std::exception& e) { - std::cerr << "debug.yaml: error parsejant: " << e.what() << " — arrancant a GAME\n"; + Log::error("debug.yaml", "error parsejant: {} — arrancant a GAME", e.what()); return StartScene::GAME; } } @@ -72,7 +72,7 @@ namespace DebugConfig { } const auto CONTENT = readFile(file_path); if (CONTENT.empty()) { - std::cerr << "debug.yaml: fitxer buit a " << file_path << ", arrancant a GAME\n"; + Log::warn("debug.yaml", "fitxer buit a {}, arrancant a GAME", file_path); return StartScene::GAME; } return parseStartScene(CONTENT); @@ -85,12 +85,12 @@ namespace DebugConfig { if (!yaml.contains("starting_players")) { return StartingPlayers::BOTH; } const auto RAW = yaml["starting_players"].get_value(); if (!isKnownPlayers(RAW)) { - std::cerr << "debug.yaml: starting_players \"" << RAW << "\" invàlid, arrancant amb BOTH\n"; + Log::warn("debug.yaml", "starting_players \"{}\" invàlid, arrancant amb BOTH", RAW); return StartingPlayers::BOTH; } return playersFromName(RAW); } catch (const std::exception& e) { - std::cerr << "debug.yaml: error parsejant starting_players: " << e.what() << " — arrancant amb BOTH\n"; + Log::error("debug.yaml", "error parsejant starting_players: {} — arrancant amb BOTH", e.what()); return StartingPlayers::BOTH; } } @@ -110,7 +110,7 @@ namespace DebugConfig { if (!yaml.contains("starting_level")) { return std::nullopt; } const auto& sl = yaml["starting_level"]; if (!sl.contains("pyramid") || !sl.contains("room")) { - std::cerr << "debug.yaml: starting_level necessita els camps `pyramid` i `room` — ignorat\n"; + Log::warn("debug.yaml", "starting_level necessita els camps `pyramid` i `room` — ignorat"); return std::nullopt; } return StartingLevel{ @@ -118,7 +118,7 @@ namespace DebugConfig { .room = sl["room"].get_value(), }; } catch (const std::exception& e) { - std::cerr << "debug.yaml: error parsejant starting_level: " << e.what() << " — ignorat\n"; + Log::error("debug.yaml", "error parsejant starting_level: {} — ignorat", e.what()); return std::nullopt; } } @@ -162,7 +162,7 @@ namespace DebugConfig { if (std::filesystem::exists(file_path, error)) { return; } std::ofstream file(file_path); if (!file) { - std::cerr << "debug.yaml: no s'ha pogut crear " << file_path << '\n'; + Log::error("debug.yaml", "no s'ha pogut crear {}", file_path); return; } file << "# debug.yaml — ajust personal de dev (no versionat).\n"; @@ -173,7 +173,7 @@ namespace DebugConfig { file << "# clau, comença a la primera (P1-R1).\n"; file << "start_scene: GAME\n"; file << "starting_players: BOTH\n"; - std::cout << "debug.yaml: creat a " << file_path << " amb start_scene=GAME starting_players=BOTH\n"; + Log::info("debug.yaml", "creat a {} amb start_scene=GAME starting_players=BOTH", file_path); } } // namespace DebugConfig diff --git a/source/game/editor/editor_config.cpp b/source/game/editor/editor_config.cpp index 9f696d2..b4fc902 100644 --- a/source/game/editor/editor_config.cpp +++ b/source/game/editor/editor_config.cpp @@ -3,13 +3,13 @@ #ifdef _DEBUG #include -#include #include #include #include "core/resources/resource_helper.hpp" #include "external/fkyaml_node.hpp" #include "utils/defaults.hpp" +#include "utils/log.hpp" namespace { @@ -34,7 +34,7 @@ namespace { if (!s.empty() && s.front() == '#') { s.erase(0, 1); } dst = static_cast(std::stoul(s, nullptr, 0)); } catch (const std::exception& e) { - std::cerr << "EditorConfig: color '" << key << "' invàlid (" << e.what() << ") — ignorat\n"; + Log::warn("EditorConfig", "color '{}' invàlid ({}) — ignorat", key, e.what()); } } @@ -56,7 +56,7 @@ auto EditorConfig::get() -> EditorConfig& { void EditorConfig::load(const std::string& file_path) { auto bytes = Resource::Helper::loadFile(file_path); if (bytes.empty()) { - std::cerr << "EditorConfig: no s'ha pogut obrir " << file_path << " — s'usaran els defaults compilats\n"; + Log::warn("EditorConfig", "no s'ha pogut obrir {} — s'usaran els defaults compilats", file_path); return; } try { @@ -76,9 +76,9 @@ void EditorConfig::load(const std::string& file_path) { readArgb(c, "picker_hover", picker_hover_argb_); } - std::cout << "EditorConfig: carregat des de " << file_path << '\n'; + Log::info("EditorConfig", "carregat des de {}", file_path); } catch (const std::exception& e) { - std::cerr << "EditorConfig: error parsejant " << file_path << ": " << e.what() << '\n'; + Log::error("EditorConfig", "error parsejant {}: {}", file_path, e.what()); } } diff --git a/source/game/entities/entity_manager_loadlevel.cpp b/source/game/entities/entity_manager_loadlevel.cpp index cc8894f..091a5c8 100644 --- a/source/game/entities/entity_manager_loadlevel.cpp +++ b/source/game/entities/entity_manager_loadlevel.cpp @@ -5,7 +5,6 @@ // stand-alone) enllacen `entity_manager.cpp` sense arrossegar aquest fitxer. #include -#include #include #include #include @@ -22,6 +21,7 @@ #include "game/entities/player.hpp" #include "game/map/map.hpp" #include "utils/defaults.hpp" +#include "utils/log.hpp" // Render centralitzat al manager per confinar la dependència cap a // `Surface`. Les entitats exposen `getSurface()` + `getPixelRect()` i el @@ -237,12 +237,12 @@ namespace { try { tmpl = EntityLoader::loadTemplate(type); } catch (const std::exception& e) { - std::cerr << "EntityManager: " << e.what() << '\n'; + Log::error("EntityManager", "{}", e.what()); return nullptr; } auto entity = EntityFactory::instance().create(type, tmpl); if (entity == nullptr) { - std::cerr << "EntityManager: tipus desconegut '" << type << "'\n"; + Log::error("EntityManager", "tipus desconegut '{}'", type); return nullptr; } sprite_out = readSpriteInfo(tmpl, type); @@ -267,7 +267,7 @@ namespace { namespace { auto placeSarcophagus(EntityManager& manager, std::unique_ptr entity, const SpriteInfo& sprite, const fkyaml::node& spawn) -> bool { if (!spawn.contains("sarc_position")) { - std::cerr << "EntityManager: sarcophagus sense sarc_position\n"; + Log::error("EntityManager", "sarcophagus sense sarc_position"); return false; } const auto& sp = spawn["sarc_position"]; @@ -304,7 +304,7 @@ namespace { // un `Sarcophagus`. Usant el retorn de `release` al ctor del nou // `unique_ptr` evitem el lint `bugprone-unused-return-value`. if (dynamic_cast(entity.get()) == nullptr) { - std::cerr << "EntityManager: la factory no ha creat un Sarcophagus\n"; + Log::error("EntityManager", "la factory no ha creat un Sarcophagus"); return false; } std::unique_ptr sarc(static_cast(entity.release())); @@ -323,7 +323,7 @@ namespace { // queden tapats — comportament intencional. auto placeDoor(EntityManager& manager, std::unique_ptr entity, const SpriteInfo& sprite) -> bool { if (Map::door_col <= 0 || Map::tile_size <= 0) { - std::cerr << "EntityManager: door requereix `geometry.door_col` definit al mapa\n"; + Log::error("EntityManager", "door requereix `geometry.door_col` definit al mapa"); return false; } const float CENTER_X = static_cast((Map::door_col * Map::tile_size) + Map::tilemap_origin_x) + (static_cast(Map::tile_size) / 2.0F); @@ -343,7 +343,7 @@ namespace { auto placeGeneric(EntityManager& manager, std::unique_ptr entity, const std::string& type, const SpriteInfo& sprite, const std::string& anchor, const fkyaml::node& spawn) -> bool { if (!spawn.contains("position")) { - std::cerr << "EntityManager: " << type << " sense position\n"; + Log::error("EntityManager", "{} sense position", type); return false; } const auto& p = spawn["position"]; @@ -444,10 +444,8 @@ void EntityManager::loadFromLevel(const std::string& level_yaml_path) { ++decal_broadcast; } if (decal_broadcast > 0) { - std::cout << "EntityManager: " << decal_broadcast - << " tile_painted broadcast inicial (decals de sòl)\n"; + Log::info("EntityManager", "{} tile_painted broadcast inicial (decals de sòl)", decal_broadcast); } - std::cout << "EntityManager: " << LOADED << " entitats carregades des de " - << level_yaml_path << '\n'; + Log::info("EntityManager", "{} entitats carregades des de {}", LOADED, level_yaml_path); } diff --git a/source/game/levels/level_manager.cpp b/source/game/levels/level_manager.cpp index 1839433..b6d6a6f 100644 --- a/source/game/levels/level_manager.cpp +++ b/source/game/levels/level_manager.cpp @@ -1,13 +1,13 @@ #include "game/levels/level_manager.hpp" #include -#include #include #include #include "core/resources/resource_helper.hpp" #include "external/fkyaml_node.hpp" #include "utils/defaults.hpp" +#include "utils/log.hpp" namespace Levels { @@ -46,8 +46,7 @@ namespace Levels { throw std::runtime_error("LevelManager: la seqüència de " + PATH + " és buida"); } index_ = 0; - std::cout << "LevelManager: " << entries_.size() << " sales carregades de " - << PATH << " (començant a " << currentLabel() << ")\n"; + Log::info("LevelManager", "{} sales carregades de {} (començant a {})", entries_.size(), PATH, currentLabel()); } auto LevelManager::currentPath() const -> const std::string& { @@ -67,22 +66,20 @@ namespace Levels { auto LevelManager::advance() -> bool { if (index_ + 1 >= count()) { return false; } ++index_; - std::cout << "LevelManager: avança a " << currentLabel() - << " (" << currentPath() << ")\n"; + Log::info("LevelManager", "avança a {} ({})", currentLabel(), currentPath()); return true; } void LevelManager::restart() { index_ = 0; - std::cout << "LevelManager: restart a " << currentLabel() << '\n'; + Log::info("LevelManager", "restart a {}", currentLabel()); } void LevelManager::setIndex(int new_index) { const int CLAMPED = std::clamp(new_index, 0, count() - 1); if (CLAMPED != index_) { index_ = CLAMPED; - std::cout << "LevelManager: setIndex(" << new_index << ") → " - << currentLabel() << " (" << currentPath() << ")\n"; + Log::info("LevelManager", "setIndex({}) → {} ({})", new_index, currentLabel(), currentPath()); } } @@ -90,14 +87,11 @@ namespace Levels { for (std::size_t i = 0; i < entries_.size(); ++i) { if (entries_[i].pyramid == pyramid && entries_[i].room == room) { index_ = static_cast(i); - std::cout << "LevelManager: starting_point P" << pyramid << "-R" << room - << " trobat a l'índex " << i << " (" << currentPath() << ")\n"; + Log::info("LevelManager", "starting_point P{}-R{} trobat a l'índex {} ({})", pyramid, room, i, currentPath()); return true; } } - std::cerr << "LevelManager: starting_point P" << pyramid << "-R" << room - << " no trobat a levels.yaml — es manté l'índex actual (" - << currentLabel() << ")\n"; + Log::warn("LevelManager", "starting_point P{}-R{} no trobat a levels.yaml — es manté l'índex actual ({})", pyramid, room, currentLabel()); return false; } diff --git a/source/game/map/map.cpp b/source/game/map/map.cpp index 8271c0e..a01e3de 100644 --- a/source/game/map/map.cpp +++ b/source/game/map/map.cpp @@ -1,11 +1,11 @@ #include "game/map/map.hpp" #include -#include #include #include "core/resources/resource_helper.hpp" #include "external/fkyaml_node.hpp" +#include "utils/log.hpp" namespace { @@ -90,11 +90,7 @@ namespace Map { // canviarà el flag a true quan transiti a OPEN. door_open = false; - std::cout << "Map: geometria " << grid_cols << "x" << grid_rows - << " sarcs " << sarc_w << "x" << sarc_h - << " pitch " << pitch_x << "x" << pitch_y - << " door_col " << door_col - << " des de " << yaml_path << '\n'; + Log::info("Map", "geometria {}x{} sarcs {}x{} pitch {}x{} door_col {} des de {}", grid_cols, grid_rows, sarc_w, sarc_h, pitch_x, pitch_y, door_col, yaml_path); } auto getSarcRect(int col, int row) -> SDL_FRect { diff --git a/source/game/map/paint_layer.cpp b/source/game/map/paint_layer.cpp index ced3edc..1bf90c8 100644 --- a/source/game/map/paint_layer.cpp +++ b/source/game/map/paint_layer.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "core/rendering/screen.hpp" @@ -11,6 +10,7 @@ #include "core/resources/resource_cache.hpp" #include "game/map/map.hpp" #include "game/map/tilemap.hpp" +#include "utils/log.hpp" // CONTRACTE BUS DE PINTAT // ----------------------- @@ -89,9 +89,7 @@ PaintLayer::PaintLayer(const Tilemap& tilemap, EventBus* bus) }); } - std::cout << "PaintLayer: " << cols_ << "x" << rows_ << " tiles (" - << width_px_ << "x" << height_px_ << " px), tileset " - << tileset_path_ << '\n'; + Log::info("PaintLayer", "{}x{} tiles ({}x{} px), tileset {}", cols_, rows_, width_px_, height_px_, tileset_path_); } PaintLayer::~PaintLayer() { diff --git a/source/game/map/tilemap.cpp b/source/game/map/tilemap.cpp index e9c69ec..577d6c7 100644 --- a/source/game/map/tilemap.cpp +++ b/source/game/map/tilemap.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -12,6 +11,7 @@ #include "core/resources/resource_cache.hpp" #include "core/resources/resource_helper.hpp" #include "external/fkyaml_node.hpp" +#include "utils/log.hpp" #ifdef _DEBUG #include "game/map/tilemap_writer.hpp" @@ -97,8 +97,7 @@ Tilemap::Tilemap(const std::string& yaml_path) { } } - std::cout << "Tilemap: " << cols_ << "x" << rows_ << " tiles (" - << width_px_ << "x" << height_px_ << " px) des de " << yaml_path << '\n'; + Log::info("Tilemap", "{}x{} tiles ({}x{} px) des de {}", cols_, rows_, width_px_, height_px_, yaml_path); } #ifdef _DEBUG diff --git a/source/game/options.cpp b/source/game/options.cpp index 02598bc..3f30ad2 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -12,6 +11,7 @@ #include "core/input/gamepad_manager.hpp" #include "external/fkyaml_node.hpp" #include "utils/defines.hpp" +#include "utils/log.hpp" namespace { @@ -104,7 +104,7 @@ namespace { std::ofstream dst(path + ".bak", std::ios::binary); if (!dst) { return; } dst << src.rdbuf(); - std::cout << "Options: còpia de seguretat a " << path << ".bak\n"; + Log::info("Options", "còpia de seguretat a {}.bak", path); } void parseWindow(const fkyaml::node& yaml) { @@ -463,7 +463,7 @@ namespace { try { auto yaml = fkyaml::node::deserialize(CONTENT); if (!yaml.contains("presets") || !yaml["presets"].is_sequence()) { - std::cout << "Options: " << kind_label << " manca `presets:`; reescrivint amb defaults.\n"; + Log::warn("Options", "{} manca `presets:`; reescrivint amb defaults.", kind_label); backupFile(path); presets = defaults_fn(); return save_fn(); @@ -475,15 +475,15 @@ namespace { presets.push_back(preset); } if (presets.empty()) { - std::cout << "Options: " << kind_label << " sense presets; reescrivint amb defaults.\n"; + Log::warn("Options", "{} sense presets; reescrivint amb defaults.", kind_label); backupFile(path); presets = defaults_fn(); return save_fn(); } return true; } catch (const std::exception& e) { - std::cout << "Options: error parsejant " << kind_label << ": " << e.what() << '\n'; - std::cout << "Options: reescrivint el fitxer amb presets per defecte.\n"; + Log::error("Options", "error parsejant {}: {}", kind_label, e.what()); + Log::info("Options", "reescrivint el fitxer amb presets per defecte."); backupFile(path); presets = defaults_fn(); return save_fn(); @@ -655,8 +655,7 @@ namespace Options { // amb els defaults de la versió nova. El fitxer original queda // a `.bak` per si l'usuari volia preservar tuning manual. if (file_version != Texts::VERSION) { - std::cout << "Options: config.yaml versió \"" << file_version - << "\" != \"" << Texts::VERSION << "\"; reescrivint amb defaults.\n"; + Log::warn("Options", "config.yaml versió \"{}\" != \"{}\"; reescrivint amb defaults.", file_version, Texts::VERSION); backupFile(g_config_file_path); return saveToFile(); } @@ -679,8 +678,8 @@ namespace Options { if (CHANGED) { saveToFile(); } return true; } catch (const std::exception& e) { - std::cout << "Options: error parsejant config.yaml: " << e.what() << '\n'; - std::cout << "Options: reescrivint el fitxer amb defaults.\n"; + Log::error("Options", "error parsejant config.yaml: {}", e.what()); + Log::info("Options", "reescrivint el fitxer amb defaults."); backupFile(g_config_file_path); return saveToFile(); } @@ -843,7 +842,7 @@ namespace Options { const auto IT = std::ranges::find_if(g_crtpi_presets, [](const CrtPiPreset& preset) { return preset.name == g_video.shader.current_crtpi_preset; }); if (IT == g_crtpi_presets.end()) { - std::cout << "Options: preset CrtPi \"" << g_video.shader.current_crtpi_preset << "\" no trobat; aplicant defaults.\n"; + Log::warn("Options", "preset CrtPi \"{}\" no trobat; aplicant defaults.", g_video.shader.current_crtpi_preset); return {}; } return { @@ -871,7 +870,7 @@ namespace Options { const auto IT = std::ranges::find_if(g_postfx_presets, [](const PostFXPreset& preset) { return preset.name == g_video.shader.current_postfx_preset; }); if (IT == g_postfx_presets.end()) { - std::cout << "Options: preset PostFX \"" << g_video.shader.current_postfx_preset << "\" no trobat; aplicant passthrough.\n"; + Log::warn("Options", "preset PostFX \"{}\" no trobat; aplicant passthrough.", g_video.shader.current_postfx_preset); return {}; } return {