Added chunks counter to debug info screen

This commit is contained in:
MihailRis
2022-06-29 15:18:31 +03:00
committed by GitHub
parent 265ebc0927
commit 191b88192b
5 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -334,7 +334,7 @@ int main() {
chunksController.loadVisible(wfile); chunksController.loadVisible(wfile);
draw_world(player, camera, assets, chunks, occlusion); draw_world(player, camera, assets, chunks, occlusion);
draw_hud(player, assets, devdata, fps); draw_hud(player, assets, chunks, devdata, fps);
Window::swapBuffers(); Window::swapBuffers();
Events::pullEvents(); Events::pullEvents();
+4
View File
@@ -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; chunks[i] = nullptr;
meshes[i] = nullptr; meshes[i] = nullptr;
} }
chunksCount = 0;
} }
Chunks::~Chunks(){ 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); worldFiles->put((const char*)chunk->voxels, chunk->x, chunk->z);
chunk->decref(); chunk->decref();
delete mesh; delete mesh;
chunksCount--;
continue; continue;
} }
meshesSecond[(ny * d + nz) * w + nx] = mesh; 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) if (x < 0 || y < 0 || z < 0 || x >= w || y >= h || z >= d)
return false; return false;
chunks[(y * d + z) * w + x] = chunk; chunks[(y * d + z) * w + x] = chunk;
chunksCount++;
return true; return true;
} }
@@ -329,4 +332,5 @@ void Chunks::clear(bool freeMemory){
chunks[i] = nullptr; chunks[i] = nullptr;
meshes[i] = nullptr; meshes[i] = nullptr;
} }
chunksCount = 0;
} }
+1
View File
@@ -20,6 +20,7 @@ public:
Mesh** meshes; Mesh** meshes;
Mesh** meshesSecond; Mesh** meshesSecond;
size_t volume; size_t volume;
size_t chunksCount;
unsigned int w,h,d; unsigned int w,h,d;
int ox,oy,oz; int ox,oy,oz;
+1 -1
View File
@@ -106,7 +106,7 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
if (worldFiles->getChunk(chunk->x, chunk->z, (char*)chunk->voxels)) if (worldFiles->getChunk(chunk->x, chunk->z, (char*)chunk->voxels))
chunk->loaded = true; chunk->loaded = true;
chunks->chunks[index] = chunk; chunks->putChunk(chunk);
Chunk* closes[27]; Chunk* closes[27];
for (int i = 0; i < 27; i++) for (int i = 0; i < 27; i++)
+3 -3
View File
@@ -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_DEPTH_TEST);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
Shader* uishader = assets->getShader("ui"); Shader* uishader = assets->getShader("ui");
@@ -122,11 +122,11 @@ void draw_hud(Player* player, Assets* assets, bool devdata, int fps){
batch->begin(); batch->begin();
batch->texture(font->texture); batch->texture(font->texture);
if (devdata){ 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.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.y), 50, 30);
font->drawWithShadow(batch, std::to_string((int)player->camera->position.z), 90, 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); font->drawWithShadow(batch, std::to_string(fps), 40, 42);
} }
batch->render(); batch->render();