options: canviat size per zoom i v_sync per vsync

options: moguda la opció de window a la seua seccio
This commit is contained in:
2025-07-23 17:32:14 +02:00
parent 2db2ba420a
commit ca328f5011
6 changed files with 69 additions and 62 deletions

View File

@@ -55,7 +55,7 @@ void toggleIntegerScale() {
// Activa / desactiva el vsync // Activa / desactiva el vsync
void toggleVSync() { void toggleVSync() {
Screen::get()->toggleVSync(); Screen::get()->toggleVSync();
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 14") + " " + boolToOnOff(Options::video.v_sync)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 14") + " " + boolToOnOff(Options::video.vsync)});
} }
// Activa o desactiva los shaders // Activa o desactiva los shaders
@@ -149,14 +149,14 @@ void toggleFullscreen() {
// Reduce el tamaño de la ventana // Reduce el tamaño de la ventana
void decWindowSize() { void decWindowSize() {
if (Screen::get()->decWindowSize()) { if (Screen::get()->decWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
} }
} }
// Aumenta el tamaño de la ventana // Aumenta el tamaño de la ventana
void incWindowSize() { void incWindowSize() {
if (Screen::get()->incWindowSize()) { if (Screen::get()->incWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
} }
} }
@@ -283,7 +283,7 @@ auto checkInputs() -> bool {
// Comprueba el teclado para decrementar el tamaño de la ventana // Comprueba el teclado para decrementar el tamaño de la ventana
if (Input::get()->checkInput(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) {
if (Screen::get()->decWindowSize()) { if (Screen::get()->decWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
} }
return true; return true;
} }
@@ -291,7 +291,7 @@ auto checkInputs() -> bool {
// Comprueba el teclado para incrementar el tamaño de la ventana // Comprueba el teclado para incrementar el tamaño de la ventana
if (Input::get()->checkInput(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) { if (Input::get()->checkInput(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) {
if (Screen::get()->incWindowSize()) { if (Screen::get()->incWindowSize()) {
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
} }
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
#include "options.h" #include "options.h"
#include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_ScaleMode, SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn #include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_ScaleMode, SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
#include <algorithm> // Para clamp, max #include <algorithm> // Para clamp, max
#include <fstream> // Para basic_ostream, operator<<, basic_ostream::operator<<, basic_ofstream, basic_istream, basic_ifstream, ifstream, ofstream #include <fstream> // Para basic_ostream, operator<<, basic_ostream::operator<<, basic_ofstream, basic_istream, basic_ifstream, ifstream, ofstream
#include <utility> // Para swap #include <utility> // Para swap
@@ -105,15 +106,20 @@ auto saveToFile() -> bool {
applyPendingChanges(); applyPendingChanges();
// Opciones de ventana
file << "## WINDOW\n";
file << "\n";
file << "window.zoom=" << window.zoom << "\n";
// Opciones de video // Opciones de video
file << "## VIDEO\n"; file << "## VIDEO\n";
file << "## video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n"; file << "## video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n";
file << "\n"; file << "\n";
file << "window.zoom=" << window.size << "\n";
file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n"; file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n";
file << "video.scale_mode=" << static_cast<int>(video.scale_mode) << "\n"; file << "video.scale_mode=" << static_cast<int>(video.scale_mode) << "\n";
file << "video.v_sync=" << boolToString(video.v_sync) << "\n"; file << "video.vsync=" << boolToString(video.vsync) << "\n";
file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n"; file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n";
file << "video.shaders=" << boolToString(video.shaders) << "\n"; file << "video.shaders=" << boolToString(video.shaders) << "\n";
@@ -168,21 +174,27 @@ auto saveToFile() -> bool {
// Asigna variables a partir de dos cadenas // Asigna variables a partir de dos cadenas
auto set(const std::string &var, const std::string &value) -> bool { auto set(const std::string &var, const std::string &value) -> bool {
// Indicador de éxito en la asignación // Indicador de éxito en la asignación
auto success = true; // Lineas vacias o que empiezan por comentario
if (var.empty() || var.starts_with("#")) {
return false;
}
// Opciones de ventana
if (var == "window.zoom") {
window.zoom = std::stoi(value);
}
// Opciones de video // Opciones de video
if (var == "video.fullscreen") { if (var == "video.fullscreen") {
video.fullscreen = stringToBool(value); video.fullscreen = stringToBool(value);
} else if (var == "window.zoom") {
window.size = std::stoi(value);
} else if (var == "video.scale_mode") { } else if (var == "video.scale_mode") {
video.scale_mode = static_cast<SDL_ScaleMode>(std::stoi(value)); video.scale_mode = static_cast<SDL_ScaleMode>(std::stoi(value));
} else if (var == "video.shaders") { } else if (var == "video.shaders") {
video.shaders = stringToBool(value); video.shaders = stringToBool(value);
} else if (var == "video.integer_scale") { } else if (var == "video.integer_scale") {
video.integer_scale = stringToBool(value); video.integer_scale = stringToBool(value);
} else if (var == "video.v_sync") { } else if (var == "video.vsync") {
video.v_sync = stringToBool(value); video.vsync = stringToBool(value);
} }
// Opciones de audio // Opciones de audio
@@ -248,13 +260,7 @@ auto set(const std::string &var, const std::string &value) -> bool {
controllers.at(1).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value)); controllers.at(1).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value));
} }
// Lineas vacias o que empiezan por comentario return true;
else if (var.empty() || var.starts_with("#")) {
} else {
success = false;
}
return success;
} }
// Asigna el teclado al jugador // Asigna el teclado al jugador

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_ScaleMode #include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_ScaleMode
#include <algorithm> // Para copy #include <algorithm> // Para copy
#include <string> // Para allocator, string #include <string> // Para allocator, string
#include <utility> // Para move #include <utility> // Para move
@@ -32,8 +33,8 @@ struct Difficulty {
// --- Opciones de ventana --- // --- Opciones de ventana ---
struct WindowOptions { struct WindowOptions {
std::string caption; // Texto que aparece en la barra de título de la ventana std::string caption; // Texto que aparece en la barra de título de la ventana
int size{2}; // Valor por el que se multiplica el tamaño de la ventana int zoom{2}; // Valor por el que se multiplica el tamaño de la ventana
int max_size{2}; // Tamaño máximo para que la ventana no sea mayor que la pantalla int max_zoom{2}; // Tamaño máximo para que la ventana no sea mayor que la pantalla
// Constructor por defecto con valores iniciales // Constructor por defecto con valores iniciales
WindowOptions() WindowOptions()
@@ -44,7 +45,7 @@ struct WindowOptions {
struct VideoOptions { struct VideoOptions {
SDL_ScaleMode scale_mode{SDL_ScaleMode::SDL_SCALEMODE_NEAREST}; // Filtro usado para el escalado de la imagen SDL_ScaleMode scale_mode{SDL_ScaleMode::SDL_SCALEMODE_NEAREST}; // Filtro usado para el escalado de la imagen
bool fullscreen{false}; // Indica si se usa pantalla completa bool fullscreen{false}; // Indica si se usa pantalla completa
bool v_sync{true}; // Indica si se usa vsync bool vsync{true}; // Indica si se usa vsync
bool integer_scale{true}; // Indica si se usa escalado entero bool integer_scale{true}; // Indica si se usa escalado entero
bool shaders{false}; // Indica si se usan shaders para los filtros de vídeo bool shaders{false}; // Indica si se usan shaders para los filtros de vídeo
std::string info; // Información sobre el modo de vídeo std::string info; // Información sobre el modo de vídeo

View File

@@ -119,18 +119,18 @@ void Screen::toggleFullscreen() {
// Cambia el tamaño de la ventana // Cambia el tamaño de la ventana
void Screen::setWindowZoom(int zoom) { void Screen::setWindowZoom(int zoom) {
Options::window.size = zoom; Options::window.zoom = zoom;
adjustWindowSize(); adjustWindowSize();
} }
// Reduce el tamaño de la ventana // Reduce el tamaño de la ventana
auto Screen::decWindowSize() -> bool { auto Screen::decWindowSize() -> bool {
if (!Options::video.fullscreen) { if (!Options::video.fullscreen) {
const int PREVIOUS_ZOOM = Options::window.size; const int PREVIOUS_ZOOM = Options::window.zoom;
--Options::window.size; --Options::window.zoom;
Options::window.size = std::max(Options::window.size, 1); Options::window.zoom = std::max(Options::window.zoom, 1);
if (Options::window.size != PREVIOUS_ZOOM) { if (Options::window.zoom != PREVIOUS_ZOOM) {
adjustWindowSize(); adjustWindowSize();
return true; return true;
} }
@@ -142,11 +142,11 @@ auto Screen::decWindowSize() -> bool {
// Aumenta el tamaño de la ventana // Aumenta el tamaño de la ventana
auto Screen::incWindowSize() -> bool { auto Screen::incWindowSize() -> bool {
if (!Options::video.fullscreen) { if (!Options::video.fullscreen) {
const int PREVIOUS_ZOOM = Options::window.size; const int PREVIOUS_ZOOM = Options::window.zoom;
++Options::window.size; ++Options::window.zoom;
Options::window.size = std::min(Options::window.size, Options::window.max_size); Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom);
if (Options::window.size != PREVIOUS_ZOOM) { if (Options::window.zoom != PREVIOUS_ZOOM) {
adjustWindowSize(); adjustWindowSize();
return true; return true;
} }
@@ -241,8 +241,8 @@ void Screen::initShaders() {
void Screen::adjustWindowSize() { void Screen::adjustWindowSize() {
if (!Options::video.fullscreen) { if (!Options::video.fullscreen) {
// 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.zoom;
const int HEIGHT = param.game.height * Options::window.size; const int HEIGHT = param.game.height * Options::window.zoom;
int old_width; int old_width;
int old_height; int old_height;
@@ -307,8 +307,8 @@ auto Screen::initSDLVideo() -> bool {
} }
window_ = SDL_CreateWindow( window_ = SDL_CreateWindow(
Options::window.caption.c_str(), Options::window.caption.c_str(),
param.game.width * Options::window.size, param.game.width * Options::window.zoom,
param.game.height * Options::window.size, param.game.height * Options::window.zoom,
window_flags); window_flags);
if (window_ == nullptr) { if (window_ == nullptr) {
@@ -335,7 +335,7 @@ auto Screen::initSDLVideo() -> bool {
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); 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_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); SDL_SetRenderVSync(renderer_, Options::video.vsync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Video system initialized successfully"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Video system initialized successfully");
return true; return true;
@@ -357,13 +357,13 @@ void Screen::getDisplayInfo() {
const auto *dm = SDL_GetCurrentDisplayMode(displays[0]); const auto *dm = SDL_GetCurrentDisplayMode(displays[0]);
// 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
Options::window.max_size = std::min(dm->w / param.game.width, dm->h / param.game.height); Options::window.max_zoom = std::min(dm->w / param.game.width, dm->h / param.game.height);
Options::window.size = std::min(Options::window.size, Options::window.max_size); Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom);
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego // Muestra información sobre el tamaño de la pantalla y de la ventana de juego
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz", static_cast<int>(dm->w), static_cast<int>(dm->h), static_cast<int>(dm->refresh_rate)); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz", static_cast<int>(dm->w), static_cast<int>(dm->h), static_cast<int>(dm->refresh_rate));
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.size); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.zoom);
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)) + " @ " +
@@ -373,7 +373,7 @@ void Screen::getDisplayInfo() {
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);
// Normaliza los valores de zoom // Normaliza los valores de zoom
Options::window.size = std::min(Options::window.size, MAX_ZOOM); Options::window.zoom = std::min(Options::window.zoom, MAX_ZOOM);
SDL_free(displays); SDL_free(displays);
} }
@@ -393,13 +393,13 @@ void Screen::toggleIntegerScale() {
// Alterna entre activar y desactivar el V-Sync // Alterna entre activar y desactivar el V-Sync
void Screen::toggleVSync() { void Screen::toggleVSync() {
Options::video.v_sync = !Options::video.v_sync; Options::video.vsync = !Options::video.vsync;
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); SDL_SetRenderVSync(renderer_, Options::video.vsync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
} }
// Establece el estado del V-Sync // Establece el estado del V-Sync
void Screen::setVSync(bool enabled) { void Screen::setVSync(bool enabled) {
Options::video.v_sync = enabled; Options::video.vsync = enabled;
SDL_SetRenderVSync(renderer_, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED); SDL_SetRenderVSync(renderer_, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED);
} }
@@ -411,7 +411,7 @@ void Screen::getSingletons() {
// Aplica los valores de las opciones // Aplica los valores de las opciones
void Screen::applySettings() { void Screen::applySettings() {
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); SDL_SetRenderVSync(renderer_, Options::video.vsync ? 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);
setFullscreenMode(); setFullscreenMode();
adjustWindowSize(); adjustWindowSize();

View File

@@ -31,7 +31,7 @@ class Screen {
// --- Configuración de ventana y render --- // --- Configuración de ventana y render ---
void setFullscreenMode(); // Establece el modo de pantalla completa void setFullscreenMode(); // Establece el modo de pantalla completa
void toggleFullscreen(); // Cambia entre pantalla completa y ventana void toggleFullscreen(); // Cambia entre pantalla completa y ventana
void setWindowZoom(int size); // Cambia el tamaño de la ventana void setWindowZoom(int zoom); // Cambia el tamaño de la ventana
auto decWindowSize() -> bool; // Reduce el tamaño de la ventana auto decWindowSize() -> bool; // Reduce el tamaño de la ventana
auto incWindowSize() -> bool; // Aumenta el tamaño de la ventana auto incWindowSize() -> bool; // Aumenta el tamaño de la ventana
void applySettings(); // Aplica los valores de las opciones void applySettings(); // Aplica los valores de las opciones
@@ -51,7 +51,7 @@ class Screen {
void show() { SDL_ShowWindow(window_); } // Muestra la ventana void show() { SDL_ShowWindow(window_); } // Muestra la ventana
void hide() { SDL_HideWindow(window_); } // Oculta la ventana void hide() { SDL_HideWindow(window_); } // Oculta la ventana
void getSingletons(); // Obtiene los punteros a los singletones void getSingletons(); // Obtiene los punteros a los singletones
[[nodiscard]] static auto getVSync() -> bool { return Options::video.v_sync; } // Obtiene el valor de V-Sync [[nodiscard]] static auto getVSync() -> bool { return Options::video.vsync; } // Obtiene el valor de V-Sync
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; } // Obtiene el puntero al texto de Screen [[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; } // Obtiene el puntero al texto de Screen
#ifdef _DEBUG #ifdef _DEBUG

View File

@@ -240,9 +240,9 @@ void ServiceMenu::initializeOptions() {
// --- Video --- // --- Video ---
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] FULLSCREEN"), SettingsGroup::VIDEO, &Options::video.fullscreen)); options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] FULLSCREEN"), SettingsGroup::VIDEO, &Options::video.fullscreen));
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, &Options::window.size, 1, Options::window.max_size, 1)); options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, &Options::window.zoom, 1, Options::window.max_zoom, 1));
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] SHADERS"), SettingsGroup::VIDEO, &Options::video.shaders)); options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] SHADERS"), SettingsGroup::VIDEO, &Options::video.shaders));
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, &Options::video.v_sync)); options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, &Options::video.vsync));
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] INTEGER_SCALE"), SettingsGroup::VIDEO, &Options::video.integer_scale)); options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] INTEGER_SCALE"), SettingsGroup::VIDEO, &Options::video.integer_scale));
// --- Audio --- // --- Audio ---