From 50bd5c1a7e1bacf93b6a4e900d2ec282223378a1 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 28 Sep 2022 10:51:15 -0400 Subject: [PATCH] dont destroy buffers until not used --- engine/xe_model.cpp | 1 + engine/xe_renderer.cpp | 2 +- engine/xe_swap_chain.cpp | 2 -- src/chunk.cpp | 4 +++- src/first_app.cpp | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/engine/xe_model.cpp b/engine/xe_model.cpp index 49d4c9d..a891d5f 100644 --- a/engine/xe_model.cpp +++ b/engine/xe_model.cpp @@ -53,6 +53,7 @@ void Model::deleteModel(Model* model) { void Model::submitDeleteQueue(bool purge) { for(Model* model: DELETION_QUEUE) { + vkDeviceWaitIdle(model->xeDevice.device()); try { delete model; } catch(int err) {}; } DELETION_QUEUE.clear(); diff --git a/engine/xe_renderer.cpp b/engine/xe_renderer.cpp index fb19846..c2eee9d 100644 --- a/engine/xe_renderer.cpp +++ b/engine/xe_renderer.cpp @@ -59,7 +59,7 @@ void Renderer::freeCommandBuffers() { } VkCommandBuffer Renderer::beginFrame() { - assert(!isFrameStarted && "Can't acll beingFrame while already in progress"); + assert(!isFrameStarted && "Can't call beingFrame while already in progress"); auto result = xeSwapChain->acquireNextImage(¤tImageIndex); diff --git a/engine/xe_swap_chain.cpp b/engine/xe_swap_chain.cpp index f6b194d..ae103db 100755 --- a/engine/xe_swap_chain.cpp +++ b/engine/xe_swap_chain.cpp @@ -109,8 +109,6 @@ VkResult SwapChain::submitCommandBuffers( submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = signalSemaphores; - - vkResetFences(device.device(), 1, &inFlightFences[currentFrame]); if (vkQueueSubmit(device.graphicsQueue(), 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) { diff --git a/src/chunk.cpp b/src/chunk.cpp index c52eeb3..395aee7 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -19,6 +19,8 @@ Chunk::~Chunk() { if(worker.joinable()) worker.join(); xe::Model::deleteModel(chunkMesh); + vertexData.data.clear(); + cubes.clear(); } // @@ -216,7 +218,7 @@ void Chunk::generate() { for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { - int height = perlin.octave2D_01((( x + gridX * 16) * 0.01), ((z + gridZ * 16) * 0.01), 4) * 10; + int height = perlin.octave2D_01((( x + gridX * 16) * 0.01), ((z + gridZ * 16) * 0.01), 4) * 20; for(int y = 0; y < 256; y++) { if(y == height){ setBlock(x, y, z, GRASS); diff --git a/src/first_app.cpp b/src/first_app.cpp index 63a960d..43047f7 100755 --- a/src/first_app.cpp +++ b/src/first_app.cpp @@ -73,8 +73,8 @@ void FirstApp::reloadLoadedChunks(xe::GameObject& viewer) { int gridZ = static_cast(floor(gameObject.transform.translation.z / 16.f)); int newGridX = minX + x; int newGridZ = minZ + z; - // if(gridX < minX || gridZ < minZ || gridX > maxX || gridZ > maxZ) - // Chunk::deleteChunk(gridX, gridZ); + if(gridX < minX || gridZ < minZ || gridX > maxX || gridZ > maxZ) + Chunk::deleteChunk(gridX, gridZ); Chunk* chunk = Chunk::getChunk(newGridX, newGridZ); if(chunk == nullptr) { chunk = Chunk::newChunk(newGridX, newGridZ, 12345);