millorada una mica la classe Debug en quant a mostrar info

This commit is contained in:
2026-03-28 21:58:54 +01:00
parent a21f530dd4
commit 9282d661aa
6 changed files with 79 additions and 50 deletions

View File

@@ -84,21 +84,21 @@ void Player::move(float delta_time) {
}
syncSpriteAndCollider(); // Actualiza la posición del sprite y las colisiones
#ifdef _DEBUG
Debug::get()->add(std::string("X : " + std::to_string(static_cast<int>(x_))));
Debug::get()->add(std::string("Y : " + std::to_string(static_cast<int>(y_))));
Debug::get()->add(std::string("LGP: " + std::to_string(last_grounded_position_)));
Debug::get()->set("P.X", std::to_string(static_cast<int>(x_)));
Debug::get()->set("P.Y", std::to_string(static_cast<int>(y_)));
Debug::get()->set("P.LGP", std::to_string(last_grounded_position_));
switch (state_) {
case State::ON_GROUND:
Debug::get()->add(std::string("ON_GROUND"));
Debug::get()->set("P.STATE", "ON_GROUND");
break;
case State::ON_SLOPE:
Debug::get()->add(std::string("ON_SLOPE"));
Debug::get()->set("P.STATE", "ON_SLOPE");
break;
case State::JUMPING:
Debug::get()->add(std::string("JUMPING"));
Debug::get()->set("P.STATE", "JUMPING");
break;
case State::FALLING:
Debug::get()->add(std::string("FALLING"));
Debug::get()->set("P.STATE", "FALLING");
break;
}
#endif
@@ -235,6 +235,9 @@ void Player::moveOnGround(float delta_time) {
y_ = SLOPE_Y - HEIGHT;
transitionToState(State::ON_SLOPE);
}
#ifdef _DEBUG
Debug::get()->set("sl.detect_y", SLOPE_Y != Collision::NONE ? std::to_string(SLOPE_Y) : "-");
#endif
// Comprueba si está sobre una rampa
if (isOnSlope()) { transitionToState(State::ON_SLOPE); }
@@ -279,12 +282,21 @@ void Player::moveOnSlope(float delta_time) {
const int MAX_X = std::max(current_slope_->x1, current_slope_->x2);
const bool OUT_OF_BOUNDS = (X < MIN_X) || (X > MAX_X);
#ifdef _DEBUG
Debug::get()->set("sl.foot", std::to_string(X));
Debug::get()->set("sl.y_c", std::to_string(static_cast<int>(y_)));
Debug::get()->set("sl.oob", OUT_OF_BOUNDS ? "YES" : "ok");
#endif
if (OUT_OF_BOUNDS) {
// Determinar si estamos saliendo por arriba o por abajo de la rampa
const bool EXITING_DOWNWARD = (X > current_slope_->x2 && IS_LEFT_SLOPE) ||
(X < current_slope_->x1 && !IS_LEFT_SLOPE);
const bool EXITING_UPWARD = (X < current_slope_->x1 && IS_LEFT_SLOPE) ||
(X > current_slope_->x2 && !IS_LEFT_SLOPE);
#ifdef _DEBUG
Debug::get()->set("sl.oob", EXITING_DOWNWARD ? "DOWN" : "UP");
#endif
if (EXITING_DOWNWARD) {
// Salida por abajo: no hacer nada
@@ -576,18 +588,17 @@ void Player::updateCurrentSlope() {
}
}
// Debug output
/*
#ifdef _DEBUG
if (current_slope_ != nullptr) {
const char* TYPE = isLeftSlope() ? "Left \\" : "Right /";
std::cout << "[SLOPE] " << TYPE
<< " from (" << current_slope_->x1 << "," << current_slope_->y1 << ")"
<< " to (" << current_slope_->x2 << "," << current_slope_->y2 << ")\n";
Debug::get()->set("sl.type", isLeftSlope() ? "L\\" : "R/");
Debug::get()->set("sl.p1", std::to_string(current_slope_->x1) + "," + std::to_string(current_slope_->y1));
Debug::get()->set("sl.p2", std::to_string(current_slope_->x2) + "," + std::to_string(current_slope_->y2));
} else {
std::cout << "[SLOPE] nullptr\n";
Debug::get()->set("sl.type", "null");
Debug::get()->unset("sl.p1");
Debug::get()->unset("sl.p2");
}
*/
#endif
}
// Comprueba que el jugador no toque ningun tile de los que matan

View File

@@ -79,25 +79,25 @@ auto CollisionMap::getSlopeHeight(SDL_FPoint p, Tile slope) -> int {
// Calcula la base del tile
int base = ((p.y / TILE_SIZE) * TILE_SIZE) + TILE_SIZE;
#ifdef _DEBUG
Debug::get()->add("BASE = " + std::to_string(base));
Debug::get()->set("slope.BASE", std::to_string(base));
#endif
// Calcula cuanto se ha entrado en el tile horizontalmente
const int POS = (static_cast<int>(p.x) % TILE_SIZE); // Esto da un valor entre 0 y 7
#ifdef _DEBUG
Debug::get()->add("POS = " + std::to_string(POS));
Debug::get()->set("slope.POS", std::to_string(POS));
#endif
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
if (slope == Tile::SLOPE_R) {
base -= POS + 1;
#ifdef _DEBUG
Debug::get()->add("BASE_R = " + std::to_string(base));
Debug::get()->set("slope.result", "BASE_R=" + std::to_string(base));
#endif
} else {
base -= (TILE_SIZE - POS);
#ifdef _DEBUG
Debug::get()->add("BASE_L = " + std::to_string(base));
Debug::get()->set("slope.result", "BASE_L=" + std::to_string(base));
#endif
}

View File

@@ -90,7 +90,7 @@ Game::Game(Mode mode)
auto ss = Debug::get()->getSpawnSettings();
ss.spawn_x = tile_x * Tile::SIZE;
ss.spawn_y = tile_y * Tile::SIZE;
ss.flip = player_->getSpawnParams().flip;
ss.flip = player_->getSpawnParams().flip;
Debug::get()->setSpawnSettings(ss);
Debug::get()->saveToFile();
return "Pos:" + std::to_string(tile_x) + "," + std::to_string(tile_y);
@@ -109,7 +109,7 @@ Game::~Game() {
GameControl::refresh_player_color = nullptr;
GameControl::toggle_debug_mode = nullptr;
GameControl::set_initial_room = nullptr;
GameControl::set_initial_pos = nullptr;
GameControl::set_initial_pos = nullptr;
#endif
}
@@ -207,10 +207,6 @@ void Game::update() {
Audio::update(); // Actualiza el objeto Audio
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
#ifdef _DEBUG
updateDebugInfo();
#endif
}
// Actualiza el juego en estado PLAYING
@@ -432,18 +428,9 @@ static void toggleCheat(Options::Cheat::State& cheat, const std::string& label)
Notifier::get()->show({label + (ENABLED ? Locale::get()->get("game.enabled") : Locale::get()->get("game.disabled"))}, Notifier::Style::DEFAULT, -1, true); // NOLINT(readability-static-accessed-through-instance)
}
// Pasa la información de debug
void Game::updateDebugInfo() {
// Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
// Debug::get()->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4));
// Debug::get()->add("STATE = " + std::to_string(static_cast<int>(player_->state_)));
}
// Pone la información de debug en pantalla
void Game::renderDebugInfo() {
if (!Debug::get()->isEnabled()) {
return;
}
if (!Debug::get()->isEnabled()) { return; }
auto surface = Screen::get()->getRendererSurface();
@@ -589,8 +576,8 @@ void Game::handleDebugMouseDrag(float delta_time) {
}
debug_dragging_player_ = true;
Debug::get()->add(std::string("X : " + std::to_string(static_cast<int>(player_rect.x))));
Debug::get()->add(std::string("Y : " + std::to_string(static_cast<int>(player_rect.y))));
Debug::get()->set("drag.x", std::to_string(static_cast<int>(player_rect.x)));
Debug::get()->set("drag.y", std::to_string(static_cast<int>(player_rect.y)));
} else if (debug_dragging_player_) {
// Botón soltado después de arrastrar: finalizar teleport
player_->finalizeDebugTeleport();

View File

@@ -92,7 +92,6 @@ class Game {
void demoInit(); // DEMO MODE: Inicializa las variables para el modo demo
void demoCheckRoomChange(float delta_time); // DEMO MODE: Comprueba si se ha de cambiar de habitación
#ifdef _DEBUG
void updateDebugInfo(); // Pone la información de debug en pantalla
static void renderDebugInfo(); // Pone la información de debug en pantalla
void handleDebugEvents(const SDL_Event& event); // Comprueba los eventos
void handleDebugMouseDrag(float delta_time); // Maneja el arrastre del jugador con el ratón (debug)