Afinada un poc mes la classe Options

This commit is contained in:
2025-02-23 20:02:55 +01:00
parent 2ee0c70319
commit 5bb5be9c33
4 changed files with 127 additions and 156 deletions

View File

@@ -869,10 +869,10 @@ bool Director::initSDL()
} }
// Crea la ventana // Crea la ventana
options.window.width = options.video.border.enabled ? options.game.width + options.video.border.width * 2 : options.game.width; const auto window_width = options.video.border.enabled ? options.game.width + options.video.border.width * 2 : options.game.width;
options.window.height = options.video.border.enabled ? options.game.height + options.video.border.height * 2 : options.game.height; const auto window_height = options.video.border.enabled ? options.game.height + options.video.border.height * 2 : options.game.height;
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options.window.width, options.window.height, SDL_WINDOW_HIDDEN); window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_HIDDEN);
if (window_ == nullptr) if (window_ == nullptr)
{ {
if (options.console) if (options.console)

View File

@@ -120,16 +120,16 @@ bool saveOptionsToFile(const std::string &file_path)
} }
// Escribe en el fichero // Escribe en el fichero
file << "## VERSION\n";
file << "version=" << options.version << "\n"; file << "version=" << options.version << "\n";
file << "\n## CONTROL\n"; file << "\n## CONTROL\n";
file << "## keys = CURSOR | OPQA | WASD\n";
file << "keys=" << static_cast<int>(options.keys) << "\n"; file << "keys=" << static_cast<int>(options.keys) << "\n";
file << "\n## WINDOW\n";
file << "window.zoom=" << options.window.zoom << "\n";
file << "\n## VIDEO\n"; file << "\n## VIDEO\n";
file << "video.mode=" << options.video.mode << "\n"; file << "video.mode=" << options.video.mode << "\n";
file << "window.zoom=" << options.window.zoom << "\n";
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n"; file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
file << "video.shaders=" << boolToString(options.video.shaders) << "\n"; file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
file << "video.vertical_sync=" << boolToString(options.video.vertical_sync) << "\n"; file << "video.vertical_sync=" << boolToString(options.video.vertical_sync) << "\n";

View File

