forked from jaildesigner-jailgames/jaildoctors_dilemma
treballant en poder incloure diferents shaders
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <filesystem> // Para create_directories
|
||||
#include <fstream> // Para ifstream, ofstream
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <string> // Para string
|
||||
@@ -364,6 +365,23 @@ namespace Options {
|
||||
}
|
||||
}
|
||||
|
||||
if (vid.contains("current_crtpi_preset")) {
|
||||
try {
|
||||
current_crtpi_preset = vid["current_crtpi_preset"].get_value<int>();
|
||||
} catch (...) {
|
||||
current_crtpi_preset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (vid.contains("current_shader")) {
|
||||
try {
|
||||
const std::string s = vid["current_shader"].get_value<std::string>();
|
||||
current_shader = (s == "crtpi") ? Rendering::ShaderType::CRTPI : Rendering::ShaderType::POSTFX;
|
||||
} catch (...) {
|
||||
current_shader = Rendering::ShaderType::POSTFX;
|
||||
}
|
||||
}
|
||||
|
||||
if (vid.contains("vertical_sync")) {
|
||||
try {
|
||||
video.vertical_sync = vid["vertical_sync"].get_value<bool>();
|
||||
@@ -722,6 +740,8 @@ namespace Options {
|
||||
file << " postfx: " << (video.postfx ? "true" : "false") << "\n";
|
||||
file << " supersampling: " << (video.supersampling ? "true" : "false") << "\n";
|
||||
file << " current_postfx_preset: " << current_postfx_preset << "\n";
|
||||
file << " current_crtpi_preset: " << current_crtpi_preset << "\n";
|
||||
file << " current_shader: " << (current_shader == Rendering::ShaderType::CRTPI ? "crtpi" : "postfx") << "\n";
|
||||
file << " vertical_sync: " << (video.vertical_sync ? "true" : "false") << "\n";
|
||||
file << " integer_scale: " << (video.integer_scale ? "true" : "false") << "\n";
|
||||
file << " keep_aspect: " << (video.keep_aspect ? "true" : "false") << "\n";
|
||||
@@ -951,4 +971,188 @@ namespace Options {
|
||||
return true;
|
||||
}
|
||||
|
||||
void setCrtPiFile(const std::string& path) {
|
||||
crtpi_file_path = path;
|
||||
}
|
||||
|
||||
// Carga los presets del shader CrtPi desde el fichero. Crea defaults si no existe.
|
||||
auto loadCrtPiFromFile() -> bool {
|
||||
crtpi_presets.clear();
|
||||
|
||||
std::ifstream file(crtpi_file_path);
|
||||
if (!file.good()) {
|
||||
if (console) {
|
||||
std::cout << "CrtPi file not found, creating default: " << crtpi_file_path << '\n';
|
||||
}
|
||||
// Crear directorio padre si no existe
|
||||
const std::filesystem::path p(crtpi_file_path);
|
||||
if (p.has_parent_path()) {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(p.parent_path(), ec);
|
||||
}
|
||||
// Escribir defaults
|
||||
std::ofstream out(crtpi_file_path);
|
||||
if (!out.is_open()) {
|
||||
if (console) {
|
||||
std::cerr << "Error: Cannot create CrtPi file: " << crtpi_file_path << '\n';
|
||||
}
|
||||
// Cargar defaults en memoria aunque no se pueda escribir
|
||||
crtpi_presets.push_back({"DEFAULT", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false});
|
||||
crtpi_presets.push_back({"CURVED", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, true, false});
|
||||
crtpi_presets.push_back({"SHARP", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, false, true, false, true});
|
||||
crtpi_presets.push_back({"MINIMAL", 8.0F, 0.05F, 2.0F, 2.4F, 2.2F, 1.00F, 0.0F, 0.0F, 0, true, false, false, false, false});
|
||||
current_crtpi_preset = 0;
|
||||
return true;
|
||||
}
|
||||
out << "# JailDoctor's Dilemma - CrtPi Shader Presets\n";
|
||||
out << "# scanline_weight: ajuste gaussiano (mayor = scanlines mas estrechas, default 6.0)\n";
|
||||
out << "# scanline_gap_brightness: brillo minimo entre scanlines (0.0-1.0, default 0.12)\n";
|
||||
out << "# bloom_factor: factor de brillo para zonas iluminadas (default 3.5)\n";
|
||||
out << "# input_gamma: gamma de entrada - linealizacion (default 2.4)\n";
|
||||
out << "# output_gamma: gamma de salida - codificacion (default 2.2)\n";
|
||||
out << "# mask_brightness: brillo sub-pixeles de la mascara de fosforo (default 0.80)\n";
|
||||
out << "# curvature_x/y: distorsion barrel CRT (0.0 = plana)\n";
|
||||
out << "# mask_type: 0=ninguna, 1=verde/magenta, 2=RGB fosforo\n";
|
||||
out << "# enable_scanlines/multisample/gamma/curvature/sharper: true/false\n";
|
||||
out << "\n";
|
||||
out << "presets:\n";
|
||||
out << " - name: \"DEFAULT\"\n";
|
||||
out << " scanline_weight: 6.0\n";
|
||||
out << " scanline_gap_brightness: 0.12\n";
|
||||
out << " bloom_factor: 3.5\n";
|
||||
out << " input_gamma: 2.4\n";
|
||||
out << " output_gamma: 2.2\n";
|
||||
out << " mask_brightness: 0.80\n";
|
||||
out << " curvature_x: 0.05\n";
|
||||
out << " curvature_y: 0.10\n";
|
||||
out << " mask_type: 2\n";
|
||||
out << " enable_scanlines: true\n";
|
||||
out << " enable_multisample: true\n";
|
||||
out << " enable_gamma: true\n";
|
||||
out << " enable_curvature: false\n";
|
||||
out << " enable_sharper: false\n";
|
||||
out << " - name: \"CURVED\"\n";
|
||||
out << " scanline_weight: 6.0\n";
|
||||
out << " scanline_gap_brightness: 0.12\n";
|
||||
out << " bloom_factor: 3.5\n";
|
||||
out << " input_gamma: 2.4\n";
|
||||
out << " output_gamma: 2.2\n";
|
||||
out << " mask_brightness: 0.80\n";
|
||||
out << " curvature_x: 0.05\n";
|
||||
out << " curvature_y: 0.10\n";
|
||||
out << " mask_type: 2\n";
|
||||
out << " enable_scanlines: true\n";
|
||||
out << " enable_multisample: true\n";
|
||||
out << " enable_gamma: true\n";
|
||||
out << " enable_curvature: true\n";
|
||||
out << " enable_sharper: false\n";
|
||||
out << " - name: \"SHARP\"\n";
|
||||
out << " scanline_weight: 6.0\n";
|
||||
out << " scanline_gap_brightness: 0.12\n";
|
||||
out << " bloom_factor: 3.5\n";
|
||||
out << " input_gamma: 2.4\n";
|
||||
out << " output_gamma: 2.2\n";
|
||||
out << " mask_brightness: 0.80\n";
|
||||
out << " curvature_x: 0.05\n";
|
||||
out << " curvature_y: 0.10\n";
|
||||
out << " mask_type: 2\n";
|
||||
out << " enable_scanlines: true\n";
|
||||
out << " enable_multisample: false\n";
|
||||
out << " enable_gamma: true\n";
|
||||
out << " enable_curvature: false\n";
|
||||
out << " enable_sharper: true\n";
|
||||
out << " - name: \"MINIMAL\"\n";
|
||||
out << " scanline_weight: 8.0\n";
|
||||
out << " scanline_gap_brightness: 0.05\n";
|
||||
out << " bloom_factor: 2.0\n";
|
||||
out << " input_gamma: 2.4\n";
|
||||
out << " output_gamma: 2.2\n";
|
||||
out << " mask_brightness: 1.00\n";
|
||||
out << " curvature_x: 0.0\n";
|
||||
out << " curvature_y: 0.0\n";
|
||||
out << " mask_type: 0\n";
|
||||
out << " enable_scanlines: true\n";
|
||||
out << " enable_multisample: false\n";
|
||||
out << " enable_gamma: false\n";
|
||||
out << " enable_curvature: false\n";
|
||||
out << " enable_sharper: false\n";
|
||||
out.close();
|
||||
if (console) {
|
||||
std::cout << "CrtPi file created with defaults: " << crtpi_file_path << '\n';
|
||||
}
|
||||
crtpi_presets.push_back({"DEFAULT", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false});
|
||||
crtpi_presets.push_back({"CURVED", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, true, false});
|
||||
crtpi_presets.push_back({"SHARP", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, false, true, false, true});
|
||||
crtpi_presets.push_back({"MINIMAL", 8.0F, 0.05F, 2.0F, 2.4F, 2.2F, 1.00F, 0.0F, 0.0F, 0, true, false, false, false, false});
|
||||
current_crtpi_preset = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
|
||||
try {
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
|
||||
if (yaml.contains("presets")) {
|
||||
const auto& presets = yaml["presets"];
|
||||
for (const auto& p : presets) {
|
||||
CrtPiPreset preset;
|
||||
if (p.contains("name")) {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
}
|
||||
parseFloatField(p, "scanline_weight", preset.scanline_weight);
|
||||
parseFloatField(p, "scanline_gap_brightness", preset.scanline_gap_brightness);
|
||||
parseFloatField(p, "bloom_factor", preset.bloom_factor);
|
||||
parseFloatField(p, "input_gamma", preset.input_gamma);
|
||||
parseFloatField(p, "output_gamma", preset.output_gamma);
|
||||
parseFloatField(p, "mask_brightness", preset.mask_brightness);
|
||||
parseFloatField(p, "curvature_x", preset.curvature_x);
|
||||
parseFloatField(p, "curvature_y", preset.curvature_y);
|
||||
if (p.contains("mask_type")) {
|
||||
try { preset.mask_type = p["mask_type"].get_value<int>(); } catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_scanlines")) {
|
||||
try { preset.enable_scanlines = p["enable_scanlines"].get_value<bool>(); } catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_multisample")) {
|
||||
try { preset.enable_multisample = p["enable_multisample"].get_value<bool>(); } catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_gamma")) {
|
||||
try { preset.enable_gamma = p["enable_gamma"].get_value<bool>(); } catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_curvature")) {
|
||||
try { preset.enable_curvature = p["enable_curvature"].get_value<bool>(); } catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_sharper")) {
|
||||
try { preset.enable_sharper = p["enable_sharper"].get_value<bool>(); } catch (...) {}
|
||||
}
|
||||
crtpi_presets.push_back(preset);
|
||||
}
|
||||
}
|
||||
|
||||
if (!crtpi_presets.empty()) {
|
||||
current_crtpi_preset = std::clamp(
|
||||
current_crtpi_preset, 0, static_cast<int>(crtpi_presets.size()) - 1);
|
||||
} else {
|
||||
current_crtpi_preset = 0;
|
||||
}
|
||||
|
||||
if (console) {
|
||||
std::cout << "CrtPi file loaded: " << crtpi_presets.size() << " preset(s)\n";
|
||||
}
|
||||
return true;
|
||||
|
||||
} catch (const fkyaml::exception& e) {
|
||||
if (console) {
|
||||
std::cerr << "Error parsing CrtPi YAML: " << e.what() << '\n';
|
||||
}
|
||||
// Cargar defaults en memoria en caso de error
|
||||
crtpi_presets.clear();
|
||||
crtpi_presets.push_back({"DEFAULT", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false});
|
||||
current_crtpi_preset = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Options
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/rendering/screen.hpp" // Para Screen::Filter
|
||||
#include "core/rendering/screen.hpp" // Para Screen::Filter
|
||||
#include "core/rendering/shader_backend.hpp" // Para Rendering::ShaderType
|
||||
#include "game/defaults.hpp"
|
||||
#include "utils/defines.hpp" // Para WINDOW_CAPTION
|
||||
#include "utils/utils.hpp" // Para Color, Palette
|
||||
@@ -131,6 +132,25 @@ namespace Options {
|
||||
float flicker{0.0F}; // Parpadeo de fósforo CRT ~50 Hz (0.0 = off, 1.0 = máximo)
|
||||
};
|
||||
|
||||
// Estructura para un preset del shader CRT-Pi
|
||||
struct CrtPiPreset {
|
||||
std::string name;
|
||||
float scanline_weight{6.0F}; // Ajuste gaussiano (mayor = scanlines más estrechas)
|
||||
float scanline_gap_brightness{0.12F}; // Brillo mínimo en las ranuras entre scanlines
|
||||
float bloom_factor{3.5F}; // Factor de brillo para zonas iluminadas
|
||||
float input_gamma{2.4F}; // Gamma de entrada (linealización)
|
||||
float output_gamma{2.2F}; // Gamma de salida (codificación)
|
||||
float mask_brightness{0.80F}; // Brillo sub-píxeles en la máscara de fósforo
|
||||
float curvature_x{0.05F}; // Distorsión barrel eje X
|
||||
float curvature_y{0.10F}; // Distorsión barrel eje Y
|
||||
int mask_type{2}; // 0=ninguna, 1=verde/magenta, 2=RGB fósforo
|
||||
bool enable_scanlines{true}; // Activar efecto de scanlines
|
||||
bool enable_multisample{true}; // Antialiasing analítico de scanlines
|
||||
bool enable_gamma{true}; // Corrección gamma
|
||||
bool enable_curvature{false}; // Distorsión barrel CRT
|
||||
bool enable_sharper{false}; // Submuestreo más nítido (modo SHARPER)
|
||||
};
|
||||
|
||||
// --- Variables globales ---
|
||||
inline std::string version{}; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
|
||||
inline bool console{false}; // Indica si ha de mostrar información por la consola de texto
|
||||
@@ -155,13 +175,23 @@ namespace Options {
|
||||
inline int current_postfx_preset{0}; // Índice del preset de PostFX actual
|
||||
inline std::string postfx_file_path{}; // Ruta del fichero postfx.yaml
|
||||
|
||||
// --- Variables CrtPi ---
|
||||
inline std::vector<CrtPiPreset> crtpi_presets{}; // Lista de presets del shader CRT-Pi
|
||||
inline int current_crtpi_preset{0}; // Índice del preset CRT-Pi actual
|
||||
inline std::string crtpi_file_path{}; // Ruta del fichero crtpi.yaml
|
||||
|
||||
// --- Shader activo ---
|
||||
inline Rendering::ShaderType current_shader{Rendering::ShaderType::POSTFX}; // Shader de post-procesado activo
|
||||
|
||||
// --- Funciones públicas ---
|
||||
void init(); // Crea e inicializa las opciones del programa
|
||||
void setConfigFile(const std::string& path); // Establece la ruta del fichero de configuración
|
||||
auto loadFromFile() -> bool; // Carga las opciones desde el fichero configurado
|
||||
auto saveToFile() -> bool; // Guarda las opciones al fichero configurado
|
||||
void setPostFXFile(const std::string& path); // Establece la ruta del fichero de PostFX
|
||||
auto loadPostFXFromFile() -> bool; // Carga los presets de PostFX desde el fichero
|
||||
auto savePostFXToFile() -> bool; // Guarda los presets de PostFX por defecto
|
||||
void setPostFXFile(const std::string& path); // Establece la ruta del fichero de PostFX
|
||||
auto loadPostFXFromFile() -> bool; // Carga los presets de PostFX desde el fichero
|
||||
auto savePostFXToFile() -> bool; // Guarda los presets de PostFX por defecto
|
||||
void setCrtPiFile(const std::string& path); // Establece la ruta del fichero de CrtPi
|
||||
auto loadCrtPiFromFile() -> bool; // Carga los presets de CrtPi desde el fichero (crea defaults si no existe)
|
||||
|
||||
} // namespace Options
|
||||
Reference in New Issue
Block a user