This commit is contained in:
2026-04-17 19:04:44 +02:00
parent 5fec0110b3
commit 1bb0ebdef8
30 changed files with 45791 additions and 23 deletions

View File

@@ -114,12 +114,29 @@ Director::Director(int argc, const char *argv[]) {
#endif
initInput();
// Precarga todos los recursos en memoria (texturas, sonidos, música, ...).
// Vivirán durante toda la vida de la app; las escenas leen handles compartidos.
// Debe ir antes de crear Screen porque Screen usa Text (propiedad de Resource).
// Orden importante: Screen + initShaders ANTES de Resource::init.
// Si `Resource::init` se ejecuta primero, carga ~100 texturas vía
// `SDL_CreateTexture` que dejan el SDL_Renderer con el swapchain en un
// estado que hace crashear al driver Vulkan cuando después `initShaders`
// intenta reclamar la ventana para el dispositivo SDL3 GPU.
//
// Por eso el constructor de Screen NO carga notificationText desde
// Resource; se enlaza después vía `screen->initNotifications()`.
screen = new Screen(window, renderer, asset, options);
#ifndef NO_SHADERS
if (options->videoGpuAcceleration) {
screen->initShaders();
}
#endif
// Ahora sí, precarga todos los recursos en memoria (texturas, sonidos,
// música, ...). Vivirán durante toda la vida de la app.
Resource::init(renderer, asset, input);
screen = new Screen(window, renderer, asset, options);
// Completa el enlazado de Screen con recursos que necesitan Resource
// inicializado (actualmente sólo el Text de las notificaciones).
screen->initNotifications();
activeSection = ActiveSection::None;
}
@@ -183,6 +200,9 @@ void Director::initInput() {
input->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
input->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
input->bindKey(input_window_fullscreen, SDL_SCANCODE_F3);
input->bindKey(input_toggle_gpu, SDL_SCANCODE_F9);
input->bindKey(input_toggle_shader, SDL_SCANCODE_F10);
input->bindKey(input_toggle_shader_type, SDL_SCANCODE_F11);
// Mando - Movimiento del jugador
input->bindGameControllerButton(input_up, SDL_GAMEPAD_BUTTON_DPAD_UP);
@@ -250,6 +270,10 @@ bool Director::initSDL() {
}
success = false;
} else {
// Modo de blending por defecto (consistente con CCAE):
// permite alpha blending para fades y notificaciones.
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
// Activa vsync si es necesario
if (options->vSync) {
SDL_SetRenderVSync(renderer, 1);
@@ -626,6 +650,12 @@ bool Director::saveConfigFile() {
file << "borderWidth=" + std::to_string(options->borderWidth) + "\n";
file << "borderHeight=" + std::to_string(options->borderHeight) + "\n";
// Opciones de GPU / shaders (post-procesado)
file << "videoGpuAcceleration=" + boolToString(options->videoGpuAcceleration) + "\n";
file << "videoGpuPreferredDriver=" + options->videoGpuPreferredDriver + "\n";
file << "videoShaderEnabled=" + boolToString(options->videoShaderEnabled) + "\n";
file << "videoShaderType=" + std::to_string(options->videoShaderType) + "\n";
// Otras opciones del programa
file << "\n## OTHER OPTIONS\n";
file << "language=" + std::to_string(options->language) + "\n";
@@ -835,6 +865,26 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
options->borderHeight = std::stoi(value);
}
// Opciones de GPU / shaders
else if (var == "videoGpuAcceleration") {
options->videoGpuAcceleration = stringToBool(value);
}
else if (var == "videoGpuPreferredDriver") {
options->videoGpuPreferredDriver = value;
}
else if (var == "videoShaderEnabled") {
options->videoShaderEnabled = stringToBool(value);
}
else if (var == "videoShaderType") {
options->videoShaderType = std::stoi(value);
if (options->videoShaderType < 0 || options->videoShaderType > 1) {
options->videoShaderType = 0;
}
}
// Opciones varias
else if (var == "language") {
options->language = std::stoi(value);