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

@@ -36,24 +36,51 @@ void Debug::render() { // NOLINT(readability-make-member-function-const)
auto text = Resource::Cache::get()->getText("aseprite");
int y = y_;
int w = 0;
constexpr int DESP_Y = 7;
const int CHAR_SIZE = text->getCharacterSize();
// Watch window: valores persistentes (key: value)
for (const auto& [key, value] : watches_) {
const std::string LINE = key + ": " + value;
text->write(x_, y, LINE);
w = std::max(w, text->length(LINE));
y += DESP_Y;
if (y > 192 - CHAR_SIZE) {
y = y_;
x_ += w + 2;
w = 0;
}
}
// Slot one-shot: mensajes de un solo frame
for (const auto& s : slot_) {
text->write(x_, y, s);
w = (std::max(w, (int)s.length()));
y += text->getCharacterSize() + 1;
if (y > 192 - text->getCharacterSize()) {
w = std::max(w, text->length(s));
y += DESP_Y;
if (y > 192 - CHAR_SIZE) {
y = y_;
x_ += (w * text->getCharacterSize()) + 2;
x_ += w + 2;
w = 0;
}
}
y = 0;
for (const auto& l : log_) {
text->writeColored(x_ + 10, y, l, static_cast<Uint8>(PaletteColor::WHITE));
y += text->getCharacterSize() + 1;
y += CHAR_SIZE + 1;
}
}
// Establece/actualiza un valor persistente en el watch window
void Debug::set(const std::string& key, const std::string& value) {
watches_[key] = value;
}
// Elimina un valor del watch window
void Debug::unset(const std::string& key) {
watches_.erase(key);
}
// Establece la posición donde se colocará la información de debug
void Debug::setPos(SDL_FPoint p) {
x_ = p.x;

View File

@@ -4,6 +4,7 @@
#include <SDL3/SDL.h>
#include <map> // Para map
#include <string> // Para string
#include <vector> // Para vector
@@ -27,10 +28,13 @@ class Debug {
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; } // Obtiene si el debug está activo
void add(const std::string& text) { slot_.push_back(text); } // Añade texto al slot de debug
void clear() { slot_.clear(); } // Limpia el slot de debug
void addToLog(const std::string& text) { log_.push_back(text); } // Añade texto al log
void clearLog() { log_.clear(); } // Limpia el log
void add(const std::string& text) { slot_.push_back(text); } // Añade texto one-shot al slot (se limpia cada frame)
void clear() { slot_.clear(); } // Limpia el slot one-shot (no afecta a watches)
void addToLog(const std::string& text) { log_.push_back(text); } // Añade texto al log
void clearLog() { log_.clear(); } // Limpia el log
void set(const std::string& key, const std::string& value); // Establece/actualiza un valor persistente en el watch window
void unset(const std::string& key); // Elimina un valor del watch window
void clearWatches() { watches_.clear(); } // Limpia todos los watches
void setEnabled(bool value) { enabled_ = value; } // Establece si el debug está activo
void toggleEnabled() { enabled_ = !enabled_; } // Alterna el estado del debug
@@ -47,8 +51,9 @@ class Debug {
~Debug() = default; // Destructor
// Variables
std::vector<std::string> slot_; // Vector con los textos a escribir
std::vector<std::string> log_; // Vector con los textos a escribir
std::map<std::string, std::string> watches_; // Watch window: valores persistentes (key→value)
std::vector<std::string> slot_; // One-shot: textos que se limpian cada frame
std::vector<std::string> log_; // Log persistente
int x_ = 0; // Posicion donde escribir el texto de debug
int y_ = 0; // Posición donde escribir el texto de debug
bool enabled_ = false; // Indica si esta activo el modo debug