From 0aa9f8fe0a0e14cade55945e18877993cd606ebd Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 14 May 2026 20:56:14 +0200 Subject: [PATCH] fix: init lists, scope reduit i rename vorbis_error --- source/core/audio/jail_audio.hpp | 6 ++--- source/core/resources/resource_list.cpp | 2 +- source/core/system/director.cpp | 27 +++++++++++++---------- source/game/editor/editor_statusbar.cpp | 9 +++----- source/game/gameplay/tilemap_renderer.cpp | 5 ++--- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/source/core/audio/jail_audio.hpp b/source/core/audio/jail_audio.hpp index 63308e0..a6289ac 100644 --- a/source/core/audio/jail_audio.hpp +++ b/source/core/audio/jail_audio.hpp @@ -265,13 +265,13 @@ inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) { auto* music = new JA_Music_t(); music->ogg_data.assign(buffer, buffer + length); - int error = 0; + int vorbis_error = 0; music->vorbis = stb_vorbis_open_memory(music->ogg_data.data(), static_cast(length), - &error, + &vorbis_error, nullptr); if (!music->vorbis) { - std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << error << ")" << '\n'; + std::cout << "JA_LoadMusic: stb_vorbis_open_memory failed (error " << vorbis_error << ")" << '\n'; delete music; return nullptr; } diff --git a/source/core/resources/resource_list.cpp b/source/core/resources/resource_list.cpp index 8beb464..7cf3cf2 100644 --- a/source/core/resources/resource_list.cpp +++ b/source/core/resources/resource_list.cpp @@ -75,11 +75,11 @@ namespace Resource { } // Buscar la Ășltima entrada con el mismo prefijo de ruta e insertar despuĂ©s - std::string entry = " - " + var_path + "\n"; auto last_pos = content.rfind(var_path.substr(0, var_path.rfind('/'))); if (last_pos != std::string::npos) { auto end_of_line = content.find('\n', last_pos); if (end_of_line != std::string::npos) { + std::string entry = " - " + var_path + "\n"; content.insert(end_of_line + 1, entry); } } diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp index 0d8eacf..0266ac6 100644 --- a/source/core/system/director.cpp +++ b/source/core/system/director.cpp @@ -45,21 +45,24 @@ #include #endif -// Constructor -Director::Director() { - std::cout << "Game start" << '\n'; - +namespace { + auto getExecutablePath() -> std::string { #ifdef __EMSCRIPTEN__ - // En Emscripten els assets estan al root del filesystem virtual (/data, /config) - executable_path_ = ""; + // En Emscripten els assets estan al root del filesystem virtual (/data, /config) + return ""; #else - // Obtiene la ruta del ejecutable - std::string base = SDL_GetBasePath(); - if (!base.empty() && base.back() == '/') { - base.pop_back(); - } - executable_path_ = base; + std::string base = SDL_GetBasePath(); + if (!base.empty() && base.back() == '/') { + base.pop_back(); + } + return base; #endif + } +} // namespace + +// Constructor +Director::Director() : executable_path_(getExecutablePath()) { + std::cout << "Game start" << '\n'; // Crea la carpeta del sistema donde guardar datos createSystemFolder("jailgames"); diff --git a/source/game/editor/editor_statusbar.cpp b/source/game/editor/editor_statusbar.cpp index 61a9325..e305ffd 100644 --- a/source/game/editor/editor_statusbar.cpp +++ b/source/game/editor/editor_statusbar.cpp @@ -15,13 +15,10 @@ // Constructor EditorStatusBar::EditorStatusBar(std::string room_number, std::string room_name) - : room_number_(std::move(room_number)), + : surface_(std::make_shared(Options::game.width, 6.0F * Tile::SIZE)), + surface_dest_{.x = 0, .y = Options::game.height - (6.0F * Tile::SIZE), .w = Options::game.width, .h = 6.0F * Tile::SIZE}, + room_number_(std::move(room_number)), room_name_(std::move(room_name)) { - const float SURFACE_WIDTH = Options::game.width; - constexpr float SURFACE_HEIGHT = 6.0F * Tile::SIZE; // 48 pixels, igual que el scoreboard - - surface_ = std::make_shared(SURFACE_WIDTH, SURFACE_HEIGHT); - surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT}; } // Pinta la barra de estado en pantalla diff --git a/source/game/gameplay/tilemap_renderer.cpp b/source/game/gameplay/tilemap_renderer.cpp index 1b21658..a42534b 100644 --- a/source/game/gameplay/tilemap_renderer.cpp +++ b/source/game/gameplay/tilemap_renderer.cpp @@ -15,9 +15,8 @@ TilemapRenderer::TilemapRenderer(std::vector tile_map, int tile_set_width, tile_set_width_(tile_set_width), tileset_surface_(std::move(tileset_surface)), bg_color_(std::move(bg_color)), - conveyor_belt_direction_(conveyor_belt_direction) { - // Crear la surface del mapa - map_surface_ = std::make_shared(PlayArea::WIDTH, PlayArea::HEIGHT); + conveyor_belt_direction_(conveyor_belt_direction), + map_surface_(std::make_shared(PlayArea::WIDTH, PlayArea::HEIGHT)) { } // Inicializa el renderizador