Muntat a c++14 per a make_unique

Mes autos, const i constexpr perl codi
Ara la classe Screen es un poc pitjor
This commit is contained in:
2024-10-06 14:58:00 +02:00
parent 25a2753b13
commit afe092c742
16 changed files with 290 additions and 381 deletions

View File

@@ -1,14 +1,14 @@
#include "options.h"
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton, SDL_C...
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN, SDL_WIND...
#include <algorithm> // for max, min
#include <fstream> // for char_traits, basic_ostream, ope...
#include <iostream> // for cout
#include <vector> // for vector
#include "input.h" // for inputs_e, INPUT_USE_ANY, INPUT_...
#include "lang.h" // for lang_e
#include "screen.h" // for SCREEN_FILTER_NEAREST, SCREEN_V...
#include "utils.h" // for op_controller_t, options_t, op_...
#include <SDL2/SDL_gamecontroller.h> // for SDL_GameControllerButton, SDL_C...
#include <SDL2/SDL_video.h> // for SDL_WINDOW_FULLSCREEN, SDL_WIND...
#include <algorithm> // for max, min
#include <fstream> // for char_traits, basic_ostream, ope...
#include <iostream> // for cout
#include <vector> // for vector
#include "input.h" // for inputs_e, INPUT_USE_ANY, INPUT_...
#include "lang.h" // for lang_e
#include "screen.h" // for screenFilter::NEAREST, SCREEN_V...
#include "utils.h" // for op_controller_t, options_t, op_...
// Variables
options_t options;
@@ -21,23 +21,21 @@ void initOptions()
{
// Opciones de video
#ifdef ANBERNIC
options.video.mode = 0;
options.video.mode = screenVideoMode::WINDOW;
options.video.window.size = 3;
#else
options.video.mode = 0;
options.video.mode = screenVideoMode::WINDOW;
options.video.window.size = 2;
#endif
options.video.filter = SCREEN_FILTER_NEAREST;
options.video.filter = screenFilter::NEAREST;
options.video.vSync = true;
options.video.integerScale = true;
options.video.keepAspect = true;
options.video.shaders = true;
// Opciones de las notificaciones
options.notification.posV = pos_top;
options.notification.posH = pos_left;
options.notification.sound = false;
options.notification.color = {48, 48, 48};
options.notification.color = (color_t){48, 48, 48};
// Opciones de audio
options.audio.music.enabled = true;
@@ -46,7 +44,7 @@ void initOptions()
options.audio.sound.volume = 64;
// Opciones de juego
options.game.difficulty = DIFFICULTY_NORMAL;
options.game.difficulty = gameDifficulty::NORMAL;
options.game.language = lang::ba_BA;
options.game.autofire = true;
@@ -135,12 +133,11 @@ bool loadOptionsFile(std::string filePath)
}
// Normaliza los valores
const bool a = options.video.mode == 0;
const bool b = options.video.mode == SDL_WINDOW_FULLSCREEN;
const bool c = options.video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP;
if (!(a || b || c))
const bool a = options.video.mode == screenVideoMode::WINDOW;
const bool b = options.video.mode == screenVideoMode::FULLSCREEN;
if (!(a || b))
{
options.video.mode = SCREEN_VIDEO_MODE_WINDOW;
options.video.mode = screenVideoMode::WINDOW;
}
if (options.video.window.size < 1 || options.video.window.size > 4)
@@ -175,29 +172,26 @@ bool saveOptionsFile(std::string filePath)
#endif
// Opciones de video
const auto valueVideoModeWinow = std::to_string(static_cast<int>(screenVideoMode::WINDOW));
const auto valueVideoModeFullscreen = std::to_string(static_cast<int>(screenVideoMode::FULLSCREEN));
const auto valueFilterNearest = std::to_string(static_cast<int>(screenFilter::NEAREST));
const auto valueFilterLineal = std::to_string(static_cast<int>(screenFilter::LINEAL));
file << "## VIDEO\n";
file << "## video.mode [0: window, 1: full screen]\n";
file << "## video.filter [0: nearest, 1: lineal]\n";
file << "## video.mode [" << valueVideoModeWinow << ": window, " << valueVideoModeFullscreen << ": fullscreen]\n";
file << "## video.filter [" << valueFilterNearest << ": nearest, " << valueFilterLineal << ": lineal]\n";
file << "\n";
if (options.video.mode == SCREEN_VIDEO_MODE_WINDOW)
{
file << "video.mode=0\n";
}
else if (options.video.mode == SCREEN_VIDEO_MODE_FULLSCREEN)
{
file << "video.mode=1\n";
}
const auto valueVideoMode = std::to_string(static_cast<int>(options.video.mode));
file << "video.mode=" << valueVideoMode << "\n";
file << "video.window.size=" + std::to_string(options.video.window.size) + "\n";
options.video.filter == SCREEN_FILTER_NEAREST ? file << "video.filter=0\n" : file << "video.filter=1\n";
const auto valueFilter = std::to_string(static_cast<int>(options.video.filter));
file << "video.filter=" << valueFilter << "\n";
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
file << "video.vSync=" + boolToString(options.video.vSync) + "\n";
file << "video.integerScale=" + boolToString(options.video.integerScale) + "\n";
file << "video.keepAspect=" + boolToString(options.video.keepAspect) + "\n";
// Opciones de notificaciones
file << "\n\n## NOTIFICATION\n";
@@ -243,13 +237,16 @@ bool saveOptionsFile(std::string filePath)
file << "audio.sound.volume=" + std::to_string(options.audio.sound.volume) + "\n";
// Opciones del juego
const auto valueDifficultyEasy = std::to_string(static_cast<int>(gameDifficulty::EASY));
const auto valueDifficultyNormal = std::to_string(static_cast<int>(gameDifficulty::NORMAL));
const auto valueDifficultyHard = std::to_string(static_cast<int>(gameDifficulty::HARD));
file << "\n\n## GAME\n";
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
file << "## game.difficulty [0: easy, 1: normal, 2: hard]\n";
file << "## game.difficulty [" << valueDifficultyEasy << ": easy, " << valueDifficultyNormal << ": normal, " << valueDifficultyHard << ": hard]\n";
file << "\n";
file << "game.language=" + std::to_string(options.game.language) + "\n";
file << "game.difficulty=" + std::to_string(options.game.difficulty) + "\n";
file << "game.difficulty=" + std::to_string(static_cast<int>(options.game.difficulty)) + "\n";
file << "game.autofire=" + boolToString(options.game.autofire) + "\n";
// Opciones de mandos
@@ -289,7 +286,8 @@ bool setOptions(std::string var, std::string value)
// Opciones de video
if (var == "video.mode")
{
options.video.mode = value == std::to_string(SCREEN_VIDEO_MODE_WINDOW) ? SCREEN_VIDEO_MODE_WINDOW : SCREEN_VIDEO_MODE_FULLSCREEN;
//options.video.mode = value == std::to_string(static_cast<int>(screenVideoMode::WINDOW)) ? screenVideoMode::WINDOW : screenVideoMode::FULLSCREEN;
options.video.mode = static_cast<screenVideoMode>(std::stoi(value));
}
else if (var == "video.window.size")
@@ -303,7 +301,8 @@ bool setOptions(std::string var, std::string value)
else if (var == "video.filter")
{
options.video.filter = value == std::to_string(SCREEN_FILTER_NEAREST) ? SCREEN_FILTER_NEAREST : SCREEN_FILTER_LINEAL;
//options.video.filter = value == std::to_string(static_cast<int>(screenFilter::NEAREST)) ? screenFilter::NEAREST : screenFilter::LINEAL;
options.video.filter = static_cast<screenFilter>(std::stoi(value));
}
else if (var == "video.shaders")
@@ -316,16 +315,6 @@ bool setOptions(std::string var, std::string value)
options.video.vSync = stringToBool(value);
}
else if (var == "video.integerScale")
{
options.video.integerScale = stringToBool(value);
}
else if (var == "video.keepAspect")
{
options.video.keepAspect = stringToBool(value);
}
// Opciones de notificaciones
else if (var == "notification.posH")
{
@@ -382,7 +371,7 @@ bool setOptions(std::string var, std::string value)
else if (var == "game.difficulty")
{
options.game.difficulty = std::stoi(value);
options.game.difficulty = static_cast<gameDifficulty>(std::stoi(value));
}
else if (var == "game.autofire")