@@ -6,14 +6,6 @@
#include "utils.h" #include "utils.h"
#include "screen.h" #include "screen.h"
constexpr int DEFAULT_WINDOW_WIDTH = 320; // Ancho de la ventana por defecto
constexpr int DEFAULT_WINDOW_HEIGHT = 240; // Alto de la ventana por defecto
constexpr int DEFAULT_WINDOW_ZOOM = 2; // Zoom de la ventana por defecto
constexpr int DEFAULT_VIDEO_MODE = 0; // Modo de pantalla completa por defecto
constexpr int DEFAULT_BORDER_WIDTH = 32; // Ancho del borde por defecto
constexpr int DEFAULT_BORDER_HEIGHT = 24; // Alto del borde por defecto
constexpr Palette DEFAULT_PALETTE = Palette::ZXSPECTRUM; // Paleta por defecto
// Secciones del programa // Secciones del programa
enum class Section enum class Section
{ {
@@ -60,6 +52,29 @@ enum class ControlScheme
WASD WASD
}; };
// Constantes
constexpr int DEFAULT_GAME_WIDTH = 256; // Ancho de la ventana por defecto
constexpr int DEFAULT_GAME_HEIGHT = 192; // Alto de la ventana por defecto
constexpr int DEFAULT_WINDOW_ZOOM = 2; // Zoom de la ventana por defecto
constexpr int DEFAULT_VIDEO_MODE = 0; // Modo de pantalla completa por defecto
constexpr ScreenFilter DEFAULT_VIDEO_FILTER = ScreenFilter::NEAREST; // Filtro por defecto
constexpr bool DEFAULT_VIDEO_VERTICAL_SYNC = true; // Vsync activado por defecto
constexpr bool DEFAULT_VIDEO_SHADERS = false; // Shaders desactivados por defecto
constexpr bool DEFAULT_VIDEO_INTEGER_SCALE = true; // Escalado entero activado por defecto
constexpr bool DEFAULT_VIDEO_KEEP_ASPECT = true; // Mantener aspecto activado por defecto
constexpr bool DEFAULT_BORDER_ENABLED = true; // Borde activado por defecto
constexpr int DEFAULT_BORDER_WIDTH = 32; // Ancho del borde por defecto
constexpr int DEFAULT_BORDER_HEIGHT = 24; // Alto del borde por defecto
constexpr Palette DEFAULT_PALETTE = Palette::ZXSPECTRUM; // Paleta por defecto
constexpr Section DEFAULT_SECTION = Section::LOGO; // Sección por defecto
constexpr Subsection DEFAULT_SUBSECTION = Subsection::LOGO_TO_INTRO; // Subsección por defecto
constexpr ControlScheme DEFAULT_CONTROL_SCHEME = ControlScheme::CURSOR; // Control por defecto
constexpr NotificationPosition DEFAULT_NOTIFICATION_POSITION = NotificationPosition::UPPER_LEFT; // Posición de las notificaciones por defecto
constexpr bool DEFAULT_NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
const Color DEFAULT_NOTIFICATION_COLOR = Color(48, 48, 48); // Color de las notificaciones por defecto
constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto
constexpr std::string DEFAULT_VERSION = "v1.09"; // Versión por defecto
// Estructura para las opciones de las notificaciones // Estructura para las opciones de las notificaciones
struct OptionsNotification struct OptionsNotification
{ {
@@ -69,36 +84,32 @@ struct OptionsNotification
// Constructor por defecto // Constructor por defecto
OptionsNotification() OptionsNotification()
{ : pos(DEFAULT_NOTIFICATION_POSITION),
pos = NotificationPosition::UPPER_LEFT; sound(DEFAULT_NOTIFICATION_SOUND),
sound = true; color(DEFAULT_NOTIFICATION_COLOR) {}
color = {48, 48, 48};
}
// Constructor // Constructor
OptionsNotification(NotificationPosition p, bool s, Color c) OptionsNotification(NotificationPosition p, bool s, Color c)
{ : pos(p),
pos = p; sound(s),
sound = s; color(c) {}
color = c;
}
// Método que devuelve la posición horizontal // Método que devuelve la posición horizontal
std::string getHorizontalPosition() const std::string getHorizontalPosition() const
{ {
switch (pos) switch (pos)
{ {
case NotificationPosition::UPPER_LEFT: case NotificationPosition::UPPER_LEFT:
case NotificationPosition::MIDDLE_LEFT: case NotificationPosition::MIDDLE_LEFT:
case NotificationPosition::BOTTOM_LEFT: case NotificationPosition::BOTTOM_LEFT:
return "LEFT"; return "LEFT";
case NotificationPosition::UPPER_CENTER: case NotificationPosition::UPPER_CENTER:
case NotificationPosition::BOTTOM_CENTER: case NotificationPosition::BOTTOM_CENTER:
return "CENTER"; return "CENTER";
case NotificationPosition::UPPER_RIGHT: case NotificationPosition::UPPER_RIGHT:
case NotificationPosition::MIDDLE_RIGHT: case NotificationPosition::MIDDLE_RIGHT:
case NotificationPosition::BOTTOM_RIGHT: case NotificationPosition::BOTTOM_RIGHT:
return "RIGHT"; return "RIGHT";
} }
return "UNKNOWN"; return "UNKNOWN";
} }
@@ -108,17 +119,17 @@ struct OptionsNotification
{ {
switch (pos) switch (pos)
{ {
case NotificationPosition::UPPER_LEFT: case NotificationPosition::UPPER_LEFT:
case NotificationPosition::UPPER_CENTER: case NotificationPosition::UPPER_CENTER:
case NotificationPosition::UPPER_RIGHT: case NotificationPosition::UPPER_RIGHT:
return "UPPER"; return "UPPER";
case NotificationPosition::MIDDLE_LEFT: case NotificationPosition::MIDDLE_LEFT:
case NotificationPosition::MIDDLE_RIGHT: case NotificationPosition::MIDDLE_RIGHT:
return "MIDDLE"; return "MIDDLE";
case NotificationPosition::BOTTOM_LEFT: case NotificationPosition::BOTTOM_LEFT:
case NotificationPosition::BOTTOM_CENTER: case NotificationPosition::BOTTOM_CENTER:
case NotificationPosition::BOTTOM_RIGHT: case NotificationPosition::BOTTOM_RIGHT:
return "BOTTOM"; return "BOTTOM";
} }
return "UNKNOWN"; return "UNKNOWN";
} }
@@ -132,17 +143,13 @@ struct SectionState
// Constructor por defecto // Constructor por defecto
SectionState() SectionState()
{ : section(DEFAULT_SECTION),
section = Section::LOGO; subsection(DEFAULT_SUBSECTION) {}
subsection = Subsection::LOGO_TO_INTRO;
}
// Constructor // Constructor
SectionState(Section s, Subsection ss) SectionState(Section s, Subsection ss)
{ : section(s),
section = s; subsection(ss) {}
subsection = ss;
}
}; };
// Estructura para albergar trucos // Estructura para albergar trucos
@@ -164,18 +171,14 @@ struct Cheat
: infinite_lives(CheatState::DISABLED), : infinite_lives(CheatState::DISABLED),
invincible(CheatState::DISABLED), invincible(CheatState::DISABLED),
jail_is_open(CheatState::DISABLED), jail_is_open(CheatState::DISABLED),
alternate_skin(CheatState::DISABLED) alternate_skin(CheatState::DISABLED) {}
{
}
// Constructor // Constructor
Cheat(CheatState il, CheatState i, CheatState je, CheatState as) Cheat(CheatState il, CheatState i, CheatState je, CheatState as)
: infinite_lives(il), : infinite_lives(il),
invincible(i), invincible(i),
jail_is_open(je), jail_is_open(je),
alternate_skin(as) alternate_skin(as) {}
{
}
// Método para comprobar si alguno de los tres primeros trucos está activo // Método para comprobar si alguno de los tres primeros trucos está activo
bool enabled() const bool enabled() const
@@ -195,43 +198,29 @@ struct OptionsStats
// Constructor por defecto // Constructor por defecto
OptionsStats() OptionsStats()
{ : rooms(0),
rooms = 0; items(0),
items = 0; worst_nightmare("") {}
worst_nightmare = "";
}
// Constructor // Constructor
OptionsStats(int r, int i, std::string wn) OptionsStats(int r, int i, std::string wn)
{ : rooms(r),
rooms = r; items(i),
items = i; worst_nightmare(wn) {}
worst_nightmare = wn;
}
}; };
// Estructura con opciones de la pantalla // Estructura con opciones de la ventana
struct OptionsWindows struct OptionsWindow
{ {
int width; // Ancho de la ventana int zoom; // Zoom de la ventana
int height; // Alto de la ventana
int zoom; // Zoom de la ventana
// Constructor por defecto // Constructor por defecto
OptionsWindows() OptionsWindow()
{ : zoom(DEFAULT_WINDOW_ZOOM) {}
width = DEFAULT_WINDOW_WIDTH;
height = DEFAULT_WINDOW_HEIGHT;
zoom = DEFAULT_WINDOW_ZOOM;
}
// Constructor // Constructor
OptionsWindows(int w, int h, int z) OptionsWindow(int z)
{ : zoom(z) {}
width = w;
height = h;
zoom = z;
}
}; };
// Estructura para gestionar el borde de la pantalla // Estructura para gestionar el borde de la pantalla
@@ -243,19 +232,15 @@ struct Border
// Constructor por defecto // Constructor por defecto
Border() Border()
{ : enabled(DEFAULT_BORDER_ENABLED),
enabled = true; width(DEFAULT_BORDER_WIDTH),
width = DEFAULT_BORDER_WIDTH; height(DEFAULT_BORDER_HEIGHT) {}
height = DEFAULT_BORDER_HEIGHT;
}
// Constructor // Constructor
Border(bool e, int w, int h) Border(bool e, int w, int h)
{ : enabled(e),
enabled = e; width(w),
width = w; height(h) {}
height = h;
}
}; };
// Estructura para las opciones de video // Estructura para las opciones de video
@@ -272,50 +257,42 @@ struct OptionsVideo
// Constructor por defecto // Constructor por defecto
OptionsVideo() OptionsVideo()
{ : mode(DEFAULT_VIDEO_MODE),
mode = DEFAULT_VIDEO_MODE; filter(DEFAULT_VIDEO_FILTER),
filter = ScreenFilter::NEAREST; vertical_sync(DEFAULT_VIDEO_VERTICAL_SYNC),
vertical_sync = true; shaders(DEFAULT_VIDEO_SHADERS),
shaders = false; integer_scale(DEFAULT_VIDEO_INTEGER_SCALE),
integer_scale = true; keep_aspect(DEFAULT_VIDEO_KEEP_ASPECT),
keep_aspect = true; border(Border()),
border = Border(); palette(DEFAULT_PALETTE) {}
palette = DEFAULT_PALETTE;
}
// Constructor // Constructor
OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, Palette p) OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, Palette p)
{ : mode(m),
mode = m; filter(f),
filter = f; vertical_sync(vs),
vertical_sync = vs; shaders(s),
shaders = s; integer_scale(is),
integer_scale = is; keep_aspect(ka),
keep_aspect = ka; border(b),
border = b; palette(p) {}
palette = p;
}
}; };
// Estructura para las opciones de juego // Estructura para las opciones de juego
struct OptionsGame struct OptionsGame
{ {
int width; // Ancho de la resolucion nativa del juego int width; // Ancho de la resolucion del juego
int height; // Alto de la resolucion nativa del juego int height; // Alto de la resolucion del juego
// Constructor por defecto // Constructor por defecto
OptionsGame() OptionsGame()
{ : width(DEFAULT_GAME_WIDTH),
width = 320; height(DEFAULT_GAME_HEIGHT) {}
height = 240;
}
// Constructor // Constructor
OptionsGame(int w, int h) OptionsGame(int w, int h)
{ : width(w),
width = w; height(h) {}
height = h;
}
}; };
// Estructura con todas las opciones de configuración del programa // Estructura con todas las opciones de configuración del programa
@@ -328,39 +305,35 @@ struct Options
OptionsVideo video; // Opciones de video OptionsVideo video; // Opciones de video
OptionsStats stats; // Datos con las estadisticas de juego OptionsStats stats; // Datos con las estadisticas de juego
OptionsNotification notifications; // Opciones relativas a las notificaciones; OptionsNotification notifications; // Opciones relativas a las notificaciones;
OptionsWindows window; // Opciones relativas a la ventana OptionsWindow window; // Opciones relativas a la ventana
ControlScheme keys; // Teclas usadas para jugar ControlScheme keys; // Teclas usadas para jugar
SectionState section; // Sección actual del programa SectionState section; // Sección actual del programa
// Constructor por defecto // Constructor por defecto
Options() Options()
{ : version(DEFAULT_VERSION),
version = "v1.07"; console(DEFAULT_CONSOLE),
console = false; cheats(Cheat()),
cheats = Cheat(); game(OptionsGame()),
game = OptionsGame(); video(OptionsVideo()),
video = OptionsVideo(); stats(OptionsStats()),
stats = OptionsStats(); notifications(OptionsNotification()),
notifications = OptionsNotification(); window(OptionsWindow()),
window = OptionsWindows(); keys(DEFAULT_CONTROL_SCHEME),
keys = ControlScheme::CURSOR; section(SectionState()) {}
section = SectionState();
}
// Constructor // Constructor
Options(std::string cv, bool c, Cheat ch, OptionsGame g, OptionsVideo v, OptionsStats s, OptionsNotification n, OptionsWindows sw, ControlScheme k, SectionState sec) Options(std::string cv, bool c, Cheat ch, OptionsGame g, OptionsVideo v, OptionsStats s, OptionsNotification n, OptionsWindow sw, ControlScheme k, SectionState sec)
{ : version(cv),
version = cv; console(c),
console = c; cheats(ch),
cheats = ch; game(g),
game = g; video(v),
video = v; stats(s),
stats = s; notifications(n),
notifications = n; window(sw),
window = sw; keys(k),
keys = k; section(sec) {}
section = sec;
}
}; };
extern Options options; extern Options options;

View File

@@ -208,13 +208,11 @@ void Screen::setVideoMode(int videoMode)
// Actualiza las opciones // Actualiza las opciones
options.video.mode = videoMode; options.video.mode = videoMode;
options.window.width = window_width_;
options.window.height = window_height_;
// Reinicia los shaders // Reinicia los shaders
if (options.video.shaders) if (options.video.shaders)
{ {
const std::string glsl_file = options.window.height == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl"; const std::string glsl_file = window_height_ == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
std::ifstream f(Asset::get()->get(glsl_file).c_str()); std::ifstream f(Asset::get()->get(glsl_file).c_str());
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());