neteja tidy a source/core/system i audio amb fixes d'arrel
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "core/system/director.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <errno.h> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <stdio.h> // for printf, perror
|
||||
#include <string.h> // for strcmp
|
||||
|
||||
#include <cerrno> // for errno, EEXIST, EACCES, ENAMETOO...
|
||||
#include <cstdio> // for printf, perror
|
||||
#include <cstring> // for strcmp
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#include <sys/stat.h> // for mkdir, stat, S_IRWXU
|
||||
#include <unistd.h> // for getuid
|
||||
@@ -40,7 +41,7 @@
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, const char *argv[]) {
|
||||
std::cout << "Game start" << std::endl;
|
||||
std::cout << "Game start" << '\n';
|
||||
// Inicializa variables
|
||||
section = new section_t();
|
||||
section->name = SECTION_PROG_LOGO;
|
||||
@@ -97,7 +98,7 @@ Director::Director(int argc, const char *argv[]) {
|
||||
const std::string pack_path = executablePath + "resources.pack";
|
||||
#endif
|
||||
if (!ResourceHelper::initializeResourceSystem(pack_path, enable_fallback)) {
|
||||
std::cerr << "Fatal: resource system init failed (missing resources.pack?)" << std::endl;
|
||||
std::cerr << "Fatal: resource system init failed (missing resources.pack?)" << '\n';
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -197,7 +198,7 @@ Director::~Director() {
|
||||
|
||||
ResourceHelper::shutdownResourceSystem();
|
||||
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
std::cout << "\nBye!" << '\n';
|
||||
}
|
||||
|
||||
// Inicializa el objeto input
|
||||
@@ -256,14 +257,14 @@ void Director::initJailAudio() {
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
bool Director::initSDL() {
|
||||
auto Director::initSDL() -> bool {
|
||||
// Indicador de éxito
|
||||
bool success = true;
|
||||
|
||||
// Inicializa SDL
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD)) {
|
||||
if (Options::settings.console) {
|
||||
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << '\n';
|
||||
}
|
||||
success = false;
|
||||
} else {
|
||||
@@ -278,18 +279,18 @@ bool Director::initSDL() {
|
||||
0);
|
||||
if (window == nullptr) {
|
||||
if (Options::settings.console) {
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << '\n';
|
||||
}
|
||||
success = false;
|
||||
} else {
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
// Crea un renderizador para la ventana
|
||||
renderer = SDL_CreateRenderer(window, NULL);
|
||||
renderer = SDL_CreateRenderer(window, nullptr);
|
||||
|
||||
if (renderer == nullptr) {
|
||||
if (Options::settings.console) {
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << '\n';
|
||||
}
|
||||
success = false;
|
||||
} else {
|
||||
@@ -315,17 +316,17 @@ bool Director::initSDL() {
|
||||
}
|
||||
|
||||
if (Options::settings.console) {
|
||||
std::cout << std::endl;
|
||||
std::cout << '\n';
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros
|
||||
bool Director::setFileList() {
|
||||
auto Director::setFileList() -> bool {
|
||||
#ifdef MACOS_BUNDLE
|
||||
const std::string prefix = "/../Resources";
|
||||
#else
|
||||
const std::string prefix = "";
|
||||
const std::string prefix;
|
||||
#endif
|
||||
|
||||
// Ficheros de configuración
|
||||
@@ -488,7 +489,7 @@ void Director::createSystemFolder(const std::string &folder) {
|
||||
// En Emscripten no necesitamos crear carpetas (MEMFS las crea automáticamente)
|
||||
(void)folder;
|
||||
#else
|
||||
struct stat st = {0};
|
||||
struct stat st = {.st_dev = 0};
|
||||
if (stat(systemFolder.c_str(), &st) == -1) {
|
||||
errno = 0;
|
||||
#ifdef _WIN32
|
||||
@@ -537,10 +538,14 @@ void Director::handleSectionTransition() {
|
||||
case SECTION_PROG_GAME:
|
||||
targetSection = ActiveSection::Game;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Si no ha cambiado, no hay nada que hacer
|
||||
if (targetSection == activeSection) return;
|
||||
if (targetSection == activeSection) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Destruye la sección anterior
|
||||
logo.reset();
|
||||
@@ -571,7 +576,7 @@ void Director::handleSectionTransition() {
|
||||
}
|
||||
|
||||
// Ejecuta un frame del juego
|
||||
SDL_AppResult Director::iterate() {
|
||||
auto Director::iterate() -> SDL_AppResult {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// En WASM no se puede salir: reinicia al logo
|
||||
if (section->name == SECTION_PROG_QUIT) {
|
||||
@@ -611,7 +616,7 @@ SDL_AppResult Director::iterate() {
|
||||
}
|
||||
|
||||
// Procesa un evento
|
||||
SDL_AppResult Director::handleEvent(SDL_Event *event) {
|
||||
auto Director::handleEvent(SDL_Event *event) -> SDL_AppResult {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// Evento de salida de la aplicación
|
||||
if (event->type == SDL_EVENT_QUIT) {
|
||||
|
||||
Reference in New Issue
Block a user