fix: debug panel

This commit is contained in:
alexei-zebra 2025-12-23 22:10:54 +03:00
parent 36efc9aa49
commit 21815a4fab

View file

@ -1,28 +1,34 @@
#include "constants.hpp"
#include <bitset>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include "audio/audio.hpp"
#include "constants.hpp"
#include "content/Content.hpp"
#include "delegates.hpp"
#include "engine/Engine.hpp"
#include "settings.hpp"
#include "hud.hpp"
#include "content/Content.hpp"
#include "graphics/core/Mesh.hpp"
#include "graphics/ui/elements/CheckBox.hpp"
#include "graphics/ui/elements/TextBox.hpp"
#include "graphics/ui/elements/TrackBar.hpp"
#include "graphics/ui/elements/InputBindBox.hpp"
#include "graphics/ui/GUI.hpp"
#include "graphics/render/WorldRenderer.hpp"
#include "graphics/render/ParticlesRenderer.hpp"
#include "graphics/render/ChunksRenderer.hpp"
#include "graphics/render/DebugLinesRenderer.hpp"
#include "graphics/render/ParticlesRenderer.hpp"
#include "graphics/render/WorldRenderer.hpp"
#include "graphics/ui/GUI.hpp"
#include "graphics/ui/elements/CheckBox.hpp"
#include "graphics/ui/elements/InputBindBox.hpp"
#include "graphics/ui/elements/TextBox.hpp"
#include "graphics/ui/elements/TrackBar.hpp"
#include "hud.hpp"
#include "logic/scripting/scripting.hpp"
#include "network/Network.hpp"
#include "objects/Entities.hpp"
#include "objects/Entity.hpp"
#include "objects/EntityDef.hpp"
#include "objects/Player.hpp"
#include "objects/Players.hpp"
#include "objects/Entities.hpp"
#include "objects/EntityDef.hpp"
#include "objects/Entity.hpp"
#include "physics/Hitbox.hpp"
#include "settings.hpp"
#include "util/stringutil.hpp"
#include "voxels/Block.hpp"
#include "voxels/Chunk.hpp"
@ -31,12 +37,6 @@
#include "world/Level.hpp"
#include "world/World.hpp"
#include <string>
#include <memory>
#include <sstream>
#include <bitset>
#include <utility>
using namespace gui;
static std::shared_ptr<Label> create_label(GUI& gui, wstringsupplier supplier) {
@ -55,10 +55,7 @@ static bool should_keep_previous(GUI& gui) {
// TODO: move to xml finally
// TODO: move to xml finally
std::shared_ptr<UINode> create_debug_panel(
Engine& engine,
Level& level,
Player& player,
bool allowDebugCheats
Engine& engine, Level& level, Player& player, bool allowDebugCheats
) {
auto network = engine.getNetwork();
auto& gui = engine.getGUI();
@ -82,7 +79,7 @@ std::shared_ptr<UINode> create_debug_panel(
static int drawCallsMaxOld = drawCallsMax;
static float drawCallsAvgLong = drawCalls;
inline const float AVG_ALPHA = 0.01;
const float AVG_ALPHA = 0.01;
static size_t lastTotalDownload = 0;
static size_t lastTotalUpload = 0;
@ -96,7 +93,8 @@ std::shared_ptr<UINode> create_debug_panel(
drawCallsMin = std::min(drawCalls, drawCallsMin);
drawCallsMax = std::max(drawCalls, drawCallsMax);
drawCallsAvgLong = drawCallsAvgLong * (1 - AVG_ALPHA) + drawCalls * AVG_ALPHA;
drawCallsAvgLong =
drawCallsAvgLong * (1 - AVG_ALPHA) + drawCalls * AVG_ALPHA;
});
panel->listenInterval(2.0f, []() {
@ -116,9 +114,10 @@ std::shared_ptr<UINode> create_debug_panel(
size_t totalDownload = network->getTotalDownload();
size_t totalUpload = network->getTotalUpload();
netSpeedString =
L"download: " + std::to_wstring(totalDownload - lastTotalDownload) +
L" B/s upload: " + std::to_wstring(totalUpload - lastTotalUpload) +
L" B/s";
L"download: " +
std::to_wstring(totalDownload - lastTotalDownload) +
L" B/s upload: " +
std::to_wstring(totalUpload - lastTotalUpload) + L" B/s";
lastTotalDownload = totalDownload;
lastTotalUpload = totalUpload;
});
@ -126,7 +125,8 @@ std::shared_ptr<UINode> create_debug_panel(
panel->add(create_label(gui, []() {
return L"fps: " + std::to_wstring(int(fpsAvgLong)) + L" / " +
std::to_wstring(std::min(fpsMinOld, fpsMin)) + L" / " + std::to_wstring(std::max(fpsMaxOld, fpsMax));
std::to_wstring(std::min(fpsMinOld, fpsMin)) + L" / " +
std::to_wstring(std::max(fpsMaxOld, fpsMax));
}));
panel->add(create_label(gui, []() {
return L"meshes: " + std::to_wstring(MeshStats::meshesCount);
@ -134,8 +134,10 @@ std::shared_ptr<UINode> create_debug_panel(
panel->add(create_label(gui, []() {
drawCalls = MeshStats::drawCalls;
MeshStats::drawCalls = 0;
return L"draw-calls: " + std::to_wstring(int(drawCallsAvgLong)) + L" / " +
std::to_wstring(std::min(drawCallsMinOld, drawCallsMin)) + L" / " +
return L"draw-calls: " + std::to_wstring(int(drawCallsAvgLong)) +
L" / " +
std::to_wstring(std::min(drawCallsMinOld, drawCallsMin)) +
L" / " +
std::to_wstring(std::max(drawCallsMaxOld, drawCallsMax));
}));
panel->add(create_label(gui, []() {
@ -143,7 +145,8 @@ std::shared_ptr<UINode> create_debug_panel(
L" streams: " + std::to_wstring(audio::count_streams());
}));
panel->add(create_label(gui, []() {
return L"lua-stack: " + std::to_wstring(scripting::get_values_on_stack());
return L"lua-stack: " +
std::to_wstring(scripting::get_values_on_stack());
}));
if (network) {
panel->add(create_label(gui, []() { return netSpeedString; }));
@ -164,12 +167,12 @@ std::shared_ptr<UINode> create_debug_panel(
L" visible: " + std::to_wstring(ChunksRenderer::visibleChunks);
}));
panel->add(create_label(gui, [&]() {
return L"entities: "+std::to_wstring(level.entities->size())+L" next: "+
std::to_wstring(level.entities->peekNextID());
return L"entities: " + std::to_wstring(level.entities->size()) +
L" next: " + std::to_wstring(level.entities->peekNextID());
}));
panel->add(create_label(gui, [&]() {
return L"players: "+std::to_wstring(level.players->size())+L" local: "+
std::to_wstring(player.getId());
return L"players: " + std::to_wstring(level.players->size()) +
L" local: " + std::to_wstring(player.getId());
}));
panel->add(create_label(gui, [&]() -> std::wstring {
// TODO: move to xml finally
@ -183,14 +186,13 @@ std::shared_ptr<UINode> create_debug_panel(
}
std::wstringstream stream;
stream << "r:" << vox.state.rotation << " s:"
<< std::bitset<3>(vox.state.segment) << " u:"
<< std::bitset<8>(vox.state.userbits);
stream << "r:" << vox.state.rotation
<< " s:" << std::bitset<3>(vox.state.segment)
<< " u:" << std::bitset<8>(vox.state.userbits);
if (vox.id == BLOCK_VOID) {
return L"block: -";
} else {
return L"block: "+std::to_wstring(vox.id)+
L" "+stream.str();
return L"block: " + std::to_wstring(vox.id) + L" " + stream.str();
}
}));
panel->add(create_label(gui, [&]() -> std::wstring {
@ -208,9 +210,9 @@ std::shared_ptr<UINode> create_debug_panel(
if (vox.id == BLOCK_VOID) {
return L"x: - y: - z: -";
}
return L"x: " + std::to_wstring(selection.actualPosition.x) +
L" y: " + std::to_wstring(selection.actualPosition.y) +
L" z: " + std::to_wstring(selection.actualPosition.z);
return L"x: " + std::to_wstring(selection.actualPosition.x) + L" y: " +
std::to_wstring(selection.actualPosition.y) + L" z: " +
std::to_wstring(selection.actualPosition.z);
}));
panel->add(create_label(gui, [&]() {
// TODO: move to xml finally
@ -286,8 +288,8 @@ std::shared_ptr<UINode> create_debug_panel(
int hour, minute, second;
timeutil::from_value(worldInfo.daytime, hour, minute, second);
std::wstring timeString =
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
std::wstring timeString = util::lfill(std::to_wstring(hour), 2, L'0') +
L":" +
util::lfill(std::to_wstring(minute), 2, L'0');
return L"time: " + timeString;
}));
@ -331,9 +333,7 @@ std::shared_ptr<UINode> create_debug_panel(
auto checkbox = std::make_shared<FullCheckBox>(
gui, L"Show Paths", glm::vec2(400, 24)
);
checkbox->setSupplier([=]() {
return DebugLinesRenderer::showPaths;
});
checkbox->setSupplier([=]() { return DebugLinesRenderer::showPaths; });
checkbox->setConsumer([=](bool checked) {
DebugLinesRenderer::showPaths = checked;
});
@ -343,9 +343,7 @@ std::shared_ptr<UINode> create_debug_panel(
auto checkbox = std::make_shared<FullCheckBox>(
gui, L"Show Generator Minimap", glm::vec2(400, 24)
);
checkbox->setSupplier([=]() {
return Hud::showGeneratorMinimap;
});
checkbox->setSupplier([=]() { return Hud::showGeneratorMinimap; });
checkbox->setConsumer([=](bool checked) {
Hud::showGeneratorMinimap = checked;
});