move chunk update back to secondary thread

fix-multithread
EmaMaker 2023-10-01 11:00:00 +02:00
parent 8a3c963721
commit 49edf2de85
2 changed files with 9 additions and 4 deletions

View File

@ -68,7 +68,7 @@ namespace chunkmanager
chunkmesher::getMeshDataQueue().push(new chunkmesher::MeshData());
should_run = true;
//update_thread = std::thread(update);
update_thread = std::thread(update);
gen_thread = std::thread(generate);
mesh_thread = std::thread(mesh);
@ -108,7 +108,9 @@ namespace chunkmanager
int nUnloaded{0};
std::queue<int32_t> chunks_todelete;
void primary_thread_update(){
void update(){
while(should_run) {
int nExplored{0}, nMeshed{0}, nGenerated{0};
int chunkX=static_cast<int>(theCamera.getAtomicPosX() / CHUNK_SIZE);
int chunkY=static_cast<int>(theCamera.getAtomicPosY() / CHUNK_SIZE);
@ -212,6 +214,7 @@ namespace chunkmanager
debug::window::set_parameter("update_chunks_meshed", nMeshed);
debug::window::set_parameter("update_chunks_explored", nExplored);
}
}
// uint32_t is fine, since i'm limiting the coordinate to only use up to ten bits (1023). There's actually two spare bits
int32_t calculateIndex(int16_t i, int16_t j, int16_t k){
@ -224,6 +227,8 @@ namespace chunkmanager
should_run=false;
std::cout << "waiting for secondary threads to finish\n";
update_thread.join();
std::cout << "update thread terminated\n";
gen_thread.join();
std::cout << "generation thread terminated\n";
mesh_thread.join();

View File

@ -103,7 +103,7 @@ int main()
// Reset blockping timeout if 200ms have passed
if(glfwGetTime() - lastBlockPick > 0.1) blockpick = false;
chunkmanager::primary_thread_update();
//chunkmanager::primary_thread_update();
// Render pass
renderer::render();