diff --git a/source/game.cpp b/source/game.cpp index 614d2e3..5882af4 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -676,7 +676,6 @@ void Game::DEMO_init() 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"}); - current_room_ = demo_.rooms.front(); } } diff --git a/source/options.cpp b/source/options.cpp index 084a207..665ebf4 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -21,7 +21,7 @@ void initOptions() options = Options(); #ifdef DEBUG - options.section = SectionState(Section::ENDING2, Subsection::NONE); + options.section = SectionState(Section::DEMO, Subsection::NONE); options.console = true; #else options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO); diff --git a/source/screen.cpp b/source/screen.cpp index 16e1fed..d68fd93 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -13,7 +13,7 @@ #include "notifier.h" // Para Notify #include "options.h" #include "mouse.h" -//#include "surface.h" +// #include "surface.h" // [SINGLETON] 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); // 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_); - // Crea la surface donde se pinta el juego - //surface_ = std::make_shared(nullptr, options.game.width, options.game.height); - //surface_->loadPalette(Asset::get()->get("test.gif")); - // Establece el modo de video setVideoMode(options.video.mode); @@ -89,17 +85,10 @@ void Screen::clean(Color color) } // Prepara para empezar a dibujar en la textura de juego -void Screen::start() -{ - //surface_->clear(surface_->getSurface(), surface_->getTransparentColor()); - SDL_SetRenderTarget(renderer_, game_texture_); -} +void Screen::start() { SDL_SetRenderTarget(renderer_, game_texture_); } // Prepara para empezar a dibujar en la textura del borde -void Screen::startDrawOnBorder() -{ - SDL_SetRenderTarget(renderer_, border_texture_); -} +void Screen::startDrawOnBorder() { SDL_SetRenderTarget(renderer_, border_texture_); } // Vuelca el contenido del renderizador en pantalla void Screen::render() @@ -107,10 +96,6 @@ void Screen::render() // Renderiza sobre gameCanvas los overlays 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 if (options.video.border.enabled) { @@ -135,52 +120,22 @@ void Screen::renderWithoutNotifier() } // 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 - 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 - 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(f)), std::istreambuf_iterator()); - - if (options.video.border.enabled) - { - shader::init(window_, border_texture_, source.c_str()); - } - else - { - shader::init(window_, game_texture_, source.c_str()); - } - } + resetShaders(); } // Camibia entre pantalla completa y ventana @@ -195,13 +150,13 @@ bool Screen::decWindowZoom() { if (options.video.mode == 0) { - int previous_zoom = options.window.zoom; + const int PREVIOUS_ZOOM = options.window.zoom; --options.window.zoom; 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; } } @@ -214,13 +169,13 @@ bool Screen::incWindowZoom() { if (options.video.mode == 0) { - int previous_zoom = options.window.zoom; + const int PREVIOUS_ZOOM = options.window.zoom; ++options.window.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; } } @@ -240,22 +195,13 @@ void Screen::setBorderColor(Color color) } // Cambia el tipo de mezcla -void Screen::setBlendMode(SDL_BlendMode blendMode) -{ - SDL_SetRenderDrawBlendMode(renderer_, blendMode); -} +void Screen::setBlendMode(SDL_BlendMode blendMode) { SDL_SetRenderDrawBlendMode(renderer_, blendMode); } // Establece el tamaño del borde -void Screen::setBorderWidth(int s) -{ - options.video.border.width = s; -} +void Screen::setBorderWidth(int s) { options.video.border.width = s; } // Establece el tamaño del borde -void Screen::setBorderHeight(int s) -{ - options.video.border.height = s; -} +void Screen::setBorderHeight(int s) { options.video.border.height = s; } // Establece si se ha de ver el borde en el modo ventana 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() { options.video.border.enabled = !options.video.border.enabled; - adjustWindowSize(); - adjustGameCanvasRect(); - adjustRenderLogicalSize(); + setVideoMode(options.video.mode); } // Dibuja las notificaciones -void Screen::renderNotifications() -{ - Notifier::get()->render(); -} +void Screen::renderNotifications() { Notifier::get()->render(); } // Copia el gameCanvas en el borderCanvas void Screen::gameCanvasToBorderCanvas() @@ -325,16 +266,10 @@ void Screen::update() } // Muestra la ventana -void Screen::show() -{ - SDL_ShowWindow(window_); -} +void Screen::show() { SDL_ShowWindow(window_); } // Oculta la ventana -void Screen::hide() -{ - SDL_HideWindow(window_); -} +void Screen::hide() { SDL_HideWindow(window_); } // Calcula el tamaño de la ventana void Screen::adjustWindowSize() @@ -353,11 +288,11 @@ void Screen::adjustWindowSize() int 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; - int new_pos_y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2; + const int NEW_POS_X = old_pos_x + (old_width - (window_width_ * 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_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 -void Screen::adjustRenderLogicalSize() -{ - 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); -} +void Screen::adjustRenderLogicalSize() { SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_); } // Obtiene el tamaño máximo de zoom posible para la ventana int Screen::getMaxZoom() @@ -387,10 +317,23 @@ int Screen::getMaxZoom() SDL_GetCurrentDisplayMode(0, &DM); // 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 - options.window.zoom = std::min(options.window.zoom, max_zoom); + options.window.zoom = std::min(options.window.zoom, MAX_ZOOM); - return max_zoom; -} \ No newline at end of file + 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(f)), std::istreambuf_iterator()); + + shader::init(window_, options.video.border.enabled ? border_texture_ : game_texture_, source.c_str()); + } +} diff --git a/source/screen.h b/source/screen.h index d73f202..67cd38e 100644 --- a/source/screen.h +++ b/source/screen.h @@ -1,11 +1,11 @@ #pragma once -#include // for SDL_BlendMode -#include // for SDL_Rect -#include // for SDL_Texture, SDL_Renderer -#include // for Uint32 -#include // for SDL_Window -#include "utils.h" // for Color +#include // for SDL_BlendMode +#include // for SDL_Rect +#include // for SDL_Texture, SDL_Renderer +#include // for Uint32 +#include // for SDL_Window +#include "utils.h" // for Color // Tipos de filtro enum class ScreenFilter : Uint32 @@ -24,12 +24,12 @@ private: static Screen *screen_; // Objetos y punteros - SDL_Window *window_; // Ventana de la aplicación - SDL_Renderer *renderer_; // El renderizador de la ventana - SDL_Texture *surface_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 - //std::shared_ptr surface_; // Objeto para trabajar con surfaces + SDL_Window *window_; // Ventana de la aplicación + SDL_Renderer *renderer_; // El renderizador de la ventana + SDL_Texture *surface_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 + // std::shared_ptr surface_; // Objeto para trabajar con surfaces // Variables int window_width_; // Ancho de la pantalla o ventana @@ -55,6 +55,9 @@ private: // Ajusta el tamaño lógico del renderizador void adjustRenderLogicalSize(); + // Reinicia los shaders + void resetShaders(); + // Constructor Screen(SDL_Window *window, SDL_Renderer *renderer); @@ -129,7 +132,7 @@ public: // Getters SDL_Renderer *getRenderer() { return renderer_; } - //std::shared_ptr getSurface() { return surface_->getSurface(); } + // std::shared_ptr getSurface() { return surface_->getSurface(); } SDL_Texture *getGameTexture() { return game_texture_; }; SDL_Texture *getBorderTexture() { return border_texture_; } }; \ No newline at end of file