forked from jaildesigner-jailgames/jaildoctors_dilemma
JA VA! Nomes s'havia de fer les coses be i no ser un ansias
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
#include <string> // Para basic_string, char_traits, string
|
||||
#include "asset.h" // Para Asset
|
||||
#include "jail_shader.h" // Para init, render
|
||||
#include "notifier.h" // Para Notify
|
||||
#include "notifier.h" // Para Notify
|
||||
#include "options.h"
|
||||
|
||||
// [SINGLETON]
|
||||
Screen *Screen::screen_ = nullptr;
|
||||
@@ -38,8 +39,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.gameWidth;
|
||||
game_canvas_height_ = options.gameHeight;
|
||||
notification_logical_width_ = game_canvas_width_;
|
||||
notification_logical_height_ = game_canvas_height_;
|
||||
|
||||
@@ -53,17 +54,17 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
game_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_, game_canvas_height_);
|
||||
if (game_canvas_ == nullptr)
|
||||
{
|
||||
if (options_->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "gameCanvas could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.borderWidth * 2, game_canvas_height_ + options.borderHeight * 2);
|
||||
if (border_canvas_ == nullptr)
|
||||
{
|
||||
if (options_->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "borderCanvas could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -71,7 +72,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
setBorderColor(border_color_);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options_->videoMode);
|
||||
setVideoMode(options.videoMode);
|
||||
|
||||
// Muestra la ventana
|
||||
SDL_ShowWindow(window);
|
||||
@@ -110,7 +111,7 @@ void Screen::render()
|
||||
renderNotifications();
|
||||
|
||||
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
||||
if (options_->borderEnabled)
|
||||
if (options.borderEnabled)
|
||||
{
|
||||
gameCanvasToBorderCanvas();
|
||||
}
|
||||
@@ -132,11 +133,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.borderEnabled)
|
||||
{
|
||||
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.borderWidth * 2;
|
||||
window_height_ = game_canvas_height_ + options.borderHeight * 2;
|
||||
dest_ = {options.borderWidth, options.borderHeight, game_canvas_width_, game_canvas_height_};
|
||||
}
|
||||
|
||||
else
|
||||
@@ -147,7 +148,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.windowSize, window_height_ * options.windowSize);
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
|
||||
@@ -161,7 +162,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.integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
@@ -175,7 +176,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.keepAspect)
|
||||
{
|
||||
float ratio = (float)game_canvas_width_ / (float)game_canvas_height_;
|
||||
if ((window_width_ - game_canvas_width_) >= (window_height_ - game_canvas_height_))
|
||||
@@ -205,18 +206,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.videoMode = videoMode;
|
||||
options.screen.windowWidth = window_width_;
|
||||
options.screen.windowHeight = window_height_;
|
||||
|
||||
// Reinicia los shaders
|
||||
if (options_->shaders)
|
||||
if (options.shaders)
|
||||
{
|
||||
const std::string glsl_file = options_->screen.windowHeight == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
||||
const std::string glsl_file = options.screen.windowHeight == 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.borderEnabled)
|
||||
{
|
||||
shader::init(window_, border_canvas_, source.c_str());
|
||||
}
|
||||
@@ -230,30 +231,30 @@ 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.videoMode = (options.videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||
setVideoMode(options.videoMode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowSize(int size)
|
||||
{
|
||||
options_->windowSize = size;
|
||||
options.windowSize = size;
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void Screen::decWindowSize()
|
||||
{
|
||||
--options_->windowSize;
|
||||
options_->windowSize = std::max(options_->windowSize, 1);
|
||||
--options.windowSize;
|
||||
options.windowSize = std::max(options.windowSize, 1);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void Screen::incWindowSize()
|
||||
{
|
||||
++options_->windowSize;
|
||||
options_->windowSize = std::min(options_->windowSize, 4);
|
||||
++options.windowSize;
|
||||
options.windowSize = std::min(options.windowSize, 4);
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
@@ -277,25 +278,25 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderWidth(int s)
|
||||
{
|
||||
options_->borderWidth = s;
|
||||
options.borderWidth = s;
|
||||
}
|
||||
|
||||
// Establece el tamaño del borde
|
||||
void Screen::setBorderHeight(int s)
|
||||
{
|
||||
options_->borderHeight = s;
|
||||
options.borderHeight = s;
|
||||
}
|
||||
|
||||
// Establece si se ha de ver el borde en el modo ventana
|
||||
void Screen::setBorderEnabled(bool value)
|
||||
{
|
||||
options_->borderEnabled = value;
|
||||
options.borderEnabled = value;
|
||||
}
|
||||
|
||||
// Cambia entre borde visible y no visible
|
||||
void Screen::toggleBorder()
|
||||
{
|
||||
options_->borderEnabled = !options_->borderEnabled;
|
||||
options.borderEnabled = !options.borderEnabled;
|
||||
setVideoMode(0);
|
||||
}
|
||||
|
||||
@@ -385,7 +386,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.palette, v));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,14 +474,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.shaders)
|
||||
{
|
||||
// Aplica shaders y renderiza el contenido
|
||||
shader::render();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options_->borderEnabled)
|
||||
if (options.borderEnabled)
|
||||
{
|
||||
SDL_RenderCopy(renderer_, border_canvas_, nullptr, nullptr);
|
||||
}
|
||||
@@ -495,6 +496,6 @@ void Screen::renderPresent()
|
||||
// Cambia el estado de los shaders
|
||||
void Screen::toggleShaders()
|
||||
{
|
||||
options_->shaders = !options_->shaders;
|
||||
setVideoMode(options_->videoMode);
|
||||
options.shaders = !options.shaders;
|
||||
setVideoMode(options.videoMode);
|
||||
}
|
||||
Reference in New Issue
Block a user