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

@@ -1,6 +1,7 @@
#include <Cubed/app.hpp>
#include <Cubed/camera.hpp>
#include <Cubed/config.hpp>
#include <Cubed/debug_collector.hpp>
#include <Cubed/gameplay/player.hpp>
#include <Cubed/gameplay/world.hpp>
#include <Cubed/texture_manager.hpp>
@@ -117,18 +118,7 @@ const Shader& Renderer::get_shader(const std::string& name) const {
void Renderer::init_text() {
const auto& shader = get_shader("text");
Text::set_loc(shader);
m_version_text
.position(0.0f, 100.0f)
.scale(0.8f)
.color(Color::WHITE)
.text("Version: v0.0.1-Debug");
m_fps_text
.position(0.0f, 50.0f)
.text("FPS: 0");
m_player_pos_text
.position(0.0f, 150.0f)
.scale(0.8f)
.text("x: 0.00 y: 0.00 z: 0.00");
DebugCollector::get().init_text();
}
void Renderer::render() {
@@ -211,16 +201,12 @@ void Renderer::render_text() {
m_proj_loc = shader.loc("projection");
glUniformMatrix4fv(m_proj_loc, 1, GL_FALSE, glm::value_ptr(m_ui_proj));
m_fps_text.text(std::string{"FPS: " + std::to_string(static_cast<int>(App::get_fps()))});
const auto& player = m_world.get_player("TestPlayer");
const auto& pos = player.get_player_pos();
std::string player_pos = std::format("x: {:.2f} y: {:.2f} z: {:.2f}", pos.x, pos.y, pos.z);
m_player_pos_text.text(player_pos);
m_fps_text.render();
m_player_pos_text.render();
m_version_text.render();
auto& texts = DebugCollector::get().all_texts();
for (auto& t : texts) {
t.second.render();
}
glEnable(GL_DEPTH_TEST);
}