forked from jaildesigner-jailgames/jaildoctors_dilemma
fix: amb shaders no canviava be el mode de vdeo
This commit is contained in:
@@ -676,7 +676,6 @@ void Game::DEMO_init()
|
|||||||
if (mode_ == GameMode::DEMO)
|
if (mode_ == GameMode::DEMO)
|
||||||
{
|
{
|
||||||
demo_ = DemoData(0, 400, 0, {"04.room", "54.room", "20.room", "09.room", "05.room", "11.room", "31.room", "44.room"});
|
demo_ = DemoData(0, 400, 0, {"04.room", "54.room", "20.room", "09.room", "05.room", "11.room", "31.room", "44.room"});
|
||||||
|
|
||||||
current_room_ = demo_.rooms.front();
|
current_room_ = demo_.rooms.front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void initOptions()
|
|||||||
options = Options();
|
options = Options();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
options.section = SectionState(Section::ENDING2, Subsection::NONE);
|
options.section = SectionState(Section::DEMO, Subsection::NONE);
|
||||||
options.console = true;
|
options.console = true;
|
||||||
#else
|
#else
|
||||||
options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO);
|
options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "notifier.h" // Para Notify
|
#include "notifier.h" // Para Notify
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
//#include "surface.h"
|
// #include "surface.h"
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Screen *Screen::screen_ = nullptr;
|
Screen *Screen::screen_ = nullptr;
|
||||||
@@ -58,13 +58,9 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
|||||||
game_texture_ = createTexture(renderer, options.game.width, options.game.height);
|
game_texture_ = createTexture(renderer, options.game.width, options.game.height);
|
||||||
|
|
||||||
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
||||||
border_texture_ = createTexture(renderer,options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
border_texture_ = createTexture(renderer, options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
|
||||||
setBorderColor(border_color_);
|
setBorderColor(border_color_);
|
||||||
|
|
||||||
// Crea la surface donde se pinta el juego
|
|
||||||
//surface_ = std::make_shared<Surface>(nullptr, options.game.width, options.game.height);
|
|
||||||
//surface_->loadPalette(Asset::get()->get("test.gif"));
|
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options.video.mode);
|
setVideoMode(options.video.mode);
|
||||||
|
|
||||||
@@ -89,17 +85,10 @@ void Screen::clean(Color color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
void Screen::start()
|
void Screen::start() { SDL_SetRenderTarget(renderer_, game_texture_); }
|
||||||
{
|
|
||||||
//surface_->clear(surface_->getSurface(), surface_->getTransparentColor());
|
|
||||||
SDL_SetRenderTarget(renderer_, game_texture_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura del borde
|
// Prepara para empezar a dibujar en la textura del borde
|
||||||
void Screen::startDrawOnBorder()
|
void Screen::startDrawOnBorder() { SDL_SetRenderTarget(renderer_, border_texture_); }
|
||||||
{
|
|
||||||
SDL_SetRenderTarget(renderer_, border_texture_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
void Screen::render()
|
void Screen::render()
|
||||||
@@ -107,10 +96,6 @@ void Screen::render()
|
|||||||
// Renderiza sobre gameCanvas los overlays
|
// Renderiza sobre gameCanvas los overlays
|
||||||
renderNotifications();
|
renderNotifications();
|
||||||
|
|
||||||
//fillTextureWithColor(renderer_, surface_texture_, 0xFF, 0x00, 0xFF, 0xFF);
|
|
||||||
//surface_->copyToTexture(renderer_, surface_texture_);
|
|
||||||
//SDL_RenderCopy(renderer_, surface_texture_, nullptr, nullptr);
|
|
||||||
|
|
||||||
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
||||||
if (options.video.border.enabled)
|
if (options.video.border.enabled)
|
||||||
{
|
{
|
||||||
@@ -135,52 +120,22 @@ void Screen::renderWithoutNotifier()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
void Screen::setVideoMode(int videoMode)
|
void Screen::setVideoMode(int video_mode)
|
||||||
{
|
{
|
||||||
// Aplica el modo de video
|
|
||||||
|
|
||||||
// Modo ventana
|
|
||||||
if (videoMode == 0)
|
|
||||||
{
|
|
||||||
// Muestra el puntero
|
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
|
||||||
|
|
||||||
SDL_SetWindowFullscreen(window_, videoMode);
|
|
||||||
adjustWindowSize();
|
|
||||||
adjustGameCanvasRect();
|
|
||||||
adjustRenderLogicalSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modo pantalla completa
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Oculta el puntero
|
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
|
||||||
adjustWindowSize();
|
|
||||||
|
|
||||||
adjustGameCanvasRect();
|
|
||||||
SDL_SetWindowFullscreen(window_, videoMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las opciones
|
// Actualiza las opciones
|
||||||
options.video.mode = videoMode;
|
options.video.mode = video_mode;
|
||||||
|
|
||||||
|
// Mostrar u ocultar el cursor según el modo
|
||||||
|
SDL_ShowCursor(options.video.mode == 0 ? SDL_ENABLE : SDL_DISABLE);
|
||||||
|
|
||||||
|
// Configura el modo de pantalla y ajusta la ventana
|
||||||
|
SDL_SetWindowFullscreen(window_, options.video.mode);
|
||||||
|
adjustWindowSize();
|
||||||
|
adjustGameCanvasRect();
|
||||||
|
adjustRenderLogicalSize();
|
||||||
|
|
||||||
// Reinicia los shaders
|
// Reinicia los shaders
|
||||||
if (options.video.shaders)
|
resetShaders();
|
||||||
{
|
|
||||||
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::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
|
||||||
|
|
||||||
if (options.video.border.enabled)
|
|
||||||
{
|
|
||||||
shader::init(window_, border_texture_, source.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
shader::init(window_, game_texture_, source.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
// Camibia entre pantalla completa y ventana
|
||||||
@@ -195,13 +150,13 @@ bool Screen::decWindowZoom()
|
|||||||
{
|
{
|
||||||
if (options.video.mode == 0)
|
if (options.video.mode == 0)
|
||||||
{
|
{
|
||||||
int previous_zoom = options.window.zoom;
|
const int PREVIOUS_ZOOM = options.window.zoom;
|
||||||
--options.window.zoom;
|
--options.window.zoom;
|
||||||
options.window.zoom = std::max(options.window.zoom, 1);
|
options.window.zoom = std::max(options.window.zoom, 1);
|
||||||
|
|
||||||
if (options.window.zoom != previous_zoom)
|
if (options.window.zoom != PREVIOUS_ZOOM)
|
||||||
{
|
{
|
||||||
adjustWindowSize();
|
setVideoMode(options.video.mode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,13 +169,13 @@ bool Screen::incWindowZoom()
|
|||||||
{
|
{
|
||||||
if (options.video.mode == 0)
|
if (options.video.mode == 0)
|
||||||
{
|
{
|
||||||
int previous_zoom = options.window.zoom;
|
const int PREVIOUS_ZOOM = options.window.zoom;
|
||||||
++options.window.zoom;
|
++options.window.zoom;
|
||||||
options.window.zoom = std::min(options.window.zoom, options.window.max_zoom);
|
options.window.zoom = std::min(options.window.zoom, options.window.max_zoom);
|
||||||
|
|
||||||
if (options.window.zoom != previous_zoom)
|
if (options.window.zoom != PREVIOUS_ZOOM)
|
||||||
{
|
{
|
||||||
adjustWindowSize();
|
setVideoMode(options.video.mode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,22 +195,13 @@ void Screen::setBorderColor(Color color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
// Cambia el tipo de mezcla
|
||||||
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
void Screen::setBlendMode(SDL_BlendMode blendMode) { SDL_SetRenderDrawBlendMode(renderer_, blendMode); }
|
||||||
{
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer_, blendMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tamaño del borde
|
// Establece el tamaño del borde
|
||||||
void Screen::setBorderWidth(int s)
|
void Screen::setBorderWidth(int s) { options.video.border.width = s; }
|
||||||
{
|
|
||||||
options.video.border.width = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tamaño del borde
|
// Establece el tamaño del borde
|
||||||
void Screen::setBorderHeight(int s)
|
void Screen::setBorderHeight(int s) { options.video.border.height = s; }
|
||||||
{
|
|
||||||
options.video.border.height = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si se ha de ver el borde en el modo ventana
|
// Establece si se ha de ver el borde en el modo ventana
|
||||||
void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value; }
|
void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value; }
|
||||||
@@ -264,16 +210,11 @@ void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value
|
|||||||
void Screen::toggleBorder()
|
void Screen::toggleBorder()
|
||||||
{
|
{
|
||||||
options.video.border.enabled = !options.video.border.enabled;
|
options.video.border.enabled = !options.video.border.enabled;
|
||||||
adjustWindowSize();
|
setVideoMode(options.video.mode);
|
||||||
adjustGameCanvasRect();
|
|
||||||
adjustRenderLogicalSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja las notificaciones
|
// Dibuja las notificaciones
|
||||||
void Screen::renderNotifications()
|
void Screen::renderNotifications() { Notifier::get()->render(); }
|
||||||
{
|
|
||||||
Notifier::get()->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copia el gameCanvas en el borderCanvas
|
// Copia el gameCanvas en el borderCanvas
|
||||||
void Screen::gameCanvasToBorderCanvas()
|
void Screen::gameCanvasToBorderCanvas()
|
||||||
@@ -325,16 +266,10 @@ void Screen::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra la ventana
|
// Muestra la ventana
|
||||||
void Screen::show()
|
void Screen::show() { SDL_ShowWindow(window_); }
|
||||||
{
|
|
||||||
SDL_ShowWindow(window_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Oculta la ventana
|
// Oculta la ventana
|
||||||
void Screen::hide()
|
void Screen::hide() { SDL_HideWindow(window_); }
|
||||||
{
|
|
||||||
SDL_HideWindow(window_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el tamaño de la ventana
|
// Calcula el tamaño de la ventana
|
||||||
void Screen::adjustWindowSize()
|
void Screen::adjustWindowSize()
|
||||||
@@ -353,11 +288,11 @@ void Screen::adjustWindowSize()
|
|||||||
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);
|
||||||
|
|
||||||
int new_pos_x = old_pos_x + (old_width - (window_width_ * options.window.zoom)) / 2;
|
const int NEW_POS_X = old_pos_x + (old_width - (window_width_ * options.window.zoom)) / 2;
|
||||||
int new_pos_y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2;
|
const int NEW_POS_Y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2;
|
||||||
|
|
||||||
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
|
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,12 +307,7 @@ void Screen::adjustGameCanvasRect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ajusta el tamaño lógico del renderizador
|
// Ajusta el tamaño lógico del renderizador
|
||||||
void Screen::adjustRenderLogicalSize()
|
void Screen::adjustRenderLogicalSize() { SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_); }
|
||||||
{
|
|
||||||
const int extra_width = options.video.border.enabled ? options.video.border.width * 2 : 0;
|
|
||||||
const int extra_height = options.video.border.enabled ? options.video.border.height * 2 : 0;
|
|
||||||
SDL_RenderSetLogicalSize(renderer_, options.game.width + extra_width, options.game.height + extra_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el tamaño máximo de zoom posible para la ventana
|
// Obtiene el tamaño máximo de zoom posible para la ventana
|
||||||
int Screen::getMaxZoom()
|
int Screen::getMaxZoom()
|
||||||
@@ -387,10 +317,23 @@ int Screen::getMaxZoom()
|
|||||||
SDL_GetCurrentDisplayMode(0, &DM);
|
SDL_GetCurrentDisplayMode(0, &DM);
|
||||||
|
|
||||||
// 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 / window_width_, (DM.h - WINDOWS_DECORATIONS_) / window_height_);
|
const int MAX_ZOOM = std::min(DM.w / window_width_, (DM.h - WINDOWS_DECORATIONS_) / window_height_);
|
||||||
|
|
||||||
// Normaliza los valores de zoom
|
// Normaliza los valores de zoom
|
||||||
options.window.zoom = std::min(options.window.zoom, max_zoom);
|
options.window.zoom = std::min(options.window.zoom, MAX_ZOOM);
|
||||||
|
|
||||||
return max_zoom;
|
return MAX_ZOOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reinicia los shaders
|
||||||
|
void Screen::resetShaders()
|
||||||
|
{
|
||||||
|
if (options.video.shaders)
|
||||||
|
{
|
||||||
|
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::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
|
shader::init(window_, options.video.border.enabled ? border_texture_ : game_texture_, source.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||||
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
#include <SDL2/SDL_render.h> // for SDL_Texture, SDL_Renderer
|
||||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include <SDL2/SDL_video.h> // for SDL_Window
|
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||||
#include "utils.h" // for Color
|
#include "utils.h" // for Color
|
||||||
|
|
||||||
// Tipos de filtro
|
// Tipos de filtro
|
||||||
enum class ScreenFilter : Uint32
|
enum class ScreenFilter : Uint32
|
||||||
@@ -24,12 +24,12 @@ private:
|
|||||||
static Screen *screen_;
|
static Screen *screen_;
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window_; // Ventana de la aplicación
|
SDL_Window *window_; // Ventana de la aplicación
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
SDL_Texture *surface_texture_; // Textura donde se dibuja el juego
|
||||||
SDL_Texture *game_texture_; // Textura donde se dibuja el juego
|
SDL_Texture *game_texture_; // Textura donde se dibuja el juego
|
||||||
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
|
SDL_Texture *border_texture_; // Textura donde se dibuja el borde del juego
|
||||||
//std::shared_ptr<Surface> surface_; // Objeto para trabajar con surfaces
|
// std::shared_ptr<Surface> surface_; // Objeto para trabajar con surfaces
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int window_width_; // Ancho de la pantalla o ventana
|
int window_width_; // Ancho de la pantalla o ventana
|
||||||
@@ -55,6 +55,9 @@ private:
|
|||||||
// Ajusta el tamaño lógico del renderizador
|
// Ajusta el tamaño lógico del renderizador
|
||||||
void adjustRenderLogicalSize();
|
void adjustRenderLogicalSize();
|
||||||
|
|
||||||
|
// Reinicia los shaders
|
||||||
|
void resetShaders();
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
@@ -129,7 +132,7 @@ public:
|
|||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
SDL_Renderer *getRenderer() { return renderer_; }
|
SDL_Renderer *getRenderer() { return renderer_; }
|
||||||
//std::shared_ptr<SurfaceData> getSurface() { return surface_->getSurface(); }
|
// std::shared_ptr<SurfaceData> getSurface() { return surface_->getSurface(); }
|
||||||
SDL_Texture *getGameTexture() { return game_texture_; };
|
SDL_Texture *getGameTexture() { return game_texture_; };
|
||||||
SDL_Texture *getBorderTexture() { return border_texture_; }
|
SDL_Texture *getBorderTexture() { return border_texture_; }
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user