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

This commit is contained in:
2026-05-16 14:15:25 +02:00
parent 08f587ffe4
commit 1ce0d9c56c
15 changed files with 645 additions and 719 deletions
+8 -8
View File
@@ -33,7 +33,7 @@ namespace Resource {
}
} // namespace
auto Cache::getMusic(const std::string& name) -> JA_Music_t* {
auto Cache::getMusic(const std::string& name) -> Ja::Music* {
auto it = std::ranges::find_if(musics_, [&](const auto& m) { return m.name == name; });
if (it != musics_.end()) {
return it->music.get();
@@ -42,7 +42,7 @@ namespace Resource {
throw std::runtime_error("Music not found: " + name);
}
auto Cache::getSound(const std::string& name) -> JA_Sound_t* {
auto Cache::getSound(const std::string& name) -> Ja::Sound* {
auto it = std::ranges::find_if(sounds_, [&](const auto& s) { return s.name == name; });
if (it != sounds_.end()) {
return it->sound.get();
@@ -192,12 +192,12 @@ namespace Resource {
std::cerr << "Resource::Cache: no s'ha pogut llegir " << path << '\n';
return;
}
JA_Music_t* music = JA_LoadMusic(bytes.data(), static_cast<Uint32>(bytes.size()), path.c_str());
Ja::Music* music = Ja::loadMusic(bytes.data(), static_cast<Uint32>(bytes.size()), path.c_str());
if (music == nullptr) {
std::cerr << "Resource::Cache: JA_LoadMusic ha fallat per " << path << '\n';
std::cerr << "Resource::Cache: Ja::loadMusic ha fallat per " << path << '\n';
return;
}
musics_.push_back(MusicResource{.name = name, .music = std::unique_ptr<JA_Music_t, MusicDeleter>(music)});
musics_.push_back(MusicResource{.name = name, .music = std::unique_ptr<Ja::Music, MusicDeleter>(music)});
++loaded_count_;
std::cout << " [music ] " << name << '\n';
}
@@ -213,12 +213,12 @@ namespace Resource {
std::cerr << "Resource::Cache: no s'ha pogut llegir " << path << '\n';
return;
}
JA_Sound_t* sound = JA_LoadSound(bytes.data(), static_cast<uint32_t>(bytes.size()));
Ja::Sound* sound = Ja::loadSound(bytes.data(), static_cast<uint32_t>(bytes.size()));
if (sound == nullptr) {
std::cerr << "Resource::Cache: JA_LoadSound ha fallat per " << path << '\n';
std::cerr << "Resource::Cache: Ja::loadSound ha fallat per " << path << '\n';
return;
}
sounds_.push_back(SoundResource{.name = name, .sound = std::unique_ptr<JA_Sound_t, SoundDeleter>(sound)});
sounds_.push_back(SoundResource{.name = name, .sound = std::unique_ptr<Ja::Sound, SoundDeleter>(sound)});
++loaded_count_;
std::cout << " [sound ] " << name << '\n';
}
+2 -2
View File
@@ -27,8 +27,8 @@ namespace Resource {
auto operator=(const Cache&) -> Cache& = delete;
// Getters: throw runtime_error si el nom no existeix al cache.
auto getMusic(const std::string& name) -> JA_Music_t*;
auto getSound(const std::string& name) -> JA_Sound_t*;
auto getMusic(const std::string& name) -> Ja::Music*;
auto getSound(const std::string& name) -> Ja::Sound*;
auto getSurfacePixels(const std::string& name) -> const std::vector<Uint8>&;
auto getPaletteBytes(const std::string& name) -> const std::vector<Uint8>&;
auto getTextFile(const std::string& name) -> const std::vector<uint8_t>&;
+12 -11
View File
@@ -8,38 +8,39 @@
#include <vector>
// Forward declarations to keep this header light.
struct JA_Music_t;
struct JA_Sound_t;
void JA_DeleteMusic(JA_Music_t* music);
void JA_DeleteSound(JA_Sound_t* sound);
namespace Ja {
struct Music;
struct Sound;
void deleteMusic(Music* music);
void deleteSound(Sound* sound);
} // namespace Ja
namespace Resource {
struct MusicDeleter {
void operator()(JA_Music_t* music) const noexcept {
void operator()(Ja::Music* music) const noexcept {
if (music != nullptr) {
JA_DeleteMusic(music);
Ja::deleteMusic(music);
}
}
};
struct SoundDeleter {
void operator()(JA_Sound_t* sound) const noexcept {
void operator()(Ja::Sound* sound) const noexcept {
if (sound != nullptr) {
JA_DeleteSound(sound);
Ja::deleteSound(sound);
}
}
};
struct MusicResource {
std::string name;
std::unique_ptr<JA_Music_t, MusicDeleter> music;
std::unique_ptr<Ja::Music, MusicDeleter> music;
};
struct SoundResource {
std::string name;
std::unique_ptr<JA_Sound_t, SoundDeleter> sound;
std::unique_ptr<Ja::Sound, SoundDeleter> sound;
};
// Una entrada BITMAP descodifica un GIF i emmagatzema els seus