singletons
This commit is contained in:
@@ -7,9 +7,8 @@
|
||||
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||
#include <string> // for basic_string, char_traits, string
|
||||
|
||||
#include "core/input/mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
|
||||
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_STROKE
|
||||
#include "core/resources/asset.h" // for Asset
|
||||
#include "core/input/mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
|
||||
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_STROKE
|
||||
#include "core/resources/resource.h"
|
||||
#include "game/defaults.hpp" // for GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT
|
||||
#include "game/options.hpp" // for Options::video, Options::settings
|
||||
@@ -60,12 +59,28 @@ namespace {
|
||||
} // namespace
|
||||
#endif // __EMSCRIPTEN__
|
||||
|
||||
// Instancia única
|
||||
Screen *Screen::instance = nullptr;
|
||||
|
||||
// Singleton API
|
||||
void Screen::init(SDL_Window *window, SDL_Renderer *renderer) {
|
||||
Screen::instance = new Screen(window, renderer);
|
||||
}
|
||||
|
||||
void Screen::destroy() {
|
||||
delete Screen::instance;
|
||||
Screen::instance = nullptr;
|
||||
}
|
||||
|
||||
auto Screen::get() -> Screen * {
|
||||
return Screen::instance;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset) {
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) {
|
||||
// Inicializa variables
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
|
||||
gameCanvasWidth = GAMECANVAS_WIDTH;
|
||||
gameCanvasHeight = GAMECANVAS_HEIGHT;
|
||||
@@ -586,8 +601,7 @@ void Screen::applyCurrentPostFXPreset() {
|
||||
#ifndef NO_SHADERS
|
||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return; }
|
||||
if (Options::postfx_presets.empty()) { return; }
|
||||
if (Options::current_postfx_preset < 0
|
||||
|| Options::current_postfx_preset >= static_cast<int>(Options::postfx_presets.size())) {
|
||||
if (Options::current_postfx_preset < 0 || Options::current_postfx_preset >= static_cast<int>(Options::postfx_presets.size())) {
|
||||
Options::current_postfx_preset = 0;
|
||||
}
|
||||
const auto &PRESET = Options::postfx_presets[Options::current_postfx_preset];
|
||||
@@ -608,8 +622,7 @@ void Screen::applyCurrentCrtPiPreset() {
|
||||
#ifndef NO_SHADERS
|
||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return; }
|
||||
if (Options::crtpi_presets.empty()) { return; }
|
||||
if (Options::current_crtpi_preset < 0
|
||||
|| Options::current_crtpi_preset >= static_cast<int>(Options::crtpi_presets.size())) {
|
||||
if (Options::current_crtpi_preset < 0 || Options::current_crtpi_preset >= static_cast<int>(Options::crtpi_presets.size())) {
|
||||
Options::current_crtpi_preset = 0;
|
||||
}
|
||||
const auto &PRESET = Options::crtpi_presets[Options::current_crtpi_preset];
|
||||
@@ -632,17 +645,15 @@ void Screen::applyCurrentCrtPiPreset() {
|
||||
#endif
|
||||
}
|
||||
|
||||
auto Screen::getCurrentPresetName() const -> const char* {
|
||||
auto Screen::getCurrentPresetName() const -> const char * {
|
||||
#ifndef NO_SHADERS
|
||||
if (!shader_backend_ || !shader_backend_->isHardwareAccelerated()) { return "---"; }
|
||||
if (Options::video.shader.current_shader == Rendering::ShaderType::POSTFX) {
|
||||
if (Options::current_postfx_preset >= 0
|
||||
&& Options::current_postfx_preset < static_cast<int>(Options::postfx_presets.size())) {
|
||||
if (Options::current_postfx_preset >= 0 && Options::current_postfx_preset < static_cast<int>(Options::postfx_presets.size())) {
|
||||
return Options::postfx_presets[Options::current_postfx_preset].name.c_str();
|
||||
}
|
||||
} else {
|
||||
if (Options::current_crtpi_preset >= 0
|
||||
&& Options::current_crtpi_preset < static_cast<int>(Options::crtpi_presets.size())) {
|
||||
if (Options::current_crtpi_preset >= 0 && Options::current_crtpi_preset < static_cast<int>(Options::crtpi_presets.size())) {
|
||||
return Options::crtpi_presets[Options::current_crtpi_preset].name.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Rendering {
|
||||
}
|
||||
#endif
|
||||
|
||||
class Asset;
|
||||
class Text;
|
||||
|
||||
class Screen {
|
||||
@@ -30,8 +29,12 @@ class Screen {
|
||||
static constexpr int WASM_RENDER_SCALE = 3;
|
||||
#endif
|
||||
|
||||
// Constructor y destructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset);
|
||||
// Singleton API
|
||||
static void init(SDL_Window *window, SDL_Renderer *renderer); // Crea la instancia
|
||||
static void destroy(); // Libera la instancia
|
||||
static auto get() -> Screen *; // Obtiene el puntero a la instancia
|
||||
|
||||
// Destructor (público por requisitos de `delete` desde destroy())
|
||||
~Screen();
|
||||
|
||||
// Render loop
|
||||
@@ -77,11 +80,17 @@ class Screen {
|
||||
// Retornen false si GPU off / shaders off / llista buida (igual que a aee_plus).
|
||||
auto nextPreset() -> bool;
|
||||
auto prevPreset() -> bool;
|
||||
auto getCurrentPresetName() const -> const char*;
|
||||
auto getCurrentPresetName() const -> const char *;
|
||||
void applyCurrentPostFXPreset(); // Escriu el preset PostFX actiu al backend
|
||||
void applyCurrentCrtPiPreset(); // Escriu el preset CrtPi actiu al backend
|
||||
|
||||
private:
|
||||
// Constructor privado (usar Screen::init)
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||
|
||||
// Instancia única
|
||||
static Screen *instance;
|
||||
|
||||
// Helpers internos de setVideoMode
|
||||
void applyFullscreen(bool fullscreen); // SDL_SetWindowFullscreen + visibilidad del cursor
|
||||
void applyWindowedLayout(); // Calcula windowWidth/Height/dest + SDL_SetWindowSize + SDL_SetWindowPosition
|
||||
@@ -104,7 +113,6 @@ class Screen {
|
||||
// Objetos y punteros
|
||||
SDL_Window *window; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con el listado de recursos
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
|
||||
// Variables
|
||||
|
||||
Reference in New Issue
Block a user