forked from jaildesigner-jailgames/jaildoctors_dilemma
Reestructurant la classe Options
This commit is contained in:
@@ -40,8 +40,8 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
: window_(window),
|
||||
renderer_(renderer)
|
||||
{
|
||||
game_canvas_width_ = options.gameWidth;
|
||||
game_canvas_height_ = options.gameHeight;
|
||||
game_canvas_width_ = options.game.width;
|
||||
game_canvas_height_ = options.game.height;
|
||||
notification_logical_width_ = game_canvas_width_;
|
||||
notification_logical_height_ = game_canvas_height_;
|
||||
|
||||
@@ -62,7 +62,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
}
|
||||
|
||||
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
||||
border_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_ + options.borderWidth * 2, game_canvas_height_ + options.borderHeight * 2);
|
||||
border_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_ + options.video.border.width * 2, game_canvas_height_ + options.video.border.height * 2);
|
||||
if (border_canvas_ == nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
@@ -73,7 +73,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
setBorderColor(border_color_);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options.videoMode);
|
||||
setVideoMode(options.video.mode);
|
||||
|
||||
// Muestra la ventana
|
||||
SDL_ShowWindow(window);
|
||||
@@ -87,7 +87,7 @@ Screen::~Screen()
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
void Screen::clean(color_t color)
|
||||
void Screen::clean(Color color)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
@@ -112,7 +112,7 @@ void Screen::render()
|
||||
renderNotifications();
|
||||
|
||||
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
||||
if (options.borderEnabled)
|
||||
if (options.video.border.enabled)
|
||||
{
|
||||
gameCanvasToBorderCanvas();
|
||||
}
|
||||
@@ -134,11 +134,11 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
// Modifica el tamaño de la ventana en función del borde
|
||||
if (options.borderEnabled)
|
||||
if (options.video.border.enabled)
|
||||
{
|
||||
window_width_ = game_canvas_width_ + options.borderWidth * 2;
|
||||
window_height_ = game_canvas_height_ + options.borderHeight * 2;
|
||||
dest_ = {options.borderWidth, options.borderHeight, game_canvas_width_, game_canvas_height_};
|
||||
window_width_ = game_canvas_width_ + options.video.border.width * 2;
|
||||
window_height_ = game_canvas_height_ + options.video.border.height * 2;
|
||||
dest_ = {options.video.border.width, options.video.border.height, game_canvas_width_, game_canvas_height_};
|
||||
}
|
||||
|
||||
else
|
||||
@@ -149,7 +149,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
}
|
||||
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_SetWindowSize(window_, window_width_ * options.windowSize, window_height_ * options.windowSize);
|
||||
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_GetWindowSize(window_, &window_width_, &window_height_);
|
||||
|
||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||
if (options.integerScale)
|
||||
if (options.video.integer_scale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
@@ -177,7 +177,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
dest_.x = (window_width_ - dest_.w) / 2;
|
||||
dest_.y = (window_height_ - dest_.h) / 2;
|
||||
}
|
||||
else if (options.keepAspect)
|
||||
else if (options.video.keep_aspect)
|
||||
{
|
||||
float ratio = (float)game_canvas_width_ / (float)game_canvas_height_;
|
||||
if ((window_width_ - game_canvas_width_) >= (window_height_ - game_canvas_height_))
|
||||
@@ -207,18 +207,18 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_);
|
||||
|
||||
// Actualiza las opciones
|
||||
options.videoMode = videoMode;
|
||||
options.screen.windowWidth = window_width_;
|
||||
options.screen.windowHeight = window_height_;
|
||||
options.video.mode = videoMode;
|
||||
options.window.width = window_width_;
|
||||
options.window.height = window_height_;
|
||||
|
||||
// Reinicia los shaders
|
||||
if (options.shaders)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
const std::string glsl_file = options.screen.windowHeight == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
||||
const std::string glsl_file = options.window.height == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
||||
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
|
||||
if (options.borderEnabled)
|
||||
if (options.video.border.enabled)
|
||||
{
|
||||
shader::init(window_, border_canvas_, source.c_str());
|
||||
}
|
||||
@@ -232,35 +232,35 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::toggleVideoMode()
|
||||
{
|
||||
options.videoMode = (options.videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options.videoMode);
|
||||
options.video.mode = (options.video.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowSize(int size)
|
||||
void Screen::setWindowZoom(int size)
|
||||
{
|
||||
options.windowSize = size;
|
||||
options.window.zoom = size;
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void Screen::decWindowSize()
|
||||
void Screen::decWindowZoom()
|
||||
{
|
||||
--options.windowSize;
|
||||
options.windowSize = std::max(options.windowSize, 1);
|
||||
--options.window.zoom;
|
||||
options.window.zoom = std::max(options.window.zoom, 1);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void Screen::incWindowSize()
|
||||
void Screen::incWindowZoom()
|
||||
{
|
||||
++options.windowSize;
|
||||
options.windowSize = std::min(options.windowSize, 4);
|
||||
++options.window.zoom;
|
||||
options.window.zoom = std::min(options.window.zoom, 4);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Cambia el color del borde
|
||||
void Screen::setBorderColor(color_t color)
|
||||
void Screen::setBorderColor(Color color)
|
||||
{
|
||||
border_color_ = color;
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
@@ -279,33 +279,27 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderWidth(int s)
|
||||
{
|
||||
options.borderWidth = s;
|
||||
options.video.border.width = s;
|
||||
}
|
||||
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderHeight(int s)
|
||||
{
|
||||
options.borderHeight = s;
|
||||
options.video.border.height = s;
|
||||
}
|
||||
|
||||
// Establece si se ha de ver el borde en el modo ventana
|
||||
void Screen::setBorderEnabled(bool value)
|
||||
{
|
||||
options.borderEnabled = value;
|
||||
}
|
||||
void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value; }
|
||||
|
||||
// Cambia entre borde visible y no visible
|
||||
void Screen::toggleBorder()
|
||||
{
|
||||
options.borderEnabled = !options.borderEnabled;
|
||||
options.video.border.enabled = !options.video.border.enabled;
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Activa el fade
|
||||
void Screen::setFade()
|
||||
{
|
||||
fade_ = true;
|
||||
}
|
||||
void Screen::setFade() { fade_ = true; }
|
||||
|
||||
// Comprueba si ha terminado el fade
|
||||
bool Screen::fadeEnded()
|
||||
@@ -367,7 +361,7 @@ void Screen::renderFade()
|
||||
}
|
||||
|
||||
const SDL_Rect rect = {0, 0, game_canvas_width_, game_canvas_height_};
|
||||
color_t color = {0, 0, 0};
|
||||
Color color = {0, 0, 0};
|
||||
const float step = (float)fade_counter_ / (float)fade_lenght_;
|
||||
const int alpha = 0 + (255 - 0) * step;
|
||||
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, alpha);
|
||||
@@ -387,7 +381,7 @@ void Screen::iniSpectrumFade()
|
||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||
for (auto v : vColors)
|
||||
{
|
||||
spectrum_color_.push_back(stringToColor(options.palette, v));
|
||||
spectrum_color_.push_back(stringToColor(options.video.palette, v));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +412,7 @@ void Screen::renderSpectrumFade()
|
||||
const float step = (float)spectrum_fade_counter_ / (float)spectrum_fade_lenght_;
|
||||
const int max = spectrum_color_.size() - 1;
|
||||
const int index = max + (0 - max) * step;
|
||||
const color_t c = spectrum_color_[index];
|
||||
const Color c = spectrum_color_[index];
|
||||
SDL_SetTextureColorMod(game_canvas_, c.r, c.g, c.b);
|
||||
}
|
||||
|
||||
@@ -460,14 +454,14 @@ void Screen::renderPresent()
|
||||
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
if (options.shaders)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
// Aplica shaders y renderiza el contenido
|
||||
shader::render();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.borderEnabled)
|
||||
if (options.video.border.enabled)
|
||||
{
|
||||
SDL_RenderCopy(renderer_, border_canvas_, nullptr, nullptr);
|
||||
}
|
||||
@@ -482,8 +476,8 @@ void Screen::renderPresent()
|
||||
// Cambia el estado de los shaders
|
||||
void Screen::toggleShaders()
|
||||
{
|
||||
options.shaders = !options.shaders;
|
||||
setVideoMode(options.videoMode);
|
||||
options.video.shaders = !options.video.shaders;
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
|
||||
Reference in New Issue
Block a user