afegit define NO_AUDIO

renombrat define DEBUG a _DEBUG
This commit is contained in:
2025-07-23 09:24:04 +02:00
parent 921975851a
commit 74c1c096f8
14 changed files with 138 additions and 88 deletions

View File

@@ -83,7 +83,7 @@ set(APP_SOURCES
# Fuentes de librerías de terceros
set(EXTERNAL_SOURCES
source/external/jail_audio.cpp
#source/external/jail_audio.cpp
source/external/jail_shader.cpp
source/external/json.hpp
source/external/gif.cpp
@@ -113,7 +113,10 @@ target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunction-sections -fdata-sections>)
# Definir _DEBUG en modo Debug
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:DEBUG>)
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
# Definir NO_AUDIO en todas las configuraciones
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_AUDIO)
# Configuración específica para cada plataforma
if(WIN32)

View File

@@ -1,9 +1,12 @@
#include "audio.h"
#include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_G...
#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
@@ -23,7 +26,11 @@ auto Audio::get() -> Audio * { return Audio::instance; }
Audio::Audio() { initSDLAudio(); }
// Destructor
Audio::~Audio() { JA_Quit(); }
Audio::~Audio() {
#ifndef NO_AUDIO
JA_Quit();
#endif
}
// Reproduce la música
void Audio::playMusic(const std::string &name, const int loop) {
@@ -31,7 +38,9 @@ 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;
}
}
@@ -39,7 +48,9 @@ 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;
}
}
@@ -47,7 +58,9 @@ void Audio::pauseMusic() {
// Detiene la música
void Audio::stopMusic() {
if (music_enabled_) {
#ifndef NO_AUDIO
JA_StopMusic();
#endif
music_.state = MusicState::STOPPED;
}
}
@@ -55,21 +68,27 @@ 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_) {
#ifndef NO_AUDIO
JA_FadeOutMusic(milliseconds);
#endif
}
}
@@ -77,8 +96,10 @@ void Audio::fadeOutMusic(int milliseconds) const {
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
}
}
@@ -86,8 +107,10 @@ 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
}
}
@@ -106,14 +129,16 @@ 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 {
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_AUDIO: INITIALIZING\n");
JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2);
enable(Options::audio.enabled);
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n");
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully");
}
#else
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system disabled");
#endif
}

View File

@@ -4,6 +4,7 @@
#include <SDL3/SDL.h> // Para SDL_Scancode, SDL_GamepadButton, SDL_LogCategory, SDL_LogInfo, SDL_SetLogPriority, SDL_LogPriority, SDL_Quit
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
#include <unistd.h> // Para getuid
#include <algorithm> // Para min
#include <cerrno> // Para errno, EEXIST, EACCES, ENAMETOOLONG
#include <cstdio> // Para printf, perror
@@ -45,7 +46,7 @@ Director::Director(int argc, std::span<char *> argv) {
#ifdef RECORDING
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
#elif DEBUG
#elif _DEBUG
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
#else // NORMAL GAME
@@ -134,7 +135,7 @@ void Director::loadParams() {
// Carga el fichero de puntuaciones
void Director::loadScoreFile() {
auto manager = std::make_unique<ManageHiScoreTable>(Options::settings.hi_score_table);
#ifdef DEBUG
#ifdef _DEBUG
manager->clear();
#else
if (overrides.clear_hi_score_table) {
@@ -546,7 +547,7 @@ void Director::runGame() {
break;
}
#ifdef DEBUG
#ifdef _DEBUG
constexpr int CURRENT_STAGE = 0;
#else
constexpr int CURRENT_STAGE = 0;

View File

@@ -102,7 +102,7 @@ Uint32 JA_UpdateCallback(void *userdata, SDL_TimerID timerID, Uint32 interval) {
}
void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) {
#ifdef DEBUG
#ifdef _DEBUG
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif

View File

@@ -276,7 +276,7 @@ bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::strin
}
usingOpenGL = true;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Shader system initialized successfully.");
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Shader system initialized successfully");
return true;
}

View File

@@ -350,7 +350,7 @@ auto checkInputs() -> bool {
return true;
}
#ifdef DEBUG
#ifdef _DEBUG
// Debug info
if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) {
Screen::get()->toggleDebugInfo();

View File

@@ -1,6 +1,7 @@
#include "resource.h"
#include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_LogError, SDL_SetRenderDrawColor, SDL_EventType, SDL_PollEvent, SDL_RenderFillRect, SDL_RenderRect, SDLK_ESCAPE, SDL_Event
#include <algorithm> // Para find_if, max
#include <array> // Para array
#include <cstdlib> // Para exit
@@ -9,7 +10,9 @@
#include "asset.h" // Para Asset, AssetType
#include "color.h" // Para Color
#ifndef NO_AUDIO
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_LoadMusic, JA_LoadSound
#endif
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamResource, ParamGame
#include "screen.h" // Para Screen
@@ -38,8 +41,10 @@ Resource::~Resource() { clear(); }
// Vacia todos los vectores de recursos
void Resource::clear() {
#ifndef NO_AUDIO
clearSounds();
clearMusics();
#endif
textures_.clear();
text_files_.clear();
texts_.clear();
@@ -59,8 +64,10 @@ 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
@@ -173,7 +180,9 @@ void Resource::loadSounds() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
#ifndef NO_AUDIO
sounds_.emplace_back(name, JA_LoadSound(l.c_str()));
#endif
printWithDots("Sound : ", name, "[ LOADED ]");
}
}
@@ -187,7 +196,9 @@ void Resource::loadMusics() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
#ifndef NO_AUDIO
musics_.emplace_back(name, JA_LoadMusic(l.c_str()));
#endif
printWithDots("Music : ", name, "[ LOADED ]");
}
}
@@ -338,7 +349,9 @@ 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;
}
}
@@ -349,7 +362,9 @@ 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;
}
}

