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
|
||||
|
||||
Reference in New Issue
Block a user