Compare commits
2 Commits
714de067c8
...
70cfe5245d
| Author | SHA1 | Date | |
|---|---|---|---|
| 70cfe5245d | |||
| c32a880b6a |
@@ -127,11 +127,27 @@ set(DEBUG_SOURCES
|
||||
)
|
||||
|
||||
# Configuración de SDL3
|
||||
if(EMSCRIPTEN)
|
||||
# En Emscripten, SDL3 se compila desde source con FetchContent
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
SDL3
|
||||
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
|
||||
GIT_TAG release-3.2.12
|
||||
GIT_SHALLOW TRUE
|
||||
)
|
||||
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_STATIC ON CACHE BOOL "" FORCE)
|
||||
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(SDL3)
|
||||
message(STATUS "SDL3 compilado desde source para Emscripten")
|
||||
else()
|
||||
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
|
||||
message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}")
|
||||
endif()
|
||||
|
||||
# --- SHADER COMPILATION (Linux/Windows only - macOS uses Metal) ---
|
||||
if(NOT APPLE)
|
||||
# --- SHADER COMPILATION (Linux/Windows only - macOS usa Metal, Emscripten no els necessita) ---
|
||||
if(NOT APPLE AND NOT EMSCRIPTEN)
|
||||
find_program(GLSLC_EXE NAMES glslc)
|
||||
|
||||
set(SHADERS_DIR "${CMAKE_SOURCE_DIR}/data/shaders")
|
||||
@@ -196,10 +212,15 @@ else()
|
||||
endif()
|
||||
|
||||
# --- 2. AÑADIR EJECUTABLE ---
|
||||
if(EMSCRIPTEN)
|
||||
# En Emscripten no compilem sdl3gpu_shader (SDL3 GPU no està suportat a WebGL2)
|
||||
add_executable(${PROJECT_NAME} ${APP_SOURCES})
|
||||
else()
|
||||
add_executable(${PROJECT_NAME} ${APP_SOURCES} ${RENDERING_SOURCES})
|
||||
endif()
|
||||
|
||||
# Shaders deben compilarse antes que el ejecutable (Linux/Windows con glslc)
|
||||
if(NOT APPLE AND GLSLC_EXE)
|
||||
if(NOT APPLE AND NOT EMSCRIPTEN AND GLSLC_EXE)
|
||||
add_dependencies(${PROJECT_NAME} shaders)
|
||||
endif()
|
||||
|
||||
@@ -243,12 +264,25 @@ elseif(APPLE)
|
||||
-rpath @executable_path/../Frameworks/
|
||||
)
|
||||
endif()
|
||||
elseif(EMSCRIPTEN)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE EMSCRIPTEN_BUILD)
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/data@/data"
|
||||
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/config@/config"
|
||||
"SHELL:--preload-file ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt@/gamecontrollerdb.txt"
|
||||
-sALLOW_MEMORY_GROWTH=1
|
||||
-sMAX_WEBGL_VERSION=2
|
||||
-sINITIAL_MEMORY=67108864
|
||||
)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".html")
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD)
|
||||
endif()
|
||||
|
||||
# Especificar la ubicación del ejecutable
|
||||
# Especificar la ubicación del ejecutable (en desktop; a wasm queda a build/wasm/)
|
||||
if(NOT EMSCRIPTEN)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# --- 5. STATIC ANALYSIS TARGETS ---
|
||||
|
||||
@@ -315,7 +349,8 @@ else()
|
||||
message(STATUS "clang-format no encontrado - targets 'format' y 'format-check' no disponibles")
|
||||
endif()
|
||||
|
||||
# --- 6. PACK RESOURCES TARGETS ---
|
||||
# --- 6. PACK RESOURCES TARGETS (no en Emscripten: s'utilitza --preload-file) ---
|
||||
if(NOT EMSCRIPTEN)
|
||||
set(PACK_TOOL_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/tools/pack_resources/pack_resources.cpp
|
||||
${CMAKE_SOURCE_DIR}/source/core/resources/resource_pack.cpp
|
||||
@@ -341,3 +376,4 @@ add_custom_command(
|
||||
|
||||
add_custom_target(pack DEPENDS "${CMAKE_SOURCE_DIR}/resources.pack")
|
||||
add_dependencies(${PROJECT_NAME} pack)
|
||||
endif()
|
||||
|
||||
20
Makefile
20
Makefile
@@ -285,6 +285,23 @@ linux_release:
|
||||
# Elimina la carpeta temporal
|
||||
$(RMDIR) "$(RELEASE_FOLDER)"
|
||||
|
||||
# ==============================================================================
|
||||
# COMPILACIÓN PARA WEBASSEMBLY (requiere Docker)
|
||||
# ==============================================================================
|
||||
wasm:
|
||||
@echo "Compilando para WebAssembly - Version: $(VERSION)"
|
||||
docker run --rm \
|
||||
-v $(DIR_ROOT):/src \
|
||||
-w /src \
|
||||
emscripten/emsdk:latest \
|
||||
bash -c "emcmake cmake -S . -B build/wasm -DCMAKE_BUILD_TYPE=Release && cmake --build build/wasm"
|
||||
$(MKDIR) "$(DIST_DIR)/wasm"
|
||||
cp build/wasm/$(TARGET_NAME).html $(DIST_DIR)/wasm/
|
||||
cp build/wasm/$(TARGET_NAME).js $(DIST_DIR)/wasm/
|
||||
cp build/wasm/$(TARGET_NAME).wasm $(DIST_DIR)/wasm/
|
||||
cp build/wasm/$(TARGET_NAME).data $(DIST_DIR)/wasm/
|
||||
@echo "Output: $(DIST_DIR)/wasm/"
|
||||
|
||||
# ==============================================================================
|
||||
# REGLAS ESPECIALES
|
||||
# ==============================================================================
|
||||
@@ -306,6 +323,7 @@ help:
|
||||
@echo " make windows_release - Crear release para Windows"
|
||||
@echo " make linux_release - Crear release para Linux"
|
||||
@echo " make macos_release - Crear release para macOS"
|
||||
@echo " make wasm - Crear release per a WebAssembly (requereix Docker)"
|
||||
@echo ""
|
||||
@echo " Herramientas:"
|
||||
@echo " make compile_shaders - Compilar shaders SPIR-V"
|
||||
@@ -316,4 +334,4 @@ help:
|
||||
@echo " make show_version - Mostrar version actual ($(VERSION))"
|
||||
@echo " make help - Mostrar esta ayuda"
|
||||
|
||||
.PHONY: all debug release windows_release macos_release linux_release compile_shaders pack_tool resources.pack show_version help
|
||||
.PHONY: all debug release windows_release macos_release linux_release wasm compile_shaders pack_tool resources.pack show_version help
|
||||
|
||||
@@ -20,6 +20,10 @@ namespace GlobalInputs {
|
||||
// Funciones internas
|
||||
namespace {
|
||||
void handleQuit() {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// A la versió web no es pot eixir del joc
|
||||
return;
|
||||
#else
|
||||
// En la escena GAME el comportamiento es siempre el mismo (con o sin modo kiosko)
|
||||
if (SceneManager::current == SceneManager::Scene::GAME) {
|
||||
const std::string CODE = "PRESS AGAIN TO RETURN TO MENU";
|
||||
@@ -48,6 +52,7 @@ namespace GlobalInputs {
|
||||
} else {
|
||||
Notifier::get()->show({Locale::get()->get("ui.press_again_exit")}, Notifier::Style::DEFAULT, -1, true, CODE); // NOLINT(readability-static-accessed-through-instance)
|
||||
}
|
||||
#endif // __EMSCRIPTEN__
|
||||
}
|
||||
|
||||
void handleSkipSection() {
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
|
||||
#include "core/input/mouse.hpp" // Para updateCursorVisibility
|
||||
#include "core/rendering/render_info.hpp" // Para RenderInfo
|
||||
#include "core/rendering/sdl3gpu/sdl3gpu_shader.hpp" // Para SDL3GPUShader
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#include "core/rendering/sdl3gpu/sdl3gpu_shader.hpp" // Para SDL3GPUShader (no suportat a WebGL2)
|
||||
#endif
|
||||
#include "core/rendering/surface.hpp" // Para Surface, readPalFile
|
||||
#include "core/rendering/text.hpp" // Para Text
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||
@@ -605,6 +607,10 @@ void Screen::nextShader() {
|
||||
// El device GPU se crea siempre (independientemente de postfx) para evitar
|
||||
// conflictos SDL_Renderer/SDL_GPU al hacer toggle F4 en Windows/Vulkan.
|
||||
void Screen::initShaders() {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// A WebGL2 no hi ha SDL3 GPU, el render va per SDL_Renderer sense shaders.
|
||||
shader_backend_.reset();
|
||||
#else
|
||||
SDL_Texture* tex = Options::video.border.enabled ? border_texture_ : game_texture_;
|
||||
|
||||
if (!shader_backend_) {
|
||||
@@ -633,6 +639,7 @@ void Screen::initShaders() {
|
||||
if (Options::video.shader.current_shader == Rendering::ShaderType::CRTPI) {
|
||||
applyCurrentCrtPiPreset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Obtiene información sobre la pantalla
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include "game/editor/map_editor.hpp" // Para MapEditor
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
@@ -48,12 +48,17 @@
|
||||
Director::Director() {
|
||||
std::cout << "Game start" << '\n';
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// En Emscripten els assets estan al root del filesystem virtual (/data, /config)
|
||||
executable_path_ = "";
|
||||
#else
|
||||
// Obtiene la ruta del ejecutable
|
||||
std::string base = SDL_GetBasePath();
|
||||
if (!base.empty() && base.back() == '/') {
|
||||
base.pop_back();
|
||||
}
|
||||
executable_path_ = base;
|
||||
#endif
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
createSystemFolder("jailgames");
|
||||
@@ -83,7 +88,7 @@ Director::Director() {
|
||||
// Preparar ruta al pack (en macOS bundle está en Contents/Resources/)
|
||||
std::string pack_path = executable_path_ + PREFIX + "/resources.pack";
|
||||
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
// ============================================================
|
||||
// RELEASE BUILD: Pack-first architecture
|
||||
// ============================================================
|
||||
@@ -141,6 +146,12 @@ Director::Director() {
|
||||
Options::setConfigFile(Resource::List::get()->get("config.yaml")); // NOLINT(readability-static-accessed-through-instance)
|
||||
Options::loadFromFile();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// A la versió web el navegador gestiona la finestra: res de fullscreen ni zoom.
|
||||
Options::video.fullscreen = false;
|
||||
Options::window.zoom = 1;
|
||||
#endif
|
||||
|
||||
// Configura la ruta y carga los presets de PostFX
|
||||
Options::setPostFXFile(Resource::List::get()->get("postfx.yaml")); // NOLINT(readability-static-accessed-through-instance)
|
||||
Options::loadPostFXFromFile();
|
||||
@@ -168,7 +179,7 @@ Director::Director() {
|
||||
Screen::get()->setNotificationsEnabled(true);
|
||||
|
||||
// Special handling for gamecontrollerdb.txt - SDL needs filesystem path
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
// In release, construct the path manually (not from Asset which has empty executable_path)
|
||||
std::string gamecontroller_db = executable_path_ + PREFIX + "/gamecontrollerdb.txt";
|
||||
Input::init(gamecontroller_db);
|
||||
@@ -192,7 +203,7 @@ Director::Director() {
|
||||
std::cout << "\n"; // Fin de inicialización de sistemas
|
||||
|
||||
// Inicializa el sistema de localización (antes de Cheevos que usa textos traducidos)
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
{
|
||||
// En release el locale está en el pack, no en el filesystem
|
||||
std::string locale_key = Resource::List::get()->get(Options::language + ".yaml"); // NOLINT(readability-static-accessed-through-instance)
|
||||
@@ -205,12 +216,15 @@ Director::Director() {
|
||||
#endif
|
||||
|
||||
// Special handling for cheevos.bin - also needs filesystem path
|
||||
#ifdef RELEASE_BUILD
|
||||
#if defined(RELEASE_BUILD) && !defined(__EMSCRIPTEN__)
|
||||
std::string cheevos_path = system_folder_ + "/cheevos.bin";
|
||||
Cheevos::init(cheevos_path);
|
||||
#else
|
||||
Cheevos::init(Resource::List::get()->get("cheevos.bin"));
|
||||
#endif
|
||||
|
||||
// Construeix la primera escena (LOGO per defecte, o la que digui Debug)
|
||||
switchToActiveScene();
|
||||
}
|
||||
|
||||
Director::~Director() {
|
||||
@@ -241,6 +255,12 @@ Director::~Director() {
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void Director::createSystemFolder(const std::string& folder) { // NOLINT(readability-convert-member-functions-to-static)
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// En Emscripten utilitzem MEMFS (no persistent entre sessions).
|
||||
// No cal crear directoris: MEMFS els crea automàticament en escriure-hi.
|
||||
system_folder_ = "/config/" + folder;
|
||||
return;
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
system_folder_ = std::string(getenv("APPDATA")) + "/" + folder;
|
||||
#elif __APPLE__
|
||||
@@ -292,6 +312,7 @@ void Director::createSystemFolder(const std::string& folder) { // NOLINT(readab
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // __EMSCRIPTEN__
|
||||
}
|
||||
|
||||
// Carga la configuración de assets desde assets.yaml
|
||||
@@ -311,118 +332,93 @@ void Director::setFileList() { // NOLINT(readability-convert-member-functions-t
|
||||
Resource::List::get()->loadFromFile(config_path, PREFIX, system_folder_);
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego con el logo
|
||||
void Director::runLogo() {
|
||||
auto logo = std::make_unique<Logo>();
|
||||
logo->run();
|
||||
// Construeix l'escena segons SceneManager::current i la deixa en active_scene_.
|
||||
// Substitueix els vells runLogo(), runTitle(), runGame(), etc.
|
||||
void Director::switchToActiveScene() {
|
||||
// Si la escena anterior va demanar RESTART_CURRENT, restaurem la que estava activa
|
||||
if (SceneManager::current == SceneManager::Scene::RESTART_CURRENT) {
|
||||
SceneManager::current = SceneManager::scene_before_restart;
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego de la pantalla de carga
|
||||
void Director::runLoadingScreen() {
|
||||
auto loading_screen = std::make_unique<LoadingScreen>();
|
||||
loading_screen->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego con el titulo y los menus
|
||||
void Director::runTitle() {
|
||||
auto title = std::make_unique<Title>();
|
||||
title->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de los creditos del juego
|
||||
void Director::runCredits() {
|
||||
auto credits = std::make_unique<Credits>();
|
||||
credits->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
||||
void Director::runDemo() {
|
||||
auto game = std::make_unique<Game>(Game::Mode::DEMO);
|
||||
game->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion del final del juego
|
||||
void Director::runEnding() {
|
||||
auto ending = std::make_unique<Ending>();
|
||||
ending->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion del final del juego
|
||||
void Director::runEnding2() {
|
||||
auto ending2 = std::make_unique<Ending2>();
|
||||
ending2->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion del final de la partida
|
||||
void Director::runGameOver() {
|
||||
auto game_over = std::make_unique<GameOver>();
|
||||
game_over->run();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void Director::runGame() {
|
||||
Audio::get()->stopMusic();
|
||||
auto game = std::make_unique<Game>(Game::Mode::GAME);
|
||||
game->run();
|
||||
}
|
||||
|
||||
auto Director::run() -> int {
|
||||
// Bucle principal
|
||||
while (SceneManager::current != SceneManager::Scene::QUIT) {
|
||||
const SceneManager::Scene ACTIVE = SceneManager::current;
|
||||
// Destrueix l'escena anterior (pot parar música, etc. al seu destructor)
|
||||
active_scene_.reset();
|
||||
|
||||
switch (SceneManager::current) {
|
||||
case SceneManager::Scene::LOGO:
|
||||
runLogo();
|
||||
active_scene_ = std::make_unique<Logo>();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::LOADING_SCREEN:
|
||||
runLoadingScreen();
|
||||
active_scene_ = std::make_unique<LoadingScreen>();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::TITLE:
|
||||
runTitle();
|
||||
active_scene_ = std::make_unique<Title>();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::CREDITS:
|
||||
runCredits();
|
||||
active_scene_ = std::make_unique<Credits>();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::DEMO:
|
||||
runDemo();
|
||||
active_scene_ = std::make_unique<Game>(Game::Mode::DEMO);
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::GAME:
|
||||
runGame();
|
||||
Audio::get()->stopMusic();
|
||||
active_scene_ = std::make_unique<Game>(Game::Mode::GAME);
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::GAME_OVER:
|
||||
runGameOver();
|
||||
active_scene_ = std::make_unique<GameOver>();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::ENDING:
|
||||
runEnding();
|
||||
active_scene_ = std::make_unique<Ending>();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::ENDING2:
|
||||
runEnding2();
|
||||
break;
|
||||
|
||||
case SceneManager::Scene::RESTART_CURRENT:
|
||||
// La escena salió por RESTART_CURRENT → relanzar la escena guardada
|
||||
SceneManager::current = SceneManager::scene_before_restart;
|
||||
active_scene_ = std::make_unique<Ending2>();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Si la escena que acaba de correr dejó RESTART_CURRENT pendiente,
|
||||
// restaurar la escena que estaba activa para relanzarla en la próxima iteración
|
||||
if (SceneManager::current == SceneManager::Scene::RESTART_CURRENT) {
|
||||
SceneManager::current = ACTIVE;
|
||||
}
|
||||
current_scene_ = SceneManager::current;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// SDL_AppIterate: executa un frame de l'escena activa
|
||||
auto Director::iterate() -> SDL_AppResult {
|
||||
if (SceneManager::current == SceneManager::Scene::QUIT) {
|
||||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
|
||||
// Si l'escena ha canviat (o s'ha demanat RESTART_CURRENT), canviar-la abans del frame
|
||||
if (SceneManager::current != current_scene_ || SceneManager::current == SceneManager::Scene::RESTART_CURRENT) {
|
||||
switchToActiveScene();
|
||||
}
|
||||
|
||||
if (active_scene_) {
|
||||
active_scene_->iterate();
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
// SDL_AppEvent: despatxa un event a l'escena activa
|
||||
auto Director::handleEvent(const SDL_Event& event) -> SDL_AppResult {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// A la versió web no tenim event de quit del navegador
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
SceneManager::current = SceneManager::Scene::QUIT;
|
||||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (active_scene_) {
|
||||
active_scene_->handleEvent(event);
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
@@ -2,29 +2,31 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <memory> // Para unique_ptr
|
||||
#include <string> // Para string
|
||||
|
||||
#include "game/scene_manager.hpp" // Para SceneManager::Scene
|
||||
#include "game/scenes/scene.hpp" // Para Scene base
|
||||
|
||||
class Director {
|
||||
public:
|
||||
Director(); // Constructor
|
||||
Director(); // Constructor: inicialitza sistemes i crea l'escena inicial
|
||||
~Director(); // Destructor
|
||||
static auto run() -> int; // Bucle principal
|
||||
|
||||
// SDL3 Callback API: un frame i un event
|
||||
auto iterate() -> SDL_AppResult;
|
||||
auto handleEvent(const SDL_Event& event) -> SDL_AppResult;
|
||||
|
||||
private:
|
||||
// --- Variables ---
|
||||
std::string executable_path_; // Path del ejecutable
|
||||
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||
|
||||
std::unique_ptr<Scene> active_scene_; // Escena activa
|
||||
SceneManager::Scene current_scene_{SceneManager::Scene::LOGO}; // Tipus d'escena activa
|
||||
|
||||
// --- Funciones ---
|
||||
void createSystemFolder(const std::string& folder); // Crea la carpeta del sistema donde guardar datos
|
||||
void setFileList(); // Carga la configuración de assets desde assets.yaml
|
||||
static void runLogo(); // Ejecuta la seccion de juego con el logo
|
||||
static void runLoadingScreen(); // Ejecuta la seccion de juego de la pantalla de carga
|
||||
static void runTitle(); // Ejecuta la seccion de juego con el titulo y los menus
|
||||
static void runCredits(); // Ejecuta la seccion de los creditos del juego
|
||||
static void runDemo(); // Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
||||
static void runEnding(); // Ejecuta la seccion del final del juego
|
||||
static void runEnding2(); // Ejecuta la seccion del final del juego
|
||||
static void runGameOver(); // Ejecuta la seccion del final de la partida
|
||||
static void runGame(); // Ejecuta la seccion de juego donde se juega
|
||||
void switchToActiveScene(); // Construeix l'escena segons SceneManager::current
|
||||
};
|
||||
@@ -2,18 +2,12 @@
|
||||
|
||||
#include "core/input/mouse.hpp"
|
||||
#include "game/options.hpp" // Para Options, options, OptionsGame, OptionsAudio
|
||||
#include "game/scene_manager.hpp" // Para SceneManager
|
||||
#include "game/ui/console.hpp" // Para Console
|
||||
|
||||
namespace GlobalEvents {
|
||||
// Comprueba los eventos que se pueden producir en cualquier sección del juego
|
||||
// Comprueba los eventos que se pueden producir en cualquier sección del juego.
|
||||
// Nota: SDL_EVENT_QUIT el gestiona Director::handleEvent() directament.
|
||||
void handle(const SDL_Event& event) {
|
||||
// Evento de salida de la aplicación
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
SceneManager::current = SceneManager::Scene::QUIT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type == SDL_EVENT_RENDER_DEVICE_RESET || event.type == SDL_EVENT_RENDER_TARGETS_RESET) {
|
||||
// reLoadTextures();
|
||||
}
|
||||
|
||||
@@ -37,13 +37,10 @@ Credits::Credits()
|
||||
Audio::get()->playMusic("title.ogg"); // Inicia la musica
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void Credits::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Credits::handleInput() {
|
||||
@@ -124,7 +121,6 @@ void Credits::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
total_time_ += DELTA_TIME; // Actualiza el tiempo total
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza la máquina de estados
|
||||
@@ -238,10 +234,8 @@ void Credits::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
void Credits::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::CREDITS) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void Credits::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,22 @@
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
class AnimatedSprite; // lines 11-11
|
||||
class Surface;
|
||||
class PixelReveal;
|
||||
class DeltaTimer;
|
||||
|
||||
class Credits {
|
||||
class Credits : public Scene {
|
||||
public:
|
||||
// --- Constructor y Destructor ---
|
||||
Credits();
|
||||
~Credits(); // NOLINT(modernize-use-equals-default, performance-trivially-destructible) -- defined in .cpp for unique_ptr with forward declarations
|
||||
~Credits() override; // NOLINT(modernize-use-equals-default, performance-trivially-destructible) -- defined in .cpp for unique_ptr with forward declarations
|
||||
|
||||
// --- Bucle principal ---
|
||||
void run();
|
||||
// --- Bucle principal (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Tipos anidados ---
|
||||
@@ -55,7 +58,6 @@ class Credits {
|
||||
// --- Métodos privados ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza la máquina de estados
|
||||
void transitionToState(State new_state); // Transición entre estados
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
#include "utils/utils.hpp" // Para PaletteColor
|
||||
|
||||
// Destructor
|
||||
Ending::~Ending() = default;
|
||||
Ending::~Ending() {
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Ending::Ending()
|
||||
@@ -32,6 +34,7 @@ Ending::Ending()
|
||||
iniScenes(); // Inicializa las escenas
|
||||
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
|
||||
Audio::get()->playMusic("ending1.ogg");
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
@@ -39,7 +42,6 @@ void Ending::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
total_time_ += DELTA_TIME; // Actualiza el tiempo total
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza la máquina de estados
|
||||
@@ -86,13 +88,10 @@ void Ending::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Ending::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void Ending::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Ending::handleInput() {
|
||||
@@ -355,18 +354,12 @@ void Ending::iniScenes() { // NOLINT(readability-convert-member-functions-to-st
|
||||
scenes_.push_back(sc);
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Ending::run() {
|
||||
Audio::get()->playMusic("ending1.ogg");
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::ENDING) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void Ending::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
|
||||
// Actualiza las cortinillas de los elementos
|
||||
void Ending::updateSpriteCovers() {
|
||||
// Skip durante WARMING_UP
|
||||
|
||||
@@ -5,19 +5,22 @@
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
class Sprite; // lines 8-8
|
||||
class Surface; // lines 9-9
|
||||
class PixelReveal;
|
||||
class DeltaTimer;
|
||||
|
||||
class Ending {
|
||||
class Ending : public Scene {
|
||||
public:
|
||||
// --- Constructor y Destructor ---
|
||||
Ending();
|
||||
~Ending(); // NOLINT(modernize-use-equals-default, performance-trivially-destructible) -- defined in .cpp for unique_ptr with forward declarations
|
||||
~Ending() override; // NOLINT(modernize-use-equals-default, performance-trivially-destructible) -- defined in .cpp for unique_ptr with forward declarations
|
||||
|
||||
// --- Bucle principal ---
|
||||
void run();
|
||||
// --- Bucle principal (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Enumeraciones ---
|
||||
@@ -77,7 +80,6 @@ class Ending {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void iniTexts(); // Inicializa los textos
|
||||
void iniPics(); // Inicializa las imágenes
|
||||
|
||||
@@ -41,13 +41,19 @@ Ending2::Ending2()
|
||||
placeSprites(); // Coloca los sprites en su sito
|
||||
createSpriteTexts(); // Crea los sprites con las texturas con los textos
|
||||
createTexts(); // Crea los sprites con las texturas con los textos del final
|
||||
|
||||
Audio::get()->playMusic("ending2.ogg");
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Ending2::~Ending2() {
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
void Ending2::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado
|
||||
@@ -95,13 +101,10 @@ void Ending2::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Ending2::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void Ending2::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Ending2::handleInput() {
|
||||
@@ -109,18 +112,12 @@ void Ending2::handleInput() {
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Ending2::run() {
|
||||
Audio::get()->playMusic("ending2.ogg");
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::ENDING2) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void Ending2::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
|
||||
// Actualiza el estado
|
||||
void Ending2::updateState(float delta_time) {
|
||||
state_time_ += delta_time;
|
||||
|
||||
@@ -7,19 +7,21 @@
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/rendering/sprite/dissolve_sprite.hpp" // Para SurfaceDissolveSprite
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
#include "utils/defines.hpp" // Para GameCanvas::WIDTH, GameCanvas::FIRST_QUAR...
|
||||
|
||||
class MovingSprite;
|
||||
class DeltaTimer;
|
||||
|
||||
class Ending2 {
|
||||
class Ending2 : public Scene {
|
||||
public:
|
||||
// --- Constructor y Destructor ---
|
||||
Ending2();
|
||||
~Ending2() = default;
|
||||
~Ending2() override;
|
||||
|
||||
// --- Bucle principal ---
|
||||
void run();
|
||||
// --- Bucle principal (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Enumeraciones ---
|
||||
@@ -58,7 +60,6 @@ class Ending2 {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado
|
||||
void transitionToState(EndingState new_state); // Transición entre estados
|
||||
|
||||
@@ -163,9 +163,19 @@ Game::Game(Mode mode)
|
||||
|
||||
SceneManager::current = (mode_ == Mode::GAME) ? SceneManager::Scene::GAME : SceneManager::Scene::DEMO;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
|
||||
// Arranca la música del juego (abans a run())
|
||||
keepMusicPlaying();
|
||||
if (!scoreboard_data_->music && mode_ == Mode::GAME) {
|
||||
Audio::get()->pauseMusic();
|
||||
}
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
if (mode_ == Mode::GAME) {
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
|
||||
ItemTracker::destroy();
|
||||
|
||||
GameControl::change_player_skin = nullptr;
|
||||
@@ -188,10 +198,8 @@ Game::~Game() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Comprueba los eventos de la cola
|
||||
void Game::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void Game::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
#ifdef _DEBUG
|
||||
// En modo editor: click del ratón cierra la consola
|
||||
@@ -220,7 +228,6 @@ void Game::handleEvents() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el teclado
|
||||
void Game::handleInput() {
|
||||
@@ -262,28 +269,16 @@ void Game::handleInput() {
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
void Game::run() {
|
||||
keepMusicPlaying();
|
||||
if (!scoreboard_data_->music && mode_ == Mode::GAME) {
|
||||
Audio::get()->pauseMusic();
|
||||
}
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::GAME || SceneManager::current == SceneManager::Scene::DEMO) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void Game::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
if (mode_ == Mode::GAME) {
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void Game::update() {
|
||||
const float DELTA_TIME = delta_timer_.tick();
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/entities/player.hpp" // Para PlayerSpawn
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
class Room; // lines 12-12
|
||||
class RoomTracker; // lines 13-13
|
||||
@@ -15,7 +16,7 @@ class Scoreboard; // lines 14-14
|
||||
class Stats; // lines 15-15
|
||||
class Surface;
|
||||
|
||||
class Game {
|
||||
class Game : public Scene {
|
||||
public:
|
||||
// --- Estructuras ---
|
||||
enum class Mode {
|
||||
@@ -33,10 +34,11 @@ class Game {
|
||||
|
||||
// --- Constructor y Destructor ---
|
||||
explicit Game(Mode mode);
|
||||
~Game();
|
||||
~Game() override;
|
||||
|
||||
// --- Bucle para el juego ---
|
||||
void run();
|
||||
// --- Bucle para el juego (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Constantes de tiempo ---
|
||||
@@ -57,7 +59,6 @@ class Game {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void render(); // Pinta los objetos en pantalla
|
||||
void handleEvents(); // Comprueba los eventos de la cola
|
||||
void renderRoomName(); // Escribe el nombre de la pantalla
|
||||
void transitionToState(State new_state); // Cambia al estado especificado y resetea los timers
|
||||
void updatePlaying(float delta_time); // Actualiza el juego en estado PLAYING
|
||||
|
||||
@@ -49,7 +49,6 @@ void GameOver::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
elapsed_time_ += DELTA_TIME;
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(); // Actualiza el estado de la escena
|
||||
@@ -91,13 +90,10 @@ void GameOver::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void GameOver::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void GameOver::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void GameOver::handleInput() {
|
||||
@@ -105,13 +101,11 @@ void GameOver::handleInput() {
|
||||
GlobalInputs::handle();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void GameOver::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::GAME_OVER) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void GameOver::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el color usado para renderizar los textos e imagenes
|
||||
void GameOver::updateColor() {
|
||||
|
||||
@@ -4,17 +4,20 @@
|
||||
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
class AnimatedSprite; // lines 7-7
|
||||
class DeltaTimer; // Forward declaration
|
||||
|
||||
class GameOver {
|
||||
class GameOver : public Scene {
|
||||
public:
|
||||
// Constructor y Destructor
|
||||
GameOver();
|
||||
~GameOver() = default;
|
||||
~GameOver() override = default;
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
// Bucle principal (SDL3 Callback API)
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Enumeraciones ---
|
||||
@@ -47,7 +50,6 @@ class GameOver {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza el objeto
|
||||
void render(); // Dibuja el final en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(); // Actualiza el estado y transiciones
|
||||
void updateColor(); // Actualiza el color usado para renderizar
|
||||
|
||||
@@ -41,20 +41,24 @@ LoadingScreen::LoadingScreen()
|
||||
// Cambia el color del borde
|
||||
Screen::get()->setBorderColor(stringToColor("white"));
|
||||
transitionToState(State::SILENT1);
|
||||
|
||||
// Ajusta el volumen i neteja la pantalla (abans a run())
|
||||
Audio::get()->setMusicVolume(50);
|
||||
Screen::get()->start();
|
||||
Screen::get()->clearRenderer();
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LoadingScreen::~LoadingScreen() {
|
||||
Audio::get()->stopMusic();
|
||||
Audio::get()->setMusicVolume(100);
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void LoadingScreen::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void LoadingScreen::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void LoadingScreen::handleInput() {
|
||||
@@ -347,7 +351,6 @@ void LoadingScreen::renderColoredBorder(PaletteColor color) {
|
||||
void LoadingScreen::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
@@ -400,24 +403,12 @@ void LoadingScreen::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
void LoadingScreen::run() {
|
||||
// Ajusta el volumen
|
||||
Audio::get()->setMusicVolume(50);
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->start();
|
||||
Screen::get()->clearRenderer();
|
||||
Screen::get()->render();
|
||||
|
||||
while (SceneManager::current == SceneManager::Scene::LOADING_SCREEN) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void LoadingScreen::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
|
||||
Audio::get()->setMusicVolume(100);
|
||||
}
|
||||
|
||||
// Pinta el borde
|
||||
void LoadingScreen::renderBorder() {
|
||||
if (Options::video.border.enabled) {
|
||||
|
||||
@@ -5,19 +5,21 @@
|
||||
#include <array> // Para std::array
|
||||
#include <memory> // Para shared_ptr
|
||||
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
#include "utils/utils.hpp" // Para PaletteColor
|
||||
class Sprite; // Forward declaration
|
||||
class Surface; // Forward declaration
|
||||
|
||||
class LoadingScreen {
|
||||
class LoadingScreen : public Scene {
|
||||
public:
|
||||
// --- Constructor y Destructor ---
|
||||
LoadingScreen();
|
||||
~LoadingScreen();
|
||||
~LoadingScreen() override;
|
||||
|
||||
// --- Bucle principal ---
|
||||
void run();
|
||||
// --- Bucle principal (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Enumeraciones ---
|
||||
@@ -81,7 +83,6 @@ class LoadingScreen {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado actual
|
||||
void transitionToState(State new_state); // Transiciona a un nuevo estado
|
||||
|
||||
@@ -54,13 +54,10 @@ Logo::Logo()
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Logo::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void Logo::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Logo::handleInput() {
|
||||
@@ -201,7 +198,6 @@ void Logo::updateState(float delta_time) {
|
||||
void Logo::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
@@ -228,13 +224,11 @@ void Logo::render() { // NOLINT(readability-convert-member-functions-to-static)
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
void Logo::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::LOGO) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void Logo::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Termina la sección
|
||||
void Logo::endSection() {
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
class Sprite; // Forward declaration
|
||||
class Surface; // Forward declaration
|
||||
|
||||
class Logo {
|
||||
class Logo : public Scene {
|
||||
public:
|
||||
// --- Tipos ---
|
||||
using EasingFunction = std::function<float(float)>; // Función de easing (permite lambdas)
|
||||
@@ -28,10 +29,11 @@ class Logo {
|
||||
|
||||
// --- Constructor y Destructor ---
|
||||
Logo();
|
||||
~Logo() = default;
|
||||
~Logo() override = default;
|
||||
|
||||
// --- Bucle principal ---
|
||||
void run();
|
||||
// --- Bucle principal (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Constantes de tiempo (en segundos) ---
|
||||
@@ -48,7 +50,6 @@ class Logo {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
static void handleEvents(); // Comprueba el manejador de eventos
|
||||
static void handleInput(); // Comprueba las entradas
|
||||
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
|
||||
void updateTextureColors(); // Gestiona el color de las texturas
|
||||
|
||||
13
source/game/scenes/scene.hpp
Normal file
13
source/game/scenes/scene.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
// Interfície base per a totes les escenes del joc.
|
||||
// Cada escena concreta implementa iterate() (un frame) i handleEvent() (un event).
|
||||
// Director crida aquests mètodes des de SDL_AppIterate / SDL_AppEvent.
|
||||
class Scene {
|
||||
public:
|
||||
virtual ~Scene() = default;
|
||||
virtual void iterate() = 0;
|
||||
virtual void handleEvent(const SDL_Event& event) = 0;
|
||||
};
|
||||
@@ -81,17 +81,15 @@ void Title::initMarquee() {
|
||||
last_active_letter_ = 0;
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Title::handleEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
// Despatx d'un event (SDL3 Callback API)
|
||||
void Title::handleEvent(const SDL_Event& event) {
|
||||
GlobalEvents::handle(event);
|
||||
|
||||
// Manejo especial para captura de botones de gamepad
|
||||
if (is_remapping_joystick_ && !remap_completed_ &&
|
||||
(event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN || event.type == SDL_EVENT_GAMEPAD_AXIS_MOTION)) {
|
||||
handleJoystickRemap(event);
|
||||
continue; // No procesar más este evento
|
||||
return; // No procesar más este evento
|
||||
}
|
||||
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && !Console::get()->isActive()) {
|
||||
@@ -105,7 +103,6 @@ void Title::handleEvents() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja las teclas del menu principal
|
||||
void Title::handleMainMenuKeyPress(SDL_Keycode key) {
|
||||
@@ -242,7 +239,6 @@ void Title::renderMarquee() const {
|
||||
void Title::update() {
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
handleEvents(); // Comprueba los eventos
|
||||
handleInput(DELTA_TIME); // Comprueba las entradas
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado actual
|
||||
@@ -434,13 +430,11 @@ void Title::render() {
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
void Title::run() {
|
||||
while (SceneManager::current == SceneManager::Scene::TITLE) {
|
||||
// Un frame de l'escena (SDL3 Callback API)
|
||||
void Title::iterate() {
|
||||
update();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Crea y rellena la textura para mostrar los logros
|
||||
void Title::createCheevosTexture() { // NOLINT(readability-convert-member-functions-to-static)
|
||||
|
||||
@@ -8,19 +8,21 @@
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/scene_manager.hpp" // Para SceneManager::Scene
|
||||
#include "game/scenes/scene.hpp" // Para Scene
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
class Sprite; // Forward declaration
|
||||
class Surface; // Forward declaration
|
||||
class Text; // Forward declaration
|
||||
|
||||
class Title {
|
||||
class Title : public Scene {
|
||||
public:
|
||||
// --- Constructor y Destructor ---
|
||||
Title();
|
||||
~Title();
|
||||
~Title() override;
|
||||
|
||||
// --- Bucle principal ---
|
||||
void run();
|
||||
// --- Bucle principal (SDL3 Callback API) ---
|
||||
void iterate() override;
|
||||
void handleEvent(const SDL_Event& event) override;
|
||||
|
||||
private:
|
||||
// --- Estructuras y enumeraciones ---
|
||||
@@ -61,7 +63,6 @@ class Title {
|
||||
// --- Métodos ---
|
||||
void update(); // Actualiza las variables
|
||||
void render(); // Dibuja en pantalla
|
||||
void handleEvents(); // Comprueba el manejador de eventos
|
||||
void handleMainMenuKeyPress(SDL_Keycode key); // Maneja las teclas del menu principal
|
||||
void handleInput(float delta_time); // Comprueba las entradas
|
||||
void updateState(float delta_time); // Actualiza el estado actual
|
||||
|
||||
@@ -5,14 +5,24 @@ Empezado en Castalla el 01/07/2022.
|
||||
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#define SDL_MAIN_USE_CALLBACKS 1
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
#include "core/system/director.hpp"
|
||||
|
||||
auto main() -> int {
|
||||
// Crea el objeto Director
|
||||
auto director = std::make_unique<Director>();
|
||||
|
||||
// Bucle principal
|
||||
return Director::run();
|
||||
SDL_AppResult SDL_AppInit(void** appstate, int /*argc*/, char* /*argv*/[]) {
|
||||
*appstate = new Director();
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppIterate(void* appstate) {
|
||||
return static_cast<Director*>(appstate)->iterate();
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
||||
return static_cast<Director*>(appstate)->handleEvent(*event);
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void* appstate, SDL_AppResult /*result*/) {
|
||||
delete static_cast<Director*>(appstate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user