diff --git a/Src/Client/ServerSession.cpp b/Src/Client/ServerSession.cpp index 34bb4eb..9110ad3 100644 --- a/Src/Client/ServerSession.cpp +++ b/Src/Client/ServerSession.cpp @@ -307,8 +307,14 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) { if(RS && !changeOrAddList_removeList.empty()) { for(auto &pair : changeOrAddList_removeList) { // Если случится что чанк был изменён и удалён, то исключаем его обновления - for(Pos::GlobalChunk removed : std::get<1>(pair.second)) - std::get<0>(pair.second).erase(removed); + for(Pos::GlobalRegion removed : std::get<1>(pair.second)) { + Pos::GlobalChunk pos = removed << 2; + for(int z = 0; z < 4; z++) + for(int y = 0; y < 4; y++) + for(int x = 0; x < 4; x++) { + std::get<0>(pair.second).erase(pos+Pos::GlobalChunk(x, y, z)); + } + } RS->onChunksChange(pair.first, std::get<0>(pair.second), std::get<1>(pair.second)); } diff --git a/Src/Client/Vulkan/VertexPool.hpp b/Src/Client/Vulkan/VertexPool.hpp index 51a16ad..1b47157 100644 --- a/Src/Client/Vulkan/VertexPool.hpp +++ b/Src/Client/Vulkan/VertexPool.hpp @@ -104,7 +104,7 @@ public: return {0, 0, 0}; // Необходимое количество блоков - uint16_t blocks = data.size() / size_t(PerBlock); + uint16_t blocks = (data.size()+PerBlock-1) / PerBlock; assert(blocks <= PerPool); // Нужно найти пулл в котором будет свободно blocks количество блоков или создать новый @@ -112,13 +112,17 @@ public: Pool &pool = Pools[iterPool]; size_t pos = pool.Allocation._Find_first(); + if(pos == PerPool) + continue; + while(true) { int countEmpty = 1; for(size_t pos2 = pos+1; pos2 < PerPool && pool.Allocation.test(pos2) && countEmpty < blocks; pos2++, countEmpty++); if(countEmpty == blocks) { - for(int block = 0; block < blocks; block++) + for(int block = 0; block < blocks; block++) { pool.Allocation.reset(pos+block); + } size_t count = data.size(); pushData(std::move(data), iterPool, pos); @@ -245,6 +249,8 @@ public: task.Data.size()*sizeof(Vertex) }; + assert(copyRegion.dstOffset+copyRegion.size < sizeof(Vertex)*PerBlock*PerPool); + vkCmdCopyBuffer(commandBuffer, HostCoherent.getBuffer(), Pools[task.PoolId].DeviceBuff.getBuffer(), 1, ©Region); diff --git a/Src/Client/Vulkan/VulkanRenderSession.cpp b/Src/Client/Vulkan/VulkanRenderSession.cpp index 7e595ab..cee62e7 100644 --- a/Src/Client/Vulkan/VulkanRenderSession.cpp +++ b/Src/Client/Vulkan/VulkanRenderSession.cpp @@ -617,6 +617,12 @@ void VulkanRenderSession::onChunksChange(WorldId_t worldId, const std::unordered auto &table = External.ChunkVoxelMesh[worldId]; for(Pos::GlobalChunk pos : changeOrAddList) { + if(pos.y < 0) { + int g = 0; + g++; + } + + Pos::GlobalRegion rPos = pos >> 2; Pos::bvec4u cPos = pos & 0x3; diff --git a/Src/Server/GameServer.cpp b/Src/Server/GameServer.cpp index ac53d69..6afa280 100644 --- a/Src/Server/GameServer.cpp +++ b/Src/Server/GameServer.cpp @@ -112,7 +112,7 @@ void GameServer::BackingChunkPressure_t::run(int id) { for(int x = 0; x < 4; x++) { auto &toPtr = dumpRegion.Nodes[Pos::bvec4u(x, y, z)]; - const Node *fromPtr = (const Node*) ®ionObj.Nodes[0][0][0][x][y][z]; + const Node *fromPtr = regionObj.Nodes[Pos::bvec4u(x, y, z).pack()].data(); std::copy(fromPtr, fromPtr+16*16*16, toPtr.data()); } } else { @@ -142,7 +142,7 @@ void GameServer::BackingChunkPressure_t::run(int id) { chunkPos.unpack(index); auto &toPtr = dumpRegion.Nodes[chunkPos]; - const Node *fromPtr = (const Node*) ®ionObj.Nodes[0][0][0][chunkPos.x][chunkPos.y][chunkPos.z]; + const Node *fromPtr = regionObj.Nodes[chunkPos.pack()].data(); std::copy(fromPtr, fromPtr+16*16*16, toPtr.data()); } } @@ -752,7 +752,7 @@ IWorldSaveBackend::TickSyncInfo_Out GameServer::stepDatabaseSync() { ContentViewCircle cvc; cvc.WorldId = oPos.WorldId; cvc.Pos = Pos::Object_t::asChunkPos(oPos.ObjectPos); - cvc.Range = 2*2; + cvc.Range = 2; std::vector newCVCs = Expanse.accumulateContentViewCircles(cvc); ContentViewInfo newCbg = Expanse_t::makeContentViewInfo(newCVCs); @@ -842,26 +842,34 @@ void GameServer::stepGeneratorAndLuaAsync(IWorldSaveBackend::TickSyncInfo_Out db auto &obj = toLoadRegions[key.WId].emplace_back(key.RegionPos, World::RegionIn()).second; float *ptr = ®ion[0]; - for(int z = 0; z < 64; z++) - for(int y = 0; y < 64; y++) - for(int x = 0; x < 64; x++, ptr++) { - // DefVoxelId_t id = *ptr > 0.9 ? 1 : 0; - Pos::bvec64u nodePos(x, y, z); - auto &node = obj.Nodes[Pos::bvec4u(nodePos >> 4).pack()][Pos::bvec16u(nodePos & 0xf).pack()]; - // node.NodeId = id; - // node.Meta = 0; - - if(y == (key.RegionPos.y % 64)) - node.NodeId = 1; - else - node.NodeId = 0; - - node.Meta = 0; + { + Node node; + node.Data = 0; + std::fill((Node*) obj.Nodes.data(), ((Node*) obj.Nodes.data())+64*64*64, node); } - // Node node; - // node.Data = 0; - // std::fill((Node*) obj.Nodes.data(), ((Node*) obj.Nodes.data())+64*64*64, node); + if((key.RegionPos.x == 0 || key.RegionPos.x == 0) && key.RegionPos.y == 0 && key.RegionPos.z == 0) { + for(int z = 0; z < 64; z++) + for(int y = 0; y < 64; y++) + for(int x = 0; x < 64; x++, ptr++) { + // DefVoxelId_t id = *ptr > 0.9 ? 1 : 0; + Pos::bvec64u nodePos(x, y, z); + auto &node = obj.Nodes[Pos::bvec4u(nodePos >> 4).pack()][Pos::bvec16u(nodePos & 0xf).pack()]; + // node.NodeId = id; + // node.Meta = 0; + + if( + (y == 0 && z == 0) + // || (x == 0 && z == 0) + // || (x == 0 && y == 0) + ) { + if(x+y+z <= 18) + node.NodeId = (((x+y+z)/3)%3)+1; + } + + node.Meta = 0; + } + } // obj.Nodes[0][0].NodeId = 1; } diff --git a/Src/Server/World.cpp b/Src/Server/World.cpp index f924cb3..c674bd9 100644 --- a/Src/Server/World.cpp +++ b/Src/Server/World.cpp @@ -40,7 +40,7 @@ std::vector World::onCEC_RegionsEnter(std::shared_ptr> regi for(auto& [key, value] : regions) { Region ®ion = *(Regions[key] = std::make_unique()); region.Voxels = std::move(value.Voxels); - - Node *ptr = (Node*) region.Nodes; - for(std::array& nodes : value.Nodes) { - - std::copy(nodes.data(), nodes.data()+16*16*16, ptr); - ptr += 16*16*16; - } + region.Nodes = value.Nodes; } } diff --git a/Src/Server/World.hpp b/Src/Server/World.hpp index b950e8f..6871674 100644 --- a/Src/Server/World.hpp +++ b/Src/Server/World.hpp @@ -22,7 +22,7 @@ public: // x y cx cy cz //LightPrism Lights[16][16][4][4][4]; - Node Nodes[16][16][16][4][4][4]; + std::array, 4*4*4> Nodes; std::vector Entityes; std::vector> CECs, NewCECs; diff --git a/assets/shaders/chunk/node.geom b/assets/shaders/chunk/node.geom index 5a91ac2..b85ee3e 100644 --- a/assets/shaders/chunk/node.geom +++ b/assets/shaders/chunk/node.geom @@ -5,13 +5,13 @@ layout (triangle_strip, max_vertices = 3) out; layout(location = 0) in GeometryObj { vec3 GeoPos; // Реальная позиция в мире - uint Texture; // Текстура + flat uint Texture; // Текстура vec2 UV; } Geometry[]; layout(location = 0) out FragmentObj { vec3 GeoPos; // Реальная позиция в мире - uint Texture; // Текстура + flat uint Texture; // Текстура vec2 UV; } Fragment; diff --git a/assets/shaders/chunk/node.geom.bin b/assets/shaders/chunk/node.geom.bin index daf5c8d..418b49b 100644 Binary files a/assets/shaders/chunk/node.geom.bin and b/assets/shaders/chunk/node.geom.bin differ diff --git a/assets/shaders/chunk/node.vert b/assets/shaders/chunk/node.vert index ee0f6cd..75383b8 100644 --- a/assets/shaders/chunk/node.vert +++ b/assets/shaders/chunk/node.vert @@ -4,7 +4,7 @@ layout(location = 0) in uvec3 Vertex; layout(location = 0) out GeometryObj { vec3 GeoPos; // Реальная позиция в мире - uint Texture; // Текстура + flat uint Texture; // Текстура vec2 UV; } Geometry; diff --git a/assets/shaders/chunk/node.vert.bin b/assets/shaders/chunk/node.vert.bin index be9b0fb..e89b91f 100644 Binary files a/assets/shaders/chunk/node.vert.bin and b/assets/shaders/chunk/node.vert.bin differ diff --git a/assets/shaders/chunk/node_opaque.frag b/assets/shaders/chunk/node_opaque.frag index fe26e51..d253531 100644 --- a/assets/shaders/chunk/node_opaque.frag +++ b/assets/shaders/chunk/node_opaque.frag @@ -2,7 +2,7 @@ layout(location = 0) in FragmentObj { vec3 GeoPos; // Реальная позиция в мире - uint Texture; // Текстура + flat uint Texture; // Текстура vec2 UV; } Fragment; diff --git a/assets/shaders/chunk/node_opaque.frag.bin b/assets/shaders/chunk/node_opaque.frag.bin index 603f8c3..7c0aa2d 100644 Binary files a/assets/shaders/chunk/node_opaque.frag.bin and b/assets/shaders/chunk/node_opaque.frag.bin differ diff --git a/assets/shaders/chunk/node_transparent.frag b/assets/shaders/chunk/node_transparent.frag index 174bcc7..cb09d72 100644 --- a/assets/shaders/chunk/node_transparent.frag +++ b/assets/shaders/chunk/node_transparent.frag @@ -2,7 +2,7 @@ layout(location = 0) in FragmentObj { vec3 GeoPos; // Реальная позиция в мире - uint Texture; // Текстура + flat uint Texture; // Текстура vec2 UV; } Fragment;