diff --git a/Src/Client/ServerSession.cpp b/Src/Client/ServerSession.cpp index 73e02ab..bf15180 100644 --- a/Src/Client/ServerSession.cpp +++ b/Src/Client/ServerSession.cpp @@ -561,7 +561,7 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) { for(auto &pair : changeOrAddList_removeList) { // Если случится что чанк был изменён и удалён, то исключаем его обновления for(Pos::GlobalRegion removed : std::get<1>(pair.second)) { - Pos::GlobalChunk pos = removed << 2; + Pos::GlobalChunk pos = Pos::GlobalChunk(removed) << 2; for(int z = 0; z < 4; z++) for(int y = 0; y < 4; y++) for(int x = 0; x < 4; x++) { diff --git a/Src/Client/Vulkan/Vulkan.cpp b/Src/Client/Vulkan/Vulkan.cpp index 85aaa85..cb16978 100644 --- a/Src/Client/Vulkan/Vulkan.cpp +++ b/Src/Client/Vulkan/Vulkan.cpp @@ -255,14 +255,17 @@ void Vulkan::run() if (err == VK_ERROR_OUT_OF_DATE_KHR) { + if(Game.RSession) + Game.RSession->pushStage(EnumRenderStage::WorldUpdate); + freeSwapchains(); buildSwapchains(); continue; - } else if (err == VK_SUBOPTIMAL_KHR) - { - LOGGER.debug() << "VK_SUBOPTIMAL_KHR Pre"; - continue; - } else if(err == VK_SUCCESS) { + // } else if (err == VK_SUBOPTIMAL_KHR) + // { + // LOGGER.debug() << "VK_SUBOPTIMAL_KHR Pre"; + // continue; + } else if(err == VK_SUBOPTIMAL_KHR || err == VK_SUCCESS) { Screen.State = DrawState::Drawing; //Готовим инструкции рисовки @@ -563,11 +566,9 @@ void Vulkan::run() vkAssert(!vkQueueSubmit(*lockQueue, 1, &submit_info, drawEndFence)); } - // auto now = std::chrono::high_resolution_clock::now(); // Насильно ожидаем завершения рендера кадра vkWaitForFences(Graphics.Device, 1, &drawEndFence, true, -1); vkResetFences(Graphics.Device, 1, &drawEndFence); - // LOG.debug() << (std::chrono::high_resolution_clock::now()-now).count(); } { @@ -587,6 +588,12 @@ void Vulkan::run() auto lockQueue = Graphics.DeviceQueueGraphic.lock(); err = vkQueuePresentKHR(*lockQueue, &present); } + + { + auto lockQueue = Graphics.DeviceQueueGraphic.lock(); + vkDeviceWaitIdle(Graphics.Device); + lockQueue.unlock(); + } if (err == VK_ERROR_OUT_OF_DATE_KHR) { @@ -1557,7 +1564,7 @@ void Vulkan::initNextSettings() "VK_LAYER_LUNARG_monitor" }; - if(!SettingsNext.Debug) + if(!SettingsNext.Debug || getenv("no_vk_debug")) knownDebugLayers.clear(); std::vector enableDebugLayers; @@ -2256,8 +2263,15 @@ void Vulkan::gui_ConnectedToServer() { if(Game.Session) { if(ImGui::Begin("MainMenu", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { - std::string text = std::to_string(ImGui::GetIO().Framerate); - ImGui::Text("%s", text.c_str()); + ImGui::Text("fps: %2.2f World: %u Pos: %i %i %i Region: %i %i %i", + ImGui::GetIO().Framerate, Game.RSession->WI, + (int) Game.RSession->PlayerPos.x, (int) Game.RSession->PlayerPos.y, (int) Game.RSession->PlayerPos.z, + (int) Game.RSession->PlayerPos.x >> 6, (int) Game.RSession->PlayerPos.y >> 6, (int) Game.RSession->PlayerPos.z >> 6 + ); + + if(ImGui::Button("Delimeter")) + LOG.debug(); + if(ImGui::Button("Выйти")) { try { if(Game.Session) diff --git a/Src/Client/Vulkan/VulkanRenderSession.cpp b/Src/Client/Vulkan/VulkanRenderSession.cpp index f253dfc..9fceb4c 100644 --- a/Src/Client/Vulkan/VulkanRenderSession.cpp +++ b/Src/Client/Vulkan/VulkanRenderSession.cpp @@ -80,6 +80,7 @@ void VulkanRenderSession::ThreadVertexObj_t::run() { toRemove.push_back(worldId); } + for(WorldId_t worldId : toRemove) ChunkMesh.erase(ChunkMesh.find(worldId)); @@ -101,6 +102,7 @@ void VulkanRenderSession::ThreadVertexObj_t::run() { State.lock()->ChunkMesh_IsUse = false; + changedContent_RegionRemove.clear(); chunksUpdate.clear(); // LOG.debug() << "ChunkMesh_IsUse: " << Time::nowSystem() - now; @@ -167,6 +169,7 @@ void VulkanRenderSession::ThreadVertexObj_t::run() { { std::vector nodes = generateMeshForNodeChunks(chunk.Nodes.data()); + if(!nodes.empty()) { drawChunk.NodePointer = VertexPool_Nodes.pushVertexs(std::move(nodes)); hasVertexChanges = true; @@ -1007,9 +1010,11 @@ void VulkanRenderSession::onChunksChange(WorldId_t worldId, const std::unordered std::unordered_map> chunkChanges; if(!changeOrAddList.empty()) chunkChanges[worldId] = std::vector(changeOrAddList.begin(), changeOrAddList.end()); + std::unordered_map> regionRemove; if(!remove.empty()) regionRemove[worldId] = std::vector(remove.begin(), remove.end()); + VKCTX->ThreadVertexObj.onContentChunkChange(chunkChanges, regionRemove); // if(chunk.Voxels.empty()) { @@ -1041,6 +1046,10 @@ void VulkanRenderSession::setCameraPos(WorldId_t worldId, Pos::Object pos, glm:: WorldId = worldId; Pos = pos; Quat = quat; + + WI = worldId; + PlayerPos = pos; + PlayerPos /= float(Pos::Object_t::BS); } void VulkanRenderSession::beforeDraw() { @@ -1209,7 +1218,15 @@ void VulkanRenderSession::drawWorld(GlobalTime gTime, float dTime, VkCommandBuff Pos::GlobalChunk x64offset = X64Offset >> Pos::Object_t::BS_Bit >> 4; Pos::GlobalRegion x64offset_region = x64offset >> 2; - auto [voxelVertexs, nodeVertexs] = VKCTX->ThreadVertexObj.getChunksForRender(WorldId, Pos, 2, PCO.ProjView, x64offset_region); + auto [voxelVertexs, nodeVertexs] = VKCTX->ThreadVertexObj.getChunksForRender(WorldId, Pos, 4, PCO.ProjView, x64offset_region); + + { + static uint32_t l = TOS::Time::getSeconds(); + if(l != TOS::Time::getSeconds()) { + l = TOS::Time::getSeconds(); + TOS::Logger("Test").debug() << nodeVertexs.size(); + } + } size_t count = 0; diff --git a/Src/Client/Vulkan/VulkanRenderSession.hpp b/Src/Client/Vulkan/VulkanRenderSession.hpp index e4e083b..0105c45 100644 --- a/Src/Client/Vulkan/VulkanRenderSession.hpp +++ b/Src/Client/Vulkan/VulkanRenderSession.hpp @@ -209,7 +209,7 @@ class VulkanRenderSession : public IRenderSession, public IVulkanDependent { continue; auto iterRegion = iterWorld->second.find(region); - if(iterRegion == iterWorld->second.end()) + if(iterRegion == iterWorld->second.end()) continue; Pos::GlobalChunk local = Pos::GlobalChunk(region) << 2; @@ -364,6 +364,8 @@ class VulkanRenderSession : public IRenderSession, public IVulkanDependent { public: WorldPCO PCO; + WorldId_t WI = 0; + glm::vec3 PlayerPos = glm::vec3(0); public: VulkanRenderSession();