migrant a SDL3

This commit is contained in:
2025-03-25 14:13:58 +01:00
parent 9cc41aaf53
commit f1b0303474
71 changed files with 303 additions and 360 deletions

View File

@@ -1,15 +1,15 @@
// IWYU pragma: no_include <bits/chrono.h>
#include "director.h"
#include <SDL2/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
#include <SDL2/SDL_audio.h> // Para AUDIO_S16
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <SDL2/SDL_events.h> // Para SDL_DISABLE
#include <SDL2/SDL_gamecontroller.h> // Para SDL_CONTROLLER_BUTTON_B, SDL_CO...
#include <SDL2/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
#include <SDL2/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
#include <SDL2/SDL_stdinc.h> // Para Uint32, SDL_bool
#include <SDL3/SDL.h> // Para SDL_Init, SDL_Quit, SDL_INIT_EV...
#include <SDL3/SDL_audio.h> // Para AUDIO_S16
#include <SDL3/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_events.h> // Para SDL_DISABLE
#include <SDL3/SDL.h> // Para SDL_GAMEPAD_BUTTON_B, SDL_CO...
#include <SDL3/SDL_hints.h> // Para SDL_SetHint, SDL_HINT_RENDER_DR...
#include <SDL3/SDL_mouse.h> // Para SDL_ShowCursor
#include <SDL3/SDL_scancode.h> // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN
#include <SDL3/SDL_stdinc.h> // Para Uint32, SDL_bool
#include <errno.h> // Para errno, EEXIST, EACCES, ENAMETOO...
#include <stdio.h> // Para printf, perror
#include <sys/stat.h> // Para mkdir, stat, S_IRWXU
@@ -101,7 +101,7 @@ void Director::init()
// Inicializa y crea el resto de objetos
initSDL();
SDL_ShowCursor(SDL_DISABLE);
SDL_HideCursor();
initJailAudio();
dbg_init(renderer_);
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
@@ -202,19 +202,19 @@ void Director::bindInputs()
for (int i = 0; i < NUM_GAMEPADS; ++i)
{
// Mando - Movimiento del jugador
Input::get()->bindGameControllerButton(i, InputAction::UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
Input::get()->bindGameControllerButton(i, InputAction::DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
Input::get()->bindGameControllerButton(i, InputAction::LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
Input::get()->bindGameControllerButton(i, InputAction::RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
Input::get()->bindGameControllerButton(i, InputAction::UP, SDL_GAMEPAD_BUTTON_DPAD_UP);
Input::get()->bindGameControllerButton(i, InputAction::DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN);
Input::get()->bindGameControllerButton(i, InputAction::LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT);
Input::get()->bindGameControllerButton(i, InputAction::RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_LEFT, SDL_CONTROLLER_BUTTON_X);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_B);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH);
Input::get()->bindGameControllerButton(i, InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST);
Input::get()->bindGameControllerButton(i, InputAction::START, SDL_CONTROLLER_BUTTON_START);
Input::get()->bindGameControllerButton(i, InputAction::START, SDL_GAMEPAD_BUTTON_START);
// Mando - Control del programa
Input::get()->bindGameControllerButton(i, InputAction::SERVICE, SDL_CONTROLLER_BUTTON_BACK);
Input::get()->bindGameControllerButton(i, InputAction::SERVICE, SDL_GAMEPAD_BUTTON_BACK);
}
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
@@ -270,7 +270,7 @@ void Director::bindInputs()
// Inicializa JailAudio
void Director::initJailAudio()
{
JA_Init(48000, AUDIO_S16, 2);
JA_Init(48000, SDL_AUDIO_S16LE, 2);
if (options.audio.enabled)
{
JA_SetMusicVolume(to_JA_volume(options.audio.music.volume));
@@ -290,7 +290,7 @@ bool Director::initSDL()
auto success = true;
// Inicializa SDL
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
if (!SDL_Init(SDL_INIT_VIDEO))
{
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
success = false;
@@ -298,22 +298,21 @@ bool Director::initSDL()
else
{
// Obtiene información sobre la pantalla
SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
auto DM= SDL_GetCurrentDisplayMode(0);
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
options.video.window.max_zoom = std::min(DM.w / param.game.width, DM.h / param.game.height);
options.video.window.max_zoom = std::min(DM->w / param.game.width, DM->h / param.game.height);
options.video.window.zoom = std::min(options.video.window.zoom, options.video.window.max_zoom);
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl;
std::cout << "\nCurrent display mode: " << DM->w << "x" << DM->h << " @ " << DM->refresh_rate << "Hz" << std::endl;
std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.zoom << std::endl;
// Establece el filtro de la textura
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
/*if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
{
std::cout << "Warning: texture filtering not enabled!\n";
}
}*/
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
{
@@ -321,7 +320,7 @@ bool Director::initSDL()
}
// Crea la ventana
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.zoom, param.game.height * options.video.window.zoom, SDL_WINDOW_HIDDEN);
window_ = SDL_CreateWindow(WINDOW_CAPTION, param.game.width * options.video.window.zoom, param.game.height * options.video.window.zoom, SDL_WINDOW_OPENGL);
if (!window_)
{
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
@@ -333,13 +332,13 @@ bool Director::initSDL()
Uint32 flags = 0;
if (options.video.v_sync)
{
flags = SDL_RENDERER_PRESENTVSYNC;
//flags = SDL_RENDERER_PRESENTVSYNC;
}
// La aceleración se activa según el define
flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
//flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
renderer_ = SDL_CreateRenderer(window_, -1, flags);
renderer_ = SDL_CreateRenderer(window_, nullptr);
if (!renderer_)
{
@@ -349,8 +348,7 @@ bool Director::initSDL()
else
{
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height);
SDL_RenderSetIntegerScale(renderer_, static_cast<SDL_bool>(options.video.integer_scale));
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.mode));
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
}