refactor: JA_* a namespace Ja:: (estil aee_arcade)

This commit is contained in:
2026-05-14 23:06:41 +02:00
parent da317e707d
commit f047ae1a56
9 changed files with 677 additions and 649 deletions

View File

@@ -9,7 +9,7 @@
#include <stdexcept> // Para runtime_error
#include <utility>
#include "core/audio/jail_audio.hpp" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
#include "core/audio/jail_audio.hpp" // Para Ja::deleteMusic, Ja::deleteSound, JA_Loa...
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/text.hpp" // Para Text, loadTextFile
#include "core/resources/resource_helper.hpp" // Para Helper
@@ -21,8 +21,10 @@
#include "utils/defines.hpp" // Para WINDOW_CAPTION
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
#include "version.h" // Para Version::GIT_HASH
struct JA_Music_t; // lines 17-17
struct JA_Sound_t; // lines 18-18
namespace Ja {
struct Music;
struct Sound;
} // namespace Ja
namespace Resource {
@@ -234,7 +236,7 @@ namespace Resource {
}
// Obtiene el sonido a partir de un nombre
auto Cache::getSound(const std::string& name) -> JA_Sound_t* { // NOLINT(readability-convert-member-functions-to-static)
auto Cache::getSound(const std::string& name) -> Ja::Sound* { // NOLINT(readability-convert-member-functions-to-static)
auto it = std::ranges::find_if(sounds_, [&name](const auto& s) -> bool { return s.name == name; });
if (it != sounds_.end()) {
@@ -246,7 +248,7 @@ namespace Resource {
}
// Obtiene la música a partir de un nombre
auto Cache::getMusic(const std::string& name) -> JA_Music_t* { // NOLINT(readability-convert-member-functions-to-static)
auto Cache::getMusic(const std::string& name) -> Ja::Music* { // NOLINT(readability-convert-member-functions-to-static)
auto it = std::ranges::find_if(musics_, [&name](const auto& m) -> bool { return m.name == name; });
if (it != musics_.end()) {
@@ -398,14 +400,14 @@ namespace Resource {
try {
auto name = getFileName(l);
setCurrentLoading(name);
JA_Sound_t* sound = nullptr;
Ja::Sound* sound = nullptr;
auto audio_data = Helper::loadFile(l);
if (!audio_data.empty()) {
sound = JA_LoadSound(audio_data.data(), static_cast<Uint32>(audio_data.size()));
sound = Ja::loadSound(audio_data.data(), static_cast<Uint32>(audio_data.size()));
}
if (sound == nullptr) {
sound = JA_LoadSound(l.c_str());
sound = Ja::loadSound(l.c_str());
}
if (sound == nullptr) {
throw std::runtime_error("Failed to decode audio file");
@@ -426,14 +428,14 @@ namespace Resource {
try {
auto name = getFileName(l);
setCurrentLoading(name);
JA_Music_t* music = nullptr;
Ja::Music* music = nullptr;
auto audio_data = Helper::loadFile(l);
if (!audio_data.empty()) {
music = JA_LoadMusic(audio_data.data(), static_cast<Uint32>(audio_data.size()));
music = Ja::loadMusic(audio_data.data(), static_cast<Uint32>(audio_data.size()));
}
if (music == nullptr) {
music = JA_LoadMusic(l.c_str());
music = Ja::loadMusic(l.c_str());
}
if (music == nullptr) {
throw std::runtime_error("Failed to decode music file");
@@ -608,10 +610,10 @@ namespace Resource {
// Vacía el vector de sonidos
void Cache::clearSounds() {
// Itera sobre el vector y libera los recursos asociados a cada JA_Sound_t
// Itera sobre el vector y libera los recursos asociados a cada Ja::Sound
for (auto& sound : sounds_) {
if (sound.sound != nullptr) {
JA_DeleteSound(sound.sound);
Ja::deleteSound(sound.sound);
sound.sound = nullptr;
}
}
@@ -620,10 +622,10 @@ namespace Resource {
// Vacía el vector de musicas
void Cache::clearMusics() {
// Itera sobre el vector y libera los recursos asociados a cada JA_Music_t
// Itera sobre el vector y libera los recursos asociados a cada Ja::Music
for (auto& music : musics_) {
if (music.music != nullptr) {
JA_DeleteMusic(music.music);
Ja::deleteMusic(music.music);
music.music = nullptr;
}
}

View File

@@ -16,8 +16,8 @@ namespace Resource {
static void destroy(); // Destrucción singleton
static auto get() -> Cache*; // Acceso al singleton
auto getSound(const std::string& name) -> JA_Sound_t*; // Getters de recursos
auto getMusic(const std::string& name) -> JA_Music_t*;
auto getSound(const std::string& name) -> Ja::Sound*; // Getters de recursos
auto getMusic(const std::string& name) -> Ja::Music*;
auto getSurface(const std::string& name) -> std::shared_ptr<Surface>;
auto getPalette(const std::string& name) -> Palette;
auto getTextFile(const std::string& name) -> std::shared_ptr<Text::File>;

View File

@@ -10,19 +10,21 @@
#include "game/gameplay/room.hpp" // Para Room::Data
// Forward declarations
struct JA_Music_t;
struct JA_Sound_t;
namespace Ja {
struct Music;
struct Sound;
} // namespace Ja
// Estructura para almacenar ficheros de sonido y su nombre
struct SoundResource {
std::string name; // Nombre del sonido
JA_Sound_t* sound{nullptr}; // Objeto con el sonido
std::string name; // Nombre del sonido
Ja::Sound* sound{nullptr}; // Objeto con el sonido
};
// Estructura para almacenar ficheros musicales y su nombre
struct MusicResource {
std::string name; // Nombre de la musica
JA_Music_t* music{nullptr}; // Objeto con la música
std::string name; // Nombre de la musica
Ja::Music* music{nullptr}; // Objeto con la música
};
// Estructura para almacenar objetos Surface y su nombre