refactor(log): migra core/resources i core/system a Log::
- resource_pack.cpp i resource_cache.cpp: tots els std::cerr passen a Log::error. - director.cpp: std::cout/cerr/fprintf → Log::info / error / critical segons severitat. - printWithDots (utils.cpp): ara és un wrapper sobre Log::info que manté l'amplada total (~50 chars) reproduint l'alineació de punts. Els callers pasen el tag sense " : " (ja l'afegeix el logger). - pack_resources: afegit log.cpp i SDL3 al target perquè resource_pack.cpp ara depèn de Log::. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1243b457be
commit
6e99fd0a8b
8 files changed
+51
-44
No files matched your search
@@ -4,10 +4,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <any>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -42,10 +40,11 @@
|
||||
#include "game/scenes/title_scene.hpp"
|
||||
#include "game/ui/service_menu.hpp"
|
||||
#include "utils/defaults.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
Director::Director() {
|
||||
if (!SDL_Init(0)) {
|
||||
std::fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
|
||||
Log::critical("Director", "SDL_Init failed: {}", SDL_GetError());
|
||||
}
|
||||
|
||||
// Sistema de recursos: el pack viu al costat del binari (build/), el
|
||||
@@ -66,7 +65,7 @@ Director::Director() {
|
||||
constexpr bool ENABLE_FALLBACK = false;
|
||||
#endif
|
||||
if (!Resource::Helper::initializeResourceSystem(pack_file, ENABLE_FALLBACK)) {
|
||||
std::fprintf(stderr, "Director: sistema de recursos no disponible; avortem\n");
|
||||
Log::critical("Director", "sistema de recursos no disponible; avortem");
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
@@ -85,7 +84,7 @@ Director::Director() {
|
||||
|
||||
Options::setConfigFile(system_folder_ + "config.yaml");
|
||||
if (!Options::loadFromFile()) {
|
||||
std::cerr << "Director: no s'ha pogut carregar ni desar config.yaml a " << system_folder_ << '\n';
|
||||
Log::error("Director", "no s'ha pogut carregar ni desar config.yaml a {}", system_folder_);
|
||||
}
|
||||
|
||||
// Vinculacions de mando per dispositiu — fitxer aïllat de `config.yaml`
|
||||
@@ -97,12 +96,12 @@ Director::Director() {
|
||||
// es crea amb presets per defecte (off, crt, ntsc).
|
||||
Options::setPostFXFile(system_folder_ + Defaults::Video::POSTFX_FILE);
|
||||
if (!Options::loadPostFXFromFile()) {
|
||||
std::cerr << "Director: no s'ha pogut carregar ni desar postfx.yaml.\n";
|
||||
Log::error("Director", "no s'ha pogut carregar ni desar postfx.yaml.");
|
||||
}
|
||||
// Presets del shader CRT-Pi (shaders/crtpi.yaml).
|
||||
Options::setCrtPiFile(system_folder_ + Defaults::Video::CRTPI_FILE);
|
||||
if (!Options::loadCrtPiFromFile()) {
|
||||
std::cerr << "Director: no s'ha pogut carregar ni desar crtpi.yaml.\n";
|
||||
Log::error("Director", "no s'ha pogut carregar ni desar crtpi.yaml.");
|
||||
}
|
||||
|
||||
// Screen es configura ara (subsystem + finestra + GPU/renderer); la seua
|
||||
@@ -295,8 +294,7 @@ Director::Director() {
|
||||
const auto START = DebugConfig::StartScene::LOGO;
|
||||
const auto STARTING_PLAYERS = DebugConfig::StartingPlayers::BOTH;
|
||||
#endif
|
||||
std::cout << "Director: start_scene=" << DebugConfig::toString(START)
|
||||
<< " starting_players=" << DebugConfig::toString(STARTING_PLAYERS) << '\n';
|
||||
Log::info("Director", "start_scene={} starting_players={}", DebugConfig::toString(START), DebugConfig::toString(STARTING_PLAYERS));
|
||||
|
||||
switch (START) {
|
||||
case DebugConfig::StartScene::LOGO:
|
||||
@@ -351,7 +349,7 @@ void Director::createSystemFolder() {
|
||||
// Subcarpeta per als presets de shaders. std::filesystem és tolerant si ja existeix.
|
||||
std::filesystem::create_directories(system_folder_ + "shaders/", error);
|
||||
if (error) {
|
||||
std::cerr << "Director: no s'ha pogut crear " << system_folder_ << ": " << error.message() << '\n';
|
||||
Log::error("Director", "no s'ha pogut crear {}: {}", system_folder_, error.message());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +431,7 @@ void Director::switchSceneIfRequested() {
|
||||
// l'escena en aquest mateix frame — l'usuari ha cancel·lat l'estat
|
||||
// de joc explícitament i no ens interessa mantenir-ne la sortida.
|
||||
if (auto menu_req = ServiceMenu::get().takePendingSceneRequest(); menu_req.has_value()) {
|
||||
std::cout << "Director: scene transition (menu) → " << toString(menu_req->next) << '\n';
|
||||
Log::info("Director", "scene transition (menu) → {}", toString(menu_req->next));
|
||||
current_scene_ = buildScene(menu_req->next, menu_req->params);
|
||||
return;
|
||||
}
|
||||
@@ -445,10 +443,10 @@ void Director::switchSceneIfRequested() {
|
||||
if (!request.has_value()) { return; }
|
||||
try {
|
||||
const auto& req = std::any_cast<const ExitRequest&>(request);
|
||||
std::cout << "Director: scene transition → " << toString(req.next) << '\n';
|
||||
Log::info("Director", "scene transition → {}", toString(req.next));
|
||||
current_scene_ = buildScene(req.next, req.params);
|
||||
} catch (const std::bad_any_cast&) {
|
||||
std::cerr << "Director: exit_request_ amb tipus inesperat — ignorant\n";
|
||||
Log::error("Director", "exit_request_ amb tipus inesperat — ignorant");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user