canvi de pc (treballant en Screen::applySettings())

This commit is contained in:
2025-06-21 22:31:19 +02:00
parent 4f81712e3c
commit 9b176a8cc0
7 changed files with 67 additions and 68 deletions

View File

@@ -17,23 +17,7 @@ void Audio::destroy() { delete Audio::instance_; }
Audio *Audio::get() { return Audio::instance_; } Audio *Audio::get() { return Audio::instance_; }
// Constructor // Constructor
Audio::Audio() Audio::Audio() { initSDLAudio(); }
{
// 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");
}
}
// Destructor // Destructor
Audio::~Audio() { JA_Quit(); } Audio::~Audio() { JA_Quit(); }
@@ -134,3 +118,21 @@ void Audio::enable(bool value)
setSoundVolume(enabled_ ? Options::audio.sound.volume : 0); setSoundVolume(enabled_ ? Options::audio.sound.volume : 0);
setMusicVolume(enabled_ ? Options::audio.music.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");
}
}

View File

@@ -71,6 +71,9 @@ private:
bool sound_enabled_ = true; // Estado de los efectos de sonido bool sound_enabled_ = true; // Estado de los efectos de sonido
bool music_enabled_ = true; // Estado de la música bool music_enabled_ = true; // Estado de la música
// --- Inicializa SDL Audio ---
void initSDLAudio();
// --- Patrón Singleton --- // --- Patrón Singleton ---
Audio(); // Constructor privado Audio(); // Constructor privado
~Audio(); // Destructor privado ~Audio(); // Destructor privado

View File

@@ -25,7 +25,7 @@ Input::Input(const std::string &game_controller_db_path)
: game_controller_db_path_(game_controller_db_path) : game_controller_db_path_(game_controller_db_path)
{ {
// Inicializa el subsistema SDL_INIT_GAMEPAD // Inicializa el subsistema SDL_INIT_GAMEPAD
initSDL(); initSDLGamePad();
// Inicializa los vectores // Inicializa los vectores
key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings()); key_bindings_.resize(static_cast<int>(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) if (SDL_WasInit(SDL_INIT_GAMEPAD) != 1)
{ {

View File

@@ -142,7 +142,7 @@ private:
std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt std::string game_controller_db_path_; // Ruta al archivo gamecontrollerdb.txt
// --- Métodos internos --- // --- 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 bool checkAxisInput(InputAction input, int controller_index, bool repeat); // Comprueba el eje del mando
// --- Constructor y destructor --- // --- Constructor y destructor ---

View File

@@ -66,7 +66,6 @@ void Resource::load()
// Restablece el sincronismo vertical a su valor original // Restablece el sincronismo vertical a su valor original
screen->setVSync(vsync); screen->setVSync(vsync);
SDL_Delay(1000);
} }
// Recarga todos los recursos (limpia y vuelve a cargar) // Recarga todos los recursos (limpia y vuelve a cargar)
@@ -486,7 +485,6 @@ void Resource::updateLoadingProgress(std::string name)
updateProgressBar(); updateProgressBar();
renderProgress(); renderProgress();
checkEvents(); checkEvents();
//SDL_Delay(100);
} }
// Inicializa los rectangulos que definen la barra de progreso // Inicializa los rectangulos que definen la barra de progreso

View File

