diff --git a/source/director.cpp b/source/director.cpp index c539b06..8f7bb6e 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -99,6 +99,10 @@ void Director::init() bindInputs(); Notifier::init(std::string(), Resource::get()->getText("8bithud")); OnScreenHelp::init(); +#ifdef DEBUG + Screen::get()->initDebugInfo(); + Screen::get()->setDebugInfoEnabled(true); +#endif } // Cierra todo diff --git a/source/jail_audio.cpp b/source/jail_audio.cpp index be55a2f..af6fdb0 100644 --- a/source/jail_audio.cpp +++ b/source/jail_audio.cpp @@ -486,7 +486,7 @@ void JA_StopChannel(const int channel) { if (channels[i].state != JA_CHANNEL_FREE) SDL_DestroyAudioStream(channels[i].stream); - channels[channel].stream = nullptr; + channels[i].stream = nullptr; channels[i].state = JA_CHANNEL_FREE; channels[i].pos = 0; channels[i].sound = NULL; diff --git a/source/screen.cpp b/source/screen.cpp index 50cc818..564080d 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -214,23 +214,21 @@ void Screen::renderShake() SDL_SetRenderTarget(renderer_, current_target); } } - +#ifdef DEBUG // Muestra información por pantalla void Screen::renderInfo() { - if (show_debug_info_ && Resource::get()) + if (debug_info_.show) { - auto text = Resource::get()->getText("smb2"); - // FPS const std::string FPS_TEXT = std::to_string(fps_.lastValue) + " FPS"; - text->writeColored(param.game.width - text->lenght(FPS_TEXT), 0, FPS_TEXT, ORANGE_SOFT_COLOR); + debug_info_.text->writeColored(param.game.width - debug_info_.text->lenght(FPS_TEXT), 0, FPS_TEXT, ORANGE_SOFT_COLOR); // Resolution - text->writeColored(0, 0, options.video.info, ORANGE_SOFT_COLOR); + debug_info_.text->writeColored(0, 0, options.video.info, ORANGE_SOFT_COLOR); } } - +#endif // Carga el contenido del archivo GLSL void Screen::loadShaders() { @@ -285,8 +283,10 @@ void Screen::renderOverlays() renderFlash(); renderAttenuate(); OnScreenHelp::get()->render(); - renderInfo(); Notifier::get()->render(); +#ifdef DEBUG + renderInfo(); +#endif } // Atenua la pantalla diff --git a/source/screen.h b/source/screen.h index 86dd11f..27ace09 100644 --- a/source/screen.h +++ b/source/screen.h @@ -4,18 +4,25 @@ #include // Para SDL_Renderer, SDL_SetRenderLogicalPrese... #include // Para Uint32 #include // Para SDL_Window, SDL_HideWindow, SDL_ShowWindow +#include // Para SDL_LogCategory, SDL_LogError, SDL_L... #include // Para string +#include // Para shared_ptr #include "options.h" // Para Options, VideoOptions, options #include "param.h" // Para Param, ParamGame, param #include "utils.h" // Para Color +#ifdef DEBUG +#include "text.h" +#include "resource.h" +#endif + class Screen { private: // Constantes static constexpr int WINDOWS_DECORATIONS_ = 35; - // Estructuras + // Estructura para gestionar los fotogramas por segundo struct FPS { Uint32 ticks; // Tiempo en milisegundos desde que se comenzó a contar. @@ -44,6 +51,7 @@ private: } }; + // Estructura para gestionar el efecto de flash en la pantalla struct FlashEffect { bool enabled; // Indica si el efecto está activo @@ -63,6 +71,7 @@ private: bool isRendarable() { return enabled && counter < lenght - delay; } }; + // Estructura para agitar la pantalla struct ShakeEffect { int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x @@ -139,7 +148,27 @@ private: return enabled; } }; +#ifdef DEBUG + // Estructura pra mostrar la información de debug + struct Debug + { + std::shared_ptr text = nullptr; // Objeto de texto para escribir + bool show = false; // Indica si se ha de mostrar la informacion por pantalla + void init() + { + if (Resource::get()) + { + text = Resource::get()->getText("smb2"); + if (!text) + { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to retrieve debug_.text object!"); + return; + } + } + } + }; +#endif // [SINGLETON] Objeto privado static Screen *screen_; @@ -156,13 +185,9 @@ private: FlashEffect flash_effect_; // Variable para gestionar el efecto de flash ShakeEffect shake_effect_; // Variable para gestionar el efecto de agitar la pantalla bool attenuate_effect_ = false; // Indica si la pantalla ha de estar atenuada - #ifdef DEBUG - bool show_debug_info_ = true; // Indica si ha de mostrar/ocultar la información de la pantalla -#else - bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla + Debug debug_info_; // Variable para gestionar la informaciçón de debug #endif - // Arranca SDL VIDEO y crea la ventana bool initSDL(); @@ -250,10 +275,12 @@ public: // Activa / desactiva los shaders void toggleShaders() { options.video.shaders = !options.video.shaders; } - +#ifdef DEBUG // Activa / desactiva la información de debug - void toggleDebugInfo() { show_debug_info_ = !show_debug_info_; } - + void toggleDebugInfo() { debug_info_.show = !debug_info_.show; } + void setDebugInfoEnabled(bool value) { debug_info_.show = value; } + void initDebugInfo() { debug_info_.init(); } +#endif // Activa / desactiva el escalado entero void toggleIntegerScale();