refactor: JA_* a namespace Ja:: (estil aee_arcade)
This commit is contained in:
+27
-27
@@ -40,15 +40,15 @@ Audio::Audio() { initSDLAudio(); }
|
||||
|
||||
// Destructor
|
||||
Audio::~Audio() {
|
||||
JA_Quit();
|
||||
Ja::quit();
|
||||
}
|
||||
|
||||
// Método principal
|
||||
void Audio::update() {
|
||||
JA_Update();
|
||||
Ja::update();
|
||||
|
||||
// Sincronizar estado: detectar cuando la música se para (ej. fade-out completado)
|
||||
if (instance && instance->music_.state == MusicState::PLAYING && JA_GetMusicState() != JA_MUSIC_PLAYING) {
|
||||
if (instance && instance->music_.state == MusicState::PLAYING && Ja::getMusicState() != Ja::MusicState::PLAYING) {
|
||||
instance->music_.state = MusicState::STOPPED;
|
||||
}
|
||||
}
|
||||
@@ -72,12 +72,12 @@ void Audio::playMusic(const std::string& name, const int loop, const int crossfa
|
||||
}
|
||||
|
||||
if (crossfade_ms > 0 && music_.state == MusicState::PLAYING) {
|
||||
JA_CrossfadeMusic(resource, crossfade_ms, loop);
|
||||
Ja::crossfadeMusic(resource, crossfade_ms, loop);
|
||||
} else {
|
||||
if (music_.state == MusicState::PLAYING) {
|
||||
JA_StopMusic();
|
||||
Ja::stopMusic();
|
||||
}
|
||||
JA_PlayMusic(resource, loop);
|
||||
Ja::playMusic(resource, loop);
|
||||
}
|
||||
|
||||
music_.name = name;
|
||||
@@ -86,18 +86,18 @@ void Audio::playMusic(const std::string& name, const int loop, const int crossfa
|
||||
}
|
||||
|
||||
// Reproduce la música por puntero (con crossfade opcional)
|
||||
void Audio::playMusic(JA_Music_t* music, const int loop, const int crossfade_ms) {
|
||||
void Audio::playMusic(Ja::Music* music, const int loop, const int crossfade_ms) {
|
||||
if (!music_enabled_ || music == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (crossfade_ms > 0 && music_.state == MusicState::PLAYING) {
|
||||
JA_CrossfadeMusic(music, crossfade_ms, loop);
|
||||
Ja::crossfadeMusic(music, crossfade_ms, loop);
|
||||
} else {
|
||||
if (music_.state == MusicState::PLAYING) {
|
||||
JA_StopMusic();
|
||||
Ja::stopMusic();
|
||||
}
|
||||
JA_PlayMusic(music, loop);
|
||||
Ja::playMusic(music, loop);
|
||||
}
|
||||
|
||||
music_.name.clear(); // nom desconegut quan es passa per punter
|
||||
@@ -108,7 +108,7 @@ void Audio::playMusic(JA_Music_t* music, const int loop, const int crossfade_ms)
|
||||
// Pausa la música
|
||||
void Audio::pauseMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PLAYING) {
|
||||
JA_PauseMusic();
|
||||
Ja::pauseMusic();
|
||||
music_.state = MusicState::PAUSED;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ void Audio::pauseMusic() {
|
||||
// Continua la música pausada
|
||||
void Audio::resumeMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PAUSED) {
|
||||
JA_ResumeMusic();
|
||||
Ja::resumeMusic();
|
||||
music_.state = MusicState::PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ void Audio::resumeMusic() {
|
||||
// Detiene la música
|
||||
void Audio::stopMusic() {
|
||||
if (music_enabled_) {
|
||||
JA_StopMusic();
|
||||
Ja::stopMusic();
|
||||
music_.state = MusicState::STOPPED;
|
||||
}
|
||||
}
|
||||
@@ -132,42 +132,42 @@ void Audio::stopMusic() {
|
||||
// Reproduce un sonido por nombre
|
||||
void Audio::playSound(const std::string& name, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
JA_PlaySound(AudioResource::getSound(name), 0, static_cast<int>(group));
|
||||
Ja::playSound(AudioResource::getSound(name), 0, static_cast<int>(group));
|
||||
}
|
||||
}
|
||||
|
||||
// Reproduce un sonido por puntero directo
|
||||
void Audio::playSound(JA_Sound_t* sound, Group group) const {
|
||||
void Audio::playSound(Ja::Sound* sound, Group group) const {
|
||||
if (sound_enabled_ && sound != nullptr) {
|
||||
JA_PlaySound(sound, 0, static_cast<int>(group));
|
||||
Ja::playSound(sound, 0, static_cast<int>(group));
|
||||
}
|
||||
}
|
||||
|
||||
// Detiene todos los sonidos
|
||||
void Audio::stopAllSounds() const {
|
||||
if (sound_enabled_) {
|
||||
JA_StopChannel(-1);
|
||||
Ja::stopChannel(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// Realiza un fundido de salida de la música
|
||||
void Audio::fadeOutMusic(int milliseconds) const {
|
||||
if (music_enabled_ && getRealMusicState() == MusicState::PLAYING) {
|
||||
JA_FadeOutMusic(milliseconds);
|
||||
Ja::fadeOutMusic(milliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
// Consulta directamente el estado real de la música en jailaudio
|
||||
auto Audio::getRealMusicState() -> MusicState {
|
||||
JA_Music_state ja_state = JA_GetMusicState();
|
||||
Ja::MusicState ja_state = Ja::getMusicState();
|
||||
switch (ja_state) {
|
||||
case JA_MUSIC_PLAYING:
|
||||
case Ja::MusicState::PLAYING:
|
||||
return MusicState::PLAYING;
|
||||
case JA_MUSIC_PAUSED:
|
||||
case Ja::MusicState::PAUSED:
|
||||
return MusicState::PAUSED;
|
||||
case JA_MUSIC_STOPPED:
|
||||
case JA_MUSIC_INVALID:
|
||||
case JA_MUSIC_DISABLED:
|
||||
case Ja::MusicState::STOPPED:
|
||||
case Ja::MusicState::INVALID:
|
||||
case Ja::MusicState::DISABLED:
|
||||
default:
|
||||
return MusicState::STOPPED;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ void Audio::setSoundVolume(float sound_volume, Group group) const {
|
||||
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const bool active = enabled_ && sound_enabled_;
|
||||
const float CONVERTED_VOLUME = active ? sound_volume * Options::audio.volume : 0.0F;
|
||||
JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
Ja::setSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
}
|
||||
|
||||
// Establece el volumen de la música (float 0.0..1.0)
|
||||
@@ -186,7 +186,7 @@ void Audio::setMusicVolume(float music_volume) const {
|
||||
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const bool active = enabled_ && music_enabled_;
|
||||
const float CONVERTED_VOLUME = active ? music_volume * Options::audio.volume : 0.0F;
|
||||
JA_SetMusicVolume(CONVERTED_VOLUME);
|
||||
Ja::setMusicVolume(CONVERTED_VOLUME);
|
||||
}
|
||||
|
||||
// Aplica la configuración
|
||||
@@ -207,7 +207,7 @@ void Audio::initSDLAudio() {
|
||||
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
std::cout << "SDL_AUDIO could not initialize! SDL Error: " << SDL_GetError() << '\n';
|
||||
} else {
|
||||
JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2);
|
||||
Ja::init(FREQUENCY, SDL_AUDIO_S16LE, 2);
|
||||
enable(Options::audio.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para move
|
||||
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
// --- Clase Audio: gestor de audio (singleton) ---
|
||||
// Implementació canònica, byte-idèntica entre projectes.
|
||||
// Els volums es manegen internament com a float 0.0–1.0; la capa de
|
||||
@@ -45,7 +50,7 @@ class Audio {
|
||||
|
||||
// --- Control de música ---
|
||||
void playMusic(const std::string& name, int loop = -1, int crossfade_ms = 0); // Reproducir música por nombre (con crossfade opcional)
|
||||
void playMusic(struct JA_Music_t* music, int loop = -1, int crossfade_ms = 0); // Reproducir música por puntero (con crossfade opcional)
|
||||
void playMusic(Ja::Music* music, int loop = -1, int crossfade_ms = 0); // Reproducir música por puntero (con crossfade opcional)
|
||||
void pauseMusic(); // Pausar reproducción de música
|
||||
void resumeMusic(); // Continua la música pausada
|
||||
void stopMusic(); // Detener completamente la música
|
||||
@@ -53,7 +58,7 @@ class Audio {
|
||||
|
||||
// --- Control de sonidos ---
|
||||
void playSound(const std::string& name, Group group = Group::GAME) const; // Reproducir sonido puntual por nombre
|
||||
void playSound(struct JA_Sound_t* sound, Group group = Group::GAME) const; // Reproducir sonido puntual por puntero
|
||||
void playSound(Ja::Sound* sound, Group group = Group::GAME) const; // Reproducir sonido puntual por puntero
|
||||
void stopAllSounds() const; // Detener todos los sonidos
|
||||
|
||||
// --- Control de volumen (API interna: float 0.0..1.0) ---
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
namespace AudioResource {
|
||||
|
||||
auto getMusic(const std::string& name) -> JA_Music_t* {
|
||||
auto getMusic(const std::string& name) -> Ja::Music* {
|
||||
return Resource::Cache::get()->getMusic(name);
|
||||
}
|
||||
|
||||
auto getSound(const std::string& name) -> JA_Sound_t* {
|
||||
auto getSound(const std::string& name) -> Ja::Sound* {
|
||||
return Resource::Cache::get()->getSound(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// --- Audio Resource Adapter ---
|
||||
// Aquest fitxer exposa una interfície comuna a Audio per obtenir JA_Music_t* /
|
||||
// JA_Sound_t* per nom. Cada projecte la implementa en audio_adapter.cpp
|
||||
// Aquest fitxer exposa una interfície comuna a Audio per obtenir Ja::Music* /
|
||||
// Ja::Sound* per nom. Cada projecte la implementa en audio_adapter.cpp
|
||||
// delegant al seu singleton de recursos (Resource::get(), Resource::Cache::get(),
|
||||
// etc.). Això permet que audio.hpp/audio.cpp siguin idèntics entre projectes.
|
||||
|
||||
#include <string> // Para string
|
||||
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
namespace AudioResource {
|
||||
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*;
|
||||
} // namespace AudioResource
|
||||
|
||||
+571
-653
File diff suppressed because it is too large
Load Diff
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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>&;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace scenes {
|
||||
// 2. Pinta títol, subtítol i número de piràmide segons info::ctx.num_piramide.
|
||||
// 3. Fade-in de paleta.
|
||||
// 4. Mostra ~5s o fins que es polse una tecla.
|
||||
// 5. JA_FadeOutMusic(250) + fade-out de paleta.
|
||||
// 5. Ja::fadeOutMusic(250) + fade-out de paleta.
|
||||
// 6. Retorna nextState=0 per a entrar al ModuleGame.
|
||||
//
|
||||
// Registrat al SceneRegistry amb state_keys 2..5 (els num_piramide on
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace scenes {
|
||||
// previ ("music/final.ogg"). Si l'escena s'arrenca directament (test
|
||||
// amb piramide_inicial=8) no hi ha res que heretar, així que
|
||||
// arranquem la mateixa pista només si no sona res. Inocu en el
|
||||
// flux normal: JA_MUSIC_PLAYING fa que no la tornem a tocar.
|
||||
// flux normal: Ja::MusicState::PLAYING fa que no la tornem a tocar.
|
||||
if (Audio::getRealMusicState() != Audio::MusicState::PLAYING) {
|
||||
playMusic("music/final.ogg");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace scenes {
|
||||
// i pinta un revelat horitzontal (~1.6 s + ~1.6 s de pausa).
|
||||
// 5. "Red pulse": anima els colors 253/254 incrementant el canal R
|
||||
// de 12 a 62 durant ~1 s (+ ~1 s de pausa).
|
||||
// 6. FadeOut + JA_FadeOutMusic(250).
|
||||
// 6. FadeOut + Ja::fadeOutMusic(250).
|
||||
// 7. Retorna nextState=0 per entrar al ModuleGame amb num_piramide=6.
|
||||
//
|
||||
// Registrada al SceneRegistry amb state_key = 6.
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace scenes {
|
||||
void SlidesScene::tick(int delta_ms) {
|
||||
// Skip: qualsevol tecla salta directament al fade final. Per fidelitat
|
||||
// al vell doSlides, el skip NO atura la música explícitament — només
|
||||
// el final natural crida JA_FadeOutMusic (beginFinalFade() distingeix).
|
||||
// el final natural crida Ja::fadeOutMusic (beginFinalFade() distingeix).
|
||||
if (!skip_triggered_ && JI_AnyKey()) {
|
||||
skip_triggered_ = true;
|
||||
if (num_piramide_at_start_ != 7) {
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace scenes {
|
||||
// → FadeOut2 + clear + reset paleta
|
||||
// → Slide3Enter (1600 ms scroll dreta→centre)
|
||||
// → Slide3Hold (4600 ms)
|
||||
// → FadeFinal (JA_FadeOutMusic si num_piramide != 7 + fade paleta)
|
||||
// → FadeFinal (Ja::fadeOutMusic si num_piramide != 7 + fade paleta)
|
||||
// → Done
|
||||
//
|
||||
// Qualsevol tecla salta directament a FadeFinal (sense cortar la música
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace scenes {
|
||||
// .once([this] { JD8_ClearScreen(0); fade_.startFadeTo(pal); })
|
||||
// .step(5000) // espera pura
|
||||
// .step(1000, [this](float p) { /*...*/ }) // animat amb progress
|
||||
// .once([this] { JA_FadeOutMusic(250); });
|
||||
// .once([this] { Ja::fadeOutMusic(250); });
|
||||
//
|
||||
// `tick(delta_ms)` avança el temps. Els passos one-shot s'executen al
|
||||
// moment d'entrar-hi i avancen immediatament. Els passos amb duració
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ auto SDL_AppInit(void** /*appstate*/, int /*argc*/, char* /*argv*/[]) -> SDL_App
|
||||
JG_Init();
|
||||
Screen::init();
|
||||
JD8_Init();
|
||||
Audio::init(); // crida internament JA_Init i aplica Options::audio
|
||||
Audio::init(); // crida internament Ja::init i aplica Options::audio
|
||||
Overlay::init();
|
||||
Menu::init();
|
||||
|
||||
@@ -146,7 +146,7 @@ void SDL_AppQuit(void* /*appstate*/, SDL_AppResult /*result*/) {
|
||||
Overlay::destroy();
|
||||
Resource::Cache::destroy();
|
||||
Resource::List::destroy();
|
||||
Audio::destroy(); // el destructor del singleton crida JA_Quit
|
||||
Audio::destroy(); // el destructor del singleton crida Ja::quit
|
||||
JD8_Quit();
|
||||
Screen::destroy();
|
||||
JG_Finalize();
|
||||
|
||||
Reference in New Issue
Block a user