From 191b88192b6d947c40b5660dd63bfc59c58c8fa1 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 29 Jun 2022 15:18:31 +0300 Subject: [PATCH] Added chunks counter to debug info screen --- src/voxel_engine.cpp | 2 +- src/voxels/Chunks.cpp | 4 ++++ src/voxels/Chunks.h | 1 + src/voxels/ChunksController.cpp | 2 +- src/world_render.h | 6 +++--- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/voxel_engine.cpp b/src/voxel_engine.cpp index 8dff8152..f4bf8af8 100644 --- a/src/voxel_engine.cpp +++ b/src/voxel_engine.cpp @@ -334,7 +334,7 @@ int main() { chunksController.loadVisible(wfile); draw_world(player, camera, assets, chunks, occlusion); - draw_hud(player, assets, devdata, fps); + draw_hud(player, assets, chunks, devdata, fps); Window::swapBuffers(); Events::pullEvents(); diff --git a/src/voxels/Chunks.cpp b/src/voxels/Chunks.cpp index 0591f2f0..ce255800 100644 --- a/src/voxels/Chunks.cpp +++ b/src/voxels/Chunks.cpp @@ -23,6 +23,7 @@ Chunks::Chunks(int w, int h, int d, int ox, int oy, int oz) : w(w), h(h), d(d), chunks[i] = nullptr; meshes[i] = nullptr; } + chunksCount = 0; } Chunks::~Chunks(){ @@ -281,6 +282,7 @@ void Chunks::translate(WorldFiles* worldFiles, int dx, int dy, int dz){ worldFiles->put((const char*)chunk->voxels, chunk->x, chunk->z); chunk->decref(); delete mesh; + chunksCount--; continue; } meshesSecond[(ny * d + nz) * w + nx] = mesh; @@ -317,6 +319,7 @@ bool Chunks::putChunk(Chunk* chunk) { if (x < 0 || y < 0 || z < 0 || x >= w || y >= h || z >= d) return false; chunks[(y * d + z) * w + x] = chunk; + chunksCount++; return true; } @@ -329,4 +332,5 @@ void Chunks::clear(bool freeMemory){ chunks[i] = nullptr; meshes[i] = nullptr; } + chunksCount = 0; } diff --git a/src/voxels/Chunks.h b/src/voxels/Chunks.h index bdd5efbb..c9c70bea 100644 --- a/src/voxels/Chunks.h +++ b/src/voxels/Chunks.h @@ -20,6 +20,7 @@ public: Mesh** meshes; Mesh** meshesSecond; size_t volume; + size_t chunksCount; unsigned int w,h,d; int ox,oy,oz; diff --git a/src/voxels/ChunksController.cpp b/src/voxels/ChunksController.cpp index d64ed858..d2b98eb1 100644 --- a/src/voxels/ChunksController.cpp +++ b/src/voxels/ChunksController.cpp @@ -106,7 +106,7 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){ if (worldFiles->getChunk(chunk->x, chunk->z, (char*)chunk->voxels)) chunk->loaded = true; - chunks->chunks[index] = chunk; + chunks->putChunk(chunk); Chunk* closes[27]; for (int i = 0; i < 27; i++) diff --git a/src/world_render.h b/src/world_render.h index f94617f0..e9f64877 100644 --- a/src/world_render.h +++ b/src/world_render.h @@ -110,7 +110,7 @@ bool chunks_comparator(size_t i, size_t j) { } -void draw_hud(Player* player, Assets* assets, bool devdata, int fps){ +void draw_hud(Player* player, Assets* assets, Chunks* chunks, bool devdata, int fps){ glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); Shader* uishader = assets->getShader("ui"); @@ -122,11 +122,11 @@ void draw_hud(Player* player, Assets* assets, bool devdata, int fps){ batch->begin(); batch->texture(font->texture); if (devdata){ - font->drawWithShadow(batch, "devdata does not exist", 16, 16); + font->drawWithShadow(batch, "chunks: "+std::to_string(chunks->chunksCount), 16, 16); font->drawWithShadow(batch, std::to_string((int)player->camera->position.x), 10, 30); font->drawWithShadow(batch, std::to_string((int)player->camera->position.y), 50, 30); font->drawWithShadow(batch, std::to_string((int)player->camera->position.z), 90, 30); - font->drawWithShadow(batch, "fps:", 16, 42); + font->drawWithShadow(batch, "fps: ", 16, 42); font->drawWithShadow(batch, std::to_string(fps), 40, 42); } batch->render();