feat: add DebugCollector

This commit is contained in:
2026-04-16 11:55:25 +08:00
parent 311c675852
commit 1d04fedb0f
10 changed files with 136 additions and 38 deletions

View File

@@ -0,0 +1,20 @@
#pragma once
#include <Cubed/ui/text.hpp>
#include <unordered_map>
class DebugCollector {
public:
static DebugCollector& get();
DebugCollector();
std::unordered_map<std::size_t, Text>& all_texts();
Text& text(std::string_view name);
void report(std::string_view name, std::string_view content);
void init_text();
private:
std::unordered_map<std::size_t, Text> m_texts;
};

View File

@@ -47,10 +47,6 @@ private:
std::vector<GLuint> m_vao;
std::vector<Vertex2D> m_ui;
Text m_version_text;
Text m_fps_text;
Text m_player_pos_text;
void init_text();
void render_outline();

View File

@@ -1,8 +1,8 @@
#pragma once
#include <string>
#include <string_view>
namespace HASH {
inline std::size_t str(const std::string& value) {
return std::hash<std::string>{}(value);
inline std::size_t str(std::string_view value) {
return std::hash<std::string_view>{}(value);
}
}

View File

@@ -12,25 +12,32 @@ class Shader;
class Text {
public:
Text();
Text(std::string_view str, glm::vec2 pos = glm::vec2{0.0f, 0.0f}, Color color = Color::BLACK);
explicit Text(std::string_view name);
Text(std::string_view name, std::string_view str, glm::vec2 pos = glm::vec2{0.0f, 0.0f}, Color color = Color::BLACK);
~Text();
Text(const Text&) = delete;
Text(Text&&) noexcept;
Text& operator=(const Text&) = delete;
Text& operator=(Text&&) noexcept = delete;
Text& color(Color color);
//Text& color(const glm::vec4& color, int pos);
Text& name(std::string_view name);
Text& position(float x, float y);
Text& scale(float s);
static void set_loc(const Shader& shader);
Text& text(std::string_view str);
std::size_t uuid() const;
static void set_loc(const Shader& shader);
void render();
bool operator==(const Text& other) const;
private:
float m_scale = 1.0f;
glm::vec2 m_pos{0.0f, 0.0f};
std::string m_name;
const std::string NAME;
const std::size_t UUID;
std::string m_text;
glm::vec4 m_color{1.0f, 1.0f, 1.0f, 1.0f};
glm::mat4 m_model_matrix;