eliminat tot el define NO_AUDIO del codi
This commit is contained in:
@@ -108,17 +108,12 @@ set(APP_SOURCES
|
||||
|
||||
# Fuentes de librerías de terceros
|
||||
set(EXTERNAL_SOURCES
|
||||
source/external/jail_audio.cpp
|
||||
source/external/jail_shader.cpp
|
||||
source/external/json.hpp
|
||||
source/external/gif.cpp
|
||||
)
|
||||
|
||||
# Añadir jail_audio.cpp solo si el audio está habilitado
|
||||
if(NOT DISABLE_AUDIO)
|
||||
list(APPEND EXTERNAL_SOURCES source/external/jail_audio.cpp)
|
||||
endif()
|
||||
|
||||
|
||||
# Configuración de SDL3
|
||||
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
|
||||
message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}")
|
||||
@@ -144,16 +139,6 @@ target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunctio
|
||||
# Definir _DEBUG en modo Debug
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
|
||||
|
||||
# Opción para habilitar/deshabilitar audio
|
||||
option(DISABLE_AUDIO "Disable audio system" OFF)
|
||||
|
||||
# Definir NO_AUDIO si la opción está activada
|
||||
if(DISABLE_AUDIO)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_AUDIO)
|
||||
message(STATUS "Audio deshabilitado - NO_AUDIO definido")
|
||||
else()
|
||||
message(STATUS "Audio habilitado")
|
||||
endif()
|
||||
|
||||
# Configuración específica para cada plataforma
|
||||
if(WIN32)
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
#include <algorithm> // Para clamp
|
||||
|
||||
#ifndef NO_AUDIO
|
||||
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
|
||||
#endif
|
||||
#include "options.h" // Para AudioOptions, audio, MusicOptions
|
||||
#include "resource.h" // Para Resource
|
||||
|
||||
@@ -27,9 +25,7 @@ Audio::Audio() { initSDLAudio(); }
|
||||
|
||||
// Destructor
|
||||
Audio::~Audio() {
|
||||
#ifndef NO_AUDIO
|
||||
JA_Quit();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Método principal
|
||||
@@ -43,9 +39,7 @@ void Audio::playMusic(const std::string &name, const int loop) {
|
||||
music_.loop = (loop != 0);
|
||||
|
||||
if (music_enabled_ && music_.state != MusicState::PLAYING) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_PlayMusic(Resource::get()->getMusic(name), loop);
|
||||
#endif
|
||||
music_.state = MusicState::PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -53,9 +47,7 @@ void Audio::playMusic(const std::string &name, const int loop) {
|
||||
// Pausa la música
|
||||
void Audio::pauseMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PLAYING) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_PauseMusic();
|
||||
#endif
|
||||
music_.state = MusicState::PAUSED;
|
||||
}
|
||||
}
|
||||
@@ -63,9 +55,7 @@ void Audio::pauseMusic() {
|
||||
// Continua la música pausada
|
||||
void Audio::resumeMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PAUSED) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_ResumeMusic();
|
||||
#endif
|
||||
music_.state = MusicState::PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -73,9 +63,7 @@ void Audio::resumeMusic() {
|
||||
// Detiene la música
|
||||
void Audio::stopMusic() {
|
||||
if (music_enabled_) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_StopMusic();
|
||||
#endif
|
||||
music_.state = MusicState::STOPPED;
|
||||
}
|
||||
}
|
||||
@@ -83,33 +71,26 @@ void Audio::stopMusic() {
|
||||
// Reproduce un sonido
|
||||
void Audio::playSound(const std::string &name, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Detiene todos los sonidos
|
||||
void Audio::stopAllSounds() const {
|
||||
if (sound_enabled_) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_StopChannel(-1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Realiza un fundido de salida de la música
|
||||
void Audio::fadeOutMusic(int milliseconds) const {
|
||||
if (music_enabled_ && getRealMusicState() == MusicState::PLAYING) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_FadeOutMusic(milliseconds);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Consulta directamente el estado real de la música en jailaudio
|
||||
auto Audio::getRealMusicState() const -> MusicState {
|
||||
#ifndef NO_AUDIO
|
||||
JA_Music_state ja_state = JA_GetMusicState();
|
||||
switch (ja_state) {
|
||||
case JA_MUSIC_PLAYING:
|
||||
@@ -122,19 +103,14 @@ auto Audio::getRealMusicState() const -> MusicState {
|
||||
default:
|
||||
return MusicState::STOPPED;
|
||||
}
|
||||
#else
|
||||
return MusicState::STOPPED;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Establece el volumen de los sonidos
|
||||
void Audio::setSoundVolume(int sound_volume, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
#ifndef NO_AUDIO
|
||||
const float CONVERTED_VOLUME = (sound_volume / 100.0F) * (Options::audio.volume / 100.0F);
|
||||
JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,10 +118,8 @@ void Audio::setSoundVolume(int sound_volume, Group group) const {
|
||||
void Audio::setMusicVolume(int music_volume) const {
|
||||
if (music_enabled_) {
|
||||
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
#ifndef NO_AUDIO
|
||||
const float CONVERTED_VOLUME = (music_volume / 100.0F) * (Options::audio.volume / 100.0F);
|
||||
JA_SetMusicVolume(CONVERTED_VOLUME);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +138,6 @@ void Audio::enable(bool value) {
|
||||
|
||||
// Inicializa SDL Audio
|
||||
void Audio::initSDLAudio() {
|
||||
#ifndef NO_AUDIO
|
||||
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_AUDIO could not initialize! SDL Error: %s", SDL_GetError());
|
||||
} else {
|
||||
@@ -173,7 +146,4 @@ void Audio::initSDLAudio() {
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully");
|
||||
}
|
||||
#else
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system disabled");
|
||||
#endif
|
||||
}
|
||||
@@ -13,9 +13,7 @@
|
||||
#include "asset.h" // Para Asset
|
||||
#include "color.h" // Para Color
|
||||
#include "version.h" // Para Version::APP_NAME y Version::GIT_HASH
|
||||
#ifndef NO_AUDIO
|
||||
#include "external/jail_audio.h" // Para JA_LoadMusic, JA_LoadSound, JA_DeleteMusic, JA_DeleteSound
|
||||
#endif
|
||||
#include "lang.h" // Para getText
|
||||
#include "param.h" // Para Param, param, ParamResource, ParamGame
|
||||
#include "resource_helper.h" // Para ResourceHelper
|
||||
@@ -325,7 +323,6 @@ auto Resource::getDemoData(int index) -> DemoData & {
|
||||
|
||||
auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading sound lazily: %s", name.c_str());
|
||||
#ifndef NO_AUDIO
|
||||
auto sound_list = Asset::get()->getListByType(Asset::Type::SOUND);
|
||||
for (const auto &file : sound_list) {
|
||||
if (getFileName(file) == name) {
|
||||
@@ -333,13 +330,11 @@ auto Resource::loadSoundLazy(const std::string &name) -> JA_Sound_t * {
|
||||
return JA_LoadSound(audio_path.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading music lazily: %s", name.c_str());
|
||||
#ifndef NO_AUDIO
|
||||
auto music_list = Asset::get()->getListByType(Asset::Type::MUSIC);
|
||||
for (const auto &file : music_list) {
|
||||
if (getFileName(file) == name) {
|
||||
@@ -347,7 +342,6 @@ auto Resource::loadMusicLazy(const std::string &name) -> JA_Music_t * {
|
||||
return JA_LoadMusic(audio_path.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -426,10 +420,8 @@ auto Resource::loadAnimationLazy(const std::string &name) -> AnimationsFileBuffe
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void Resource::clear() {
|
||||
#ifndef NO_AUDIO
|
||||
clearSounds();
|
||||
clearMusics();
|
||||
#endif
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
@@ -449,10 +441,8 @@ void Resource::load() {
|
||||
screen->setVSync(false);
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
|
||||
#ifndef NO_AUDIO
|
||||
loadSounds(); // Carga sonidos
|
||||
loadMusics(); // Carga músicas
|
||||
#endif
|
||||
loadTextures(); // Carga texturas
|
||||
loadTextFiles(); // Carga ficheros de texto
|
||||
loadAnimations(); // Carga animaciones
|
||||
@@ -485,12 +475,8 @@ void Resource::loadSounds() {
|
||||
for (const auto &l : list) {
|
||||
auto name = getFileName(l);
|
||||
updateLoadingProgress(name);
|
||||
#ifndef NO_AUDIO
|
||||
std::string audio_path = createTempAudioFile(l, temp_audio_files_);
|
||||
sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str()));
|
||||
#else
|
||||
sounds_.emplace_back(name, nullptr);
|
||||
#endif
|
||||
printWithDots("Sound : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
@@ -504,12 +490,8 @@ void Resource::loadMusics() {
|
||||
for (const auto &l : list) {
|
||||
auto name = getFileName(l);
|
||||
updateLoadingProgress(name);
|
||||
#ifndef NO_AUDIO
|
||||
std::string audio_path = createTempAudioFile(l, temp_audio_files_);
|
||||
musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str()));
|
||||
#else
|
||||
musics_.emplace_back(name, nullptr);
|
||||
#endif
|
||||
printWithDots("Music : ", name, "[ LOADED ]");
|
||||
}
|
||||
}
|
||||
@@ -739,9 +721,7 @@ void Resource::createText() {
|
||||
void Resource::clearSounds() {
|
||||
for (auto &sound : sounds_) {
|
||||
if (sound.sound != nullptr) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_DeleteSound(sound.sound);
|
||||
#endif
|
||||
sound.sound = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -752,9 +732,7 @@ void Resource::clearSounds() {
|
||||
void Resource::clearMusics() {
|
||||
for (auto &music : musics_) {
|
||||
if (music.music != nullptr) {
|
||||
#ifndef NO_AUDIO
|
||||
JA_DeleteMusic(music.music);
|
||||
#endif
|
||||
music.music = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user