passant Asset a singleton de tota la vida

This commit is contained in:
2025-05-29 13:39:53 +02:00
parent 5fd987c6a1
commit 2c2685f73c
7 changed files with 196 additions and 173 deletions

View File

@@ -5,6 +5,28 @@
#include <string> // Para allocator, string, char_traits, operator+ #include <string> // Para allocator, string, char_traits, operator+
#include "utils.h" // Para getFileName #include "utils.h" // Para getFileName
// Instancia estática del singleton
std::unique_ptr<Asset> Asset::instance_ = nullptr;
// Inicializa la instancia única del singleton
void Asset::init(const std::string &executable_path)
{
if (!instance_)
instance_ = std::make_unique<Asset>(executable_path);
}
// Libera la instancia única
void Asset::destroy()
{
instance_.reset();
}
// Obtiene la instancia única
Asset *Asset::get()
{
return instance_.get();
}
// Añade un elemento a la lista // Añade un elemento a la lista
void Asset::add(const std::string &file, AssetType type, bool required, bool absolute) void Asset::add(const std::string &file, AssetType type, bool required, bool absolute)
{ {

View File

@@ -2,6 +2,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include "utils.h" #include "utils.h"
// Tipos de recursos gestionados por Asset // Tipos de recursos gestionados por Asset
@@ -23,18 +24,14 @@ enum class AssetType : int
class Asset class Asset
{ {
public: public:
// Obtención de la instancia única (Meyers Singleton) // Inicializa la instancia única del singleton
static Asset &get() static void init(const std::string &executable_path);
{
static Asset instance;
return instance;
}
// Inicializa el gestor de recursos con la ruta del ejecutable // Libera la instancia única
void init(const std::string &executable_path) static void destroy();
{
executable_path_ = getPath(executable_path); // Obtiene la instancia única
} static Asset *get();
// Añade un recurso a la lista // Añade un recurso a la lista
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
@@ -70,8 +67,11 @@ private:
std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso
// Patrón Singleton: constructor y destructor privados, sin copia ni asignación // Patrón Singleton: constructor y destructor privados, sin copia ni asignación
Asset() = default; Asset(const std::string &executable_path)
: executable_path_(executable_path) {};
~Asset() = default; ~Asset() = default;
Asset(const Asset &) = delete; Asset(const Asset &) = delete;
Asset &operator=(const Asset &) = delete; Asset &operator=(const Asset &) = delete;
static std::unique_ptr<Asset> instance_;
}; };

View File

@@ -85,18 +85,18 @@ Director::~Director()
void Director::init() void Director::init()
{ {
// Configuración inicial de recursos // Configuración inicial de recursos
Asset::get().init(executable_path_); // Inicializa el sistema de gestión de archivos Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos
setFileList(); // Crea el índice de archivos setFileList(); // Crea el índice de archivos
loadOptionsFile(Asset::get().get("config.txt")); // Carga el archivo de configuración loadOptionsFile(Asset::get()->get("config.txt")); // Carga el archivo de configuración
loadParams(); // Carga los parámetros del programa loadParams(); // Carga los parámetros del programa
loadScoreFile(); // Carga el archivo de puntuaciones loadScoreFile(); // Carga el archivo de puntuaciones
// Inicialización de subsistemas // Inicialización de subsistemas
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language))); // Carga el archivo de idioma lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language))); // Carga el archivo de idioma
Screen::init(); // Inicializa la pantalla y el sistema de renderizado Screen::init(); // Inicializa la pantalla y el sistema de renderizado
Audio::get(); // Activa el sistema de audio Audio::get(); // Activa el sistema de audio
Resource::init(); // Inicializa el sistema de gestión de recursos Resource::init(); // Inicializa el sistema de gestión de recursos
Input::init(Asset::get().get("gamecontrollerdb.txt")); // Carga configuración de controles Input::init(Asset::get()->get("gamecontrollerdb.txt")); // Carga configuración de controles
bindInputs(); // Asigna los controles a la entrada del sistema bindInputs(); // Asigna los controles a la entrada del sistema
// Inicialización del sistema de notificaciones // Inicialización del sistema de notificaciones
@@ -112,12 +112,13 @@ void Director::init()
// Cierra todo // Cierra todo
void Director::close() void Director::close()
{ {
saveOptionsFile(Asset::get().get("config.txt")); saveOptionsFile(Asset::get()->get("config.txt"));
Notifier::destroy(); Notifier::destroy();
Input::destroy(); Input::destroy();
Resource::destroy(); Resource::destroy();
Screen::destroy(); Screen::destroy();
Asset::destroy();
SDL_Quit(); SDL_Quit();
@@ -133,7 +134,7 @@ void Director::loadParams()
#ifdef ANBERNIC #ifdef ANBERNIC
const std::string paramFilePath = asset->get("param_320x240.txt"); const std::string paramFilePath = asset->get("param_320x240.txt");
#else #else
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get().get("param_320x240.txt") : Asset::get().get("param_320x256.txt"); const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
#endif #endif
loadParamsFromFile(paramFilePath); loadParamsFromFile(paramFilePath);
} }
@@ -148,7 +149,7 @@ void Director::loadScoreFile()
} }
else else
{ {
manager->loadFromFile(Asset::get().get("score.bin")); manager->loadFromFile(Asset::get()->get("score.bin"));
} }
} }
@@ -267,189 +268,189 @@ void Director::setFileList()
#endif #endif
// Ficheros de configuración // Ficheros de configuración
Asset::get().add(system_folder_ + "/config.txt", AssetType::DATA, false, true); Asset::get()->add(system_folder_ + "/config.txt", AssetType::DATA, false, true);
Asset::get().add(system_folder_ + "/score.bin", AssetType::DATA, false, true); Asset::get()->add(system_folder_ + "/score.bin", AssetType::DATA, false, true);
Asset::get().add(prefix + "/data/config/param_320x240.txt", AssetType::DATA); Asset::get()->add(prefix + "/data/config/param_320x240.txt", AssetType::DATA);
Asset::get().add(prefix + "/data/config/param_320x256.txt", AssetType::DATA); Asset::get()->add(prefix + "/data/config/param_320x256.txt", AssetType::DATA);
Asset::get().add(prefix + "/data/config/demo1.bin", AssetType::DATA); Asset::get()->add(prefix + "/data/config/demo1.bin", AssetType::DATA);
Asset::get().add(prefix + "/data/config/demo2.bin", AssetType::DATA); Asset::get()->add(prefix + "/data/config/demo2.bin", AssetType::DATA);
Asset::get().add(prefix + "/data/config/gamecontrollerdb.txt", AssetType::DATA); Asset::get()->add(prefix + "/data/config/gamecontrollerdb.txt", AssetType::DATA);
// Musicas // Musicas
Asset::get().add(prefix + "/data/music/intro.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/intro.ogg", AssetType::MUSIC);
Asset::get().add(prefix + "/data/music/playing.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/playing.ogg", AssetType::MUSIC);
Asset::get().add(prefix + "/data/music/title.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/title.ogg", AssetType::MUSIC);
Asset::get().add(prefix + "/data/music/credits.ogg", AssetType::MUSIC); Asset::get()->add(prefix + "/data/music/credits.ogg", AssetType::MUSIC);
// Sonidos // Sonidos
Asset::get().add(prefix + "/data/sound/balloon.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/balloon.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/bubble1.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/bubble1.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/bubble2.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/bubble2.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/bubble3.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/bubble3.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/bubble4.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/bubble4.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/bullet.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/bullet.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/clock.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/clock.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/coffee_out.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/coffee_out.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/continue_clock.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/continue_clock.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/game_start.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/game_start.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/hi_score_achieved.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/hi_score_achieved.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/item_drop.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/item_drop.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/item_pickup.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/item_pickup.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/logo.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/logo.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/notify.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/notify.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/player_collision.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/player_collision.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/power_ball_explosion.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/power_ball_explosion.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/stage_change.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/stage_change.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/tabe.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/tabe.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/title.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/title.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/voice_coffee.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/voice_coffee.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/voice_get_ready.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/voice_get_ready.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/voice_no.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/voice_no.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/voice_power_up.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/voice_power_up.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/walk.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/walk.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/debian_drop.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/debian_drop.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/debian_pickup.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/debian_pickup.wav", AssetType::SOUND);
Asset::get().add(prefix + "/data/sound/tabe_hit.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/tabe_hit.wav", AssetType::SOUND);
// Shaders // Shaders
Asset::get().add(prefix + "/data/shaders/crtpi_256.glsl", AssetType::DATA); Asset::get()->add(prefix + "/data/shaders/crtpi_256.glsl", AssetType::DATA);
Asset::get().add(prefix + "/data/shaders/crtpi_240.glsl", AssetType::DATA); Asset::get()->add(prefix + "/data/shaders/crtpi_240.glsl", AssetType::DATA);
// Texturas // Texturas
{ // Controllers { // Controllers
Asset::get().add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP);
} }
{ // Balloons { // Balloons
Asset::get().add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/balloon2.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/balloon/balloon3.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION);
} }
{ // Explosions { // Explosions
Asset::get().add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/explosion2.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/balloon/explosion3.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION);
} }
{ // Power Ball { // Power Ball
Asset::get().add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION);
} }
{ // Bala { // Bala
Asset::get().add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP);
} }
{ // Tabe { // Tabe
Asset::get().add(prefix + "/data/gfx/tabe/tabe.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/tabe/tabe.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/tabe/tabe.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/tabe/tabe.ani", AssetType::ANIMATION);
} }
{ // Juego { // Juego
Asset::get().add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_sun.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_sun.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/game/game_moon.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/game/game_moon.png", AssetType::BITMAP);
} }
{ // Intro { // Intro
Asset::get().add(prefix + "/data/gfx/intro/intro1.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/intro/intro1.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/intro/intro2.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/intro/intro2.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/intro/intro3.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/intro/intro3.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/intro/intro4.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/intro/intro4.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/intro/intro5.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/intro/intro5.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/intro/intro6.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/intro/intro6.png", AssetType::BITMAP);
} }
{ // Logo { // Logo
Asset::get().add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP);
} }
{ // Items { // Items
Asset::get().add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_points2_gavina.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/item/item_points3_pacmar.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_points3_pacmar.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/item/item_clock.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_clock.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_clock.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_clock.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/item/item_coffee.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_coffee.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/item/item_debian.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_debian.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_debian.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_debian.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION);
} }
{ // Titulo { // Titulo
Asset::get().add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION);
} }
{ // Jugador 1 { // Jugador 1
Asset::get().add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/player/player1_1_coffee_palette.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/gfx/player/player1_1_coffee_palette.gif", AssetType::PALETTE);
Asset::get().add(prefix + "/data/gfx/player/player1_2_coffee_palette.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/gfx/player/player1_2_coffee_palette.gif", AssetType::PALETTE);
Asset::get().add(prefix + "/data/gfx/player/player1_invencible_palette.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/gfx/player/player1_invencible_palette.gif", AssetType::PALETTE);
Asset::get().add(prefix + "/data/gfx/player/player1_power.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/player/player1_power.png", AssetType::BITMAP);
} }
{ // Jugador 2 { // Jugador 2
Asset::get().add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP);
Asset::get().add(prefix + "/data/gfx/player/player2_1_coffee_palette.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/gfx/player/player2_1_coffee_palette.gif", AssetType::PALETTE);
Asset::get().add(prefix + "/data/gfx/player/player2_2_coffee_palette.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/gfx/player/player2_2_coffee_palette.gif", AssetType::PALETTE);
Asset::get().add(prefix + "/data/gfx/player/player2_invencible_palette.gif", AssetType::PALETTE); Asset::get()->add(prefix + "/data/gfx/player/player2_invencible_palette.gif", AssetType::PALETTE);
Asset::get().add(prefix + "/data/gfx/player/player2_power.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/gfx/player/player2_power.png", AssetType::BITMAP);
} }
{ // Animaciones del jugador { // Animaciones del jugador
Asset::get().add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION);
Asset::get().add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION); Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION);
} }
// Fuentes de texto // Fuentes de texto
Asset::get().add(prefix + "/data/font/8bithud.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/font/8bithud.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
Asset::get().add(prefix + "/data/font/smb2.gif", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP);
Asset::get().add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE); Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE);
Asset::get().add(prefix + "/data/font/smb2.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT);
Asset::get().add(prefix + "/data/font/04b_25.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/04b_25.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/font/04b_25.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/04b_25.txt", AssetType::FONT);
Asset::get().add(prefix + "/data/font/04b_25_2x.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/04b_25_2x.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/font/04b_25_2x.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/04b_25_2x.txt", AssetType::FONT);
Asset::get().add(prefix + "/data/font/04b_25_metal.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/04b_25_metal.png", AssetType::BITMAP);
Asset::get().add(prefix + "/data/font/04b_25_grey.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/04b_25_grey.png", AssetType::BITMAP);
// Textos // Textos
Asset::get().add(prefix + "/data/lang/es_ES.txt", AssetType::LANG); Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG);
Asset::get().add(prefix + "/data/lang/en_UK.txt", AssetType::LANG); Asset::get()->add(prefix + "/data/lang/en_UK.txt", AssetType::LANG);
Asset::get().add(prefix + "/data/lang/ba_BA.txt", AssetType::LANG); Asset::get()->add(prefix + "/data/lang/ba_BA.txt", AssetType::LANG);
// Si falta algun fichero, sale del programa // Si falta algun fichero, sale del programa
if (!Asset::get().check()) if (!Asset::get()->check())
{ {
throw std::runtime_error("Falta algun fichero"); throw std::runtime_error("Falta algun fichero");
} }
@@ -677,19 +678,19 @@ std::string Director::getLangFile(lang::Code code)
switch (code) switch (code)
{ {
case lang::Code::ba_BA: case lang::Code::ba_BA:
return Asset::get().get("ba_BA.txt"); return Asset::get()->get("ba_BA.txt");
break; break;
case lang::Code::es_ES: case lang::Code::es_ES:
return Asset::get().get("es_ES.txt"); return Asset::get()->get("es_ES.txt");
break; break;
case lang::Code::en_UK: case lang::Code::en_UK:
return Asset::get().get("en_UK.txt"); return Asset::get()->get("en_UK.txt");
break; break;
default: default:
break; break;
} }
return Asset::get().get("en_UK.txt"); return Asset::get()->get("en_UK.txt");
} }
#ifdef ARCADE #ifdef ARCADE

