From 1a2298963d9e0c0f70a07021250fb6d7e7f58021 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 4 Apr 2026 10:42:31 +0200 Subject: [PATCH] afegit mode autoplay en debug --- source/core/system/director.cpp | 12 +++++ source/core/system/director.hpp | 2 + source/game/scenes/game.cpp | 83 ++++++++++++++++++++++++++++++++- source/game/scenes/game.hpp | 5 ++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp index d70c8de..072b1d4 100644 --- a/source/core/system/director.cpp +++ b/source/core/system/director.cpp @@ -230,6 +230,8 @@ void Director::loadDebugConfig() { out << "initial_stage: 0\n"; out << "show_render_info: true\n"; out << "resource_loading: preload\n"; + out << "autoplay: false\n"; + out << "invincibility: false\n"; out.close(); } // Usar defaults de DebugConfig @@ -263,6 +265,16 @@ void Director::loadDebugConfig() { debug_config.resource_loading = yaml["resource_loading"].get_value(); } catch (...) {} } + if (yaml.contains("autoplay")) { + try { + debug_config.autoplay = yaml["autoplay"].get_value(); + } catch (...) {} + } + if (yaml.contains("invincibility")) { + try { + debug_config.invincibility = yaml["invincibility"].get_value(); + } catch (...) {} + } } catch (...) { std::cout << "Error parsing debug.yaml, using defaults" << '\n'; } diff --git a/source/core/system/director.hpp b/source/core/system/director.hpp index 9d5cf75..dd72d74 100644 --- a/source/core/system/director.hpp +++ b/source/core/system/director.hpp @@ -38,6 +38,8 @@ class Director { int initial_stage = 0; bool show_render_info = true; std::string resource_loading; + bool autoplay = false; + bool invincibility = false; DebugConfig() : initial_section("game"), diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index f5f5739..908ffea 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -48,7 +48,8 @@ #ifdef _DEBUG #include // Para basic_ostream, basic_ostream::operator<<, operator<<, cout -#include "game/ui/notifier.hpp" // Para Notifier +#include "core/system/director.hpp" // Para Director::debug_config +#include "game/ui/notifier.hpp" // Para Notifier #endif // Constructor @@ -805,6 +806,12 @@ void Game::handlePlayerCollision(std::shared_ptr& player, std::shared_pt return; // Si no está jugando o tiene inmunidad, no hace nada } +#ifdef _DEBUG + if (Director::debug_config.invincibility) { + return; + } +#endif + // Si tiene cafes if (player->hasExtraHit()) { // Lo pierde @@ -1255,7 +1262,17 @@ void Game::checkInput() { // Comprueba las entradas si no está el menú de servicio activo if (!ServiceMenu::get()->isEnabled()) { checkPauseInput(); - demo_.enabled ? demoHandlePassInput() : handlePlayersInput(); + if (demo_.enabled) { + demoHandlePassInput(); + } else { +#ifdef _DEBUG + if (!autoplay_) { + handlePlayersInput(); + } +#else + handlePlayersInput(); +#endif + } } // Mueve los jugadores en el modo demo @@ -1263,6 +1280,12 @@ void Game::checkInput() { demoHandleInput(); } +#ifdef _DEBUG + if (autoplay_) { + autoplayHandleInput(); + } +#endif + // Verifica los inputs globales. GlobalInputs::check(); } @@ -1568,6 +1591,29 @@ void Game::initDemo(Player::Id player_id) { demo_.recording = false; #endif demo_.index = 0; + +#ifdef _DEBUG + autoplay_ = Director::debug_config.autoplay && !demo_.enabled; + if (autoplay_) { + auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size(); + for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) { + autoplay_data_.emplace_back(Resource::get()->getDemoData(num_demo)); + } + + std::vector demo_indices(NUM_DEMOS); + std::iota(demo_indices.begin(), demo_indices.end(), 0); + std::random_device rd; + std::default_random_engine rng(rd()); + std::shuffle(demo_indices.begin(), demo_indices.end(), rng); + + for (size_t i = 0; i < players_.size(); ++i) { + size_t demo_index = demo_indices[i % NUM_DEMOS]; + players_.at(i)->setDemoFile(demo_index); + } + autoplay_elapsed_s_ = 0.0F; + autoplay_index_ = 0; + } +#endif } // Inicializa el marcador @@ -1812,6 +1858,14 @@ void Game::updateGameStatePlaying(float delta_time) { if (auto_pop_balloons_) { stage_manager_->addPower(2); } + if (autoplay_) { + autoplay_elapsed_s_ += delta_time; + autoplay_index_ = static_cast(autoplay_elapsed_s_ * 60.0F); + if (autoplay_index_ >= TOTAL_DEMO_DATA) { + autoplay_elapsed_s_ = 0.0F; + autoplay_index_ = 0; + } + } #endif updatePlayers(delta_time); checkPlayersStatusPlaying(); @@ -2073,6 +2127,31 @@ void Game::bringPlayerToFront(Players& elements, const std::shared_ptr& } #ifdef _DEBUG +// Alimenta input de demo a los jugadores durante el autoplay +void Game::autoplayHandleInput() { + for (const auto& player : players_) { + if (player->isPlaying()) { + const auto& demo_data = autoplay_data_.at(player->getDemoFile()).at(autoplay_index_); + + if (demo_data.left == 1) { + player->setInput(Input::Action::LEFT); + } else if (demo_data.right == 1) { + player->setInput(Input::Action::RIGHT); + } else if (demo_data.no_input == 1) { + player->setInput(Input::Action::NONE); + } + + if (demo_data.fire == 1) { + handleFireInput(player, Bullet::Type::UP); + } else if (demo_data.fire_left == 1) { + handleFireInput(player, Bullet::Type::LEFT); + } else if (demo_data.fire_right == 1) { + handleFireInput(player, Bullet::Type::RIGHT); + } + } + } +} + // Comprueba los eventos en el modo DEBUG void Game::handleDebugEvents(const SDL_Event& event) { static int formation_id_ = 0; diff --git a/source/game/scenes/game.hpp b/source/game/scenes/game.hpp index 441f9d6..3130f76 100644 --- a/source/game/scenes/game.hpp +++ b/source/game/scenes/game.hpp @@ -198,6 +198,10 @@ class Game { #ifdef _DEBUG bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados + bool autoplay_ = false; // Si es true, los jugadores se mueven solos con datos de demo + float autoplay_elapsed_s_ = 0.0F; + int autoplay_index_ = 0; + std::vector autoplay_data_; #endif // --- Ciclo principal del juego --- @@ -349,5 +353,6 @@ class Game { // --- Depuración (solo en modo DEBUG) --- #ifdef _DEBUG void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos en el modo DEBUG + void autoplayHandleInput(); // Alimenta input de demo a los jugadores en autoplay #endif }; \ No newline at end of file