resource.pack

This commit is contained in:
2026-04-15 23:26:43 +02:00
parent c3534ace9c
commit 0faa605ad9
35 changed files with 1537 additions and 1851 deletions

View File

@@ -10,6 +10,7 @@
#endif
#include <cstdlib> // for exit, EXIT_FAILURE, srand
#include <filesystem>
#include <fstream> // for basic_ostream, operator<<, basi...
#include <iostream> // for cout
#include <memory>
@@ -23,6 +24,8 @@
#include "intro.h" // for Intro
#include "jail_audio.hpp" // for JA_Init
#include "lang.h" // for Lang, MAX_LANGUAGES, ba_BA, en_UK
#include "resource.h"
#include "resource_helper.h"
#include "logo.h" // for Logo
#include "mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
#include "screen.h" // for FILTER_NEAREST, Screen, FILTER_...
@@ -55,6 +58,19 @@ Director::Director(int argc, const char *argv[]) {
createSystemFolder("jailgames/coffee_crisis_debug");
#endif
// Inicializa el sistema de recursos (pack + fallback)
{
#ifdef RELEASE_BUILD
const bool enable_fallback = false;
#else
const bool enable_fallback = true;
#endif
if (!ResourceHelper::initializeResourceSystem("resources.pack", enable_fallback)) {
std::cerr << "Fatal: resource system init failed (missing resources.pack?)" << std::endl;
exit(EXIT_FAILURE);
}
}
// Crea el objeto que controla los ficheros de recursos
asset = new Asset(executablePath);
asset->setVerbose(options->console);
@@ -80,9 +96,25 @@ Director::Director(int argc, const char *argv[]) {
lang = new Lang(asset);
lang->setLang(options->language);
input = new Input(asset->get("gamecontrollerdb.txt"));
#ifdef __EMSCRIPTEN__
input = new Input("/gamecontrollerdb.txt");
#else
{
const std::string binDir = std::filesystem::path(executablePath).parent_path().string();
#ifdef MACOS_BUNDLE
input = new Input(binDir + "/../Resources/gamecontrollerdb.txt");
#else
input = new Input(binDir + "/gamecontrollerdb.txt");
#endif
}
#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).
Resource::init(renderer, asset, input);
screen = new Screen(window, renderer, asset, options);
activeSection = ActiveSection::None;
@@ -99,9 +131,15 @@ Director::~Director() {
title.reset();
game.reset();
// Screen puede tener referencias a Text propiedad de Resource: destruir
// Screen antes que Resource.
delete screen;
// Libera todos los recursos precargados antes de cerrar SDL.
Resource::destroy();
delete asset;
delete input;
delete screen;
delete lang;
delete options;
delete section;
@@ -111,6 +149,8 @@ Director::~Director() {
SDL_Quit();
ResourceHelper::shutdownResourceSystem();
std::cout << "\nBye!" << std::endl;
}
@@ -240,8 +280,7 @@ bool Director::setFileList() {
// Ficheros de configuración
asset->add(systemFolder + "/config.txt", t_data, false, true);
asset->add(systemFolder + "/score.bin", t_data, false, true);
asset->add(prefix + "/data/config/demo.bin", t_data);
asset->add(prefix + "/data/config/gamecontrollerdb.txt", t_data);
asset->add(prefix + "/data/demo/demo.bin", t_data);
// Musicas
asset->add(prefix + "/data/music/intro.ogg", t_music);