View File

@@ -107,13 +107,13 @@ Game::~Game()
{ {
// [Modo JUEGO] Guarda puntuaciones y transita a modo título // [Modo JUEGO] Guarda puntuaciones y transita a modo título
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table); auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
manager->saveToFile(Asset::get().get("score.bin")); manager->saveToFile(Asset::get()->get("score.bin"));
section::attract_mode = section::AttractMode::TITLE_TO_DEMO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
Audio::get().stopMusic(); Audio::get().stopMusic();
} }
#ifdef RECORDING #ifdef RECORDING
saveDemoFile(Asset::get().get("demo1.bin"), demo_.data.at(0)); saveDemoFile(Asset::get()->get("demo1.bin"), demo_.data.at(0));
#endif #endif
Scoreboard::destroy(); Scoreboard::destroy();
@@ -1268,7 +1268,7 @@ void Game::addScoreToScoreBoard(const std::shared_ptr<Player> &player)
const auto entry = HiScoreEntry(trim(player->getRecordName()), player->getScore(), player->get1CC()); const auto entry = HiScoreEntry(trim(player->getRecordName()), player->getScore(), player->get1CC());
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table); auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
options.game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry); options.game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry);
manager->saveToFile(Asset::get().get("score.bin")); manager->saveToFile(Asset::get()->get("score.bin"));
hi_score_.name = options.game.hi_score_table.front().name; hi_score_.name = options.game.hi_score_table.front().name;
} }

