debug window: populate with data
parent
f526e9b152
commit
9d2d0c8772
|
@ -12,6 +12,7 @@
|
|||
#include "chunk.hpp"
|
||||
#include "chunkgenerator.hpp"
|
||||
#include "chunkmesher.hpp"
|
||||
#include "debugwindow.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "renderer.hpp"
|
||||
|
||||
|
@ -117,6 +118,16 @@ namespace chunkmanager
|
|||
int chunkY=static_cast<int>(theCamera.getAtomicPosY() / CHUNK_SIZE);
|
||||
int chunkZ=static_cast<int>(theCamera.getAtomicPosZ() / CHUNK_SIZE);
|
||||
|
||||
debug::window::set_parameter("px", theCamera.getAtomicPosX());
|
||||
debug::window::set_parameter("py", theCamera.getAtomicPosY());
|
||||
debug::window::set_parameter("pz", theCamera.getAtomicPosZ());
|
||||
debug::window::set_parameter("cx", chunkX);
|
||||
debug::window::set_parameter("cy", chunkY);
|
||||
debug::window::set_parameter("cz", chunkZ);
|
||||
debug::window::set_parameter("lx", theCamera.getFront().x);
|
||||
debug::window::set_parameter("ly", theCamera.getFront().y);
|
||||
debug::window::set_parameter("lz", theCamera.getFront().z);
|
||||
|
||||
// Update other chunks
|
||||
for(int i = 0; i < chunks_volume_real; i++) {
|
||||
const uint16_t x = chunks_indices[i][0] + chunkX;
|
||||
|
@ -152,6 +163,9 @@ namespace chunkmanager
|
|||
a.release();
|
||||
}
|
||||
|
||||
debug::window::set_parameter("update_chunks_total", (int) (chunks.size()));
|
||||
debug::window::set_parameter("update_chunks_bucket", (int) (chunks.max_size()));
|
||||
|
||||
Chunk::Chunk* n;
|
||||
nUnloaded = 0;
|
||||
while(chunks_todelete.try_pop(n)){
|
||||
|
@ -245,6 +259,12 @@ namespace chunkmanager
|
|||
// mark the mesh of the chunk the be updated
|
||||
chunks_to_mesh_queue.push(std::make_pair(c1, MESHING_PRIORITY_PLAYER_EDIT));
|
||||
chunks_to_mesh_queue.push(std::make_pair(c, MESHING_PRIORITY_PLAYER_EDIT));
|
||||
|
||||
debug::window::set_parameter("block_last_action", place);
|
||||
debug::window::set_parameter("block_last_action_block_type", (int)(Block::STONE));
|
||||
debug::window::set_parameter("block_last_action_x", px1*CHUNK_SIZE + bx1);
|
||||
debug::window::set_parameter("block_last_action_y", px1*CHUNK_SIZE + by1);
|
||||
debug::window::set_parameter("block_last_action_z", px1*CHUNK_SIZE + bz1);
|
||||
}else{
|
||||
// replace the current block with air to remove it
|
||||
c->setBlock( Block::AIR, bx, by, bz);
|
||||
|
@ -265,6 +285,13 @@ namespace chunkmanager
|
|||
chunkmesher::mesh(b2->second);
|
||||
if(bz == CHUNK_SIZE - 1 && pz +1 < 1024 && chunks.find(c2, calculateIndex(px, py, pz +1)))
|
||||
chunkmesher::mesh(c2->second);
|
||||
|
||||
debug::window::set_parameter("block_last_action", place);
|
||||
debug::window::set_parameter("block_last_action_block_type", (int) (Block::AIR));
|
||||
debug::window::set_parameter("block_last_action_x", px*CHUNK_SIZE + bx);
|
||||
debug::window::set_parameter("block_last_action_y", py*CHUNK_SIZE + by);
|
||||
debug::window::set_parameter("block_last_action_z", pz*CHUNK_SIZE + bz);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,20 @@
|
|||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_impl_opengl3.h>
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
#include <imgui_stdlib.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace debug{
|
||||
namespace window{
|
||||
|
||||
void show_debug_window();
|
||||
constexpr int frametimes_array_size = 20;
|
||||
float frametimes_array[frametimes_array_size]{};
|
||||
|
||||
std::unordered_map<std::string, std::any> parameters;
|
||||
|
||||
void init(GLFWwindow* window){
|
||||
// Setup Dear ImGui context
|
||||
|
@ -25,7 +35,8 @@ namespace debug{
|
|||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGui::ShowDemoWindow(); // Show demo window! :)
|
||||
//ImGui::ShowDemoWindow(); // Show demo window! :)
|
||||
show_debug_window();
|
||||
}
|
||||
|
||||
void render(){
|
||||
|
@ -43,5 +54,77 @@ namespace debug{
|
|||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void set_parameter(std::string key, std::any value){
|
||||
parameters[key] = value;
|
||||
}
|
||||
|
||||
int ch_type{0};
|
||||
int block_type{0};
|
||||
void show_debug_window(){
|
||||
ImGui::Begin("Debug Window");
|
||||
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
|
||||
|
||||
try{
|
||||
if (ImGui::CollapsingHeader("Frametimes")){
|
||||
ImGui::Text("FPS: %d", std::any_cast<int>(parameters.at("fps")));
|
||||
ImGui::Text("Frametime (ms): %f",
|
||||
std::any_cast<float>(parameters.at("frametime"))*1000);
|
||||
//ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr);
|
||||
}
|
||||
|
||||
if(ImGui::CollapsingHeader("Player")){
|
||||
ImGui::Text("X: %f, Y: %f, Z: %f",
|
||||
std::any_cast<float>(parameters.at("px")),std::any_cast<float>(parameters.at("py")),std::any_cast<float>(parameters.at("pz")) );
|
||||
ImGui::Text("X: %d, Y: %d, Z: %d (chunk)", std::any_cast<int>(parameters.at("cx")),std::any_cast<int>(parameters.at("cy")),std::any_cast<int>(parameters.at("cz")) );
|
||||
ImGui::Text("Pointing in direction: %f, %f, %f",
|
||||
std::any_cast<float>(parameters.at("lx")),std::any_cast<float>(parameters.at("ly")),std::any_cast<float>(parameters.at("lz")) );
|
||||
|
||||
if(parameters.find("block_last_action") != parameters.end()){
|
||||
ImGui::Text("Last Block action: %s",
|
||||
std::any_cast<bool>(parameters.at("block_last_action")) ? "place" : "destroy");
|
||||
ImGui::Text("Last Block action block type: %d",
|
||||
std::any_cast<int>(parameters.at("block_last_action_block_type")));
|
||||
ImGui::Text("Last Block action position: X: %d, Y: %d, Z: %d",
|
||||
std::any_cast<int>(parameters.at("block_last_action_x")),std::any_cast<int>(parameters.at("block_last_action_y")),std::any_cast<int>(parameters.at("block_last_action_z")) );
|
||||
}
|
||||
|
||||
ImGui::SliderInt("Crosshair type",
|
||||
&ch_type, 0, 1);
|
||||
ImGui::SliderInt("Block to place",
|
||||
&block_type, 2, 6);
|
||||
}
|
||||
|
||||
if(ImGui::CollapsingHeader("Mesh")){
|
||||
ImGui::Text("Total chunks updated: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_total")));
|
||||
ImGui::Text("Chunks rendered: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_rendered")));
|
||||
ImGui::Text("Frustum culled: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_culled")));
|
||||
ImGui::Text("Chunks out of view: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_oof")));
|
||||
if(parameters.find("render_chunks_deleted") != parameters.end())
|
||||
ImGui::Text("Chunks deleted: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_deleted")));
|
||||
ImGui::Text("Vertices in the scene: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_vertices")));
|
||||
}
|
||||
|
||||
if(ImGui::CollapsingHeader("Chunks")){
|
||||
ImGui::Text("Total chunks present: %d",
|
||||
std::any_cast<int>(parameters.at("update_chunks_total")));
|
||||
/*ImGui::Text("Chunks freed from memory: %d",
|
||||
std::any_cast<int>(parameters.at("update_chunks_delete")));*/
|
||||
ImGui::Text("Bucket size: %d",
|
||||
std::any_cast<int>(parameters.at("update_chunks_bucket")));
|
||||
}
|
||||
}catch(const std::bad_any_cast& e){
|
||||
std::cout << e.what();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,10 +82,12 @@ int main()
|
|||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
debug::window::set_parameter("frametime", deltaTime);
|
||||
// FPS Counter
|
||||
frames++;
|
||||
if(currentFrame - lastFPSFrame >= 1.0f){
|
||||
std::cout << "FPS: " << frames << " Frametime: " << deltaTime << std::endl;
|
||||
//std::cout << "FPS: " << frames << " Frametime: " << deltaTime << std::endl;
|
||||
debug::window::set_parameter("fps", frames);
|
||||
frames = 0;
|
||||
lastFPSFrame = currentFrame;
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace renderer{
|
|||
debug::window::prerender();
|
||||
|
||||
/* RENDER THE WORLD TO TEXTURE */
|
||||
int total{0}, toGpu{0};
|
||||
int total{0}, toGpu{0}, oof{0}, vertices{0};
|
||||
glm::vec4 frustumPlanes[6];
|
||||
theCamera.getFrustumPlanes(frustumPlanes, true);
|
||||
glm::vec3 cameraPos = theCamera.getPos();
|
||||
|
@ -143,6 +143,9 @@ namespace renderer{
|
|||
if(dist <= static_cast<float>(RENDER_DISTANCE)){
|
||||
if(!c->getState(Chunk::CHUNK_STATE_MESH_LOADED)) continue;
|
||||
|
||||
// Increase total vertex count
|
||||
vertices += c->numVertices;
|
||||
|
||||
// reset out-of-vision and unload flags
|
||||
c->setState(Chunk::CHUNK_STATE_OUTOFVISION, false);
|
||||
c->setState(Chunk::CHUNK_STATE_UNLOADED, false);
|
||||
|
@ -179,12 +182,15 @@ namespace renderer{
|
|||
glBindVertexArray(c->VAO);
|
||||
glDrawArrays(GL_POINTS, 0, c->numVertices);
|
||||
glBindVertexArray(0);
|
||||
|
||||
toGpu++;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// When the chunk is outside render distance
|
||||
|
||||
if(c->getState(Chunk::CHUNK_STATE_OUTOFVISION)){
|
||||
oof++;
|
||||
if(glfwGetTime() - c->unload_timer > UNLOAD_TIMEOUT){
|
||||
// If chunk was already out and enough time has passed
|
||||
// Mark the chunk to be unloaded
|
||||
|
@ -201,6 +207,14 @@ namespace renderer{
|
|||
}
|
||||
}
|
||||
|
||||
total = chunks_torender.size();
|
||||
debug::window::set_parameter("render_chunks_total", total);
|
||||
debug::window::set_parameter("render_chunks_rendered", toGpu);
|
||||
debug::window::set_parameter("render_chunks_culled", total-toGpu);
|
||||
debug::window::set_parameter("render_chunks_oof", oof);
|
||||
debug::window::set_parameter("render_chunks_deleted", (int) (render_todelete.size()));
|
||||
debug::window::set_parameter("render_chunks_vertices", vertices);
|
||||
|
||||
for(auto& c : render_todelete){
|
||||
// we can get away with unsafe erase as access to the container is only done by this
|
||||
// thread
|
||||
|
|
Loading…
Reference in New Issue