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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user