refactor(log): migra core/input i core/audio a Log::
- gamepad_manager.cpp (12 logs): connect/disconnect com a info, errors d'open/init com a error, warning per BD no carregada. - key_config.cpp (5 logs): error per arxius malformats, info per al recompte de bindings carregats. - gamepad_bindings.cpp (4 logs): error/info anàleg. - audio_effects.cpp (2 errors de format). - sound_effects_config.cpp (3 logs): warn quan no hi ha presets, error de parse. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6e99fd0a8b
commit
0b708f1515
5 files changed
+30
-41
No files matched your search
@@ -5,10 +5,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core/audio/jail_audio.hpp"
|
#include "core/audio/jail_audio.hpp"
|
||||||
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
namespace AudioEffects {
|
namespace AudioEffects {
|
||||||
|
|
||||||
@@ -46,11 +46,11 @@ namespace AudioEffects {
|
|||||||
} else if (spec.format == SDL_AUDIO_U8) {
|
} else if (spec.format == SDL_AUDIO_U8) {
|
||||||
bytes_per_sample = 1;
|
bytes_per_sample = 1;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "AudioEffects: format de so no suportat (només U8 o S16)\n";
|
Log::error("AudioEffects", "format de so no suportat (només U8 o S16)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (spec.channels < 1 || spec.channels > 2) {
|
if (spec.channels < 1 || spec.channels > 2) {
|
||||||
std::cerr << "AudioEffects: el so ha de ser mono o estèreo\n";
|
Log::error("AudioEffects", "el so ha de ser mono o estèreo");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "core/audio/sound_effects_config.hpp"
|
#include "core/audio/sound_effects_config.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "core/resources/resource_helper.hpp"
|
#include "core/resources/resource_helper.hpp"
|
||||||
#include "external/fkyaml_node.hpp"
|
#include "external/fkyaml_node.hpp"
|
||||||
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ auto SoundEffectsConfig::get() -> SoundEffectsConfig& {
|
|||||||
void SoundEffectsConfig::load(const std::string& file_path) {
|
void SoundEffectsConfig::load(const std::string& file_path) {
|
||||||
auto bytes = Resource::Helper::loadFile(file_path);
|
auto bytes = Resource::Helper::loadFile(file_path);
|
||||||
if (bytes.empty()) {
|
if (bytes.empty()) {
|
||||||
std::cerr << "SoundEffectsConfig: no s'ha pogut obrir " << file_path << " — cap preset d'efecte disponible\n";
|
Log::warn("SoundEffectsConfig", "no s'ha pogut obrir {} — cap preset d'efecte disponible", file_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ void SoundEffectsConfig::load(const std::string& file_path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "SoundEffectsConfig: " << echoes_.size() << " preset(s) d'eco i " << reverbs_.size() << " de reverb des de " << file_path << '\n';
|
Log::info("SoundEffectsConfig", "{} preset(s) d'eco i {} de reverb des de {}", echoes_.size(), reverbs_.size(), file_path);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "SoundEffectsConfig: error parsejant " << file_path << ": " << e.what() << '\n';
|
Log::error("SoundEffectsConfig", "error parsejant {}: {}", file_path, e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "external/fkyaml_node.hpp"
|
#include "external/fkyaml_node.hpp"
|
||||||
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -167,8 +167,7 @@ void GamepadBindings::load(const std::string& file_path) {
|
|||||||
try {
|
try {
|
||||||
auto yaml = fkyaml::node::deserialize(CONTENT);
|
auto yaml = fkyaml::node::deserialize(CONTENT);
|
||||||
if (!yaml.contains("gamepads") || !yaml["gamepads"].is_sequence()) {
|
if (!yaml.contains("gamepads") || !yaml["gamepads"].is_sequence()) {
|
||||||
std::cerr << "GamepadBindings: secció 'gamepads' absent o invàlida a "
|
Log::error("GamepadBindings", "secció 'gamepads' absent o invàlida a {}", file_path);
|
||||||
<< file_path << '\n';
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const auto& entry : yaml["gamepads"]) {
|
for (const auto& entry : yaml["gamepads"]) {
|
||||||
@@ -188,11 +187,9 @@ void GamepadBindings::load(const std::string& file_path) {
|
|||||||
}
|
}
|
||||||
configs_.push_back(std::move(cfg));
|
configs_.push_back(std::move(cfg));
|
||||||
}
|
}
|
||||||
std::cout << "GamepadBindings: " << configs_.size() << " mandos carregats de "
|
Log::info("GamepadBindings", "{} mandos carregats de {}", configs_.size(), file_path);
|
||||||
<< file_path << '\n';
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "GamepadBindings: error parsejant " << file_path << ": "
|
Log::error("GamepadBindings", "error parsejant {}: {}", file_path, e.what());
|
||||||
<< e.what() << '\n';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +212,7 @@ auto GamepadBindings::save() -> bool {
|
|||||||
|
|
||||||
std::ofstream file(file_path_, std::ios::binary);
|
std::ofstream file(file_path_, std::ios::binary);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
std::cerr << "GamepadBindings: no es pot escriure " << file_path_ << '\n';
|
Log::error("GamepadBindings", "no es pot escriure {}", file_path_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
file << out.str();
|
file << out.str();
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "core/input/gamepad_manager.hpp"
|
#include "core/input/gamepad_manager.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "core/locale/locale.hpp"
|
#include "core/locale/locale.hpp"
|
||||||
#include "core/rendering/notification_presets.hpp"
|
#include "core/rendering/notification_presets.hpp"
|
||||||
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -94,8 +94,7 @@ void GamepadManager::addGamepad(SDL_JoystickID jid, bool notify) {
|
|||||||
if (!SDL_IsGamepad(jid)) { return; }
|
if (!SDL_IsGamepad(jid)) { return; }
|
||||||
SDL_Gamepad* pad = SDL_OpenGamepad(jid);
|
SDL_Gamepad* pad = SDL_OpenGamepad(jid);
|
||||||
if (pad == nullptr) {
|
if (pad == nullptr) {
|
||||||
std::cout << "GamepadManager: SDL_OpenGamepad(" << jid
|
Log::error("GamepadManager", "SDL_OpenGamepad({}) ha fallat: {}", jid, SDL_GetError());
|
||||||
<< ") ha fallat: " << SDL_GetError() << '\n';
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string name = uniqueName(prettyName(SDL_GetGamepadName(pad)));
|
std::string name = uniqueName(prettyName(SDL_GetGamepadName(pad)));
|
||||||
@@ -104,8 +103,7 @@ void GamepadManager::addGamepad(SDL_JoystickID jid, bool notify) {
|
|||||||
// reconnexió es resoldrà per nom.
|
// reconnexió es resoldrà per nom.
|
||||||
const char* raw_path = SDL_GetGamepadPath(pad);
|
const char* raw_path = SDL_GetGamepadPath(pad);
|
||||||
std::string path = (raw_path != nullptr) ? raw_path : "";
|
std::string path = (raw_path != nullptr) ? raw_path : "";
|
||||||
std::cout << "GamepadManager: connectat " << name
|
Log::info("GamepadManager", "connectat {}{}", name, path.empty() ? std::string{} : " [" + path + "]");
|
||||||
<< (path.empty() ? "" : " [" + path + "]") << '\n';
|
|
||||||
entries_.push_back(Entry{.pad = pad, .instance_id = jid, .pretty_name = name, .path = path});
|
entries_.push_back(Entry{.pad = pad, .instance_id = jid, .pretty_name = name, .path = path});
|
||||||
|
|
||||||
// Hot-plug: si alguna assignació pendent encaixa amb aquest mando,
|
// Hot-plug: si alguna assignació pendent encaixa amb aquest mando,
|
||||||
@@ -129,7 +127,7 @@ void GamepadManager::removeGamepad(SDL_JoystickID jid) {
|
|||||||
std::string name = std::move(it->pretty_name);
|
std::string name = std::move(it->pretty_name);
|
||||||
SDL_Gamepad* pad = it->pad;
|
SDL_Gamepad* pad = it->pad;
|
||||||
if (pad != nullptr) { SDL_CloseGamepad(pad); }
|
if (pad != nullptr) { SDL_CloseGamepad(pad); }
|
||||||
std::cout << "GamepadManager: desconnectat " << name << '\n';
|
Log::info("GamepadManager", "desconnectat {}", name);
|
||||||
entries_.erase(it);
|
entries_.erase(it);
|
||||||
|
|
||||||
// Qualsevol assignació que apuntava a aquest mando queda amb `pad`
|
// Qualsevol assignació que apuntava a aquest mando queda amb `pad`
|
||||||
@@ -145,8 +143,7 @@ void GamepadManager::removeGamepad(SDL_JoystickID jid) {
|
|||||||
void GamepadManager::init() {
|
void GamepadManager::init() {
|
||||||
if (initialized_) { return; }
|
if (initialized_) { return; }
|
||||||
if (!SDL_InitSubSystem(SDL_INIT_GAMEPAD)) {
|
if (!SDL_InitSubSystem(SDL_INIT_GAMEPAD)) {
|
||||||
std::cout << "GamepadManager: SDL_INIT_GAMEPAD ha fallat: "
|
Log::error("GamepadManager", "SDL_INIT_GAMEPAD ha fallat: {}", SDL_GetError());
|
||||||
<< SDL_GetError() << '\n';
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// `gamecontrollerdb.txt` és opcional. Viu a l'arrel del projecte
|
// `gamecontrollerdb.txt` és opcional. Viu a l'arrel del projecte
|
||||||
@@ -161,10 +158,9 @@ void GamepadManager::init() {
|
|||||||
}
|
}
|
||||||
const int ADDED = SDL_AddGamepadMappingsFromFile(db_path.c_str());
|
const int ADDED = SDL_AddGamepadMappingsFromFile(db_path.c_str());
|
||||||
if (ADDED < 0) {
|
if (ADDED < 0) {
|
||||||
std::cout << "GamepadManager: no s'ha pogut carregar " << db_path
|
Log::warn("GamepadManager", "no s'ha pogut carregar {}: {}", db_path, SDL_GetError());
|
||||||
<< ": " << SDL_GetError() << '\n';
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << "GamepadManager: " << ADDED << " mappings carregats de " << db_path << '\n';
|
Log::info("GamepadManager", "{} mappings carregats de {}", ADDED, db_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -175,7 +171,7 @@ void GamepadManager::init() {
|
|||||||
}
|
}
|
||||||
SDL_free(ids);
|
SDL_free(ids);
|
||||||
}
|
}
|
||||||
std::cout << "GamepadManager: " << entries_.size() << " mando(s) detectat(s) a l'inici\n";
|
Log::info("GamepadManager", "{} mando(s) detectat(s) a l'inici", entries_.size());
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +264,7 @@ void GamepadManager::assignToPlayer(int player_id, const std::string& name, cons
|
|||||||
if (a.pad != nullptr) {
|
if (a.pad != nullptr) {
|
||||||
for (auto& other : assignments_) {
|
for (auto& other : assignments_) {
|
||||||
if (&other != &a && other.pad == a.pad) {
|
if (&other != &a && other.pad == a.pad) {
|
||||||
std::cout << "GamepadManager: mando " << a.name
|
Log::info("GamepadManager", "mando {} reassignat (last-wins)", a.name);
|
||||||
<< " reassignat (last-wins)\n";
|
|
||||||
other.pad = nullptr;
|
other.pad = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,11 +272,9 @@ void GamepadManager::assignToPlayer(int player_id, const std::string& name, cons
|
|||||||
// Traç de l'assignació persistida (vinculada o pendent) perquè quede
|
// Traç de l'assignació persistida (vinculada o pendent) perquè quede
|
||||||
// visible a la consola igual que les autoassignacions.
|
// visible a la consola igual que les autoassignacions.
|
||||||
if (a.pad != nullptr) {
|
if (a.pad != nullptr) {
|
||||||
std::cout << "GamepadManager: assignat " << a.name
|
Log::info("GamepadManager", "assignat {} → P{}", a.name, player_id + 1);
|
||||||
<< " → P" << (player_id + 1) << '\n';
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << "GamepadManager: P" << (player_id + 1) << " pendent ("
|
Log::info("GamepadManager", "P{} pendent ({} no connectat)", player_id + 1, a.name.empty() ? a.path : a.name);
|
||||||
<< (a.name.empty() ? a.path : a.name) << " no connectat)\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,8 +300,7 @@ auto GamepadManager::autoAssignFreeSlots() -> std::vector<AutoAssigned> {
|
|||||||
slot.name = e.pretty_name;
|
slot.name = e.pretty_name;
|
||||||
slot.path = e.path;
|
slot.path = e.path;
|
||||||
assigned.push_back(AutoAssigned{.player_id = pid, .name = e.pretty_name, .path = e.path});
|
assigned.push_back(AutoAssigned{.player_id = pid, .name = e.pretty_name, .path = e.path});
|
||||||
std::cout << "GamepadManager: auto-assigned " << e.pretty_name
|
Log::info("GamepadManager", "auto-assigned {} → P{}", e.pretty_name, pid + 1);
|
||||||
<< " → P" << (pid + 1) << '\n';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "core/input/key_config.hpp"
|
#include "core/input/key_config.hpp"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "core/resources/resource_helper.hpp"
|
#include "core/resources/resource_helper.hpp"
|
||||||
#include "external/fkyaml_node.hpp"
|
#include "external/fkyaml_node.hpp"
|
||||||
|
#include "utils/log.hpp"
|
||||||
|
|
||||||
auto KeyConfig::get() -> KeyConfig& {
|
auto KeyConfig::get() -> KeyConfig& {
|
||||||
static KeyConfig instance_;
|
static KeyConfig instance_;
|
||||||
@@ -15,7 +15,7 @@ auto KeyConfig::get() -> KeyConfig& {
|
|||||||
void KeyConfig::load(const std::string& file_path) {
|
void KeyConfig::load(const std::string& file_path) {
|
||||||
auto bytes = Resource::Helper::loadFile(file_path);
|
auto bytes = Resource::Helper::loadFile(file_path);
|
||||||
if (bytes.empty()) {
|
if (bytes.empty()) {
|
||||||
std::cerr << "KeyConfig: no s'ha pogut obrir " << file_path << '\n';
|
Log::error("KeyConfig", "no s'ha pogut obrir {}", file_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ void KeyConfig::load(const std::string& file_path) {
|
|||||||
const auto* end = begin + bytes.size();
|
const auto* end = begin + bytes.size();
|
||||||
auto yaml = fkyaml::node::deserialize(begin, end);
|
auto yaml = fkyaml::node::deserialize(begin, end);
|
||||||
if (!yaml.contains("keys") || !yaml["keys"].is_sequence()) {
|
if (!yaml.contains("keys") || !yaml["keys"].is_sequence()) {
|
||||||
std::cerr << "KeyConfig: falta la secció 'keys' a " << file_path << '\n';
|
Log::error("KeyConfig", "falta la secció 'keys' a {}", file_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bindings_.clear();
|
bindings_.clear();
|
||||||
@@ -34,14 +34,14 @@ void KeyConfig::load(const std::string& file_path) {
|
|||||||
const auto CODE = entry["code"].get_value<std::string>();
|
const auto CODE = entry["code"].get_value<std::string>();
|
||||||
const SDL_Scancode SC = SDL_GetScancodeFromName(CODE.c_str());
|
const SDL_Scancode SC = SDL_GetScancodeFromName(CODE.c_str());
|
||||||
if (SC == SDL_SCANCODE_UNKNOWN) {
|
if (SC == SDL_SCANCODE_UNKNOWN) {
|
||||||
std::cerr << "KeyConfig: codi SDL desconegut '" << CODE << "' per id '" << ID << "'\n";
|
Log::warn("KeyConfig", "codi SDL desconegut '{}' per id '{}'", CODE, ID);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bindings_[ID] = SC;
|
bindings_[ID] = SC;
|
||||||
}
|
}
|
||||||
std::cout << "KeyConfig: " << bindings_.size() << " bindings des de " << file_path << '\n';
|
Log::info("KeyConfig", "{} bindings des de {}", bindings_.size(), file_path);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "KeyConfig: error parsejant " << file_path << ": " << e.what() << '\n';
|
Log::error("KeyConfig", "error parsejant {}: {}", file_path, e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user