unificats els resources en un namespace
This commit is contained in:
@@ -645,7 +645,7 @@ Achievements trigger notifications on unlock.
|
|||||||
Available types: `DATA`, `BITMAP`, `ANIMATION`, `MUSIC`, `SOUND`, `FONT`, `ROOM`, `TILEMAP`, `PALETTE`
|
Available types: `DATA`, `BITMAP`, `ANIMATION`, `MUSIC`, `SOUND`, `FONT`, `ROOM`, `TILEMAP`, `PALETTE`
|
||||||
3. Optional flags can be added: `TYPE|${PREFIX}/path/file.ext|optional,absolute`
|
3. Optional flags can be added: `TYPE|${PREFIX}/path/file.ext|optional,absolute`
|
||||||
4. Resource loads automatically during `Resource::init()`
|
4. Resource loads automatically during `Resource::init()`
|
||||||
5. Access via: `Resource::get()->getSurface("name")`
|
5. Access via: `Resource::Cache::get()->getSurface("name")`
|
||||||
|
|
||||||
**Note:** No recompilation needed when adding/removing/modifying assets in `config/assets.txt`
|
**Note:** No recompilation needed when adding/removing/modifying assets in `config/assets.txt`
|
||||||
|
|
||||||
@@ -788,7 +788,7 @@ Binary 256-color palette format (256 × 4 bytes RGBA).
|
|||||||
### For Asset Management
|
### For Asset Management
|
||||||
- `config/assets.txt` - Asset configuration file (text-based, no recompilation needed)
|
- `config/assets.txt` - Asset configuration file (text-based, no recompilation needed)
|
||||||
- `Asset::loadFromFile()` - Loads assets from config file
|
- `Asset::loadFromFile()` - Loads assets from config file
|
||||||
- `Asset::get()` - Retrieves asset path (O(1) lookup with unordered_map)
|
- `Resource::List::get()` - Retrieves asset path (O(1) lookup with unordered_map)
|
||||||
- `Resource::load()` - Asset loading
|
- `Resource::load()` - Asset loading
|
||||||
- `Director::setFileList()` - Calls `Asset::loadFromFile()` with PREFIX and system_folder
|
- `Director::setFileList()` - Calls `Asset::loadFromFile()` with PREFIX and system_folder
|
||||||
|
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ set(APP_SOURCES
|
|||||||
source/core/rendering/texture.cpp
|
source/core/rendering/texture.cpp
|
||||||
|
|
||||||
# Core - Resources
|
# Core - Resources
|
||||||
source/core/resources/asset.cpp
|
source/core/resources/resource_list.cpp
|
||||||
source/core/resources/resource.cpp
|
source/core/resources/resource_cache.cpp
|
||||||
source/core/resources/resource_pack.cpp
|
source/core/resources/resource_pack.cpp
|
||||||
source/core/resources/resource_loader.cpp
|
source/core/resources/resource_loader.cpp
|
||||||
source/core/resources/resource_helper.cpp
|
source/core/resources/resource_helper.cpp
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#include <algorithm> // Para clamp
|
#include <algorithm> // Para clamp
|
||||||
#include <iostream> // Para std::cout
|
#include <iostream> // Para std::cout
|
||||||
|
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
|
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
|
||||||
#include "game/options.hpp" // Para AudioOptions, audio, MusicOptions
|
#include "game/options.hpp" // Para AudioOptions, audio, MusicOptions
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
Audio* Audio::instance = nullptr;
|
Audio* Audio::instance = nullptr;
|
||||||
@@ -44,7 +44,7 @@ void Audio::playMusic(const std::string& name, const int loop) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Intentar obtener recurso; si falla, no tocar estado
|
// Intentar obtener recurso; si falla, no tocar estado
|
||||||
auto* resource = Resource::get()->getMusic(name);
|
auto* resource = Resource::Cache::get()->getMusic(name);
|
||||||
if (resource == nullptr) {
|
if (resource == nullptr) {
|
||||||
// manejo de error opcional
|
// manejo de error opcional
|
||||||
return;
|
return;
|
||||||
@@ -91,7 +91,7 @@ void Audio::stopMusic() {
|
|||||||
// Reproduce un sonido por nombre
|
// Reproduce un sonido por nombre
|
||||||
void Audio::playSound(const std::string& name, Group group) const {
|
void Audio::playSound(const std::string& name, Group group) const {
|
||||||
if (sound_enabled_) {
|
if (sound_enabled_) {
|
||||||
JA_PlaySound(Resource::get()->getSound(name), 0, static_cast<int>(group));
|
JA_PlaySound(Resource::Cache::get()->getSound(name), 0, static_cast<int>(group));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
#include "core/rendering/opengl/opengl_shader.hpp" // Para OpenGLShader
|
#include "core/rendering/opengl/opengl_shader.hpp" // Para OpenGLShader
|
||||||
#include "core/rendering/surface.hpp" // Para Surface, readPalFile
|
#include "core/rendering/surface.hpp" // Para Surface, readPalFile
|
||||||
#include "core/rendering/text.hpp" // Para Text
|
#include "core/rendering/text.hpp" // Para Text
|
||||||
#include "core/resources/asset.hpp" // Para Asset, AssetType
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
|
||||||
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
||||||
|
#include "core/resources/resource_list.hpp" // Para Asset, AssetType
|
||||||
#include "game/options.hpp" // Para Options, options, OptionsVideo, Border
|
#include "game/options.hpp" // Para Options, options, OptionsVideo, Border
|
||||||
#include "game/ui/notifier.hpp" // Para Notifier
|
#include "game/ui/notifier.hpp" // Para Notifier
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ auto Screen::get() -> Screen* {
|
|||||||
Screen::Screen()
|
Screen::Screen()
|
||||||
: window_width_(0),
|
: window_width_(0),
|
||||||
window_height_(0),
|
window_height_(0),
|
||||||
palettes_(Asset::get()->getListByType(Asset::Type::PALETTE)) {
|
palettes_(Resource::List::get()->getListByType(Resource::List::Type::PALETTE)) {
|
||||||
// Arranca SDL VIDEO, crea la ventana y el renderizador
|
// Arranca SDL VIDEO, crea la ventana y el renderizador
|
||||||
initSDLVideo();
|
initSDLVideo();
|
||||||
if (Options::video.fullscreen) {
|
if (Options::video.fullscreen) {
|
||||||
@@ -274,8 +274,8 @@ void Screen::previousPalette() {
|
|||||||
|
|
||||||
// Establece la paleta
|
// Establece la paleta
|
||||||
void Screen::setPalete() {
|
void Screen::setPalete() {
|
||||||
game_surface_->loadPalette(Resource::get()->getPalette(palettes_.at(current_palette_)));
|
game_surface_->loadPalette(Resource::Cache::get()->getPalette(palettes_.at(current_palette_)));
|
||||||
border_surface_->loadPalette(Resource::get()->getPalette(palettes_.at(current_palette_)));
|
border_surface_->loadPalette(Resource::Cache::get()->getPalette(palettes_.at(current_palette_)));
|
||||||
|
|
||||||
Options::video.palette = palettes_.at(current_palette_);
|
Options::video.palette = palettes_.at(current_palette_);
|
||||||
|
|
||||||
@@ -341,8 +341,8 @@ auto Screen::findPalette(const std::string& name) -> size_t {
|
|||||||
|
|
||||||
// Muestra información por pantalla
|
// Muestra información por pantalla
|
||||||
void Screen::renderInfo() {
|
void Screen::renderInfo() {
|
||||||
if (show_debug_info_ && (Resource::get() != nullptr)) {
|
if (show_debug_info_ && (Resource::Cache::get() != nullptr)) {
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
auto color = static_cast<Uint8>(PaletteColor::YELLOW);
|
auto color = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||||
|
|
||||||
// FPS
|
// FPS
|
||||||
@@ -397,7 +397,7 @@ auto Screen::getBorderSurface() -> std::shared_ptr<Surface> { return border_surf
|
|||||||
|
|
||||||
auto loadData(const std::string& filepath) -> std::vector<uint8_t> {
|
auto loadData(const std::string& filepath) -> std::vector<uint8_t> {
|
||||||
// Load using ResourceHelper (supports both filesystem and pack)
|
// Load using ResourceHelper (supports both filesystem and pack)
|
||||||
return Jdd::ResourceHelper::loadFile(filepath);
|
return Resource::Helper::loadFile(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el contenido de los archivos GLSL
|
// Carga el contenido de los archivos GLSL
|
||||||
@@ -406,12 +406,12 @@ void Screen::loadShaders() {
|
|||||||
// Detectar si necesitamos OpenGL ES (Raspberry Pi)
|
// Detectar si necesitamos OpenGL ES (Raspberry Pi)
|
||||||
// Intentar cargar versión ES primero si existe
|
// Intentar cargar versión ES primero si existe
|
||||||
std::string vertex_file = "crtpi_vertex_es.glsl";
|
std::string vertex_file = "crtpi_vertex_es.glsl";
|
||||||
auto data = loadData(Asset::get()->get(vertex_file));
|
auto data = loadData(Resource::List::get()->get(vertex_file));
|
||||||
|
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
// Si no existe versión ES, usar versión Desktop
|
// Si no existe versión ES, usar versión Desktop
|
||||||
vertex_file = "crtpi_vertex.glsl";
|
vertex_file = "crtpi_vertex.glsl";
|
||||||
data = loadData(Asset::get()->get(vertex_file));
|
data = loadData(Resource::List::get()->get(vertex_file));
|
||||||
std::cout << "Usando shaders OpenGL Desktop 3.3\n";
|
std::cout << "Usando shaders OpenGL Desktop 3.3\n";
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Usando shaders OpenGL ES 3.0 (Raspberry Pi)\n";
|
std::cout << "Usando shaders OpenGL ES 3.0 (Raspberry Pi)\n";
|
||||||
@@ -424,12 +424,12 @@ void Screen::loadShaders() {
|
|||||||
if (fragment_shader_source_.empty()) {
|
if (fragment_shader_source_.empty()) {
|
||||||
// Intentar cargar versión ES primero si existe
|
// Intentar cargar versión ES primero si existe
|
||||||
std::string fragment_file = "crtpi_fragment_es.glsl";
|
std::string fragment_file = "crtpi_fragment_es.glsl";
|
||||||
auto data = loadData(Asset::get()->get(fragment_file));
|
auto data = loadData(Resource::List::get()->get(fragment_file));
|
||||||
|
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
// Si no existe versión ES, usar versión Desktop
|
// Si no existe versión ES, usar versión Desktop
|
||||||
fragment_file = "crtpi_fragment.glsl";
|
fragment_file = "crtpi_fragment.glsl";
|
||||||
data = loadData(Asset::get()->get(fragment_file));
|
data = loadData(Resource::List::get()->get(fragment_file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
@@ -582,8 +582,8 @@ auto Screen::initSDLVideo() -> bool {
|
|||||||
// Crea el objeto de texto
|
// Crea el objeto de texto
|
||||||
void Screen::createText() {
|
void Screen::createText() {
|
||||||
// Carga la surface de la fuente directamente del archivo
|
// Carga la surface de la fuente directamente del archivo
|
||||||
auto surface = std::make_shared<Surface>(Asset::get()->get("aseprite.gif"));
|
auto surface = std::make_shared<Surface>(Resource::List::get()->get("aseprite.gif"));
|
||||||
|
|
||||||
// Crea el objeto de texto (el constructor de Text carga el archivo text_file internamente)
|
// Crea el objeto de texto (el constructor de Text carga el archivo text_file internamente)
|
||||||
text_ = std::make_shared<Text>(surface, Asset::get()->get("aseprite.txt"));
|
text_ = std::make_shared<Text>(surface, Resource::List::get()->get("aseprite.txt"));
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
// Carga una paleta desde un archivo .gif
|
// Carga una paleta desde un archivo .gif
|
||||||
auto loadPalette(const std::string& file_path) -> Palette {
|
auto loadPalette(const std::string& file_path) -> Palette {
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
auto buffer = Jdd::ResourceHelper::loadFile(file_path);
|
auto buffer = Resource::Helper::loadFile(file_path);
|
||||||
if (buffer.empty()) {
|
if (buffer.empty()) {
|
||||||
throw std::runtime_error("Error opening file: " + file_path);
|
throw std::runtime_error("Error opening file: " + file_path);
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ auto readPalFile(const std::string& file_path) -> Palette {
|
|||||||
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
||||||
|
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
auto file_data = Jdd::ResourceHelper::loadFile(file_path);
|
auto file_data = Resource::Helper::loadFile(file_path);
|
||||||
if (file_data.empty()) {
|
if (file_data.empty()) {
|
||||||
throw std::runtime_error("No se pudo abrir el archivo .pal: " + file_path);
|
throw std::runtime_error("No se pudo abrir el archivo .pal: " + file_path);
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ Surface::Surface(const std::string& file_path)
|
|||||||
// Carga una superficie desde un archivo
|
// Carga una superficie desde un archivo
|
||||||
auto Surface::loadSurface(const std::string& file_path) -> SurfaceData {
|
auto Surface::loadSurface(const std::string& file_path) -> SurfaceData {
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
std::vector<Uint8> buffer = Jdd::ResourceHelper::loadFile(file_path);
|
std::vector<Uint8> buffer = Resource::Helper::loadFile(file_path);
|
||||||
if (buffer.empty()) {
|
if (buffer.empty()) {
|
||||||
std::cerr << "Error opening file: " << file_path << '\n';
|
std::cerr << "Error opening file: " << file_path << '\n';
|
||||||
throw std::runtime_error("Error opening file");
|
throw std::runtime_error("Error opening file");
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
||||||
#include "utils/utils.hpp" // Para printWithDots
|
#include "utils/utils.hpp" // Para printWithDots
|
||||||
|
|
||||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||||
auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
|
auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
auto file_data = Jdd::ResourceHelper::loadFile(file_path);
|
auto file_data = Resource::Helper::loadFile(file_path);
|
||||||
if (file_data.empty()) {
|
if (file_data.empty()) {
|
||||||
std::cerr << "Error: Fichero no encontrado " << file_path << '\n';
|
std::cerr << "Error: Fichero no encontrado " << file_path << '\n';
|
||||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||||
@@ -192,7 +192,7 @@ auto parseGlobalParameter(const std::string& line, std::shared_ptr<Surface>& sur
|
|||||||
|
|
||||||
if (key == "tileSetFile") {
|
if (key == "tileSetFile") {
|
||||||
std::string value = line.substr(pos + 1);
|
std::string value = line.substr(pos + 1);
|
||||||
surface = Resource::get()->getSurface(value);
|
surface = Resource::Cache::get()->getSurface(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (key == "frame_width") {
|
if (key == "frame_width") {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ auto loadTextFile(const std::string& file_path) -> std::shared_ptr<TextFile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
auto file_data = Jdd::ResourceHelper::loadFile(file_path);
|
auto file_data = Resource::Helper::loadFile(file_path);
|
||||||
if (file_data.empty()) {
|
if (file_data.empty()) {
|
||||||
std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << '\n';
|
std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << '\n';
|
||||||
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
|
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "core/resources/resource.hpp"
|
#include "core/resources/resource_cache.hpp"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
@@ -8,40 +8,42 @@
|
|||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/rendering/text.hpp" // Para Text, loadTextFile
|
#include "core/rendering/text.hpp" // Para Text, loadTextFile
|
||||||
#include "core/resources/asset.hpp" // Para AssetType, Asset
|
#include "core/resources/resource_list.hpp" // Para List, List::Type
|
||||||
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
#include "core/resources/resource_helper.hpp" // Para Helper
|
||||||
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
||||||
#include "game/defaults.hpp" // Para GameDefaults::VERSION
|
#include "game/defaults.hpp" // Para GameDefaults::VERSION
|
||||||
#include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
|
#include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
|
||||||
#include "game/options.hpp" // Para Options, OptionsGame, options
|
#include "game/options.hpp" // Para Options, OptionsGame, options
|
||||||
#include "utils/defines.hpp" // Para WINDOW_CAPTION
|
#include "utils/defines.hpp" // Para WINDOW_CAPTION
|
||||||
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
|
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
|
||||||
#include "version.h" // Para Version::GIT_HASH
|
#include "version.h" // Para Version::GIT_HASH
|
||||||
struct JA_Music_t; // lines 17-17
|
struct JA_Music_t; // lines 17-17
|
||||||
struct JA_Sound_t; // lines 18-18
|
struct JA_Sound_t; // lines 18-18
|
||||||
|
|
||||||
|
namespace Resource {
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Resource* Resource::resource = nullptr;
|
Cache* Cache::cache = nullptr;
|
||||||
|
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto cache con esta función estática
|
||||||
void Resource::init() { Resource::resource = new Resource(); }
|
void Cache::init() { Cache::cache = new Cache(); }
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto screen con esta función estática
|
// [SINGLETON] Destruiremos el objeto cache con esta función estática
|
||||||
void Resource::destroy() { delete Resource::resource; }
|
void Cache::destroy() { delete Cache::cache; }
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto cache y podemos trabajar con él
|
||||||
auto Resource::get() -> Resource* { return Resource::resource; }
|
auto Cache::get() -> Cache* { return Cache::cache; }
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Resource::Resource()
|
Cache::Cache()
|
||||||
: loading_text_(Screen::get()->getText()) {
|
: loading_text_(Screen::get()->getText()) {
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vacia todos los vectores de recursos
|
// Vacia todos los vectores de recursos
|
||||||
void Resource::clear() {
|
void Cache::clear() {
|
||||||
clearSounds();
|
clearSounds();
|
||||||
clearMusics();
|
clearMusics();
|
||||||
surfaces_.clear();
|
surfaces_.clear();
|
||||||
@@ -52,7 +54,7 @@ void Resource::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga todos los recursos
|
// Carga todos los recursos
|
||||||
void Resource::load() {
|
void Cache::load() {
|
||||||
calculateTotal();
|
calculateTotal();
|
||||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
||||||
std::cout << "** LOADING RESOURCES" << '\n';
|
std::cout << "** LOADING RESOURCES" << '\n';
|
||||||
@@ -69,13 +71,13 @@ void Resource::load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todos los recursos
|
// Recarga todos los recursos
|
||||||
void Resource::reload() {
|
void Cache::reload() {
|
||||||
clear();
|
clear();
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el sonido a partir de un nombre
|
// Obtiene el sonido a partir de un nombre
|
||||||
auto Resource::getSound(const std::string& name) -> JA_Sound_t* {
|
auto Cache::getSound(const std::string& name) -> JA_Sound_t* {
|
||||||
auto it = std::ranges::find_if(sounds_, [&name](const auto& s) { return s.name == name; });
|
auto it = std::ranges::find_if(sounds_, [&name](const auto& s) { return s.name == name; });
|
||||||
|
|
||||||
if (it != sounds_.end()) {
|
if (it != sounds_.end()) {
|
||||||
@@ -87,7 +89,7 @@ auto Resource::getSound(const std::string& name) -> JA_Sound_t* {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la música a partir de un nombre
|
// Obtiene la música a partir de un nombre
|
||||||
auto Resource::getMusic(const std::string& name) -> JA_Music_t* {
|
auto Cache::getMusic(const std::string& name) -> JA_Music_t* {
|
||||||
auto it = std::ranges::find_if(musics_, [&name](const auto& m) { return m.name == name; });
|
auto it = std::ranges::find_if(musics_, [&name](const auto& m) { return m.name == name; });
|
||||||
|
|
||||||
if (it != musics_.end()) {
|
if (it != musics_.end()) {
|
||||||
@@ -99,7 +101,7 @@ auto Resource::getMusic(const std::string& name) -> JA_Music_t* {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la surface a partir de un nombre
|
// Obtiene la surface a partir de un nombre
|
||||||
auto Resource::getSurface(const std::string& name) -> std::shared_ptr<Surface> {
|
auto Cache::getSurface(const std::string& name) -> std::shared_ptr<Surface> {
|
||||||
auto it = std::ranges::find_if(surfaces_, [&name](const auto& t) { return t.name == name; });
|
auto it = std::ranges::find_if(surfaces_, [&name](const auto& t) { return t.name == name; });
|
||||||
|
|
||||||
if (it != surfaces_.end()) {
|
if (it != surfaces_.end()) {
|
||||||
@@ -111,7 +113,7 @@ auto Resource::getSurface(const std::string& name) -> std::shared_ptr<Surface> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la paleta a partir de un nombre
|
// Obtiene la paleta a partir de un nombre
|
||||||
auto Resource::getPalette(const std::string& name) -> Palette {
|
auto Cache::getPalette(const std::string& name) -> Palette {
|
||||||
auto it = std::ranges::find_if(palettes_, [&name](const auto& t) { return t.name == name; });
|
auto it = std::ranges::find_if(palettes_, [&name](const auto& t) { return t.name == name; });
|
||||||
|
|
||||||
if (it != palettes_.end()) {
|
if (it != palettes_.end()) {
|
||||||
@@ -123,7 +125,7 @@ auto Resource::getPalette(const std::string& name) -> Palette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el fichero de texto a partir de un nombre
|
// Obtiene el fichero de texto a partir de un nombre
|
||||||
auto Resource::getTextFile(const std::string& name) -> std::shared_ptr<TextFile> {
|
auto Cache::getTextFile(const std::string& name) -> std::shared_ptr<TextFile> {
|
||||||
auto it = std::ranges::find_if(text_files_, [&name](const auto& t) { return t.name == name; });
|
auto it = std::ranges::find_if(text_files_, [&name](const auto& t) { return t.name == name; });
|
||||||
|
|
||||||
if (it != text_files_.end()) {
|
if (it != text_files_.end()) {
|
||||||
@@ -135,7 +137,7 @@ auto Resource::getTextFile(const std::string& name) -> std::shared_ptr<TextFile>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el objeto de texto a partir de un nombre
|
// Obtiene el objeto de texto a partir de un nombre
|
||||||
auto Resource::getText(const std::string& name) -> std::shared_ptr<Text> {
|
auto Cache::getText(const std::string& name) -> std::shared_ptr<Text> {
|
||||||
auto it = std::ranges::find_if(texts_, [&name](const auto& t) { return t.name == name; });
|
auto it = std::ranges::find_if(texts_, [&name](const auto& t) { return t.name == name; });
|
||||||
|
|
||||||
if (it != texts_.end()) {
|
if (it != texts_.end()) {
|
||||||
@@ -147,7 +149,7 @@ auto Resource::getText(const std::string& name) -> std::shared_ptr<Text> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la animación a partir de un nombre
|
// Obtiene la animación a partir de un nombre
|
||||||
auto Resource::getAnimations(const std::string& name) -> Animations& {
|
auto Cache::getAnimations(const std::string& name) -> Animations& {
|
||||||
auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; });
|
auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; });
|
||||||
|
|
||||||
if (it != animations_.end()) {
|
if (it != animations_.end()) {
|
||||||
@@ -159,7 +161,7 @@ auto Resource::getAnimations(const std::string& name) -> Animations& {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el mapa de tiles a partir de un nombre
|
// Obtiene el mapa de tiles a partir de un nombre
|
||||||
auto Resource::getTileMap(const std::string& name) -> std::vector<int>& {
|
auto Cache::getTileMap(const std::string& name) -> std::vector<int>& {
|
||||||
auto it = std::ranges::find_if(tile_maps_, [&name](const auto& t) { return t.name == name; });
|
auto it = std::ranges::find_if(tile_maps_, [&name](const auto& t) { return t.name == name; });
|
||||||
|
|
||||||
if (it != tile_maps_.end()) {
|
if (it != tile_maps_.end()) {
|
||||||
@@ -171,7 +173,7 @@ auto Resource::getTileMap(const std::string& name) -> std::vector<int>& {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene la habitación a partir de un nombre
|
// Obtiene la habitación a partir de un nombre
|
||||||
auto Resource::getRoom(const std::string& name) -> std::shared_ptr<Room::Data> {
|
auto Cache::getRoom(const std::string& name) -> std::shared_ptr<Room::Data> {
|
||||||
auto it = std::ranges::find_if(rooms_, [&name](const auto& r) { return r.name == name; });
|
auto it = std::ranges::find_if(rooms_, [&name](const auto& r) { return r.name == name; });
|
||||||
|
|
||||||
if (it != rooms_.end()) {
|
if (it != rooms_.end()) {
|
||||||
@@ -183,14 +185,14 @@ auto Resource::getRoom(const std::string& name) -> std::shared_ptr<Room::Data> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene todas las habitaciones
|
// Obtiene todas las habitaciones
|
||||||
auto Resource::getRooms() -> std::vector<ResourceRoom>& {
|
auto Cache::getRooms() -> std::vector<ResourceRoom>& {
|
||||||
return rooms_;
|
return rooms_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los sonidos
|
// Carga los sonidos
|
||||||
void Resource::loadSounds() {
|
void Cache::loadSounds() {
|
||||||
std::cout << "\n>> SOUND FILES" << '\n';
|
std::cout << "\n>> SOUND FILES" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::SOUND);
|
auto list = List::get()->getListByType(List::Type::SOUND);
|
||||||
sounds_.clear();
|
sounds_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -198,7 +200,7 @@ void Resource::loadSounds() {
|
|||||||
JA_Sound_t* sound = nullptr;
|
JA_Sound_t* sound = nullptr;
|
||||||
|
|
||||||
// Try loading from resource pack first
|
// Try loading from resource pack first
|
||||||
auto audio_data = Jdd::ResourceHelper::loadFile(l);
|
auto audio_data = Helper::loadFile(l);
|
||||||
if (!audio_data.empty()) {
|
if (!audio_data.empty()) {
|
||||||
sound = JA_LoadSound(audio_data.data(), static_cast<Uint32>(audio_data.size()));
|
sound = JA_LoadSound(audio_data.data(), static_cast<Uint32>(audio_data.size()));
|
||||||
}
|
}
|
||||||
@@ -215,9 +217,9 @@ void Resource::loadSounds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las musicas
|
// Carga las musicas
|
||||||
void Resource::loadMusics() {
|
void Cache::loadMusics() {
|
||||||
std::cout << "\n>> MUSIC FILES" << '\n';
|
std::cout << "\n>> MUSIC FILES" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::MUSIC);
|
auto list = List::get()->getListByType(List::Type::MUSIC);
|
||||||
musics_.clear();
|
musics_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -225,7 +227,7 @@ void Resource::loadMusics() {
|
|||||||
JA_Music_t* music = nullptr;
|
JA_Music_t* music = nullptr;
|
||||||
|
|
||||||
// Try loading from resource pack first
|
// Try loading from resource pack first
|
||||||
auto audio_data = Jdd::ResourceHelper::loadFile(l);
|
auto audio_data = Helper::loadFile(l);
|
||||||
if (!audio_data.empty()) {
|
if (!audio_data.empty()) {
|
||||||
music = JA_LoadMusic(audio_data.data(), static_cast<Uint32>(audio_data.size()));
|
music = JA_LoadMusic(audio_data.data(), static_cast<Uint32>(audio_data.size()));
|
||||||
}
|
}
|
||||||
@@ -242,9 +244,9 @@ void Resource::loadMusics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las texturas
|
// Carga las texturas
|
||||||
void Resource::loadSurfaces() {
|
void Cache::loadSurfaces() {
|
||||||
std::cout << "\n>> SURFACES" << '\n';
|
std::cout << "\n>> SURFACES" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::BITMAP);
|
auto list = List::get()->getListByType(List::Type::BITMAP);
|
||||||
surfaces_.clear();
|
surfaces_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -265,9 +267,9 @@ void Resource::loadSurfaces() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las paletas
|
// Carga las paletas
|
||||||
void Resource::loadPalettes() {
|
void Cache::loadPalettes() {
|
||||||
std::cout << "\n>> PALETTES" << '\n';
|
std::cout << "\n>> PALETTES" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::PALETTE);
|
auto list = List::get()->getListByType(List::Type::PALETTE);
|
||||||
palettes_.clear();
|
palettes_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -278,9 +280,9 @@ void Resource::loadPalettes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga los ficheros de texto
|
// Carga los ficheros de texto
|
||||||
void Resource::loadTextFiles() {
|
void Cache::loadTextFiles() {
|
||||||
std::cout << "\n>> TEXT FILES" << '\n';
|
std::cout << "\n>> TEXT FILES" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::FONT);
|
auto list = List::get()->getListByType(List::Type::FONT);
|
||||||
text_files_.clear();
|
text_files_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -291,9 +293,9 @@ void Resource::loadTextFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las animaciones
|
// Carga las animaciones
|
||||||
void Resource::loadAnimations() {
|
void Cache::loadAnimations() {
|
||||||
std::cout << "\n>> ANIMATIONS" << '\n';
|
std::cout << "\n>> ANIMATIONS" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::ANIMATION);
|
auto list = List::get()->getListByType(List::Type::ANIMATION);
|
||||||
animations_.clear();
|
animations_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -304,9 +306,9 @@ void Resource::loadAnimations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga los mapas de tiles
|
// Carga los mapas de tiles
|
||||||
void Resource::loadTileMaps() {
|
void Cache::loadTileMaps() {
|
||||||
std::cout << "\n>> TILE MAPS" << '\n';
|
std::cout << "\n>> TILE MAPS" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::TILEMAP);
|
auto list = List::get()->getListByType(List::Type::TILEMAP);
|
||||||
tile_maps_.clear();
|
tile_maps_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -318,9 +320,9 @@ void Resource::loadTileMaps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga las habitaciones
|
// Carga las habitaciones
|
||||||
void Resource::loadRooms() {
|
void Cache::loadRooms() {
|
||||||
std::cout << "\n>> ROOMS" << '\n';
|
std::cout << "\n>> ROOMS" << '\n';
|
||||||
auto list = Asset::get()->getListByType(Asset::Type::ROOM);
|
auto list = List::get()->getListByType(List::Type::ROOM);
|
||||||
rooms_.clear();
|
rooms_.clear();
|
||||||
|
|
||||||
for (const auto& l : list) {
|
for (const auto& l : list) {
|
||||||
@@ -331,7 +333,7 @@ void Resource::loadRooms() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::createText() {
|
void Cache::createText() {
|
||||||
struct ResourceInfo {
|
struct ResourceInfo {
|
||||||
std::string key; // Identificador del recurso
|
std::string key; // Identificador del recurso
|
||||||
std::string texture_file; // Nombre del archivo de textura
|
std::string texture_file; // Nombre del archivo de textura
|
||||||
@@ -360,7 +362,7 @@ void Resource::createText() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vacía el vector de sonidos
|
// Vacía el vector de sonidos
|
||||||
void Resource::clearSounds() {
|
void Cache::clearSounds() {
|
||||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Sound_t
|
// Itera sobre el vector y libera los recursos asociados a cada JA_Sound_t
|
||||||
for (auto& sound : sounds_) {
|
for (auto& sound : sounds_) {
|
||||||
if (sound.sound != nullptr) {
|
if (sound.sound != nullptr) {
|
||||||
@@ -372,7 +374,7 @@ void Resource::clearSounds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vacía el vector de musicas
|
// Vacía el vector de musicas
|
||||||
void Resource::clearMusics() {
|
void Cache::clearMusics() {
|
||||||
// Itera sobre el vector y libera los recursos asociados a cada JA_Music_t
|
// Itera sobre el vector y libera los recursos asociados a cada JA_Music_t
|
||||||
for (auto& music : musics_) {
|
for (auto& music : musics_) {
|
||||||
if (music.music != nullptr) {
|
if (music.music != nullptr) {
|
||||||
@@ -384,20 +386,20 @@ void Resource::clearMusics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calcula el numero de recursos para cargar
|
// Calcula el numero de recursos para cargar
|
||||||
void Resource::calculateTotal() {
|
void Cache::calculateTotal() {
|
||||||
std::vector<Asset::Type> asset_types = {
|
std::vector<List::Type> asset_types = {
|
||||||
Asset::Type::SOUND,
|
List::Type::SOUND,
|
||||||
Asset::Type::MUSIC,
|
List::Type::MUSIC,
|
||||||
Asset::Type::BITMAP,
|
List::Type::BITMAP,
|
||||||
Asset::Type::PALETTE,
|
List::Type::PALETTE,
|
||||||
Asset::Type::FONT,
|
List::Type::FONT,
|
||||||
Asset::Type::ANIMATION,
|
List::Type::ANIMATION,
|
||||||
Asset::Type::TILEMAP,
|
List::Type::TILEMAP,
|
||||||
Asset::Type::ROOM};
|
List::Type::ROOM};
|
||||||
|
|
||||||
size_t total = 0;
|
size_t total = 0;
|
||||||
for (const auto& asset_type : asset_types) {
|
for (const auto& asset_type : asset_types) {
|
||||||
auto list = Asset::get()->getListByType(asset_type);
|
auto list = List::get()->getListByType(asset_type);
|
||||||
total += list.size();
|
total += list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +407,7 @@ void Resource::calculateTotal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra el progreso de carga
|
// Muestra el progreso de carga
|
||||||
void Resource::renderProgress() {
|
void Cache::renderProgress() {
|
||||||
constexpr float X_PADDING = 60.0F;
|
constexpr float X_PADDING = 60.0F;
|
||||||
constexpr float Y_PADDING = 10.0F;
|
constexpr float Y_PADDING = 10.0F;
|
||||||
constexpr float BAR_HEIGHT = 5.0F;
|
constexpr float BAR_HEIGHT = 5.0F;
|
||||||
@@ -451,7 +453,7 @@ void Resource::renderProgress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos de la pantalla de carga
|
// Comprueba los eventos de la pantalla de carga
|
||||||
void Resource::checkEvents() {
|
void Cache::checkEvents() {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
@@ -468,10 +470,12 @@ void Resource::checkEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el progreso de carga
|
// Actualiza el progreso de carga
|
||||||
void Resource::updateLoadingProgress(int steps) {
|
void Cache::updateLoadingProgress(int steps) {
|
||||||
count_.add(1);
|
count_.add(1);
|
||||||
if (count_.loaded % steps == 0 || count_.loaded == count_.total) {
|
if (count_.loaded % steps == 0 || count_.loaded == count_.total) {
|
||||||
renderProgress();
|
renderProgress();
|
||||||
}
|
}
|
||||||
checkEvents();
|
checkEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Resource
|
||||||
@@ -137,10 +137,12 @@ struct ResourceCount {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Resource {
|
namespace Resource {
|
||||||
|
|
||||||
|
class Cache {
|
||||||
private:
|
private:
|
||||||
// [SINGLETON] Objeto resource privado para Don Melitón
|
// [SINGLETON] Objeto cache privado para Don Melitón
|
||||||
static Resource* resource;
|
static Cache* cache;
|
||||||
|
|
||||||
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
std::vector<ResourceSound> sounds_; // Vector con los sonidos
|
||||||
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
std::vector<ResourceMusic> musics_; // Vector con las musicas
|
||||||
@@ -206,23 +208,23 @@ class Resource {
|
|||||||
// Actualiza el progreso de carga
|
// Actualiza el progreso de carga
|
||||||
void updateLoadingProgress(int steps = 5);
|
void updateLoadingProgress(int steps = 5);
|
||||||
|
|
||||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos cache desde fuera
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Resource();
|
Cache();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Resource() = default;
|
~Cache() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto resource con esta función estática
|
// [SINGLETON] Crearemos el objeto cache con esta función estática
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
// [SINGLETON] Destruiremos el objeto resource con esta función estática
|
// [SINGLETON] Destruiremos el objeto cache con esta función estática
|
||||||
static void destroy();
|
static void destroy();
|
||||||
|
|
||||||
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
|
// [SINGLETON] Con este método obtenemos el objeto cache y podemos trabajar con él
|
||||||
static auto get() -> Resource*;
|
static auto get() -> Cache*;
|
||||||
|
|
||||||
// Obtiene el sonido a partir de un nombre
|
// Obtiene el sonido a partir de un nombre
|
||||||
auto getSound(const std::string& name) -> JA_Sound_t*;
|
auto getSound(const std::string& name) -> JA_Sound_t*;
|
||||||
@@ -257,3 +259,5 @@ class Resource {
|
|||||||
// Recarga todos los recursos
|
// Recarga todos los recursos
|
||||||
void reload();
|
void reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Resource
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "resource_loader.hpp"
|
#include "resource_loader.hpp"
|
||||||
|
|
||||||
namespace Jdd::ResourceHelper {
|
namespace Resource::Helper {
|
||||||
|
|
||||||
static bool resource_system_initialized = false;
|
static bool resource_system_initialized = false;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ auto initializeResourceSystem(const std::string& pack_file, bool enable_fallback
|
|||||||
std::cout << "ResourceHelper: Fallback enabled: " << (enable_fallback ? "Yes" : "No")
|
std::cout << "ResourceHelper: Fallback enabled: " << (enable_fallback ? "Yes" : "No")
|
||||||
<< '\n';
|
<< '\n';
|
||||||
|
|
||||||
bool success = ResourceLoader::get().initialize(pack_file, enable_fallback);
|
bool success = Loader::get().initialize(pack_file, enable_fallback);
|
||||||
if (success) {
|
if (success) {
|
||||||
resource_system_initialized = true;
|
resource_system_initialized = true;
|
||||||
std::cout << "ResourceHelper: Initialization successful\n";
|
std::cout << "ResourceHelper: Initialization successful\n";
|
||||||
@@ -40,7 +40,7 @@ auto initializeResourceSystem(const std::string& pack_file, bool enable_fallback
|
|||||||
// Shutdown the resource system
|
// Shutdown the resource system
|
||||||
void shutdownResourceSystem() {
|
void shutdownResourceSystem() {
|
||||||
if (resource_system_initialized) {
|
if (resource_system_initialized) {
|
||||||
ResourceLoader::get().shutdown();
|
Loader::get().shutdown();
|
||||||
resource_system_initialized = false;
|
resource_system_initialized = false;
|
||||||
std::cout << "ResourceHelper: Shutdown complete\n";
|
std::cout << "ResourceHelper: Shutdown complete\n";
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ auto loadFile(const std::string& filepath) -> std::vector<uint8_t> {
|
|||||||
std::string pack_path = getPackPath(filepath);
|
std::string pack_path = getPackPath(filepath);
|
||||||
|
|
||||||
// Try to load from pack
|
// Try to load from pack
|
||||||
auto data = ResourceLoader::get().loadResource(pack_path);
|
auto data = Loader::get().loadResource(pack_path);
|
||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ auto loadFile(const std::string& filepath) -> std::vector<uint8_t> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load from filesystem
|
// Load from filesystem
|
||||||
return ResourceLoader::get().loadResource(filepath);
|
return Loader::get().loadResource(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a file exists
|
// Check if a file exists
|
||||||
@@ -91,7 +91,7 @@ auto fileExists(const std::string& filepath) -> bool {
|
|||||||
// Check pack if appropriate
|
// Check pack if appropriate
|
||||||
if (shouldUseResourcePack(filepath)) {
|
if (shouldUseResourcePack(filepath)) {
|
||||||
std::string pack_path = getPackPath(filepath);
|
std::string pack_path = getPackPath(filepath);
|
||||||
if (ResourceLoader::get().resourceExists(pack_path)) {
|
if (Loader::get().resourceExists(pack_path)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ auto shouldUseResourcePack(const std::string& filepath) -> bool {
|
|||||||
std::ranges::replace(path, '\\', '/');
|
std::ranges::replace(path, '\\', '/');
|
||||||
|
|
||||||
// Don't use pack for most config files (except config/assets.txt which is loaded
|
// Don't use pack for most config files (except config/assets.txt which is loaded
|
||||||
// directly via ResourceLoader::loadAssetsConfig() in release builds)
|
// directly via Loader::loadAssetsConfig() in release builds)
|
||||||
if (path.find("config/") != std::string::npos) {
|
if (path.find("config/") != std::string::npos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ auto isPackLoaded() -> bool {
|
|||||||
if (!resource_system_initialized) {
|
if (!resource_system_initialized) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ResourceLoader::get().isPackLoaded();
|
return Loader::get().isPackLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Jdd::ResourceHelper
|
} // namespace Resource::Helper
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Jdd::ResourceHelper {
|
namespace Resource::Helper {
|
||||||
|
|
||||||
// Initialize the resource system
|
// Initialize the resource system
|
||||||
// pack_file: Path to resources.pack
|
// pack_file: Path to resources.pack
|
||||||
@@ -36,6 +36,6 @@ auto shouldUseResourcePack(const std::string& filepath) -> bool;
|
|||||||
// Check if pack is loaded
|
// Check if pack is loaded
|
||||||
auto isPackLoaded() -> bool;
|
auto isPackLoaded() -> bool;
|
||||||
|
|
||||||
} // namespace Jdd::ResourceHelper
|
} // namespace Resource::Helper
|
||||||
|
|
||||||
#endif // RESOURCE_HELPER_HPP
|
#endif // RESOURCE_HELPER_HPP
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "core/resources/asset.hpp"
|
#include "core/resources/resource_list.hpp"
|
||||||
|
|
||||||
#include <SDL3/SDL.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError
|
#include <SDL3/SDL.h> // Para SDL_LogWarn, SDL_LogCategory, SDL_LogError
|
||||||
|
|
||||||
@@ -13,23 +13,25 @@
|
|||||||
|
|
||||||
#include "utils/utils.hpp" // Para getFileName, printWithDots
|
#include "utils/utils.hpp" // Para getFileName, printWithDots
|
||||||
|
|
||||||
|
namespace Resource {
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
Asset* Asset::instance = nullptr;
|
List* List::instance = nullptr;
|
||||||
|
|
||||||
void Asset::init(const std::string& executable_path) {
|
void List::init(const std::string& executable_path) {
|
||||||
Asset::instance = new Asset(executable_path);
|
List::instance = new List(executable_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Asset::destroy() {
|
void List::destroy() {
|
||||||
delete Asset::instance;
|
delete List::instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Asset::get() -> Asset* {
|
auto List::get() -> List* {
|
||||||
return Asset::instance;
|
return List::instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade un elemento al mapa (función auxiliar)
|
// Añade un elemento al mapa (función auxiliar)
|
||||||
void Asset::addToMap(const std::string& file_path, Type type, bool required, bool absolute) {
|
void List::addToMap(const std::string& file_path, Type type, bool required, bool absolute) {
|
||||||
std::string full_path = absolute ? file_path : executable_path_ + file_path;
|
std::string full_path = absolute ? file_path : executable_path_ + file_path;
|
||||||
std::string filename = getFileName(full_path);
|
std::string filename = getFileName(full_path);
|
||||||
|
|
||||||
@@ -44,12 +46,12 @@ void Asset::addToMap(const std::string& file_path, Type type, bool required, boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void Asset::add(const std::string& file_path, Type type, bool required, bool absolute) {
|
void List::add(const std::string& file_path, Type type, bool required, bool absolute) {
|
||||||
addToMap(file_path, type, required, absolute);
|
addToMap(file_path, type, required, absolute);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga recursos desde un archivo de configuración con soporte para variables
|
// Carga recursos desde un archivo de configuración con soporte para variables
|
||||||
void Asset::loadFromFile(const std::string& config_file_path, const std::string& prefix, const std::string& system_folder) {
|
void List::loadFromFile(const std::string& config_file_path, const std::string& prefix, const std::string& system_folder) {
|
||||||
std::ifstream file(config_file_path);
|
std::ifstream file(config_file_path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
@@ -68,7 +70,7 @@ void Asset::loadFromFile(const std::string& config_file_path, const std::string&
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga recursos desde un string de configuración (para release con pack)
|
// Carga recursos desde un string de configuración (para release con pack)
|
||||||
void Asset::loadFromString(const std::string& config_content, const std::string& prefix, const std::string& system_folder) {
|
void List::loadFromString(const std::string& config_content, const std::string& prefix, const std::string& system_folder) {
|
||||||
std::istringstream stream(config_content);
|
std::istringstream stream(config_content);
|
||||||
std::string line;
|
std::string line;
|
||||||
int line_number = 0;
|
int line_number = 0;
|
||||||
@@ -136,7 +138,7 @@ void Asset::loadFromString(const std::string& config_content, const std::string&
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve la ruta completa a un fichero (búsqueda O(1))
|
// Devuelve la ruta completa a un fichero (búsqueda O(1))
|
||||||
auto Asset::get(const std::string& filename) const -> std::string {
|
auto List::get(const std::string& filename) const -> std::string {
|
||||||
auto it = file_list_.find(filename);
|
auto it = file_list_.find(filename);
|
||||||
if (it != file_list_.end()) {
|
if (it != file_list_.end()) {
|
||||||
return it->second.file;
|
return it->second.file;
|
||||||
@@ -147,7 +149,7 @@ auto Asset::get(const std::string& filename) const -> std::string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga datos del archivo
|
// Carga datos del archivo
|
||||||
auto Asset::loadData(const std::string& filename) const -> std::vector<uint8_t> {
|
auto List::loadData(const std::string& filename) const -> std::vector<uint8_t> {
|
||||||
auto it = file_list_.find(filename);
|
auto it = file_list_.find(filename);
|
||||||
if (it != file_list_.end()) {
|
if (it != file_list_.end()) {
|
||||||
std::ifstream file(it->second.file, std::ios::binary);
|
std::ifstream file(it->second.file, std::ios::binary);
|
||||||
@@ -176,12 +178,12 @@ auto Asset::loadData(const std::string& filename) const -> std::vector<uint8_t>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verifica si un recurso existe
|
// Verifica si un recurso existe
|
||||||
auto Asset::exists(const std::string& filename) const -> bool {
|
auto List::exists(const std::string& filename) const -> bool {
|
||||||
return file_list_.find(filename) != file_list_.end();
|
return file_list_.find(filename) != file_list_.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba que existen todos los elementos
|
// Comprueba que existen todos los elementos
|
||||||
auto Asset::check() const -> bool {
|
auto List::check() const -> bool {
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
std::cout << "\n** CHECKING FILES" << '\n';
|
std::cout << "\n** CHECKING FILES" << '\n';
|
||||||
@@ -223,7 +225,7 @@ auto Asset::check() const -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
// Comprueba que existe un fichero
|
||||||
auto Asset::checkFile(const std::string& path) -> bool {
|
auto List::checkFile(const std::string& path) -> bool {
|
||||||
std::ifstream file(path);
|
std::ifstream file(path);
|
||||||
bool success = file.good();
|
bool success = file.good();
|
||||||
file.close();
|
file.close();
|
||||||
@@ -236,7 +238,7 @@ auto Asset::checkFile(const std::string& path) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parsea string a Type
|
// Parsea string a Type
|
||||||
auto Asset::parseAssetType(const std::string& type_str) -> Type {
|
auto List::parseAssetType(const std::string& type_str) -> Type {
|
||||||
if (type_str == "DATA") {
|
if (type_str == "DATA") {
|
||||||
return Type::DATA;
|
return Type::DATA;
|
||||||
}
|
}
|
||||||
@@ -269,7 +271,7 @@ auto Asset::parseAssetType(const std::string& type_str) -> Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el nombre del tipo de recurso
|
// Devuelve el nombre del tipo de recurso
|
||||||
auto Asset::getTypeName(Type type) -> std::string {
|
auto List::getTypeName(Type type) -> std::string {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::DATA:
|
case Type::DATA:
|
||||||
return "DATA";
|
return "DATA";
|
||||||
@@ -295,7 +297,7 @@ auto Asset::getTypeName(Type type) -> std::string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve la lista de recursos de un tipo
|
// Devuelve la lista de recursos de un tipo
|
||||||
auto Asset::getListByType(Type type) const -> std::vector<std::string> {
|
auto List::getListByType(Type type) const -> std::vector<std::string> {
|
||||||
std::vector<std::string> list;
|
std::vector<std::string> list;
|
||||||
|
|
||||||
for (const auto& [filename, item] : file_list_) {
|
for (const auto& [filename, item] : file_list_) {
|
||||||
@@ -311,7 +313,7 @@ auto Asset::getListByType(Type type) const -> std::vector<std::string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reemplaza variables en las rutas
|
// Reemplaza variables en las rutas
|
||||||
auto Asset::replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string {
|
auto List::replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string {
|
||||||
std::string result = path;
|
std::string result = path;
|
||||||
|
|
||||||
// Reemplazar ${PREFIX}
|
// Reemplazar ${PREFIX}
|
||||||
@@ -332,7 +334,7 @@ auto Asset::replaceVariables(const std::string& path, const std::string& prefix,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parsea las opciones de una línea de configuración
|
// Parsea las opciones de una línea de configuración
|
||||||
auto Asset::parseOptions(const std::string& options, bool& required, bool& absolute) -> void {
|
auto List::parseOptions(const std::string& options, bool& required, bool& absolute) -> void {
|
||||||
if (options.empty()) {
|
if (options.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -352,3 +354,5 @@ auto Asset::parseOptions(const std::string& options, bool& required, bool& absol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Resource
|
||||||
@@ -6,8 +6,10 @@
|
|||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
// --- Clase Asset: gestor optimizado de recursos (singleton) ---
|
namespace Resource {
|
||||||
class Asset {
|
|
||||||
|
// --- Clase List: gestor optimizado de recursos (singleton) ---
|
||||||
|
class List {
|
||||||
public:
|
public:
|
||||||
// --- Enums ---
|
// --- Enums ---
|
||||||
enum class Type : int {
|
enum class Type : int {
|
||||||
@@ -26,9 +28,9 @@ class Asset {
|
|||||||
// --- Métodos de singleton ---
|
// --- Métodos de singleton ---
|
||||||
static void init(const std::string& executable_path);
|
static void init(const std::string& executable_path);
|
||||||
static void destroy();
|
static void destroy();
|
||||||
static auto get() -> Asset*;
|
static auto get() -> List*;
|
||||||
Asset(const Asset&) = delete;
|
List(const List&) = delete;
|
||||||
auto operator=(const Asset&) -> Asset& = delete;
|
auto operator=(const List&) -> List& = delete;
|
||||||
|
|
||||||
// --- Métodos para la gestión de recursos ---
|
// --- Métodos para la gestión de recursos ---
|
||||||
void add(const std::string& file_path, Type type, bool required = true, bool absolute = false);
|
void add(const std::string& file_path, Type type, bool required = true, bool absolute = false);
|
||||||
@@ -66,10 +68,12 @@ class Asset {
|
|||||||
static auto parseOptions(const std::string& options, bool& required, bool& absolute) -> void; // Parsea opciones
|
static auto parseOptions(const std::string& options, bool& required, bool& absolute) -> void; // Parsea opciones
|
||||||
|
|
||||||
// --- Constructores y destructor privados (singleton) ---
|
// --- Constructores y destructor privados (singleton) ---
|
||||||
explicit Asset(std::string executable_path) // Constructor privado
|
explicit List(std::string executable_path) // Constructor privado
|
||||||
: executable_path_(std::move(executable_path)) {}
|
: executable_path_(std::move(executable_path)) {}
|
||||||
~Asset() = default; // Destructor privado
|
~List() = default; // Destructor privado
|
||||||
|
|
||||||
// --- Instancia singleton ---
|
// --- Instancia singleton ---
|
||||||
static Asset* instance; // Instancia única de Asset
|
static List* instance; // Instancia única de List
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Resource
|
||||||
@@ -7,19 +7,19 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace Jdd {
|
namespace Resource {
|
||||||
|
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
auto ResourceLoader::get() -> ResourceLoader& {
|
auto Loader::get() -> Loader& {
|
||||||
static ResourceLoader instance_;
|
static Loader instance_;
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize with a pack file
|
// Initialize with a pack file
|
||||||
auto ResourceLoader::initialize(const std::string& pack_file, bool enable_fallback)
|
auto Loader::initialize(const std::string& pack_file, bool enable_fallback)
|
||||||
-> bool {
|
-> bool {
|
||||||
if (initialized_) {
|
if (initialized_) {
|
||||||
std::cout << "ResourceLoader: Already initialized\n";
|
std::cout << "Loader: Already initialized\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,35 +27,35 @@ auto ResourceLoader::initialize(const std::string& pack_file, bool enable_fallba
|
|||||||
|
|
||||||
// Try to load the pack file
|
// Try to load the pack file
|
||||||
if (!pack_file.empty() && fileExistsOnFilesystem(pack_file)) {
|
if (!pack_file.empty() && fileExistsOnFilesystem(pack_file)) {
|
||||||
std::cout << "ResourceLoader: Loading pack file: " << pack_file << '\n';
|
std::cout << "Loader: Loading pack file: " << pack_file << '\n';
|
||||||
resource_pack_ = std::make_unique<ResourcePack>();
|
resource_pack_ = std::make_unique<Pack>();
|
||||||
if (resource_pack_->loadPack(pack_file)) {
|
if (resource_pack_->loadPack(pack_file)) {
|
||||||
std::cout << "ResourceLoader: Pack loaded successfully\n";
|
std::cout << "Loader: Pack loaded successfully\n";
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::cerr << "ResourceLoader: Failed to load pack file\n";
|
std::cerr << "Loader: Failed to load pack file\n";
|
||||||
resource_pack_.reset();
|
resource_pack_.reset();
|
||||||
} else {
|
} else {
|
||||||
std::cout << "ResourceLoader: Pack file not found: " << pack_file << '\n';
|
std::cout << "Loader: Pack file not found: " << pack_file << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// If pack loading failed and fallback is disabled, fail
|
// If pack loading failed and fallback is disabled, fail
|
||||||
if (!fallback_to_files_) {
|
if (!fallback_to_files_) {
|
||||||
std::cerr << "ResourceLoader: Pack required but not found (fallback disabled)\n";
|
std::cerr << "Loader: Pack required but not found (fallback disabled)\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, fallback to filesystem
|
// Otherwise, fallback to filesystem
|
||||||
std::cout << "ResourceLoader: Using filesystem fallback\n";
|
std::cout << "Loader: Using filesystem fallback\n";
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a resource
|
// Load a resource
|
||||||
auto ResourceLoader::loadResource(const std::string& filename) -> std::vector<uint8_t> {
|
auto Loader::loadResource(const std::string& filename) -> std::vector<uint8_t> {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
std::cerr << "ResourceLoader: Not initialized\n";
|
std::cerr << "Loader: Not initialized\n";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ auto ResourceLoader::loadResource(const std::string& filename) -> std::vector<ui
|
|||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
std::cerr << "ResourceLoader: Failed to extract from pack: " << filename
|
std::cerr << "Loader: Failed to extract from pack: " << filename
|
||||||
<< '\n';
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,12 +76,12 @@ auto ResourceLoader::loadResource(const std::string& filename) -> std::vector<ui
|
|||||||
return loadFromFilesystem(filename);
|
return loadFromFilesystem(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "ResourceLoader: Resource not found: " << filename << '\n';
|
std::cerr << "Loader: Resource not found: " << filename << '\n';
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a resource exists
|
// Check if a resource exists
|
||||||
auto ResourceLoader::resourceExists(const std::string& filename) -> bool {
|
auto Loader::resourceExists(const std::string& filename) -> bool {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -102,12 +102,12 @@ auto ResourceLoader::resourceExists(const std::string& filename) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if pack is loaded
|
// Check if pack is loaded
|
||||||
auto ResourceLoader::isPackLoaded() const -> bool {
|
auto Loader::isPackLoaded() const -> bool {
|
||||||
return resource_pack_ && resource_pack_->isLoaded();
|
return resource_pack_ && resource_pack_->isLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get pack statistics
|
// Get pack statistics
|
||||||
auto ResourceLoader::getPackResourceCount() const -> size_t {
|
auto Loader::getPackResourceCount() const -> size_t {
|
||||||
if (resource_pack_ && resource_pack_->isLoaded()) {
|
if (resource_pack_ && resource_pack_->isLoaded()) {
|
||||||
return resource_pack_->getResourceCount();
|
return resource_pack_->getResourceCount();
|
||||||
}
|
}
|
||||||
@@ -115,14 +115,14 @@ auto ResourceLoader::getPackResourceCount() const -> size_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
void ResourceLoader::shutdown() {
|
void Loader::shutdown() {
|
||||||
resource_pack_.reset();
|
resource_pack_.reset();
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
std::cout << "ResourceLoader: Shutdown complete\n";
|
std::cout << "Loader: Shutdown complete\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from filesystem
|
// Load from filesystem
|
||||||
auto ResourceLoader::loadFromFilesystem(const std::string& filepath)
|
auto Loader::loadFromFilesystem(const std::string& filepath)
|
||||||
-> std::vector<uint8_t> {
|
-> std::vector<uint8_t> {
|
||||||
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -134,7 +134,7 @@ auto ResourceLoader::loadFromFilesystem(const std::string& filepath)
|
|||||||
|
|
||||||
std::vector<uint8_t> data(file_size);
|
std::vector<uint8_t> data(file_size);
|
||||||
if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) {
|
if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) {
|
||||||
std::cerr << "ResourceLoader: Failed to read file: " << filepath << '\n';
|
std::cerr << "Loader: Failed to read file: " << filepath << '\n';
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,14 +142,14 @@ auto ResourceLoader::loadFromFilesystem(const std::string& filepath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if file exists on filesystem
|
// Check if file exists on filesystem
|
||||||
auto ResourceLoader::fileExistsOnFilesystem(const std::string& filepath) -> bool {
|
auto Loader::fileExistsOnFilesystem(const std::string& filepath) -> bool {
|
||||||
return std::filesystem::exists(filepath);
|
return std::filesystem::exists(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate pack integrity
|
// Validate pack integrity
|
||||||
auto ResourceLoader::validatePack() const -> bool {
|
auto Loader::validatePack() const -> bool {
|
||||||
if (!initialized_ || !resource_pack_ || !resource_pack_->isLoaded()) {
|
if (!initialized_ || !resource_pack_ || !resource_pack_->isLoaded()) {
|
||||||
std::cerr << "ResourceLoader: Cannot validate - pack not loaded\n";
|
std::cerr << "Loader: Cannot validate - pack not loaded\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,20 +157,20 @@ auto ResourceLoader::validatePack() const -> bool {
|
|||||||
uint32_t checksum = resource_pack_->calculatePackChecksum();
|
uint32_t checksum = resource_pack_->calculatePackChecksum();
|
||||||
|
|
||||||
if (checksum == 0) {
|
if (checksum == 0) {
|
||||||
std::cerr << "ResourceLoader: Pack checksum is zero (invalid)\n";
|
std::cerr << "Loader: Pack checksum is zero (invalid)\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "ResourceLoader: Pack checksum: 0x" << std::hex << checksum << std::dec
|
std::cout << "Loader: Pack checksum: 0x" << std::hex << checksum << std::dec
|
||||||
<< '\n';
|
<< '\n';
|
||||||
std::cout << "ResourceLoader: Pack validation successful\n";
|
std::cout << "Loader: Pack validation successful\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load assets.txt from pack
|
// Load assets.txt from pack
|
||||||
auto ResourceLoader::loadAssetsConfig() const -> std::string {
|
auto Loader::loadAssetsConfig() const -> std::string {
|
||||||
if (!initialized_ || !resource_pack_ || !resource_pack_->isLoaded()) {
|
if (!initialized_ || !resource_pack_ || !resource_pack_->isLoaded()) {
|
||||||
std::cerr << "ResourceLoader: Cannot load assets config - pack not loaded\n";
|
std::cerr << "Loader: Cannot load assets config - pack not loaded\n";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,22 +178,22 @@ auto ResourceLoader::loadAssetsConfig() const -> std::string {
|
|||||||
std::string config_path = "config/assets.txt";
|
std::string config_path = "config/assets.txt";
|
||||||
|
|
||||||
if (!resource_pack_->hasResource(config_path)) {
|
if (!resource_pack_->hasResource(config_path)) {
|
||||||
std::cerr << "ResourceLoader: assets.txt not found in pack: " << config_path << '\n';
|
std::cerr << "Loader: assets.txt not found in pack: " << config_path << '\n';
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = resource_pack_->getResource(config_path);
|
auto data = resource_pack_->getResource(config_path);
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
std::cerr << "ResourceLoader: Failed to load assets.txt from pack\n";
|
std::cerr << "Loader: Failed to load assets.txt from pack\n";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert bytes to string
|
// Convert bytes to string
|
||||||
std::string config_content(data.begin(), data.end());
|
std::string config_content(data.begin(), data.end());
|
||||||
std::cout << "ResourceLoader: Loaded assets.txt from pack (" << data.size()
|
std::cout << "Loader: Loaded assets.txt from pack (" << data.size()
|
||||||
<< " bytes)\n";
|
<< " bytes)\n";
|
||||||
|
|
||||||
return config_content;
|
return config_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Jdd
|
} // namespace Resource
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
|
|
||||||
#include "resource_pack.hpp"
|
#include "resource_pack.hpp"
|
||||||
|
|
||||||
namespace Jdd {
|
namespace Resource {
|
||||||
|
|
||||||
// Singleton class for loading resources from pack or filesystem
|
// Singleton class for loading resources from pack or filesystem
|
||||||
class ResourceLoader {
|
class Loader {
|
||||||
public:
|
public:
|
||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
static auto get() -> ResourceLoader&;
|
static auto get() -> Loader&;
|
||||||
|
|
||||||
// Initialize with a pack file (optional)
|
// Initialize with a pack file (optional)
|
||||||
auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool;
|
auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool;
|
||||||
@@ -43,14 +43,14 @@ class ResourceLoader {
|
|||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
// Disable copy/move
|
// Disable copy/move
|
||||||
ResourceLoader(const ResourceLoader&) = delete;
|
Loader(const Loader&) = delete;
|
||||||
auto operator=(const ResourceLoader&) -> ResourceLoader& = delete;
|
auto operator=(const Loader&) -> Loader& = delete;
|
||||||
ResourceLoader(ResourceLoader&&) = delete;
|
Loader(Loader&&) = delete;
|
||||||
auto operator=(ResourceLoader&&) -> ResourceLoader& = delete;
|
auto operator=(Loader&&) -> Loader& = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResourceLoader() = default;
|
Loader() = default;
|
||||||
~ResourceLoader() = default;
|
~Loader() = default;
|
||||||
|
|
||||||
// Load from filesystem
|
// Load from filesystem
|
||||||
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>;
|
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>;
|
||||||
@@ -59,11 +59,11 @@ class ResourceLoader {
|
|||||||
static auto fileExistsOnFilesystem(const std::string& filepath) -> bool;
|
static auto fileExistsOnFilesystem(const std::string& filepath) -> bool;
|
||||||
|
|
||||||
// Member data
|
// Member data
|
||||||
std::unique_ptr<ResourcePack> resource_pack_;
|
std::unique_ptr<Pack> resource_pack_;
|
||||||
bool fallback_to_files_{true};
|
bool fallback_to_files_{true};
|
||||||
bool initialized_{false};
|
bool initialized_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Jdd
|
} // namespace Resource
|
||||||
|
|
||||||
#endif // RESOURCE_LOADER_HPP
|
#endif // RESOURCE_LOADER_HPP
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace Jdd {
|
namespace Resource {
|
||||||
|
|
||||||
// Calculate CRC32 checksum for data verification
|
// Calculate CRC32 checksum for data verification
|
||||||
auto ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
|
auto Pack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
|
||||||
uint32_t checksum = 0x12345678;
|
uint32_t checksum = 0x12345678;
|
||||||
for (unsigned char byte : data) {
|
for (unsigned char byte : data) {
|
||||||
checksum = ((checksum << 5) + checksum) + byte;
|
checksum = ((checksum << 5) + checksum) + byte;
|
||||||
@@ -22,7 +22,7 @@ auto ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XOR encryption (symmetric - same function for encrypt/decrypt)
|
// XOR encryption (symmetric - same function for encrypt/decrypt)
|
||||||
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
|
void Pack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
|
||||||
if (key.empty()) {
|
if (key.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -31,13 +31,13 @@ void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& ke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePack::decryptData(std::vector<uint8_t>& data, const std::string& key) {
|
void Pack::decryptData(std::vector<uint8_t>& data, const std::string& key) {
|
||||||
// XOR is symmetric
|
// XOR is symmetric
|
||||||
encryptData(data, key);
|
encryptData(data, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read entire file into memory
|
// Read entire file into memory
|
||||||
auto ResourcePack::readFile(const std::string& filepath) -> std::vector<uint8_t> {
|
auto Pack::readFile(const std::string& filepath) -> std::vector<uint8_t> {
|
||||||
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
std::cerr << "ResourcePack: Failed to open file: " << filepath << '\n';
|
std::cerr << "ResourcePack: Failed to open file: " << filepath << '\n';
|
||||||
@@ -57,7 +57,7 @@ auto ResourcePack::readFile(const std::string& filepath) -> std::vector<uint8_t>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a single file to the pack
|
// Add a single file to the pack
|
||||||
auto ResourcePack::addFile(const std::string& filepath, const std::string& pack_name)
|
auto Pack::addFile(const std::string& filepath, const std::string& pack_name)
|
||||||
-> bool {
|
-> bool {
|
||||||
auto file_data = readFile(filepath);
|
auto file_data = readFile(filepath);
|
||||||
if (file_data.empty()) {
|
if (file_data.empty()) {
|
||||||
@@ -80,7 +80,7 @@ auto ResourcePack::addFile(const std::string& filepath, const std::string& pack_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add all files from a directory recursively
|
// Add all files from a directory recursively
|
||||||
auto ResourcePack::addDirectory(const std::string& dir_path,
|
auto Pack::addDirectory(const std::string& dir_path,
|
||||||
const std::string& base_path) -> bool {
|
const std::string& base_path) -> bool {
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ auto ResourcePack::addDirectory(const std::string& dir_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the pack to a file
|
// Save the pack to a file
|
||||||
auto ResourcePack::savePack(const std::string& pack_file) -> bool {
|
auto Pack::savePack(const std::string& pack_file) -> bool {
|
||||||
std::ofstream file(pack_file, std::ios::binary);
|
std::ofstream file(pack_file, std::ios::binary);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
std::cerr << "ResourcePack: Failed to create pack file: " << pack_file << '\n';
|
std::cerr << "ResourcePack: Failed to create pack file: " << pack_file << '\n';
|
||||||
@@ -162,7 +162,7 @@ auto ResourcePack::savePack(const std::string& pack_file) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load a pack from a file
|
// Load a pack from a file
|
||||||
auto ResourcePack::loadPack(const std::string& pack_file) -> bool {
|
auto Pack::loadPack(const std::string& pack_file) -> bool {
|
||||||
std::ifstream file(pack_file, std::ios::binary);
|
std::ifstream file(pack_file, std::ios::binary);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
std::cerr << "ResourcePack: Failed to open pack file: " << pack_file << '\n';
|
std::cerr << "ResourcePack: Failed to open pack file: " << pack_file << '\n';
|
||||||
@@ -229,7 +229,7 @@ auto ResourcePack::loadPack(const std::string& pack_file) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get a resource by name
|
// Get a resource by name
|
||||||
auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8_t> {
|
auto Pack::getResource(const std::string& filename) -> std::vector<uint8_t> {
|
||||||
auto it = resources_.find(filename);
|
auto it = resources_.find(filename);
|
||||||
if (it == resources_.end()) {
|
if (it == resources_.end()) {
|
||||||
return {};
|
return {};
|
||||||
@@ -258,12 +258,12 @@ auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if a resource exists
|
// Check if a resource exists
|
||||||
auto ResourcePack::hasResource(const std::string& filename) const -> bool {
|
auto Pack::hasResource(const std::string& filename) const -> bool {
|
||||||
return resources_.find(filename) != resources_.end();
|
return resources_.find(filename) != resources_.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get list of all resources
|
// Get list of all resources
|
||||||
auto ResourcePack::getResourceList() const -> std::vector<std::string> {
|
auto Pack::getResourceList() const -> std::vector<std::string> {
|
||||||
std::vector<std::string> list;
|
std::vector<std::string> list;
|
||||||
list.reserve(resources_.size());
|
list.reserve(resources_.size());
|
||||||
for (const auto& [name, entry] : resources_) {
|
for (const auto& [name, entry] : resources_) {
|
||||||
@@ -274,7 +274,7 @@ auto ResourcePack::getResourceList() const -> std::vector<std::string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate overall pack checksum for validation
|
// Calculate overall pack checksum for validation
|
||||||
auto ResourcePack::calculatePackChecksum() const -> uint32_t {
|
auto Pack::calculatePackChecksum() const -> uint32_t {
|
||||||
if (!loaded_ || data_.empty()) {
|
if (!loaded_ || data_.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -300,4 +300,4 @@ auto ResourcePack::calculatePackChecksum() const -> uint32_t {
|
|||||||
return global_checksum;
|
return global_checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Jdd
|
} // namespace Resource
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Jdd {
|
namespace Resource {
|
||||||
|
|
||||||
// Entry metadata for each resource in the pack
|
// Entry metadata for each resource in the pack
|
||||||
struct ResourceEntry {
|
struct ResourceEntry {
|
||||||
@@ -25,16 +25,16 @@ struct ResourceEntry {
|
|||||||
// Header: "JDDI" (4 bytes) + Version (4 bytes)
|
// Header: "JDDI" (4 bytes) + Version (4 bytes)
|
||||||
// Metadata: Count + array of ResourceEntry
|
// Metadata: Count + array of ResourceEntry
|
||||||
// Data: Encrypted data block
|
// Data: Encrypted data block
|
||||||
class ResourcePack {
|
class Pack {
|
||||||
public:
|
public:
|
||||||
ResourcePack() = default;
|
Pack() = default;
|
||||||
~ResourcePack() = default;
|
~Pack() = default;
|
||||||
|
|
||||||
// Disable copy/move
|
// Disable copy/move
|
||||||
ResourcePack(const ResourcePack&) = delete;
|
Pack(const Pack&) = delete;
|
||||||
auto operator=(const ResourcePack&) -> ResourcePack& = delete;
|
auto operator=(const Pack&) -> Pack& = delete;
|
||||||
ResourcePack(ResourcePack&&) = delete;
|
Pack(Pack&&) = delete;
|
||||||
auto operator=(ResourcePack&&) -> ResourcePack& = delete;
|
auto operator=(Pack&&) -> Pack& = delete;
|
||||||
|
|
||||||
// Add a single file to the pack
|
// Add a single file to the pack
|
||||||
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool;
|
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool;
|
||||||
@@ -89,6 +89,6 @@ class ResourcePack {
|
|||||||
bool loaded_{false};
|
bool loaded_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Jdd
|
} // namespace Resource
|
||||||
|
|
||||||
#endif // RESOURCE_PACK_HPP
|
#endif // RESOURCE_PACK_HPP
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
#include <algorithm> // Para max
|
#include <algorithm> // Para max
|
||||||
#include <memory> // Para __shared_ptr_access, shared_ptr
|
#include <memory> // Para __shared_ptr_access, shared_ptr
|
||||||
|
|
||||||
#include "core/rendering/text.hpp" // Para Text
|
#include "core/rendering/text.hpp" // Para Text
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "utils/utils.hpp" // Para Color
|
#include "utils/utils.hpp" // Para Color
|
||||||
|
|
||||||
// [SINGLETON]
|
// [SINGLETON]
|
||||||
Debug* Debug::debug = nullptr;
|
Debug* Debug::debug = nullptr;
|
||||||
@@ -27,7 +27,7 @@ auto Debug::get() -> Debug* {
|
|||||||
|
|
||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
void Debug::render() {
|
void Debug::render() {
|
||||||
auto text = Resource::get()->getText("aseprite");
|
auto text = Resource::Cache::get()->getText("aseprite");
|
||||||
int y = y_;
|
int y = y_;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
#include "core/audio/audio.hpp" // Para Audio
|
#include "core/audio/audio.hpp" // Para Audio
|
||||||
#include "core/input/input.hpp" // Para Input, InputAction
|
#include "core/input/input.hpp" // Para Input, InputAction
|
||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/resources/asset.hpp" // Para Asset, AssetType
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
|
||||||
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
||||||
|
#include "core/resources/resource_list.hpp" // Para Asset, AssetType
|
||||||
#include "core/resources/resource_loader.hpp" // Para ResourceLoader
|
#include "core/resources/resource_loader.hpp" // Para ResourceLoader
|
||||||
#include "core/system/debug.hpp" // Para Debug
|
#include "core/system/debug.hpp" // Para Debug
|
||||||
#include "game/gameplay/cheevos.hpp" // Para Cheevos
|
#include "game/gameplay/cheevos.hpp" // Para Cheevos
|
||||||
@@ -69,7 +69,7 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
|
|
||||||
// 1. Initialize resource pack system (required, no fallback)
|
// 1. Initialize resource pack system (required, no fallback)
|
||||||
std::cout << "Initializing resource pack: " << pack_path << '\n';
|
std::cout << "Initializing resource pack: " << pack_path << '\n';
|
||||||
if (!jdd::ResourceHelper::initializeResourceSystem(pack_path, false)) {
|
if (!Resource::Helper::initializeResourceSystem(pack_path, false)) {
|
||||||
std::cerr << "ERROR: Failed to load resources.pack (required in release builds)\n";
|
std::cerr << "ERROR: Failed to load resources.pack (required in release builds)\n";
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -92,8 +92,8 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
// 4. Initialize Asset system with config from pack
|
// 4. Initialize Asset system with config from pack
|
||||||
// NOTE: In release, don't use executable_path or PREFIX - paths in pack are relative
|
// NOTE: In release, don't use executable_path or PREFIX - paths in pack are relative
|
||||||
// Pass empty string to avoid issues when running from different directories
|
// Pass empty string to avoid issues when running from different directories
|
||||||
Asset::init(""); // Empty executable_path in release
|
Resource::List::init(""); // Empty executable_path in release
|
||||||
Asset::get()->loadFromString(assets_config, "", system_folder_); // Empty PREFIX for pack
|
Resource::List::get()->loadFromString(assets_config, "", system_folder_); // Empty PREFIX for pack
|
||||||
std::cout << "Asset system initialized from pack\n";
|
std::cout << "Asset system initialized from pack\n";
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -103,7 +103,7 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
std::cout << "\n** DEVELOPMENT MODE: Filesystem-first initialization\n";
|
std::cout << "\n** DEVELOPMENT MODE: Filesystem-first initialization\n";
|
||||||
|
|
||||||
// 1. Initialize Asset system from filesystem
|
// 1. Initialize Asset system from filesystem
|
||||||
Asset::init(executable_path_);
|
Resource::List::init(executable_path_);
|
||||||
|
|
||||||
// 2. Load and verify assets from disk
|
// 2. Load and verify assets from disk
|
||||||
if (!setFileList()) {
|
if (!setFileList()) {
|
||||||
@@ -112,12 +112,12 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
|
|
||||||
// 3. Initialize resource pack system (optional, with fallback)
|
// 3. Initialize resource pack system (optional, with fallback)
|
||||||
std::cout << "Initializing resource pack (development mode): " << pack_path << '\n';
|
std::cout << "Initializing resource pack (development mode): " << pack_path << '\n';
|
||||||
Jdd::ResourceHelper::initializeResourceSystem(pack_path, true);
|
Resource::Helper::initializeResourceSystem(pack_path, true);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Carga las opciones desde un fichero
|
// Carga las opciones desde un fichero
|
||||||
Options::loadFromFile(Asset::get()->get("config.txt"));
|
Options::loadFromFile(Resource::List::get()->get("config.txt"));
|
||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
Audio::init();
|
Audio::init();
|
||||||
@@ -126,7 +126,7 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
Screen::init();
|
Screen::init();
|
||||||
|
|
||||||
// Initialize resources (works for both release and development)
|
// Initialize resources (works for both release and development)
|
||||||
Resource::init();
|
Resource::Cache::init();
|
||||||
Notifier::init("", "8bithud");
|
Notifier::init("", "8bithud");
|
||||||
Screen::get()->setNotificationsEnabled(true);
|
Screen::get()->setNotificationsEnabled(true);
|
||||||
|
|
||||||
@@ -134,10 +134,10 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
#ifdef RELEASE_BUILD
|
#ifdef RELEASE_BUILD
|
||||||
// In release, construct the path manually (not from Asset which has empty executable_path)
|
// In release, construct the path manually (not from Asset which has empty executable_path)
|
||||||
std::string gamecontroller_db = executable_path_ + PREFIX + "/gamecontrollerdb.txt";
|
std::string gamecontroller_db = executable_path_ + PREFIX + "/gamecontrollerdb.txt";
|
||||||
Input::init(gamecontroller_db, Asset::get()->get("controllers.json"));
|
Input::init(gamecontroller_db, Resource::List::get()->get("controllers.json"));
|
||||||
#else
|
#else
|
||||||
// In development, use Asset as normal
|
// In development, use Asset as normal
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
|
Input::init(Resource::List::get()->get("gamecontrollerdb.txt"), Resource::List::get()->get("controllers.json")); // Carga configuración de controles
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Aplica las teclas configuradas desde Options
|
// Aplica las teclas configuradas desde Options
|
||||||
@@ -150,24 +150,24 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
std::string cheevos_path = system_folder_ + "/cheevos.bin";
|
std::string cheevos_path = system_folder_ + "/cheevos.bin";
|
||||||
Cheevos::init(cheevos_path);
|
Cheevos::init(cheevos_path);
|
||||||
#else
|
#else
|
||||||
Cheevos::init(Asset::get()->get("cheevos.bin"));
|
Cheevos::init(Resource::List::get()->get("cheevos.bin"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Director::~Director() {
|
Director::~Director() {
|
||||||
// Guarda las opciones a un fichero
|
// Guarda las opciones a un fichero
|
||||||
Options::saveToFile(Asset::get()->get("config.txt"));
|
Options::saveToFile(Resource::List::get()->get("config.txt"));
|
||||||
|
|
||||||
// Destruye los singletones
|
// Destruye los singletones
|
||||||
Cheevos::destroy();
|
Cheevos::destroy();
|
||||||
Debug::destroy();
|
Debug::destroy();
|
||||||
Input::destroy();
|
Input::destroy();
|
||||||
Notifier::destroy();
|
Notifier::destroy();
|
||||||
Resource::destroy();
|
Resource::Cache::destroy();
|
||||||
Jdd::ResourceHelper::shutdownResourceSystem(); // Shutdown resource pack system
|
Resource::Helper::shutdownResourceSystem(); // Shutdown resource pack system
|
||||||
Audio::destroy();
|
Audio::destroy();
|
||||||
Screen::destroy();
|
Screen::destroy();
|
||||||
Asset::destroy();
|
Resource::List::destroy();
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
@@ -264,10 +264,10 @@ auto Director::setFileList() -> bool {
|
|||||||
std::string config_path = executable_path_ + PREFIX + "/config/assets.txt";
|
std::string config_path = executable_path_ + PREFIX + "/config/assets.txt";
|
||||||
|
|
||||||
// Cargar todos los assets desde el archivo de configuración
|
// Cargar todos los assets desde el archivo de configuración
|
||||||
Asset::get()->loadFromFile(config_path, PREFIX, system_folder_);
|
Resource::List::get()->loadFromFile(config_path, PREFIX, system_folder_);
|
||||||
|
|
||||||
// Verificar que todos los assets requeridos existen
|
// Verificar que todos los assets requeridos existen
|
||||||
return Asset::get()->check();
|
return Resource::List::get()->check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el logo
|
// Ejecuta la seccion de juego con el logo
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
#include <cstdlib> // Para rand
|
#include <cstdlib> // Para rand
|
||||||
|
|
||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "utils/utils.hpp" // Para stringToColor
|
#include "utils/utils.hpp" // Para stringToColor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Enemy::Enemy(const Data& enemy)
|
Enemy::Enemy(const Data& enemy)
|
||||||
// [DOC:29/10/2025] la surface ara se pillarà del .ANI
|
// [DOC:29/10/2025] la surface ara se pillarà del .ANI
|
||||||
: sprite_(std::make_shared<SurfaceAnimatedSprite>(/*Resource::get()->getSurface(enemy.surface_path), */ Resource::get()->getAnimations(enemy.animation_path))),
|
: sprite_(std::make_shared<SurfaceAnimatedSprite>(/*Resource::Cache::get()->getSurface(enemy.surface_path), */ Resource::Cache::get()->getAnimations(enemy.animation_path))),
|
||||||
color_string_(enemy.color),
|
color_string_(enemy.color),
|
||||||
x1_(enemy.x1),
|
x1_(enemy.x1),
|
||||||
x2_(enemy.x2),
|
x2_(enemy.x2),
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "game/entities/item.hpp"
|
#include "game/entities/item.hpp"
|
||||||
|
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(const Data& item)
|
Item::Item(const Data& item)
|
||||||
: sprite_(std::make_shared<SurfaceSprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE, ITEM_SIZE)),
|
: sprite_(std::make_shared<SurfaceSprite>(Resource::Cache::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE, ITEM_SIZE)),
|
||||||
time_accumulator_(static_cast<float>(item.counter) * COLOR_CHANGE_INTERVAL),
|
time_accumulator_(static_cast<float>(item.counter) * COLOR_CHANGE_INTERVAL),
|
||||||
is_paused_(false) {
|
is_paused_(false) {
|
||||||
// Inicia variables
|
// Inicia variables
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "core/audio/audio.hpp" // Para Audio
|
#include "core/audio/audio.hpp" // Para Audio
|
||||||
#include "core/input/input.hpp" // Para Input, InputAction
|
#include "core/input/input.hpp" // Para Input, InputAction
|
||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "game/gameplay/room.hpp" // Para Room, TileType
|
#include "game/gameplay/room.hpp" // Para Room, TileType
|
||||||
#include "game/options.hpp" // Para Cheat, Options, options
|
#include "game/options.hpp" // Para Cheat, Options, options
|
||||||
#include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
|
#include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
|
||||||
@@ -196,7 +196,7 @@ void Player::handleState(float delta_time) {
|
|||||||
} else if (state_ == State::STANDING) {
|
} else if (state_ == State::STANDING) {
|
||||||
// Si no tiene suelo debajo y no está en rampa descendente -> FALLING
|
// Si no tiene suelo debajo y no está en rampa descendente -> FALLING
|
||||||
if (!isOnFloor() && !isOnConveyorBelt() && !isOnDownSlope()) {
|
if (!isOnFloor() && !isOnConveyorBelt() && !isOnDownSlope()) {
|
||||||
transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
|
transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
|
||||||
}
|
}
|
||||||
} else if (state_ == State::JUMPING) {
|
} else if (state_ == State::JUMPING) {
|
||||||
playJumpSound(delta_time);
|
playJumpSound(delta_time);
|
||||||
@@ -545,10 +545,10 @@ void Player::updateFeet() {
|
|||||||
void Player::initSounds() {
|
void Player::initSounds() {
|
||||||
for (int i = 0; i < 24; ++i) {
|
for (int i = 0; i < 24; ++i) {
|
||||||
std::string sound_file = "jump" + std::to_string(i + 1) + ".wav";
|
std::string sound_file = "jump" + std::to_string(i + 1) + ".wav";
|
||||||
jumping_sound_[i] = Resource::get()->getSound(sound_file);
|
jumping_sound_[i] = Resource::Cache::get()->getSound(sound_file);
|
||||||
|
|
||||||
if (i >= 10) { // i+1 >= 11
|
if (i >= 10) { // i+1 >= 11
|
||||||
falling_sound_[i - 10] = Resource::get()->getSound(sound_file);
|
falling_sound_[i - 10] = Resource::Cache::get()->getSound(sound_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -649,7 +649,7 @@ void Player::applySpawnValues(const SpawnData& spawn) {
|
|||||||
|
|
||||||
// Inicializa el sprite del jugador
|
// Inicializa el sprite del jugador
|
||||||
void Player::initSprite(const std::string& animations_path) {
|
void Player::initSprite(const std::string& animations_path) {
|
||||||
auto animations = Resource::get()->getAnimations(animations_path);
|
auto animations = Resource::Cache::get()->getAnimations(animations_path);
|
||||||
sprite_ = std::make_unique<SurfaceAnimatedSprite>(animations);
|
sprite_ = std::make_unique<SurfaceAnimatedSprite>(animations);
|
||||||
sprite_->setWidth(WIDTH);
|
sprite_->setWidth(WIDTH);
|
||||||
sprite_->setHeight(HEIGHT);
|
sprite_->setHeight(HEIGHT);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "core/audio/audio.hpp" // Para Audio
|
#include "core/audio/audio.hpp" // Para Audio
|
||||||
#include "core/input/input.hpp" // Para Input, InputAction
|
#include "core/input/input.hpp" // Para Input, InputAction
|
||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "game/gameplay/room.hpp" // Para Room, TileType
|
#include "game/gameplay/room.hpp" // Para Room, TileType
|
||||||
#include "game/options.hpp" // Para Cheat, Options, options
|
#include "game/options.hpp" // Para Cheat, Options, options
|
||||||
#include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
|
#include "utils/defines.hpp" // Para RoomBorder::BOTTOM, RoomBorder::LEFT, RoomBorder::RIGHT
|
||||||
@@ -585,10 +585,10 @@ void Player::initSounds() {
|
|||||||
|
|
||||||
for (int i = 1; i <= 24; ++i) {
|
for (int i = 1; i <= 24; ++i) {
|
||||||
std::string sound_file = "jump" + std::to_string(i) + ".wav";
|
std::string sound_file = "jump" + std::to_string(i) + ".wav";
|
||||||
jumping_sound_.push_back(Resource::get()->getSound(sound_file));
|
jumping_sound_.push_back(Resource::Cache::get()->getSound(sound_file));
|
||||||
|
|
||||||
if (i >= 11) {
|
if (i >= 11) {
|
||||||
falling_sound_.push_back(Resource::get()->getSound(sound_file));
|
falling_sound_.push_back(Resource::Cache::get()->getSound(sound_file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -607,7 +607,7 @@ void Player::applySpawnValues(const SpawnData& spawn) {
|
|||||||
|
|
||||||
// Inicializa el sprite del jugador
|
// Inicializa el sprite del jugador
|
||||||
void Player::initSprite(const std::string& animations_path) {
|
void Player::initSprite(const std::string& animations_path) {
|
||||||
auto animations = Resource::get()->getAnimations(animations_path);
|
auto animations = Resource::Cache::get()->getAnimations(animations_path);
|
||||||
|
|
||||||
sprite_ = std::make_unique<SurfaceAnimatedSprite>(animations);
|
sprite_ = std::make_unique<SurfaceAnimatedSprite>(animations);
|
||||||
sprite_->setWidth(WIDTH);
|
sprite_->setWidth(WIDTH);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
|
||||||
#include "core/system/debug.hpp" // Para Debug
|
#include "core/system/debug.hpp" // Para Debug
|
||||||
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
|
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
|
Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
|
||||||
: data_(std::move(std::move(data))) {
|
: data_(std::move(std::move(data))) {
|
||||||
auto room = Resource::get()->getRoom(room_path);
|
auto room = Resource::Cache::get()->getRoom(room_path);
|
||||||
initializeRoom(*room);
|
initializeRoom(*room);
|
||||||
|
|
||||||
openTheJail(); // Abre la Jail si se da el caso
|
openTheJail(); // Abre la Jail si se da el caso
|
||||||
@@ -49,8 +49,8 @@ void Room::initializeRoom(const Data& room) {
|
|||||||
tile_set_file_ = room.tile_set_file;
|
tile_set_file_ = room.tile_set_file;
|
||||||
tile_map_file_ = room.tile_map_file;
|
tile_map_file_ = room.tile_map_file;
|
||||||
conveyor_belt_direction_ = room.conveyor_belt_direction;
|
conveyor_belt_direction_ = room.conveyor_belt_direction;
|
||||||
tile_map_ = Resource::get()->getTileMap(room.tile_map_file);
|
tile_map_ = Resource::Cache::get()->getTileMap(room.tile_map_file);
|
||||||
surface_ = Resource::get()->getSurface(room.tile_set_file);
|
surface_ = Resource::Cache::get()->getSurface(room.tile_set_file);
|
||||||
tile_set_width_ = surface_->getWidth() / TILE_SIZE;
|
tile_set_width_ = surface_->getWidth() / TILE_SIZE;
|
||||||
is_paused_ = false;
|
is_paused_ = false;
|
||||||
time_accumulator_ = 0.0F;
|
time_accumulator_ = 0.0F;
|
||||||
@@ -930,7 +930,7 @@ auto Room::loadRoomTileFile(const std::string& file_path, bool verbose) -> std::
|
|||||||
const std::string FILENAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const std::string FILENAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
|
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
auto file_data = Jdd::ResourceHelper::loadFile(file_path);
|
auto file_data = Resource::Helper::loadFile(file_path);
|
||||||
|
|
||||||
if (!file_data.empty()) {
|
if (!file_data.empty()) {
|
||||||
// Convert bytes to string and parse
|
// Convert bytes to string and parse
|
||||||
@@ -992,7 +992,7 @@ auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data {
|
|||||||
room.number = FILE_NAME.substr(0, FILE_NAME.find_last_of('.'));
|
room.number = FILE_NAME.substr(0, FILE_NAME.find_last_of('.'));
|
||||||
|
|
||||||
// Load file using ResourceHelper (supports both filesystem and pack)
|
// Load file using ResourceHelper (supports both filesystem and pack)
|
||||||
auto file_data = Jdd::ResourceHelper::loadFile(file_path);
|
auto file_data = Resource::Helper::loadFile(file_path);
|
||||||
|
|
||||||
if (!file_data.empty()) {
|
if (!file_data.empty()) {
|
||||||
// Convert bytes to string and parse
|
// Convert bytes to string and parse
|
||||||
|
|||||||
@@ -8,21 +8,21 @@
|
|||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text
|
#include "core/rendering/text.hpp" // Para Text
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "game/options.hpp" // Para Options, options, Cheat, OptionsGame
|
#include "game/options.hpp" // Para Options, options, Cheat, OptionsGame
|
||||||
#include "utils/defines.hpp" // Para BLOCK
|
#include "utils/defines.hpp" // Para BLOCK
|
||||||
#include "utils/utils.hpp" // Para stringToColor
|
#include "utils/utils.hpp" // Para stringToColor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard::Scoreboard(std::shared_ptr<Data> data)
|
Scoreboard::Scoreboard(std::shared_ptr<Data> data)
|
||||||
: item_surface_(Resource::get()->getSurface("items.gif")),
|
: item_surface_(Resource::Cache::get()->getSurface("items.gif")),
|
||||||
data_(std::move(std::move(data))) {
|
data_(std::move(std::move(data))) {
|
||||||
const float SURFACE_WIDTH = Options::game.width;
|
const float SURFACE_WIDTH = Options::game.width;
|
||||||
constexpr float SURFACE_HEIGHT = 6.0F * TILE_SIZE;
|
constexpr float SURFACE_HEIGHT = 6.0F * TILE_SIZE;
|
||||||
|
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
// auto player_texture = Resource::get()->getSurface(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif");
|
// auto player_texture = Resource::Cache::get()->getSurface(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif");
|
||||||
auto player_animations = Resource::get()->getAnimations(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.ani" : "player.ani");
|
auto player_animations = Resource::Cache::get()->getAnimations(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.ani" : "player.ani");
|
||||||
player_sprite_ = std::make_shared<SurfaceAnimatedSprite>(player_animations);
|
player_sprite_ = std::make_shared<SurfaceAnimatedSprite>(player_animations);
|
||||||
player_sprite_->setCurrentAnimation("walk_menu");
|
player_sprite_->setCurrentAnimation("walk_menu");
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ void Scoreboard::fillTexture() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Escribe los textos
|
// Escribe los textos
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
const std::string TIME_TEXT = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10);
|
const std::string TIME_TEXT = std::to_string((clock_.minutes % 100) / 10) + std::to_string(clock_.minutes % 10) + clock_.separator + std::to_string((clock_.seconds % 60) / 10) + std::to_string(clock_.seconds % 10);
|
||||||
const std::string ITEMS_TEXT = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10);
|
const std::string ITEMS_TEXT = std::to_string(data_->items / 100) + std::to_string((data_->items % 100) / 10) + std::to_string(data_->items % 10);
|
||||||
text->writeColored(TILE_SIZE, LINE1, "Items collected ", data_->color);
|
text->writeColored(TILE_SIZE, LINE1, "Items collected ", data_->color);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
|
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
Credits::Credits()
|
Credits::Credits()
|
||||||
: text_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
: text_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||||
cover_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
cover_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||||
shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("shine.ani"))),
|
shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations("shine.ani"))),
|
||||||
delta_timer_(std::make_unique<DeltaTimer>()) {
|
delta_timer_(std::make_unique<DeltaTimer>()) {
|
||||||
// Configura la escena
|
// Configura la escena
|
||||||
SceneManager::current = SceneManager::Scene::CREDITS;
|
SceneManager::current = SceneManager::Scene::CREDITS;
|
||||||
@@ -111,7 +111,7 @@ void Credits::fillTexture() {
|
|||||||
Screen::get()->setRendererSurface(text_surface_);
|
Screen::get()->setRendererSurface(text_surface_);
|
||||||
text_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
|
text_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
|
||||||
|
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
const int SIZE = text->getCharacterSize();
|
const int SIZE = text->getCharacterSize();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text, TEXT_STROKE
|
#include "core/rendering/text.hpp" // Para Text, TEXT_STROKE
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, options, OptionsGame, SectionS...
|
#include "game/options.hpp" // Para Options, options, OptionsGame, SectionS...
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
@@ -209,7 +209,7 @@ void Ending::iniTexts() {
|
|||||||
sprite_texts_.clear();
|
sprite_texts_.clear();
|
||||||
|
|
||||||
for (const auto& txt : texts) {
|
for (const auto& txt : texts) {
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
|
|
||||||
const float WIDTH = text->lenght(txt.caption, 1) + 2 + 2;
|
const float WIDTH = text->lenght(txt.caption, 1) + 2 + 2;
|
||||||
const float HEIGHT = text->getCharacterSize() + 2 + 2;
|
const float HEIGHT = text->getCharacterSize() + 2 + 2;
|
||||||
@@ -284,7 +284,7 @@ void Ending::iniPics() {
|
|||||||
EndingSurface sp;
|
EndingSurface sp;
|
||||||
|
|
||||||
// Crea la texture
|
// Crea la texture
|
||||||
sp.image_surface = Resource::get()->getSurface(pic.caption);
|
sp.image_surface = Resource::Cache::get()->getSurface(pic.caption);
|
||||||
sp.image_surface->setTransparentColor();
|
sp.image_surface->setTransparentColor();
|
||||||
const float WIDTH = sp.image_surface->getWidth();
|
const float WIDTH = sp.image_surface->getWidth();
|
||||||
const float HEIGHT = sp.image_surface->getHeight();
|
const float HEIGHT = sp.image_surface->getHeight();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/rendering/surface_moving_sprite.hpp" // Para SMovingSprite
|
#include "core/rendering/surface_moving_sprite.hpp" // Para SMovingSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text
|
#include "core/rendering/text.hpp" // Para Text
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
|
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
@@ -34,13 +34,12 @@ Ending2::Ending2()
|
|||||||
colors_.push_back(stringToColor(color));
|
colors_.push_back(stringToColor(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
|
||||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));// Cambia el color del borde
|
iniSpriteList(); // Inicializa la lista de sprites
|
||||||
iniSpriteList();// Inicializa la lista de sprites
|
loadSprites(); // Carga todos los sprites desde una lista
|
||||||
loadSprites();// Carga todos los sprites desde una lista
|
placeSprites(); // Coloca los sprites en su sito
|
||||||
placeSprites();// Coloca los sprites en su sito
|
createSpriteTexts(); // Crea los sprites con las texturas con los textos
|
||||||
createSpriteTexts();// Crea los sprites con las texturas con los textos
|
createTexts(); // Crea los sprites con las texturas con los textos del final
|
||||||
createTexts();// Crea los sprites con las texturas con los textos del final
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
@@ -288,7 +287,7 @@ void Ending2::loadSprites() {
|
|||||||
|
|
||||||
// Carga los sprites
|
// Carga los sprites
|
||||||
for (const auto& file : sprite_list_) {
|
for (const auto& file : sprite_list_) {
|
||||||
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations(file + ".ani")));
|
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations(file + ".ani")));
|
||||||
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
|
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
|
||||||
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
|
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
|
||||||
}
|
}
|
||||||
@@ -358,7 +357,7 @@ void Ending2::renderTexts() {
|
|||||||
void Ending2::placeSprites() {
|
void Ending2::placeSprites() {
|
||||||
for (int i = 0; i < static_cast<int>(sprites_.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(sprites_.size()); ++i) {
|
||||||
const float X = i % 2 == 0 ? FIRST_COL : SECOND_COL;
|
const float X = i % 2 == 0 ? FIRST_COL : SECOND_COL;
|
||||||
const float Y = ((i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT + Resource::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE)) + Options::game.height + INITIAL_Y_OFFSET;
|
const float Y = ((i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT + Resource::Cache::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE)) + Options::game.height + INITIAL_Y_OFFSET;
|
||||||
const float W = sprites_.at(i)->getWidth();
|
const float W = sprites_.at(i)->getWidth();
|
||||||
const float H = sprites_.at(i)->getHeight();
|
const float H = sprites_.at(i)->getHeight();
|
||||||
const float DX = -(W / 2);
|
const float DX = -(W / 2);
|
||||||
@@ -379,7 +378,7 @@ void Ending2::placeSprites() {
|
|||||||
void Ending2::createSpriteTexts() {
|
void Ending2::createSpriteTexts() {
|
||||||
// Crea los sprites de texto a partir de la lista
|
// Crea los sprites de texto a partir de la lista
|
||||||
for (size_t i = 0; i < sprite_list_.size(); ++i) {
|
for (size_t i = 0; i < sprite_list_.size(); ++i) {
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
|
|
||||||
// Procesa y ajusta el texto del sprite actual
|
// Procesa y ajusta el texto del sprite actual
|
||||||
std::string txt = sprite_list_[i];
|
std::string txt = sprite_list_[i];
|
||||||
@@ -420,7 +419,7 @@ void Ending2::createTexts() {
|
|||||||
std::vector<std::string> list;
|
std::vector<std::string> list;
|
||||||
list.emplace_back("STARRING");
|
list.emplace_back("STARRING");
|
||||||
|
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
|
|
||||||
// Crea los sprites de texto a partir de la lista
|
// Crea los sprites de texto a partir de la lista
|
||||||
for (size_t i = 0; i < list.size(); ++i) {
|
for (size_t i = 0; i < list.size(); ++i) {
|
||||||
|
|||||||
@@ -5,26 +5,26 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
#include "core/audio/audio.hpp" // Para Audio
|
#include "core/audio/audio.hpp" // Para Audio
|
||||||
#include "core/input/global_inputs.hpp" // Para check
|
#include "core/input/global_inputs.hpp" // Para check
|
||||||
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
|
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
|
||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "core/resources/asset.hpp" // Para Asset
|
#include "core/resources/resource_cache.hpp" // Para ResourceRoom, Resource
|
||||||
#include "core/resources/resource.hpp" // Para ResourceRoom, Resource
|
#include "core/resources/resource_list.hpp" // Para Asset
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/gameplay/cheevos.hpp" // Para Cheevos
|
#include "game/gameplay/cheevos.hpp" // Para Cheevos
|
||||||
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
|
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
|
||||||
#include "game/gameplay/room.hpp" // Para Room, RoomData
|
#include "game/gameplay/room.hpp" // Para Room, RoomData
|
||||||
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
|
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
|
||||||
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data, Scoreboard
|
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data, Scoreboard
|
||||||
#include "game/gameplay/stats.hpp" // Para Stats
|
#include "game/gameplay/stats.hpp" // Para Stats
|
||||||
#include "game/options.hpp" // Para Options, options, Cheat, SectionState
|
#include "game/options.hpp" // Para Options, options, Cheat, SectionState
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
|
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
|
||||||
#include "utils/defines.hpp" // Para TILE_SIZE, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
|
#include "utils/defines.hpp" // Para TILE_SIZE, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
|
||||||
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
|
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#include "core/system/debug.hpp" // Para Debug
|
#include "core/system/debug.hpp" // Para Debug
|
||||||
@@ -35,7 +35,7 @@ Game::Game(Mode mode)
|
|||||||
: board_(std::make_shared<Scoreboard::Data>(0, 9, 0, true, 0, SDL_GetTicks(), Options::cheats.jail_is_open == Options::Cheat::State::ENABLED)),
|
: board_(std::make_shared<Scoreboard::Data>(0, 9, 0, true, 0, SDL_GetTicks(), Options::cheats.jail_is_open == Options::Cheat::State::ENABLED)),
|
||||||
scoreboard_(std::make_shared<Scoreboard>(board_)),
|
scoreboard_(std::make_shared<Scoreboard>(board_)),
|
||||||
room_tracker_(std::make_shared<RoomTracker>()),
|
room_tracker_(std::make_shared<RoomTracker>()),
|
||||||
stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))),
|
stats_(std::make_shared<Stats>(Resource::List::get()->get("stats.csv"), Resource::List::get()->get("stats_buffer.csv"))),
|
||||||
mode_(mode),
|
mode_(mode),
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
current_room_("03.room"),
|
current_room_("03.room"),
|
||||||
@@ -229,7 +229,7 @@ void Game::handleDebugEvents(const SDL_Event& event) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_R:
|
case SDL_SCANCODE_R:
|
||||||
Resource::get()->reload();
|
Resource::Cache::get()->reload();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_W:
|
case SDL_SCANCODE_W:
|
||||||
@@ -273,7 +273,7 @@ auto Game::changeRoom(const std::string& room_path) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verifica que exista el fichero que se va a cargar
|
// Verifica que exista el fichero que se va a cargar
|
||||||
if (!Asset::get()->get(room_path).empty()) {
|
if (!Resource::List::get()->get(room_path).empty()) {
|
||||||
// Crea un objeto habitación nuevo a partir del fichero
|
// Crea un objeto habitación nuevo a partir del fichero
|
||||||
room_ = std::make_shared<Room>(room_path, board_);
|
room_ = std::make_shared<Room>(room_path, board_);
|
||||||
|
|
||||||
@@ -441,7 +441,7 @@ auto Game::checkEndGame() -> bool {
|
|||||||
// Obtiene la cantidad total de items que hay en el mapeado del juego
|
// Obtiene la cantidad total de items que hay en el mapeado del juego
|
||||||
auto Game::getTotalItems() -> int {
|
auto Game::getTotalItems() -> int {
|
||||||
int items = 0;
|
int items = 0;
|
||||||
auto rooms = Resource::get()->getRooms();
|
auto rooms = Resource::Cache::get()->getRooms();
|
||||||
|
|
||||||
for (const auto& room : rooms) {
|
for (const auto& room : rooms) {
|
||||||
items += room.room->items.size();
|
items += room.room->items.size();
|
||||||
@@ -486,7 +486,7 @@ void Game::checkRestoringJail(float delta_time) {
|
|||||||
|
|
||||||
// Inicializa el diccionario de las estadísticas
|
// Inicializa el diccionario de las estadísticas
|
||||||
void Game::initStats() {
|
void Game::initStats() {
|
||||||
auto list = Resource::get()->getRooms();
|
auto list = Resource::Cache::get()->getRooms();
|
||||||
|
|
||||||
for (const auto& room : list) {
|
for (const auto& room : list) {
|
||||||
stats_->addDictionary(room.room->number, room.room->name);
|
stats_->addDictionary(room.room->number, room.room->name);
|
||||||
@@ -505,7 +505,7 @@ void Game::fillRoomNameTexture() {
|
|||||||
room_name_surface_->clear(stringToColor("white"));
|
room_name_surface_->clear(stringToColor("white"));
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor());
|
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor());
|
||||||
|
|
||||||
// Deja el renderizador por defecto
|
// Deja el renderizador por defecto
|
||||||
@@ -580,7 +580,7 @@ void Game::initPlayer(const Player::SpawnData& spawn_point, std::shared_ptr<Room
|
|||||||
|
|
||||||
// Crea la textura para poner el nombre de la habitación
|
// Crea la textura para poner el nombre de la habitación
|
||||||
void Game::createRoomNameTexture() {
|
void Game::createRoomNameTexture() {
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
room_name_surface_ = std::make_shared<Surface>(Options::game.width, text->getCharacterSize() * 2);
|
room_name_surface_ = std::make_shared<Surface>(Options::game.width, text->getCharacterSize() * 2);
|
||||||
|
|
||||||
// Establece el destino de la textura
|
// Establece el destino de la textura
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||||
#include "core/rendering/text.hpp" // Para TEXT_CENTER, TEXT_COLOR, Text
|
#include "core/rendering/text.hpp" // Para TEXT_CENTER, TEXT_COLOR, Text
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, options, OptionsStats, Secti...
|
#include "game/options.hpp" // Para Options, options, OptionsStats, Secti...
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver()
|
GameOver::GameOver()
|
||||||
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("player_game_over.ani"))),
|
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations("player_game_over.ani"))),
|
||||||
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("tv.ani"))),
|
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations("tv.ani"))),
|
||||||
delta_timer_(std::make_shared<DeltaTimer>()) {
|
delta_timer_(std::make_shared<DeltaTimer>()) {
|
||||||
SceneManager::current = SceneManager::Scene::GAME_OVER;
|
SceneManager::current = SceneManager::Scene::GAME_OVER;
|
||||||
SceneManager::options = SceneManager::Options::NONE;
|
SceneManager::options = SceneManager::Options::NONE;
|
||||||
@@ -65,7 +65,7 @@ void GameOver::render() {
|
|||||||
Screen::get()->start();
|
Screen::get()->start();
|
||||||
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
||||||
|
|
||||||
auto text = Resource::get()->getText("smb2");
|
auto text = Resource::Cache::get()->getText("smb2");
|
||||||
|
|
||||||
// Escribe el texto de GAME OVER
|
// Escribe el texto de GAME OVER
|
||||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, TEXT_Y, "G A M E O V E R", 1, color_);
|
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, TEXT_Y, "G A M E O V E R", 1, color_);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, options, SectionState, Options...
|
#include "game/options.hpp" // Para Options, options, SectionState, Options...
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
@@ -20,11 +20,11 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
LoadingScreen::LoadingScreen()
|
LoadingScreen::LoadingScreen()
|
||||||
: mono_loading_screen_surface_(Resource::get()->getSurface("loading_screen_bn.gif")),
|
: mono_loading_screen_surface_(Resource::Cache::get()->getSurface("loading_screen_bn.gif")),
|
||||||
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
|
color_loading_screen_surface_(Resource::Cache::get()->getSurface("loading_screen_color.gif")),
|
||||||
mono_loading_screen_sprite_(std::make_unique<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
mono_loading_screen_sprite_(std::make_unique<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
||||||
color_loading_screen_sprite_(std::make_unique<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
color_loading_screen_sprite_(std::make_unique<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
||||||
program_sprite_(std::make_unique<SurfaceSprite>(Resource::get()->getSurface("program_jaildoc.gif"))),
|
program_sprite_(std::make_unique<SurfaceSprite>(Resource::Cache::get()->getSurface("program_jaildoc.gif"))),
|
||||||
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||||
delta_timer_(std::make_unique<DeltaTimer>()) {
|
delta_timer_(std::make_unique<DeltaTimer>()) {
|
||||||
// Configura la superficie donde se van a pintar los sprites
|
// Configura la superficie donde se van a pintar los sprites
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "core/rendering/screen.hpp" // Para Screen
|
#include "core/rendering/screen.hpp" // Para Screen
|
||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/options.hpp" // Para Options, SectionState, options, Section
|
#include "game/options.hpp" // Para Options, SectionState, options, Section
|
||||||
#include "game/scene_manager.hpp" // Para SceneManager
|
#include "game/scene_manager.hpp" // Para SceneManager
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo()
|
Logo::Logo()
|
||||||
: jailgames_surface_(Resource::get()->getSurface("jailgames.gif")),
|
: jailgames_surface_(Resource::Cache::get()->getSurface("jailgames.gif")),
|
||||||
since_1998_surface_(Resource::get()->getSurface("since_1998.gif")),
|
since_1998_surface_(Resource::Cache::get()->getSurface("since_1998.gif")),
|
||||||
since_1998_sprite_(std::make_shared<SurfaceSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())),
|
since_1998_sprite_(std::make_shared<SurfaceSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())),
|
||||||
delta_timer_(std::make_unique<DeltaTimer>()) {
|
delta_timer_(std::make_unique<DeltaTimer>()) {
|
||||||
// Configura variables
|
// Configura variables
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "core/resources/asset.hpp" // Para Asset
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_list.hpp" // Para Asset
|
||||||
#include "core/system/global_events.hpp" // Para check
|
#include "core/system/global_events.hpp" // Para check
|
||||||
#include "game/gameplay/cheevos.hpp" // Para Cheevos, Achievement
|
#include "game/gameplay/cheevos.hpp" // Para Cheevos, Achievement
|
||||||
#include "game/options.hpp" // Para Options, options, SectionState, Section
|
#include "game/options.hpp" // Para Options, options, SectionState, Section
|
||||||
@@ -22,14 +22,14 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Title::Title()
|
Title::Title()
|
||||||
: game_logo_surface_(Resource::get()->getSurface("title_logo.gif")),
|
: game_logo_surface_(Resource::Cache::get()->getSurface("title_logo.gif")),
|
||||||
game_logo_sprite_(std::make_unique<SurfaceSprite>(game_logo_surface_, 29, 9, game_logo_surface_->getWidth(), game_logo_surface_->getHeight())),
|
game_logo_sprite_(std::make_unique<SurfaceSprite>(game_logo_surface_, 29, 9, game_logo_surface_->getWidth(), game_logo_surface_->getHeight())),
|
||||||
loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
|
loading_screen_surface_(Resource::Cache::get()->getSurface("loading_screen_color.gif")),
|
||||||
loading_screen_sprite_(std::make_unique<SurfaceSprite>(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())),
|
loading_screen_sprite_(std::make_unique<SurfaceSprite>(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())),
|
||||||
title_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
title_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||||
delta_timer_(std::make_unique<DeltaTimer>()),
|
delta_timer_(std::make_unique<DeltaTimer>()),
|
||||||
marquee_text_(Resource::get()->getText("gauntlet")),
|
marquee_text_(Resource::Cache::get()->getText("gauntlet")),
|
||||||
menu_text_(Resource::get()->getText("gauntlet")) {
|
menu_text_(Resource::Cache::get()->getText("gauntlet")) {
|
||||||
// Inicializa arrays con valores por defecto
|
// Inicializa arrays con valores por defecto
|
||||||
temp_keys_.fill(SDL_SCANCODE_UNKNOWN);
|
temp_keys_.fill(SDL_SCANCODE_UNKNOWN);
|
||||||
temp_buttons_.fill(-1);
|
temp_buttons_.fill(-1);
|
||||||
@@ -437,7 +437,7 @@ void Title::createCheevosTexture() {
|
|||||||
|
|
||||||
// Crea la textura con el listado de logros
|
// Crea la textura con el listado de logros
|
||||||
const auto CHEEVOS_LIST = Cheevos::get()->list();
|
const auto CHEEVOS_LIST = Cheevos::get()->list();
|
||||||
const auto TEXT = Resource::get()->getText("subatomic");
|
const auto TEXT = Resource::Cache::get()->getText("subatomic");
|
||||||
constexpr int CHEEVOS_TEXTURE_WIDTH = 200;
|
constexpr int CHEEVOS_TEXTURE_WIDTH = 200;
|
||||||
constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = MENU_ZONE_HEIGHT;
|
constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = MENU_ZONE_HEIGHT;
|
||||||
constexpr int CHEEVOS_PADDING = 10;
|
constexpr int CHEEVOS_PADDING = 10;
|
||||||
@@ -653,7 +653,7 @@ void Title::applyKeyboardRemap() {
|
|||||||
Input::get()->applyKeyboardBindingsFromOptions();
|
Input::get()->applyKeyboardBindingsFromOptions();
|
||||||
|
|
||||||
// Guardar a archivo de configuracion
|
// Guardar a archivo de configuracion
|
||||||
Options::saveToFile(Asset::get()->get("config.txt"));
|
Options::saveToFile(Resource::List::get()->get("config.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja la pantalla de redefinir teclado
|
// Dibuja la pantalla de redefinir teclado
|
||||||
@@ -836,7 +836,7 @@ void Title::applyJoystickRemap() {
|
|||||||
Input::get()->applyGamepadBindingsFromOptions();
|
Input::get()->applyGamepadBindingsFromOptions();
|
||||||
|
|
||||||
// Guardar a archivo de configuracion
|
// Guardar a archivo de configuracion
|
||||||
Options::saveToFile(Asset::get()->get("config.txt"));
|
Options::saveToFile(Resource::List::get()->get("config.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retorna el nombre amigable del botón del gamepad
|
// Retorna el nombre amigable del botón del gamepad
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "core/rendering/surface.hpp" // Para Surface
|
#include "core/rendering/surface.hpp" // Para Surface
|
||||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||||
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "game/options.hpp" // Para Options, options, NotificationPosition
|
#include "game/options.hpp" // Para Options, options, NotificationPosition
|
||||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
#include "utils/utils.hpp" // Para PaletteColor
|
#include "utils/utils.hpp" // Para PaletteColor
|
||||||
@@ -38,8 +38,8 @@ auto Notifier::get() -> Notifier* {
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notifier::Notifier(const std::string& icon_file, const std::string& text)
|
Notifier::Notifier(const std::string& icon_file, const std::string& text)
|
||||||
: icon_surface_(!icon_file.empty() ? Resource::get()->getSurface(icon_file) : nullptr),
|
: icon_surface_(!icon_file.empty() ? Resource::Cache::get()->getSurface(icon_file) : nullptr),
|
||||||
text_(Resource::get()->getText(text)),
|
text_(Resource::Cache::get()->getText(text)),
|
||||||
delta_timer_(std::make_unique<DeltaTimer>()),
|
delta_timer_(std::make_unique<DeltaTimer>()),
|
||||||
bg_color_(Options::notifications.color),
|
bg_color_(Options::notifications.color),
|
||||||
has_icons_(!icon_file.empty()) {}
|
has_icons_(!icon_file.empty()) {}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
#include <unordered_map> // Para unordered_map, operator==, _Node_const_iter...
|
#include <unordered_map> // Para unordered_map, operator==, _Node_const_iter...
|
||||||
#include <utility> // Para pair
|
#include <utility> // Para pair
|
||||||
|
|
||||||
#include "core/resources/resource.hpp" // Para Resource
|
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||||
#include "external/jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic
|
#include "external/jail_audio.h" // Para JA_GetMusicState, JA_Music_state, JA_PlayMusic
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
auto distanceSquared(int x1, int y1, int x2, int y2) -> double {
|
auto distanceSquared(int x1, int y1, int x2, int y2) -> double {
|
||||||
@@ -429,7 +429,7 @@ auto stringInVector(const std::vector<std::string>& vec, const std::string& str)
|
|||||||
void playMusic(const std::string& music_path) {
|
void playMusic(const std::string& music_path) {
|
||||||
// Si la música no está sonando
|
// Si la música no está sonando
|
||||||
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) {
|
if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) {
|
||||||
JA_PlayMusic(Resource::get()->getMusic(music_path));
|
JA_PlayMusic(Resource::Cache::get()->getMusic(music_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user