renderer: correct distance check

fix-multithread
EmaMaker 2023-09-21 17:13:21 +02:00
parent 3f02ca91db
commit a65fc44069
1 changed files with 6 additions and 4 deletions

View File

@ -150,9 +150,12 @@ namespace renderer{
for(auto& c : chunks_torender){ for(auto& c : chunks_torender){
//float dist = glm::distance(c->getPosition(), cameraChunkPos); //float dist = glm::distance(c->getPosition(), cameraChunkPos);
//if(static_cast<int>(dist) <= RENDER_DISTANCE + 1){ //if(static_cast<int>(dist) <= RENDER_DISTANCE + 1){
if(abs(c->getPosition().x - cameraChunkPos.x) <= RENDER_DISTANCE && int distx = c->getPosition().x - cameraChunkPos.x;
abs(c->getPosition().y - cameraChunkPos.y) <= RENDER_DISTANCE && int disty = c->getPosition().y - cameraChunkPos.y;
abs(c->getPosition().z - cameraChunkPos.z) <= RENDER_DISTANCE){ int distz = c->getPosition().z - cameraChunkPos.z;
if(distx >= -RENDER_DISTANCE && distx < RENDER_DISTANCE &&
disty >= -RENDER_DISTANCE && disty < RENDER_DISTANCE &&
distz >= -RENDER_DISTANCE && distz < RENDER_DISTANCE){
if(!c->getState(Chunk::CHUNK_STATE_MESH_LOADED)) continue; if(!c->getState(Chunk::CHUNK_STATE_MESH_LOADED)) continue;
// Increase total vertex count // Increase total vertex count
@ -210,7 +213,6 @@ namespace renderer{
render_todelete.push_back(c); render_todelete.push_back(c);
} }
} else{ } else{
std::cout << "chunk at " << glm::to_string(c->getPosition()) << std::endl;
// Mark has out of vision and annotate when it started // Mark has out of vision and annotate when it started
c->setState(Chunk::CHUNK_STATE_OUTOFVISION, true); c->setState(Chunk::CHUNK_STATE_OUTOFVISION, true);
c->setState(Chunk::CHUNK_STATE_UNLOADED, false); c->setState(Chunk::CHUNK_STATE_UNLOADED, false);