View File

@@ -1,6 +1,7 @@
#include "screen.h"
#include <SDL3/SDL.h> // Para SDL_SetRenderTarget, SDL_LogCategory, SDL_LogInfo, SDL_RenderTexture, SDL_SetRenderDrawColor, SDL_SetRenderVSync, SDL_GetError, SDL_LogError, SDL_RendererLogicalPresentation, SDL_SetRenderLogicalPresentation, SDL_CreateTexture, SDL_DestroyTexture, SDL_DestroyWindow, SDL_GetTicks, SDL_Quit, SDL_RENDERER_VSYNC_DISABLED, SDL_RenderClear, SDL_CreateRenderer, SDL_CreateWindow, SDL_DestroyRenderer, SDL_DisplayID, SDL_FRect, SDL_GetCurrentDisplayMode, SDL_GetDisplayName, SDL_GetDisplays, SDL_GetRenderTarget, SDL_GetWindowPosition, SDL_GetWindowSize, SDL_Init, SDL_LogWarn, SDL_PixelFormat, SDL_RenderFillRect, SDL_RenderPresent, SDL_SetHint, SDL_SetRenderDrawBlendMode, SDL_SetTextureScaleMode, SDL_SetWindowFullscreen, SDL_SetWindowPosition, SDL_SetWindowSize, SDL_TextureAccess, SDL_free, SDL_BLENDMODE_BLEND, SDL_HINT_RENDER_DRIVER, SDL_INIT_VIDEO, SDL_PRIu32, SDL_ScaleMode, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_OPENGL, SDL_WindowFlags
#include <algorithm> // Para min, max
#include <fstream> // Para basic_ifstream, ifstream
#include <iterator> // Para istreambuf_iterator, operator==
@@ -49,7 +50,7 @@ Screen::Screen()
// Crea el objeto de texto
createText();
#ifdef DEBUG
#ifdef _DEBUG
debug_info_.text = text_;
setDebugInfoEnabled(true);
#endif
@@ -86,7 +87,7 @@ void Screen::render() {
// Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes
void Screen::coreRender() {
fps_.increment();
#ifdef DEBUG
#ifdef _DEBUG
renderInfo();
#endif
renderScreen(); // Renderiza el contenido del game_canvas_
@@ -206,7 +207,7 @@ void Screen::renderShake() {
SDL_SetRenderTarget(renderer_, current_target);
}
}
#ifdef DEBUG
#ifdef _DEBUG
// Muestra información por pantalla
void Screen::renderInfo() {
if (debug_info_.show) {
@@ -267,7 +268,7 @@ void Screen::renderOverlays() {
renderAttenuate();
service_menu_->render();
notifier_->render();
#ifdef DEBUG
#ifdef _DEBUG
renderInfo();
#endif
}
@@ -335,9 +336,8 @@ auto Screen::initSDLVideo() -> bool {
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
// SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL Video initialized successfully.");
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Video system initialized successfully");
return true;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FRect, SDL_HideWindow, SDL_Renderer, SDL_ShowWindow, Uint32, SDL_Texture, SDL_Window
#include <memory> // Para shared_ptr
#include <string> // Para string
@@ -53,7 +54,7 @@ class Screen {
[[nodiscard]] static auto getVSync() -> bool { return Options::video.v_sync; } // Obtiene el valor de V-Sync
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; } // Obtiene el puntero al texto de Screen
#ifdef DEBUG
#ifdef _DEBUG
// --- Debug ---
void toggleDebugInfo() { debug_info_.show = !debug_info_.show; }
void setDebugInfoEnabled(bool value) { debug_info_.show = value; }
@@ -161,7 +162,7 @@ class Screen {
[[nodiscard]] auto isEnabled() const -> bool { return enabled; }
};
#ifdef DEBUG
#ifdef _DEBUG
struct Debug {
std::shared_ptr<Text> text;
bool show = false;
@@ -187,7 +188,7 @@ class Screen {
FlashEffect flash_effect_; // Efecto de flash en pantalla
ShakeEffect shake_effect_; // Efecto de agitar la pantalla
bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada
#ifdef DEBUG
#ifdef _DEBUG
Debug debug_info_; // Información de debug
#endif

View File

@@ -1,6 +1,7 @@
#include "game.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_EventType, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_Event, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
#include <algorithm> // Para max, find_if, clamp, find, min
#include <array> // Para array
#include <cstdlib> // Para rand, size_t
@@ -88,7 +89,7 @@ Game::Game(int player_id, int current_stage, bool demo)
initPaths();
setTotalPower();
#ifdef DEBUG
#ifdef _DEBUG
// Si se empieza en una fase que no es la primera
if (!demo_.enabled) {
for (int i = 0; i < Stage::number; ++i) {
@@ -1120,7 +1121,7 @@ void Game::checkEvents() {
break;
}
#ifdef DEBUG
#ifdef _DEBUG
checkDebugEvents(event);
#endif
GlobalEvents::check(event);
@@ -1685,7 +1686,7 @@ void Game::updateGameStateShowingGetReadyMessage() {
// Actualiza las variables durante el transcurso normal del juego
void Game::updateGameStatePlaying() {
#ifdef DEBUG
#ifdef _DEBUG
if (auto_pop_balloons_) {
Stage::addPower(5);
}
@@ -1818,7 +1819,7 @@ void Game::checkServiceMenu() {
service_menu_was_active_ = service_menu_is_active;
}
#ifdef DEBUG
#ifdef _DEBUG
// Comprueba los eventos en el modo DEBUG
void Game::checkDebugEvents(const SDL_Event &event) {
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {

View File

@@ -1,6 +1,7 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Event, SDL_Renderer, SDL_Texture, Uint64
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
@@ -146,7 +147,7 @@ class Game {
GameState state_ = GameState::FADE_IN; // Estado
std::vector<std::shared_ptr<Player>> players_to_reorder_;
#ifdef DEBUG
#ifdef _DEBUG
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
// Comprueba los eventos en el modo DEBUG

View File

@@ -1,6 +1,7 @@
#include "intro.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderDrawColor, SDL_FRect, SDL_RenderFillRect, SDL_GetRenderTarget, SDL_RenderClear, SDL_RenderRect, SDL_SetRenderTarget, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_PollEvent, SDL_RenderTexture, SDL_TextureAccess, SDLK_A, SDLK_C, SDLK_D, SDLK_F, SDLK_S, SDLK_V, SDLK_X, SDLK_Z, SDL_Event, SDL_EventType, Uint32
#include <algorithm> // Para max
#include <array> // Para array
#include <functional> // Para function
@@ -25,7 +26,7 @@
#include "utils.h"
#include "writer.h" // Para Writer
#ifdef DEBUG
#ifdef _DEBUG
#include <iomanip> // Para operator<<, setfill, setw
#endif
@@ -51,7 +52,7 @@ Intro::Intro()
void Intro::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
#ifdef DEBUG
#ifdef _DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
static Color color_ = param.intro.bg_color;
handleDebugColorKeys(event.key.key, color_);
@@ -536,7 +537,7 @@ void Intro::renderTextRect() {
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
}
#ifdef DEBUG
#ifdef _DEBUG
// Helper functions for color adjustment
void Intro::adjustColorComponent(uint8_t &component, bool increase) {
if (increase && component < 255) {

View File

@@ -2,6 +2,7 @@
#include <SDL3/SDL.h> // Para SDL_Keycode, Uint32, Uint64
#include <stdint.h> // Para uint8_t
#include <memory> // Para unique_ptr
#include <vector> // Para vector
@@ -69,7 +70,7 @@ class Intro {
void renderTexts(); // Dibuja los textos
static void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
void updatePostState(); // Actualiza el estado POST
#ifdef DEBUG
#ifdef _DEBUG
void adjustColorComponent(uint8_t& component, bool increase);
void adjustAllColorComponents(Color& color, bool increase);
void handleDebugColorKeys(SDL_Keycode key, Color& color);

View File

@@ -1,6 +1,7 @@
#include "title.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, Uint32, SDL_EventType
#include <algorithm> // Para find_if
#include <cstddef> // Para size_t
#include <iostream> // Para basic_ostream, basic_ostream::operator<<
@@ -31,7 +32,7 @@
class Texture;
#ifdef DEBUG
#ifdef _DEBUG
#include <iomanip> // Para operator<<, setfill, setw
#endif
@@ -107,7 +108,7 @@ void Title::render() {
void Title::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
#ifdef DEBUG
#ifdef _DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
static Color color_ = param.title.bg_color;
switch (event.key.key) {