Сейчас оно компилируется, пересмотр расчёта зон наблюдения

This commit is contained in:
2025-06-29 11:55:46 +06:00
parent e083510525
commit cfc80660dd
17 changed files with 1286 additions and 893 deletions

View File

@@ -34,7 +34,12 @@ struct GlobalTime {
};
struct VoxelCube {
DefVoxelId_t VoxelId;
union {
struct {
DefVoxelId_t VoxelId : 24, Meta : 8;
};
DefVoxelId_t Data;
};
Pos::bvec256u Left, Size;
};
@@ -77,39 +82,32 @@ public:
virtual void onBinaryResourceAdd(std::unordered_map<EnumBinResource, std::unordered_map<ResourceId_t, BinaryResource>>) = 0;
virtual void onBinaryResourceLost(std::unordered_map<EnumBinResource, std::vector<ResourceId_t>>) = 0;
// Профили использования двоичных ресурсов
// В этом месте нужно зарание распарсить
virtual void onBinaryProfileAdd(std::unordered_map<EnumBinResource, std::unordered_map<ResourceId_t, std::u8string>>) = 0;
virtual void onBinaryProfileLost(std::unordered_map<EnumBinResource, std::vector<ResourceId_t>>) = 0;
virtual void onContentDefines(std::unordered_map<EnumDefContent, std::unordered_map<>>);
EnumDefContent
virtual void onDefWorldUpdates(const std::vector<DefWorldId_c> &updates) = 0;
virtual void onDefVoxelUpdates(const std::vector<DefVoxelId_c> &updates) = 0;
virtual void onDefNodeUpdates(const std::vector<DefNodeId_c> &updates) = 0;
virtual void onDefPortalUpdates(const std::vector<DefPortalId_c> &updates) = 0;
virtual void onDefEntityUpdates(const std::vector<DefEntityId_c> &updates) = 0;
virtual void onContentDefinesAdd(std::unordered_map<EnumDefContent, std::unordered_map<ResourceId_t, std::u8string>>) = 0;
virtual void onContentDefinesLost(std::unordered_map<EnumDefContent, std::vector<ResourceId_t>>) = 0;
// Сообщаем об изменившихся чанках
virtual void onChunksChange(WorldId_c worldId, const std::unordered_set<Pos::GlobalChunk> &changeOrAddList, const std::unordered_set<Pos::GlobalChunk> &remove) = 0;
virtual void onChunksChange(WorldId_t worldId, const std::unordered_set<Pos::GlobalChunk> &changeOrAddList, const std::unordered_set<Pos::GlobalChunk> &remove) = 0;
// Установить позицию для камеры
virtual void setCameraPos(WorldId_c worldId, Pos::Object pos, glm::quat quat) = 0;
virtual void setCameraPos(WorldId_t worldId, Pos::Object pos, glm::quat quat) = 0;
virtual ~IRenderSession();
};
struct Region {
std::unordered_map<Pos::Local16_u, Chunk> Chunks;
std::unordered_map<Pos::bvec16u, Chunk> Chunks;
};
struct World {
std::vector<EntityId_c> Entitys;
std::unordered_map<Pos::GlobalRegion::Key, Region> Regions;
};
struct DefVoxelInfo {
};
struct DefNodeInfo {
};
struct DefWorldInfo {
@@ -123,10 +121,16 @@ struct DefEntityInfo {
};
struct WorldInfo {
struct DefFuncEntityInfo {
};
struct WorldInfo {
std::vector<EntityId_t> Entitys;
std::vector<FuncEntityId_t> FuncEntitys;
std::unordered_map<Pos::GlobalRegion, Region> Regions;
};
struct VoxelInfo {
};
@@ -143,24 +147,33 @@ struct EntityInfo {
};
struct FuncEntityInfo {
};
struct DefItemInfo {
};
/* Интерфейс обработчика сессии с сервером */
class IServerSession {
public:
struct {
std::unordered_map<DefWorldId_c, DefWorldInfo> DefWorlds;
std::unordered_map<DefVoxelId_c, VoxelInfo> DefVoxels;
std::unordered_map<DefNodeId_c, NodeInfo> DefNodes;
std::unordered_map<DefPortalId_c, DefPortalInfo> DefPortals;
std::unordered_map<DefEntityId_c, DefEntityInfo> DefEntityes;
std::unordered_map<WorldId_c, WorldInfo> Worlds;
std::unordered_map<PortalId_c, PortalInfo> Portals;
std::unordered_map<EntityId_c, EntityInfo> Entityes;
std::unordered_map<DefVoxelId_t, DefVoxelInfo> DefVoxel;
std::unordered_map<DefNodeId_t, DefNodeInfo> DefNode;
std::unordered_map<DefWorldId_t, DefWorldInfo> DefWorld;
std::unordered_map<DefPortalId_t, DefPortalInfo> DefPortal;
std::unordered_map<DefEntityId_t, DefEntityInfo> DefEntity;
std::unordered_map<DefFuncEntityId_t, DefFuncEntityInfo> DefFuncEntity;
std::unordered_map<DefItemId_t, DefItemInfo> DefItem;
} Registry;
struct {
std::unordered_map<WorldId_c, World> Worlds;
} External;
std::unordered_map<WorldId_t, WorldInfo> Worlds;
std::unordered_map<PortalId_t, PortalInfo> Portals;
std::unordered_map<EntityId_t, EntityInfo> Entityes;
std::unordered_map<FuncEntityId_t, FuncEntityInfo> FuncEntityes;
} Data;
virtual ~IServerSession();

View File

@@ -20,20 +20,20 @@ namespace LV::Client {
ParsedPacket::~ParsedPacket() = default;
struct PP_Content_ChunkVoxels : public ParsedPacket {
WorldId_c Id;
WorldId_t Id;
Pos::GlobalChunk Pos;
std::vector<VoxelCube> Cubes;
PP_Content_ChunkVoxels(ToClient::L1 l1, uint8_t l2, WorldId_c id, Pos::GlobalChunk pos, std::vector<VoxelCube> &&cubes)
PP_Content_ChunkVoxels(ToClient::L1 l1, uint8_t l2, WorldId_t id, Pos::GlobalChunk pos, std::vector<VoxelCube> &&cubes)
: ParsedPacket(l1, l2), Id(id), Pos(pos), Cubes(std::move(cubes))
{}
};
struct PP_Content_ChunkRemove : public ParsedPacket {
WorldId_c Id;
WorldId_t Id;
Pos::GlobalChunk Pos;
PP_Content_ChunkRemove(ToClient::L1 l1, uint8_t l2, WorldId_c id, Pos::GlobalChunk pos)
PP_Content_ChunkRemove(ToClient::L1 l1, uint8_t l2, WorldId_t id, Pos::GlobalChunk pos)
: ParsedPacket(l1, l2), Id(id), Pos(pos)
{}
};
@@ -252,7 +252,7 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) {
Speed += glm::vec3(0, 1, 0)*float(Keys.SPACE)*mltpl;
{
std::unordered_map<WorldId_c, std::tuple<std::unordered_set<Pos::GlobalChunk>, std::unordered_set<Pos::GlobalChunk>>> changeOrAddList_removeList;
std::unordered_map<WorldId_t, std::tuple<std::unordered_set<Pos::GlobalChunk>, std::unordered_set<Pos::GlobalChunk>>> changeOrAddList_removeList;
// Пакеты
ParsedPacket *pack;
@@ -261,19 +261,19 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) {
ToClient::L2Content l2 = ToClient::L2Content(pack->Level2);
if(l2 == ToClient::L2Content::ChunkVoxels) {
PP_Content_ChunkVoxels &p = *dynamic_cast<PP_Content_ChunkVoxels*>(pack);
Pos::GlobalRegion rPos(p.Pos.X >> 4, p.Pos.Y >> 4, p.Pos.Z >> 4);
Pos::Local16_u cPos(p.Pos.X & 0xf, p.Pos.Y & 0xf, p.Pos.Z & 0xf);
Pos::GlobalRegion rPos = p.Pos >> 2;
Pos::bvec4u cPos = p.Pos & 0x3;
External.Worlds[p.Id].Regions[rPos].Chunks[cPos].Voxels = std::move(p.Cubes);
Data.Worlds[p.Id].Regions[rPos].Chunks[cPos].Voxels = std::move(p.Cubes);
auto &pair = changeOrAddList_removeList[p.Id];
std::get<0>(pair).insert(p.Pos);
} else if(l2 == ToClient::L2Content::RemoveChunk) {
PP_Content_ChunkRemove &p = *dynamic_cast<PP_Content_ChunkRemove*>(pack);
Pos::GlobalRegion rPos(p.Pos.X >> 4, p.Pos.Y >> 4, p.Pos.Z >> 4);
Pos::Local16_u cPos(p.Pos.X & 0xf, p.Pos.Y & 0xf, p.Pos.Z & 0xf);
auto &obj = External.Worlds[p.Id].Regions[rPos].Chunks;
Pos::GlobalRegion rPos = p.Pos >> 2;
Pos::bvec4u cPos = p.Pos & 0x3;
auto &obj = Data.Worlds[p.Id].Regions[rPos].Chunks;
auto iter = obj.find(cPos);
if(iter != obj.end())
obj.erase(iter);
@@ -443,22 +443,22 @@ coro<> ServerSession::rP_Definition(Net::AsyncSocket &sock) {
switch((ToClient::L2Definition) second) {
case ToClient::L2Definition::World: {
DefWorldId_c cdId = co_await sock.read<DefWorldId_c>();
DefWorldId_t cdId = co_await sock.read<DefWorldId_t>();
co_return;
}
case ToClient::L2Definition::FreeWorld: {
DefWorldId_c cdId = co_await sock.read<DefWorldId_c>();
DefWorldId_t cdId = co_await sock.read<DefWorldId_t>();
co_return;
}
case ToClient::L2Definition::Voxel: {
DefVoxelId_c cdId = co_await sock.read<DefVoxelId_c>();
DefVoxelId_t cdId = co_await sock.read<DefVoxelId_t>();
co_return;
}
case ToClient::L2Definition::FreeVoxel: {
DefVoxelId_c cdId = co_await sock.read<DefVoxelId_c>();
DefVoxelId_t cdId = co_await sock.read<DefVoxelId_t>();
co_return;
}
@@ -509,9 +509,9 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
co_return;
case ToClient::L2Content::ChunkVoxels:
{
WorldId_c wcId = co_await sock.read<WorldId_c>();
Pos::GlobalChunk::Key posKey = co_await sock.read<Pos::GlobalChunk::Key>();
Pos::GlobalChunk pos = *(Pos::GlobalChunk*) &posKey;
WorldId_t wcId = co_await sock.read<WorldId_t>();
Pos::GlobalChunk pos;
pos.unpack(co_await sock.read<Pos::GlobalChunk::Pack>());
std::vector<VoxelCube> cubes(co_await sock.read<uint16_t>());
uint16_t debugCubesCount = cubes.size();
@@ -522,13 +522,13 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
for(size_t iter = 0; iter < cubes.size(); iter++) {
VoxelCube &cube = cubes[iter];
cube.VoxelId = co_await sock.read<uint16_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>();
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>();
}
PP_Content_ChunkVoxels *packet = new PP_Content_ChunkVoxels(
@@ -551,9 +551,9 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
co_return;
case ToClient::L2Content::RemoveChunk: {
WorldId_c wcId = co_await sock.read<uint8_t>();
Pos::GlobalChunk::Key posKey = co_await sock.read<Pos::GlobalChunk::Key>();
Pos::GlobalChunk pos = *(Pos::GlobalChunk*) &posKey;
WorldId_t wcId = co_await sock.read<uint8_t>();
Pos::GlobalChunk pos;
pos.unpack(co_await sock.read<Pos::GlobalChunk::Pack>());
PP_Content_ChunkRemove *packet = new PP_Content_ChunkRemove(
ToClient::L1::Content,

View File

@@ -232,16 +232,16 @@ void VulkanRenderSession::init(Vulkan *instance) {
{
std::vector<VoxelCube> cubes;
cubes.emplace_back(0, Pos::Local256_u{0, 0, 0}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(1, Pos::Local256_u{255, 0, 0}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(1, Pos::Local256_u{0, 255, 0}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(1, Pos::Local256_u{0, 0, 255}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(2, Pos::Local256_u{255, 255, 0}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(2, Pos::Local256_u{0, 255, 255}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(2, Pos::Local256_u{255, 0, 255}, Pos::Local256_u{0, 0, 0});
cubes.emplace_back(3, Pos::Local256_u{255, 255, 255}, Pos::Local256_u{0, 0, 0});
cubes.push_back({0, 0, Pos::bvec256u{0, 0, 0}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({1, 0, Pos::bvec256u{255, 0, 0}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({1, 0, Pos::bvec256u{0, 255, 0}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({1, 0, Pos::bvec256u{0, 0, 255}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({2, 0, Pos::bvec256u{255, 255, 0}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({2, 0, Pos::bvec256u{0, 255, 255}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({2, 0, Pos::bvec256u{255, 0, 255}, Pos::bvec256u{0, 0, 0}});
cubes.push_back({3, 0, Pos::bvec256u{255, 255, 255}, Pos::bvec256u{0, 0, 0}});
cubes.emplace_back(4, Pos::Local256_u{64, 64, 64}, Pos::Local256_u{127, 127, 127});
cubes.push_back({4, 0, Pos::bvec256u{64, 64, 64}, Pos::bvec256u{127, 127, 127}});
std::vector<VoxelVertexPoint> vertexs = generateMeshForVoxelChunks(cubes);
@@ -595,50 +595,30 @@ void VulkanRenderSession::init(Vulkan *instance) {
}
}
void VulkanRenderSession::onDefTexture(TextureId_c id, std::vector<std::byte> &&info) {
void VulkanRenderSession::onBinaryResourceAdd(std::unordered_map<EnumBinResource, std::unordered_map<ResourceId_t, BinaryResource>>) {
}
void VulkanRenderSession::onDefTextureLost(const std::vector<TextureId_c> &&lost) {
void VulkanRenderSession::onBinaryResourceLost(std::unordered_map<EnumBinResource, std::vector<ResourceId_t>>) {
}
void VulkanRenderSession::onDefModel(ModelId_c id, std::vector<std::byte> &&info) {
void VulkanRenderSession::onContentDefinesAdd(std::unordered_map<EnumDefContent, std::unordered_map<ResourceId_t, std::u8string>>) {
}
void VulkanRenderSession::onDefModelLost(const std::vector<ModelId_c> &&lost) {
void VulkanRenderSession::onContentDefinesLost(std::unordered_map<EnumDefContent, std::vector<ResourceId_t>>) {
}
void VulkanRenderSession::onDefWorldUpdates(const std::vector<DefWorldId_c> &updates) {
}
void VulkanRenderSession::onDefVoxelUpdates(const std::vector<DefVoxelId_c> &updates) {
}
void VulkanRenderSession::onDefNodeUpdates(const std::vector<DefNodeId_c> &updates) {
}
void VulkanRenderSession::onDefPortalUpdates(const std::vector<DefPortalId_c> &updates) {
}
void VulkanRenderSession::onDefEntityUpdates(const std::vector<DefEntityId_c> &updates) {
}
void VulkanRenderSession::onChunksChange(WorldId_c worldId, const std::unordered_set<Pos::GlobalChunk> &changeOrAddList, const std::unordered_set<Pos::GlobalChunk> &remove) {
auto &table = External.ChunkVoxelMesh[worldId];
void VulkanRenderSession::onChunksChange(WorldId_t worldId, const std::unordered_set<Pos::GlobalChunk> &changeOrAddList, const std::unordered_set<Pos::GlobalChunk> &remove) {
auto &table = External.ChunkVoxelMesh[worldId];
for(Pos::GlobalChunk pos : changeOrAddList) {
Pos::GlobalRegion rPos(pos.X >> 4, pos.Y >> 4, pos.Z >> 4);
Pos::Local16_u cPos(pos.X & 0xf, pos.Y & 0xf, pos.Z & 0xf);
Pos::GlobalRegion rPos = pos >> 4;
Pos::bvec16u cPos = pos & 0xf;
const auto &voxels = ServerSession->External.Worlds[worldId].Regions[rPos].Chunks[cPos].Voxels;
const auto &voxels = ServerSession->Data.Worlds[worldId].Regions[rPos].Chunks[cPos].Voxels;
if(voxels.empty()) {
auto iter = table.find(pos);
@@ -669,7 +649,7 @@ void VulkanRenderSession::onChunksChange(WorldId_c worldId, const std::unordered
External.ChunkVoxelMesh.erase( External.ChunkVoxelMesh.find(worldId));
}
void VulkanRenderSession::setCameraPos(WorldId_c worldId, Pos::Object pos, glm::quat quat) {
void VulkanRenderSession::setCameraPos(WorldId_t worldId, Pos::Object pos, glm::quat quat) {
WorldId = worldId;
Pos = pos;
Quat = quat;
@@ -738,7 +718,7 @@ void VulkanRenderSession::drawWorld(GlobalTime gTime, float dTime, VkCommandBuff
glm::mat4 orig = PCO.Model;
for(auto &pair : iterWorld->second) {
glm::vec3 cpos(pair.first.X, pair.first.Y, pair.first.Z);
glm::vec3 cpos(pair.first.x, pair.first.y, pair.first.z);
PCO.Model = glm::translate(orig, cpos*16.f);
vkBuffer = *pair.second;
@@ -759,78 +739,78 @@ std::vector<VoxelVertexPoint> VulkanRenderSession::generateMeshForVoxelChunks(co
for(const VoxelCube &cube : cubes) {
out.emplace_back(
cube.Left.X,
cube.Left.Y,
cube.Left.Z,
cube.Left.x,
cube.Left.y,
cube.Left.z,
0,
0, 0,
cube.Size.X,
cube.Size.Z,
cube.Size.x,
cube.Size.z,
cube.VoxelId,
0, 0,
0
);
out.emplace_back(
cube.Left.X,
cube.Left.Y,
cube.Left.Z,
cube.Left.x,
cube.Left.y,
cube.Left.z,
1,
0, 0,
cube.Size.X,
cube.Size.Y,
cube.Size.x,
cube.Size.y,
cube.VoxelId,
0, 0,
0
);
out.emplace_back(
cube.Left.X,
cube.Left.Y,
cube.Left.Z,
cube.Left.x,
cube.Left.y,
cube.Left.z,
2,
0, 0,
cube.Size.Z,
cube.Size.Y,
cube.Size.z,
cube.Size.y,
cube.VoxelId,
0, 0,
0
);
out.emplace_back(
cube.Left.X,
cube.Left.Y+cube.Size.Y+1,
cube.Left.Z,
cube.Left.x,
cube.Left.y+cube.Size.y+1,
cube.Left.z,
3,
0, 0,
cube.Size.X,
cube.Size.Z,
cube.Size.x,
cube.Size.z,
cube.VoxelId,
0, 0,
0
);
out.emplace_back(
cube.Left.X,
cube.Left.Y,
cube.Left.Z+cube.Size.Z+1,
cube.Left.x,
cube.Left.y,
cube.Left.z+cube.Size.z+1,
4,
0, 0,
cube.Size.X,
cube.Size.Y,
cube.Size.x,
cube.Size.y,
cube.VoxelId,
0, 0,
0
);
out.emplace_back(
cube.Left.X+cube.Size.X+1,
cube.Left.Y,
cube.Left.Z,
cube.Left.x+cube.Size.x+1,
cube.Left.y,
cube.Left.z,
5,
0, 0,
cube.Size.Z,
cube.Size.Y,
cube.Size.z,
cube.Size.y,
cube.VoxelId,
0, 0,
0

View File

@@ -78,7 +78,7 @@ class VulkanRenderSession : public IRenderSession, public IVulkanDependent {
IServerSession *ServerSession = nullptr;
// Положение камеры
WorldId_c WorldId;
WorldId_t WorldId;
Pos::Object Pos;
glm::quat Quat;
@@ -130,10 +130,10 @@ class VulkanRenderSession : public IRenderSession, public IVulkanDependent {
NodeStaticTransparentPipeline = VK_NULL_HANDLE;
std::map<TextureId_c, uint16_t> ServerToAtlas;
std::map<BinTextureId_t, uint16_t> ServerToAtlas;
struct {
std::unordered_map<WorldId_c, std::unordered_map<Pos::GlobalChunk, std::unique_ptr<Buffer>>> ChunkVoxelMesh;
std::unordered_map<WorldId_t, std::unordered_map<Pos::GlobalChunk, std::unique_ptr<Buffer>>> ChunkVoxelMesh;
} External;
virtual void free(Vulkan *instance) override;
@@ -151,19 +151,12 @@ public:
assert(serverSession);
}
virtual void onDefTexture(TextureId_c id, std::vector<std::byte> &&info) override;
virtual void onDefTextureLost(const std::vector<TextureId_c> &&lost) override;
virtual void onDefModel(ModelId_c id, std::vector<std::byte> &&info) override;
virtual void onDefModelLost(const std::vector<ModelId_c> &&lost) override;
virtual void onDefWorldUpdates(const std::vector<DefWorldId_c> &updates) override;
virtual void onDefVoxelUpdates(const std::vector<DefVoxelId_c> &updates) override;
virtual void onDefNodeUpdates(const std::vector<DefNodeId_c> &updates) override;
virtual void onDefPortalUpdates(const std::vector<DefPortalId_c> &updates) override;
virtual void onDefEntityUpdates(const std::vector<DefEntityId_c> &updates) override;
virtual void onChunksChange(WorldId_c worldId, const std::unordered_set<Pos::GlobalChunk> &changeOrAddList, const std::unordered_set<Pos::GlobalChunk> &remove) override;
virtual void setCameraPos(WorldId_c worldId, Pos::Object pos, glm::quat quat) override;
virtual void onBinaryResourceAdd(std::unordered_map<EnumBinResource, std::unordered_map<ResourceId_t, BinaryResource>>) override;
virtual void onBinaryResourceLost(std::unordered_map<EnumBinResource, std::vector<ResourceId_t>>) override;
virtual void onContentDefinesAdd(std::unordered_map<EnumDefContent, std::unordered_map<ResourceId_t, std::u8string>>) override;
virtual void onContentDefinesLost(std::unordered_map<EnumDefContent, std::vector<ResourceId_t>>) override;
virtual void onChunksChange(WorldId_t worldId, const std::unordered_set<Pos::GlobalChunk> &changeOrAddList, const std::unordered_set<Pos::GlobalChunk> &remove) override;
virtual void setCameraPos(WorldId_t worldId, Pos::Object pos, glm::quat quat) override;
glm::mat4 calcViewMatrix(glm::quat quat, glm::vec3 camOffset = glm::vec3(0)) {
return glm::translate(glm::mat4(quat), camOffset);