*
This commit is contained in:
@@ -33,24 +33,6 @@ struct GlobalTime {
|
||||
}
|
||||
};
|
||||
|
||||
struct VoxelCube {
|
||||
union {
|
||||
struct {
|
||||
DefVoxelId_t VoxelId : 24, Meta : 8;
|
||||
};
|
||||
DefVoxelId_t Data;
|
||||
};
|
||||
Pos::bvec256u Left, Size;
|
||||
};
|
||||
|
||||
union Node {
|
||||
struct {
|
||||
DefNodeId_t NodeId : 24, Meta : 8;
|
||||
};
|
||||
|
||||
DefNodeId_t Data;
|
||||
};
|
||||
|
||||
// 16 метров ребро
|
||||
// 256 вокселей ребро
|
||||
struct Chunk {
|
||||
|
||||
@@ -34,10 +34,9 @@ struct PP_Content_ChunkNodes : public ParsedPacket {
|
||||
Pos::GlobalChunk Pos;
|
||||
Node Nodes[16][16][16];
|
||||
|
||||
PP_Content_ChunkNodes(ToClient::L1 l1, uint8_t l2, WorldId_t id, Pos::GlobalChunk pos, Node* nodes)
|
||||
PP_Content_ChunkNodes(ToClient::L1 l1, uint8_t l2, WorldId_t id, Pos::GlobalChunk pos)
|
||||
: ParsedPacket(l1, l2), Id(id), Pos(pos)
|
||||
{
|
||||
std::copy(nodes, nodes+16*16*16, (Node*) Nodes);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -281,14 +280,14 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) {
|
||||
auto &pair = changeOrAddList_removeList[p.Id];
|
||||
std::get<0>(pair).insert(p.Pos);
|
||||
} else if(l2 == ToClient::L2Content::ChunkNodes) {
|
||||
PP_Content_ChunkNodes &p = *dynamic_cast<PP_Content_ChunkNodes*>(pack);
|
||||
Pos::GlobalRegion rPos = p.Pos >> 2;
|
||||
Pos::bvec4u cPos = p.Pos & 0x3;
|
||||
// PP_Content_ChunkNodes &p = *dynamic_cast<PP_Content_ChunkNodes*>(pack);
|
||||
// Pos::GlobalRegion rPos = p.Pos >> 2;
|
||||
// Pos::bvec4u cPos = p.Pos & 0x3;
|
||||
|
||||
Node *nodes = (Node*) Data.Worlds[p.Id].Regions[rPos].Chunks[cPos.x][cPos.y][cPos.z].Nodes;
|
||||
std::copy((const Node*)p.Nodes, ((const Node*) p.Nodes)+16*16*16, nodes);
|
||||
auto &pair = changeOrAddList_removeList[p.Id];
|
||||
std::get<0>(pair).insert(p.Pos);
|
||||
// Node *nodes = (Node*) Data.Worlds[p.Id].Regions[rPos].Chunks[cPos.x][cPos.y][cPos.z].Nodes;
|
||||
// std::copy((const Node*) p.Nodes, ((const Node*) p.Nodes)+16*16*16, nodes);
|
||||
// auto &pair = changeOrAddList_removeList[p.Id];
|
||||
// std::get<0>(pair).insert(p.Pos);
|
||||
} else if(l2 == ToClient::L2Content::RemoveRegion) {
|
||||
PP_Content_RegionRemove &p = *dynamic_cast<PP_Content_RegionRemove*>(pack);
|
||||
|
||||
@@ -532,25 +531,17 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
|
||||
Pos::GlobalChunk pos;
|
||||
pos.unpack(co_await sock.read<Pos::GlobalChunk::Pack>());
|
||||
|
||||
std::vector<VoxelCube> cubes(co_await sock.read<uint16_t>());
|
||||
|
||||
for(size_t iter = 0; iter < cubes.size(); iter++) {
|
||||
VoxelCube &cube = cubes[iter];
|
||||
cube.Data = co_await sock.read<DefVoxelId_t>();
|
||||
cube.Left.x = co_await sock.read<uint8_t>();
|
||||
cube.Left.y = co_await sock.read<uint8_t>();
|
||||
cube.Left.z = co_await sock.read<uint8_t>();
|
||||
cube.Size.x = co_await sock.read<uint8_t>();
|
||||
cube.Size.y = co_await sock.read<uint8_t>();
|
||||
cube.Size.z = co_await sock.read<uint8_t>();
|
||||
}
|
||||
uint32_t compressedSize = co_await sock.read<uint32_t>();
|
||||
assert(compressedSize <= std::pow(2, 24));
|
||||
std::u8string compressed(compressedSize, '\0');
|
||||
co_await sock.read((std::byte*) compressed.data(), compressedSize);
|
||||
|
||||
PP_Content_ChunkVoxels *packet = new PP_Content_ChunkVoxels(
|
||||
ToClient::L1::Content,
|
||||
(uint8_t) ToClient::L2Content::ChunkVoxels,
|
||||
wcId,
|
||||
pos,
|
||||
std::move(cubes)
|
||||
unCompressVoxels(compressed)
|
||||
);
|
||||
|
||||
while(!NetInputPackets.push(packet));
|
||||
@@ -563,20 +554,21 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
|
||||
WorldId_t wcId = co_await sock.read<WorldId_t>();
|
||||
Pos::GlobalChunk pos;
|
||||
pos.unpack(co_await sock.read<Pos::GlobalChunk::Pack>());
|
||||
std::array<Node, 16*16*16> nodes;
|
||||
|
||||
for(Node& node : nodes) {
|
||||
node.Data = co_await sock.read<DefNodeId_t>();
|
||||
}
|
||||
uint32_t compressedSize = co_await sock.read<uint32_t>();
|
||||
assert(compressedSize <= std::pow(2, 24));
|
||||
std::u8string compressed(compressedSize, '\0');
|
||||
co_await sock.read((std::byte*) compressed.data(), compressedSize);
|
||||
|
||||
PP_Content_ChunkNodes *packet = new PP_Content_ChunkNodes(
|
||||
ToClient::L1::Content,
|
||||
(uint8_t) ToClient::L2Content::ChunkVoxels,
|
||||
(uint8_t) ToClient::L2Content::ChunkNodes,
|
||||
wcId,
|
||||
pos,
|
||||
nodes.data()
|
||||
pos
|
||||
);
|
||||
|
||||
unCompressNodes(compressed, (Node*) packet->Nodes);
|
||||
|
||||
while(!NetInputPackets.push(packet));
|
||||
|
||||
co_return;
|
||||
|
||||
@@ -93,6 +93,11 @@ Vulkan::Vulkan(asio::io_context &ioc)
|
||||
LOG.error() << "Vulkan::run: " << exc.what();
|
||||
}
|
||||
|
||||
try {
|
||||
if(Graphics.Window)
|
||||
glfwSetWindowAttrib(Graphics.Window, GLFW_VISIBLE, false);
|
||||
} catch(...) {}
|
||||
|
||||
try { Game.RSession = nullptr; } catch(const std::exception &exc) {
|
||||
LOG.error() << "Game.RSession = nullptr: " << exc.what();
|
||||
}
|
||||
@@ -3832,7 +3837,7 @@ void AtlasImage::atlasChangeTextureData(uint16_t id, const uint32_t *rgba)
|
||||
InfoSubTexture *info = const_cast<InfoSubTexture*>(atlasGetTextureInfo(id));
|
||||
|
||||
auto iter = CachedData.find(id);
|
||||
// Если есть данные в кэше, то меняем их
|
||||
// Если есть данные в кеше, то меняем их
|
||||
if(iter != CachedData.end())
|
||||
{
|
||||
if(iter->second.size() == 0)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Client/Abstract.hpp"
|
||||
#include "Client/Vulkan/Vulkan.hpp"
|
||||
#include "Common/Abstract.hpp"
|
||||
#include "TOSLib.hpp"
|
||||
#include "assets.hpp"
|
||||
#include "glm/ext/matrix_transform.hpp"
|
||||
#include "glm/trigonometric.hpp"
|
||||
@@ -198,10 +199,10 @@ void VulkanRenderSession::init(Vulkan *instance) {
|
||||
int width, height;
|
||||
bool hasAlpha;
|
||||
for(const char *path : {
|
||||
"grass.png",
|
||||
"tropical_rainforest_wood.png",
|
||||
"willow_wood.png",
|
||||
"xnether_blue_wood.png",
|
||||
//"tropical_rainforest_wood.png",
|
||||
"grass.png",
|
||||
"willow_wood.png",
|
||||
//"xnether_blue_wood.png",
|
||||
"xnether_purple_wood.png"
|
||||
}) {
|
||||
ByteBuffer image = VK::loadPNG(getResource(std::string("textures/") + path)->makeStream().Stream, width, height, hasAlpha);
|
||||
@@ -612,7 +613,7 @@ void VulkanRenderSession::onContentDefinesLost(std::unordered_map<EnumDefContent
|
||||
}
|
||||
|
||||
void VulkanRenderSession::onChunksChange(WorldId_t worldId, const std::unordered_set<Pos::GlobalChunk>& changeOrAddList, const std::unordered_set<Pos::GlobalRegion>& remove) {
|
||||
auto &table = External.ChunkVoxelMesh[worldId];
|
||||
auto &table = External.ChunkVoxelMesh[worldId];
|
||||
|
||||
for(Pos::GlobalChunk pos : changeOrAddList) {
|
||||
Pos::GlobalRegion rPos = pos >> 4;
|
||||
@@ -625,7 +626,9 @@ auto &table = External.ChunkVoxelMesh[worldId];
|
||||
if(iter != table.end())
|
||||
table.erase(iter);
|
||||
} else {
|
||||
Logger("Test").debug() << voxels.size();
|
||||
std::vector<VoxelVertexPoint> vertexs = generateMeshForVoxelChunks(voxels);
|
||||
Logger("Test").debug() << vertexs.size();
|
||||
|
||||
if(!vertexs.empty()) {
|
||||
auto &buffer = table[pos] = std::make_unique<Buffer>(VkInst, vertexs.size()*sizeof(VoxelVertexPoint));
|
||||
@@ -743,9 +746,9 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
|
||||
|
||||
for(const VoxelCube &cube : cubes) {
|
||||
out.emplace_back(
|
||||
cube.Left.x,
|
||||
cube.Left.y,
|
||||
cube.Left.z,
|
||||
cube.Pos.x,
|
||||
cube.Pos.y,
|
||||
cube.Pos.z,
|
||||
0,
|
||||
0, 0,
|
||||
cube.Size.x,
|
||||
@@ -756,9 +759,9 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
|
||||
);
|
||||
|
||||
out.emplace_back(
|
||||
cube.Left.x,
|
||||
cube.Left.y,
|
||||
cube.Left.z,
|
||||
cube.Pos.x,
|
||||
cube.Pos.y,
|
||||
cube.Pos.z,
|
||||
1,
|
||||
0, 0,
|
||||
cube.Size.x,
|
||||
@@ -769,9 +772,9 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
|
||||
);
|
||||
|
||||
out.emplace_back(
|
||||
cube.Left.x,
|
||||
cube.Left.y,
|
||||
cube.Left.z,
|
||||
cube.Pos.x,
|
||||
cube.Pos.y,
|
||||
cube.Pos.z,
|
||||
2,
|
||||
0, 0,
|
||||
cube.Size.z,
|
||||
@@ -782,9 +785,9 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
|
||||
);
|
||||
|
||||
out.emplace_back(
|
||||
cube.Left.x,
|
||||
cube.Left.y+cube.Size.y+1,
|
||||
cube.Left.z,
|
||||
cube.Pos.x,
|
||||
cube.Pos.y+cube.Size.y+1,
|
||||
cube.Pos.z,
|
||||
3,
|
||||
0, 0,
|
||||
cube.Size.x,
|
||||
@@ -795,9 +798,9 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
|
||||
);
|
||||
|
||||
out.emplace_back(
|
||||
cube.Left.x,
|
||||
cube.Left.y,
|
||||
cube.Left.z+cube.Size.z+1,
|
||||
cube.Pos.x,
|
||||
cube.Pos.y,
|
||||
cube.Pos.z+cube.Size.z+1,
|
||||
4,
|
||||
0, 0,
|
||||
cube.Size.x,
|
||||
@@ -808,9 +811,9 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
|
||||
);
|
||||
|
||||
out.emplace_back(
|
||||
cube.Left.x+cube.Size.x+1,
|
||||
cube.Left.y,
|
||||
cube.Left.z,
|
||||
cube.Pos.x+cube.Size.x+1,
|
||||
cube.Pos.y,
|
||||
cube.Pos.z,
|
||||
5,
|
||||
0, 0,
|
||||
cube.Size.z,
|
||||
|
||||
Reference in New Issue
Block a user