View File

@@ -91,13 +91,13 @@ namespace globalInputs
switch (code) switch (code)
{ {
case lang::Code::ba_BA: case lang::Code::ba_BA:
return Asset::get().get("ba_BA.txt"); return Asset::get()->get("ba_BA.txt");
break; break;
case lang::Code::es_ES: case lang::Code::es_ES:
return Asset::get().get("es_ES.txt"); return Asset::get()->get("es_ES.txt");
break; break;
default: default:
return Asset::get().get("en_UK.txt"); return Asset::get()->get("en_UK.txt");
break; break;
} }
} }

View File

@@ -180,7 +180,7 @@ DemoData &Resource::getDemoData(int index)
void Resource::loadSounds() void Resource::loadSounds()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> SOUND FILES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> SOUND FILES");
auto list = Asset::get().getListByType(AssetType::SOUND); auto list = Asset::get()->getListByType(AssetType::SOUND);
sounds_.clear(); sounds_.clear();
for (const auto &l : list) for (const auto &l : list)
@@ -195,7 +195,7 @@ void Resource::loadSounds()
void Resource::loadMusics() void Resource::loadMusics()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> MUSIC FILES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> MUSIC FILES");
auto list = Asset::get().getListByType(AssetType::MUSIC); auto list = Asset::get()->getListByType(AssetType::MUSIC);
musics_.clear(); musics_.clear();
for (const auto &l : list) for (const auto &l : list)
@@ -210,7 +210,7 @@ void Resource::loadMusics()
void Resource::loadTextures() void Resource::loadTextures()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXTURES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXTURES");
auto list = Asset::get().getListByType(AssetType::BITMAP); auto list = Asset::get()->getListByType(AssetType::BITMAP);
textures_.clear(); textures_.clear();
for (const auto &l : list) for (const auto &l : list)
@@ -224,7 +224,7 @@ void Resource::loadTextures()
void Resource::loadTextFiles() void Resource::loadTextFiles()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES");
auto list = Asset::get().getListByType(AssetType::FONT); auto list = Asset::get()->getListByType(AssetType::FONT);
text_files_.clear(); text_files_.clear();
for (const auto &l : list) for (const auto &l : list)
@@ -238,7 +238,7 @@ void Resource::loadTextFiles()
void Resource::loadAnimations() void Resource::loadAnimations()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> ANIMATIONS"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> ANIMATIONS");
auto list = Asset::get().getListByType(AssetType::ANIMATION); auto list = Asset::get()->getListByType(AssetType::ANIMATION);
animations_.clear(); animations_.clear();
for (const auto &l : list) for (const auto &l : list)
@@ -252,8 +252,8 @@ void Resource::loadAnimations()
void Resource::loadDemoData() void Resource::loadDemoData()
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES");
demos_.emplace_back(loadDemoDataFromFile(Asset::get().get("demo1.bin"))); demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo1.bin")));
demos_.emplace_back(loadDemoDataFromFile(Asset::get().get("demo2.bin"))); demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get("demo2.bin")));
} }
// Añade paletas a las texturas // Añade paletas a las texturas
@@ -262,17 +262,17 @@ void Resource::addPalettes()
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> PALETTES"); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> PALETTES");
// Jugador 1 // Jugador 1
getTexture("player1.gif")->addPaletteFromFile(Asset::get().get("player1_1_coffee_palette.gif")); getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_1_coffee_palette.gif"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get().get("player1_2_coffee_palette.gif")); getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_2_coffee_palette.gif"));
getTexture("player1.gif")->addPaletteFromFile(Asset::get().get("player1_invencible_palette.gif")); getTexture("player1.gif")->addPaletteFromFile(Asset::get()->get("player1_invencible_palette.gif"));
// Jugador 2 // Jugador 2
getTexture("player2.gif")->addPaletteFromFile(Asset::get().get("player2_1_coffee_palette.gif")); getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_1_coffee_palette.gif"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get().get("player2_2_coffee_palette.gif")); getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_2_coffee_palette.gif"));
getTexture("player2.gif")->addPaletteFromFile(Asset::get().get("player2_invencible_palette.gif")); getTexture("player2.gif")->addPaletteFromFile(Asset::get()->get("player2_invencible_palette.gif"));
// Fuentes // Fuentes
getTexture("smb2.gif")->addPaletteFromFile(Asset::get().get("smb2_palette1.pal")); getTexture("smb2.gif")->addPaletteFromFile(Asset::get()->get("smb2_palette1.pal"));
} }
// Crea texturas // Crea texturas

View File

@@ -231,7 +231,7 @@ void Screen::renderInfo()
void Screen::loadShaders() void Screen::loadShaders()
{ {
const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl"; const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl";
std::ifstream f(Asset::get().get(GLSL_FILE).c_str()); std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
shader_source_ = std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); shader_source_ = std::string((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
} }