diff --git a/source/audio.cpp b/source/audio.cpp index 84b8201..32afe9f 100644 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -17,23 +17,7 @@ void Audio::destroy() { delete Audio::instance_; } Audio *Audio::get() { return Audio::instance_; } // Constructor -Audio::Audio() -{ - // Inicializa SDL - 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(48000, SDL_AUDIO_S16LE, 2); - enable(Options::audio.enabled); - - SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n"); - } -} +Audio::Audio() { initSDLAudio(); } // Destructor Audio::~Audio() { JA_Quit(); } @@ -133,4 +117,22 @@ void Audio::enable(bool value) setSoundVolume(enabled_ ? Options::audio.sound.volume : 0); setMusicVolume(enabled_ ? Options::audio.music.volume : 0); +} + +// Inicializa SDL Audio +void Audio::initSDLAudio() +{ + 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(48000, SDL_AUDIO_S16LE, 2); + enable(Options::audio.enabled); + + SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n"); + } } \ No newline at end of file diff --git a/source/audio.h b/source/audio.h index 8f8f57b..ce5acec 100644 --- a/source/audio.h +++ b/source/audio.h @@ -71,6 +71,9 @@ private: bool sound_enabled_ = true; // Estado de los efectos de sonido bool music_enabled_ = true; // Estado de la música + // --- Inicializa SDL Audio --- + void initSDLAudio(); + // --- Patrón Singleton --- Audio(); // Constructor privado ~Audio(); // Destructor privado diff --git a/source/input.cpp b/source/input.cpp index b4a19ba..b8c1283 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -25,7 +25,7 @@ Input::Input(const std::string &game_controller_db_path) : game_controller_db_path_(game_controller_db_path) { // Inicializa el subsistema SDL_INIT_GAMEPAD - initSDL(); + initSDLGamePad(); // Inicializa los vectores key_bindings_.resize(static_cast(InputAction::SIZE), KeyBindings()); @@ -436,7 +436,7 @@ bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat) } } -void Input::initSDL() +void Input::initSDLGamePad() { if (SDL_WasInit(SDL_INIT_GAMEPAD) != 1) { diff --git a/source/input.h b/source/input.h index 2bf58d2..a3f1142 100644 --- a/source/input.h +++ b/source/input.h @@ -142,7 +142,7 @@ private: std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt // --- Métodos internos --- - void initSDL(); // Inicializa SDL para la gestión de mandos + void initSDLGamePad(); // Inicializa SDL para la gestión de mandos bool checkAxisInput(InputAction input, int controller_index, bool repeat); // Comprueba el eje del mando // --- Constructor y destructor --- diff --git a/source/resource.cpp b/source/resource.cpp index 9e55b91..96ce9a4 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -66,7 +66,6 @@ void Resource::load() // Restablece el sincronismo vertical a su valor original screen->setVSync(vsync); - SDL_Delay(1000); } // Recarga todos los recursos (limpia y vuelve a cargar) @@ -486,7 +485,6 @@ void Resource::updateLoadingProgress(std::string name) updateProgressBar(); renderProgress(); checkEvents(); - //SDL_Delay(100); } // Inicializa los rectangulos que definen la barra de progreso diff --git a/source/screen.cpp b/source/screen.cpp index e045bdc..73b09c8 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -1,25 +1,25 @@ #include "screen.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_SetHint, SDL_HINT_RENDER_DRIVER -#include // Para SDL_Init, SDL_INIT_VIDEO -#include // Para SDL_LogCategory, SDL_LogError, SDL_L... -#include // Para SDL_PixelFormat -#include // Para SDL_ScaleMode -#include // Para SDL_GetTicks -#include // Para min, max -#include // Para basic_ifstream, ifstream -#include // Para istreambuf_iterator, operator== -#include // Para __shared_ptr_access, shared_ptr -#include // Para allocator, char_traits, operator+ -#include "asset.h" // Para Asset -#include "external/jail_shader.h" // Para init, render -#include "mouse.h" // Para updateCursorVisibility -#include "notifier.h" // Para Notifier -#include "options.h" // Para Options, options, WindowOptions, Vid... -#include "resource.h" // Para Resource -#include "ui/service_menu.h" // Para ServiceMenu -#include "text.h" // Para Text +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_GetError +#include // Para SDL_SetHint, SDL_HINT_RENDER_DRIVER +#include // Para SDL_Init, SDL_INIT_VIDEO +#include // Para SDL_LogCategory, SDL_LogError, SDL_L... +#include // Para SDL_PixelFormat +#include // Para SDL_ScaleMode +#include // Para SDL_GetTicks +#include // Para min, max +#include // Para basic_ifstream, ifstream +#include // Para istreambuf_iterator, operator== +#include // Para __shared_ptr_access, shared_ptr +#include // Para allocator, char_traits, operator+ +#include "asset.h" // Para Asset +#include "external/jail_shader.h" // Para init, render +#include "mouse.h" // Para updateCursorVisibility +#include "notifier.h" // Para Notifier +#include "options.h" // Para Options, options, WindowOptions, Vid... +#include "resource.h" // Para Resource +#include "ui/service_menu.h" // Para ServiceMenu +#include "text.h" // Para Text // Singleton Screen *Screen::instance_ = nullptr; @@ -44,7 +44,7 @@ Screen::Screen() dst_rect_(SDL_FRect{0, 0, static_cast(param.game.width), static_cast(param.game.height)}) { // Arranca SDL VIDEO, crea la ventana y el renderizador - initSDL(); + initSDLVideo(); // Crea la textura de destino game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); @@ -53,9 +53,6 @@ Screen::Screen() // Inicializa variables adjustRenderLogicalSize(); - // Inicializa los shaders - initShaders(); - // Crea el objeto de texto createText(); @@ -63,6 +60,10 @@ Screen::Screen() debug_info_.text = text_; setDebugInfoEnabled(true); #endif + + // Inicializa los shaders + show(); + initShaders(); } // Destructor @@ -125,12 +126,8 @@ void Screen::renderScreen() // Establece el modo de video void Screen::setFullscreenMode(bool mode) { - // Actualiza las opciones Options::video.fullscreen = mode; - - // Configura el modo de pantalla SDL_SetWindowFullscreen(window_, Options::video.fullscreen); - initShaders(); } @@ -271,7 +268,6 @@ void Screen::loadShaders() // Inicializa los shaders void Screen::initShaders() { - show(); // Se ha de ejecutar con la ventana visible loadShaders(); shader::init(window_, game_canvas_, shader_source_); } @@ -280,22 +276,22 @@ void Screen::initShaders() void Screen::adjustWindowSize() { // Establece el nuevo tamaño - const int WIDTH = param.game.width * Options::window.size; - const int HEIGHT = param.game.height * Options::window.size; + const int WIDTH = param.game.width * Options::window.size; + const int HEIGHT = param.game.height * Options::window.size; - int old_width, old_height; - SDL_GetWindowSize(window_, &old_width, &old_height); + int old_width, old_height; + SDL_GetWindowSize(window_, &old_width, &old_height); - int old_pos_x, old_pos_y; - SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y); + int old_pos_x, old_pos_y; + SDL_GetWindowPosition(window_, &old_pos_x, &old_pos_y); - const int NEW_POS_X = old_pos_x + (old_width - WIDTH) / 2; - const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2; + const int NEW_POS_X = old_pos_x + (old_width - WIDTH) / 2; + const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2; - SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0)); - SDL_SetWindowSize(window_, WIDTH, HEIGHT); + SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0)); + SDL_SetWindowSize(window_, WIDTH, HEIGHT); - initShaders(); + initShaders(); } // Renderiza todos los overlays y efectos @@ -323,7 +319,7 @@ void Screen::renderAttenuate() } // Arranca SDL VIDEO y crea la ventana -bool Screen::initSDL() +bool Screen::initSDLVideo() { // Indicador de éxito auto success = true; @@ -405,8 +401,8 @@ void Screen::getDisplayInfo() static_cast(param.game.width), static_cast(param.game.height), Options::window.size); Options::video.info = std::to_string(static_cast(DM->w)) + "x" + - std::to_string(static_cast(DM->h)) + " @ " + - std::to_string(static_cast(DM->refresh_rate)) + " Hz"; + std::to_string(static_cast(DM->h)) + " @ " + + std::to_string(static_cast(DM->refresh_rate)) + " Hz"; // Calcula el máximo factor de zoom que se puede aplicar a la pantalla const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height); @@ -451,8 +447,8 @@ void Screen::applySettings() { SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); - adjustWindowSize(); setFullscreenMode(); + adjustWindowSize(); } // Crea el objeto de texto diff --git a/source/screen.h b/source/screen.h index ddc8509..8de09cb 100644 --- a/source/screen.h +++ b/source/screen.h @@ -197,7 +197,7 @@ private: std::shared_ptr text_; // Objeto para escribir texto en pantalla // --- Métodos internos --- - bool initSDL(); // Arranca SDL VIDEO y crea la ventana + bool initSDLVideo(); // Arranca SDL VIDEO y crea la ventana void renderFlash(); // Dibuja el efecto de flash en la pantalla void renderShake(); // Aplica el efecto de agitar la pantalla void renderInfo(); // Muestra información por pantalla