@@ -1,25 +1,25 @@
#include "screen.h" #include "screen.h"
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND #include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL3/SDL_error.h> // Para SDL_GetError #include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DRIVER #include <SDL3/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DRIVER
#include <SDL3/SDL_init.h> // Para SDL_Init, SDL_INIT_VIDEO #include <SDL3/SDL_init.h> // Para SDL_Init, SDL_INIT_VIDEO
#include <SDL3/SDL_log.h> // Para SDL_LogCategory, SDL_LogError, SDL_L... #include <SDL3/SDL_log.h> // Para SDL_LogCategory, SDL_LogError, SDL_L...
#include <SDL3/SDL_pixels.h> // Para SDL_PixelFormat #include <SDL3/SDL_pixels.h> // Para SDL_PixelFormat
#include <SDL3/SDL_surface.h> // Para SDL_ScaleMode #include <SDL3/SDL_surface.h> // Para SDL_ScaleMode
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks #include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <algorithm> // Para min, max #include <algorithm> // Para min, max
#include <fstream> // Para basic_ifstream, ifstream #include <fstream> // Para basic_ifstream, ifstream
#include <iterator> // Para istreambuf_iterator, operator== #include <iterator> // Para istreambuf_iterator, operator==
#include <memory> // Para __shared_ptr_access, shared_ptr #include <memory> // Para __shared_ptr_access, shared_ptr
#include <string> // Para allocator, char_traits, operator+ #include <string> // Para allocator, char_traits, operator+
#include "asset.h" // Para Asset #include "asset.h" // Para Asset
#include "external/jail_shader.h" // Para init, render #include "external/jail_shader.h" // Para init, render
#include "mouse.h" // Para updateCursorVisibility #include "mouse.h" // Para updateCursorVisibility
#include "notifier.h" // Para Notifier #include "notifier.h" // Para Notifier
#include "options.h" // Para Options, options, WindowOptions, Vid... #include "options.h" // Para Options, options, WindowOptions, Vid...
#include "resource.h" // Para Resource #include "resource.h" // Para Resource
#include "ui/service_menu.h" // Para ServiceMenu #include "ui/service_menu.h" // Para ServiceMenu
#include "text.h" // Para Text #include "text.h" // Para Text
// Singleton // Singleton
Screen *Screen::instance_ = nullptr; Screen *Screen::instance_ = nullptr;
@@ -44,7 +44,7 @@ Screen::Screen()
dst_rect_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)}) dst_rect_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)})
{ {
// Arranca SDL VIDEO, crea la ventana y el renderizador // Arranca SDL VIDEO, crea la ventana y el renderizador
initSDL(); initSDLVideo();
// Crea la textura de destino // Crea la textura de destino
game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height); 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 // Inicializa variables
adjustRenderLogicalSize(); adjustRenderLogicalSize();
// Inicializa los shaders
initShaders();
// Crea el objeto de texto // Crea el objeto de texto
createText(); createText();
@@ -63,6 +60,10 @@ Screen::Screen()
debug_info_.text = text_; debug_info_.text = text_;
setDebugInfoEnabled(true); setDebugInfoEnabled(true);
#endif #endif
// Inicializa los shaders
show();
initShaders();
} }
// Destructor // Destructor
@@ -125,12 +126,8 @@ void Screen::renderScreen()
// Establece el modo de video // Establece el modo de video
void Screen::setFullscreenMode(bool mode) void Screen::setFullscreenMode(bool mode)
{ {
// Actualiza las opciones
Options::video.fullscreen = mode; Options::video.fullscreen = mode;
// Configura el modo de pantalla
SDL_SetWindowFullscreen(window_, Options::video.fullscreen); SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
initShaders(); initShaders();
} }
@@ -271,7 +268,6 @@ void Screen::loadShaders()
// Inicializa los shaders // Inicializa los shaders
void Screen::initShaders() void Screen::initShaders()
{ {
show(); // Se ha de ejecutar con la ventana visible
loadShaders(); loadShaders();
shader::init(window_, game_canvas_, shader_source_); shader::init(window_, game_canvas_, shader_source_);
} }
@@ -280,22 +276,22 @@ void Screen::initShaders()
void Screen::adjustWindowSize() void Screen::adjustWindowSize()
{ {
// Establece el nuevo tamaño // Establece el nuevo tamaño
const int WIDTH = param.game.width * Options::window.size; const int WIDTH = param.game.width * Options::window.size;
const int HEIGHT = param.game.height * Options::window.size; const int HEIGHT = param.game.height * Options::window.size;
int old_width, old_height; int old_width, old_height;
SDL_GetWindowSize(window_, &old_width, &old_height); SDL_GetWindowSize(window_, &old_width, &old_height);
int old_pos_x, old_pos_y; int old_pos_x, old_pos_y;
SDL_GetWindowPosition(window_, &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_X = old_pos_x + (old_width - WIDTH) / 2;
const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 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_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
SDL_SetWindowSize(window_, WIDTH, HEIGHT); SDL_SetWindowSize(window_, WIDTH, HEIGHT);
initShaders(); initShaders();
} }
// Renderiza todos los overlays y efectos // Renderiza todos los overlays y efectos
@@ -323,7 +319,7 @@ void Screen::renderAttenuate()
} }
// Arranca SDL VIDEO y crea la ventana // Arranca SDL VIDEO y crea la ventana
bool Screen::initSDL() bool Screen::initSDLVideo()
{ {
// Indicador de éxito // Indicador de éxito
auto success = true; auto success = true;
@@ -405,8 +401,8 @@ void Screen::getDisplayInfo()
static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.size); static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.size);
Options::video.info = std::to_string(static_cast<int>(DM->w)) + "x" + Options::video.info = std::to_string(static_cast<int>(DM->w)) + "x" +
std::to_string(static_cast<int>(DM->h)) + " @ " + std::to_string(static_cast<int>(DM->h)) + " @ " +
std::to_string(static_cast<int>(DM->refresh_rate)) + " Hz"; std::to_string(static_cast<int>(DM->refresh_rate)) + " Hz";
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla // 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); 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_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); 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(); setFullscreenMode();
adjustWindowSize();
} }
// Crea el objeto de texto // Crea el objeto de texto

View File

@@ -197,7 +197,7 @@ private:
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
// --- Métodos internos --- // --- 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 renderFlash(); // Dibuja el efecto de flash en la pantalla
void renderShake(); // Aplica el efecto de agitar la pantalla void renderShake(); // Aplica el efecto de agitar la pantalla
void renderInfo(); // Muestra información por pantalla void renderInfo(); // Muestra información por pantalla