Options: creat namespace
This commit is contained in:
@@ -111,7 +111,7 @@ void Screen::renderScreen()
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
clean();
|
||||
|
||||
if (options.video.shaders)
|
||||
if (Options::video.shaders)
|
||||
{
|
||||
shader::render();
|
||||
}
|
||||
@@ -126,10 +126,10 @@ void Screen::renderScreen()
|
||||
void Screen::setFullscreenMode(bool mode)
|
||||
{
|
||||
// Actualiza las opciones
|
||||
options.video.fullscreen = mode;
|
||||
Options::video.fullscreen = mode;
|
||||
|
||||
// Configura el modo de pantalla
|
||||
SDL_SetWindowFullscreen(window_, options.video.fullscreen);
|
||||
SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
|
||||
|
||||
initShaders();
|
||||
}
|
||||
@@ -137,27 +137,27 @@ void Screen::setFullscreenMode(bool mode)
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::toggleFullscreen()
|
||||
{
|
||||
options.video.fullscreen = !options.video.fullscreen;
|
||||
Options::video.fullscreen = !Options::video.fullscreen;
|
||||
setFullscreenMode();
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowZoom(int zoom)
|
||||
{
|
||||
options.window.size = zoom;
|
||||
Options::window.size = zoom;
|
||||
adjustWindowSize();
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
bool Screen::decWindowSize()
|
||||
{
|
||||
if (!options.video.fullscreen)
|
||||
if (!Options::video.fullscreen)
|
||||
{
|
||||
const int PREVIOUS_ZOOM = options.window.size;
|
||||
--options.window.size;
|
||||
options.window.size = std::max(options.window.size, 1);
|
||||
const int PREVIOUS_ZOOM = Options::window.size;
|
||||
--Options::window.size;
|
||||
Options::window.size = std::max(Options::window.size, 1);
|
||||
|
||||
if (options.window.size != PREVIOUS_ZOOM)
|
||||
if (Options::window.size != PREVIOUS_ZOOM)
|
||||
{
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
@@ -170,13 +170,13 @@ bool Screen::decWindowSize()
|
||||
// Aumenta el tamaño de la ventana
|
||||
bool Screen::incWindowSize()
|
||||
{
|
||||
if (!options.video.fullscreen)
|
||||
if (!Options::video.fullscreen)
|
||||
{
|
||||
const int PREVIOUS_ZOOM = options.window.size;
|
||||
++options.window.size;
|
||||
options.window.size = std::min(options.window.size, options.window.max_size);
|
||||
const int PREVIOUS_ZOOM = Options::window.size;
|
||||
++Options::window.size;
|
||||
Options::window.size = std::min(Options::window.size, Options::window.max_size);
|
||||
|
||||
if (options.window.size != PREVIOUS_ZOOM)
|
||||
if (Options::window.size != PREVIOUS_ZOOM)
|
||||
{
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
@@ -249,7 +249,7 @@ void Screen::renderInfo()
|
||||
if (debug_info_.show)
|
||||
{
|
||||
// Resolution
|
||||
debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(options.video.info) - 2, 1, options.video.info, 1, DEBUG_COLOR, 1, DEBUG_COLOR.darken(150));
|
||||
debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(Options::video.info) - 2, 1, Options::video.info, 1, DEBUG_COLOR, 1, DEBUG_COLOR.darken(150));
|
||||
|
||||
// FPS
|
||||
const std::string FPS_TEXT = std::to_string(fps_.lastValue) + " FPS";
|
||||
@@ -280,10 +280,10 @@ void Screen::initShaders()
|
||||
void Screen::adjustWindowSize()
|
||||
{
|
||||
// Establece el nuevo tamaño
|
||||
if (!options.video.fullscreen)
|
||||
if (!Options::video.fullscreen)
|
||||
{
|
||||
const int WIDTH = param.game.width * options.window.size;
|
||||
const int HEIGHT = param.game.height * options.window.size;
|
||||
const int WIDTH = param.game.width * Options::window.size;
|
||||
const int HEIGHT = param.game.height * Options::window.size;
|
||||
|
||||
int old_width, old_height;
|
||||
SDL_GetWindowSize(window_, &old_width, &old_height);
|
||||
@@ -349,7 +349,7 @@ bool Screen::initSDL()
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
window_ = SDL_CreateWindow(options.window.caption.c_str(), param.game.width * options.window.size, param.game.height * options.window.size, SDL_WINDOW_OPENGL);
|
||||
window_ = SDL_CreateWindow(Options::window.caption.c_str(), param.game.width * Options::window.size, param.game.height * Options::window.size, SDL_WINDOW_OPENGL);
|
||||
if (!window_)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window could not be created! SDL Error: %s", SDL_GetError());
|
||||
@@ -368,9 +368,9 @@ bool Screen::initSDL()
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
|
||||
SDL_SetWindowFullscreen(window_, options.video.fullscreen);
|
||||
SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -397,17 +397,17 @@ void Screen::getDisplayInfo()
|
||||
auto DM = SDL_GetCurrentDisplayMode(displays[0]);
|
||||
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
options.window.max_size = std::min(DM->w / param.game.width, DM->h / param.game.height);
|
||||
options.window.size = std::min(options.window.size, options.window.max_size);
|
||||
Options::window.max_size = std::min(DM->w / param.game.width, DM->h / param.game.height);
|
||||
Options::window.size = std::min(Options::window.size, Options::window.max_size);
|
||||
|
||||
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz",
|
||||
static_cast<int>(DM->w), static_cast<int>(DM->h), static_cast<int>(DM->refresh_rate));
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d",
|
||||
static_cast<int>(param.game.width), static_cast<int>(param.game.height), options.window.size);
|
||||
static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.size);
|
||||
|
||||
options.video.info = std::to_string(static_cast<int>(DM->w)) + "x" +
|
||||
Options::video.info = std::to_string(static_cast<int>(DM->w)) + "x" +
|
||||
std::to_string(static_cast<int>(DM->h)) + " @ " +
|
||||
std::to_string(static_cast<int>(DM->refresh_rate)) + " Hz";
|
||||
|
||||
@@ -415,7 +415,7 @@ void Screen::getDisplayInfo()
|
||||
const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height);
|
||||
|
||||
// Normaliza los valores de zoom
|
||||
options.window.size = std::min(options.window.size, MAX_ZOOM);
|
||||
Options::window.size = std::min(Options::window.size, MAX_ZOOM);
|
||||
|
||||
SDL_free(displays);
|
||||
}
|
||||
@@ -424,21 +424,21 @@ void Screen::getDisplayInfo()
|
||||
// Alterna entre activar y desactivar el escalado entero
|
||||
void Screen::toggleIntegerScale()
|
||||
{
|
||||
options.video.integer_scale = !options.video.integer_scale;
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
Options::video.integer_scale = !Options::video.integer_scale;
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
}
|
||||
|
||||
// Alterna entre activar y desactivar el V-Sync
|
||||
void Screen::toggleVSync()
|
||||
{
|
||||
options.video.v_sync = !options.video.v_sync;
|
||||
SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
Options::video.v_sync = !Options::video.v_sync;
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
}
|
||||
|
||||
// Establece el estado del V-Sync
|
||||
void Screen::setVSync(bool enabled)
|
||||
{
|
||||
options.video.v_sync = enabled;
|
||||
Options::video.v_sync = enabled;
|
||||
SDL_SetRenderVSync(renderer_, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
}
|
||||
|
||||
@@ -452,8 +452,8 @@ void Screen::getSingletons()
|
||||
// Aplica los valores de las opciones
|
||||
void Screen::applySettings()
|
||||
{
|
||||
SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
adjustWindowSize();
|
||||
setFullscreenMode();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user