Advancec Frustum Culling & fixes

This commit is contained in:
@clasher113
2023-11-16 16:42:57 +02:00
parent 11f004b582
commit 883dcbf168
12 changed files with 178 additions and 53 deletions
+18
View File
@@ -3,6 +3,8 @@
#include "../lighting/Lightmap.h"
Chunk::Chunk(int xpos, int zpos) : x(xpos), z(zpos){
bottom = 0;
top = CHUNK_H;
voxels = new voxel[CHUNK_VOL];
for (size_t i = 0; i < CHUNK_VOL; i++) {
voxels[i].id = 2;
@@ -30,6 +32,22 @@ bool Chunk::isEmpty(){
return true;
}
void Chunk::updateHeights() {
for (int i = 0; i < CHUNK_VOL; i++) {
if (voxels[i].id != 0) {
bottom = i / (CHUNK_D * CHUNK_W);
break;
}
}
for (int i = CHUNK_VOL - 1; i > -1; i--) {
if (voxels[i].id != 0) {
top = i / (CHUNK_D * CHUNK_W) + 1;
break;
}
}
}
Chunk* Chunk::clone() const {
Chunk* other = new Chunk(x,z);
for (int i = 0; i < CHUNK_VOL; i++)
+3
View File
@@ -26,6 +26,7 @@ struct RenderData {
class Chunk {
public:
int x, z;
int bottom, top;
voxel* voxels;
Lightmap* lightmap;
int flags = 0;
@@ -37,6 +38,8 @@ public:
bool isEmpty();
void updateHeights();
Chunk* clone() const;
// flags getters/setters below
+4
View File
@@ -139,6 +139,10 @@ void Chunks::set(int x, int y, int z, int id, uint8_t states){
chunk->setUnsaved(true);
chunk->setModified(true);
if (y < chunk->bottom) chunk->bottom = y;
else if (y + 1 > chunk->top) chunk->top = y + 1;
else if (id == 0) chunk->updateHeights();
if (lx == 0 && (chunk = getChunk(cx+ox-1, cz+oz))) chunk->setModified(true);
if (lz == 0 && (chunk = getChunk(cx+ox, cz+oz-1))) chunk->setModified(true);
+1
View File
@@ -19,6 +19,7 @@ public:
std::shared_ptr<Chunk>* chunksSecond;
size_t volume;
size_t chunksCount;
size_t visible;
int w,d;
int ox,oz;
WorldFiles* worldFiles;
+2
View File
@@ -116,6 +116,8 @@ bool ChunksController::loadVisible(){
chunk->setUnsaved(true);
}
chunk->updateHeights();
for (size_t i = 0; i < CHUNK_VOL; i++) {
blockid_t id = chunk->voxels[i].id;
if (Block::blocks[id] == nullptr) {