This commit is contained in:
2025-07-10 17:06:53 +06:00
parent c0989a53ea
commit 62959a36b2
21 changed files with 2053 additions and 88 deletions

View File

@@ -286,6 +286,7 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) {
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) {
@@ -293,11 +294,12 @@ void ServerSession::atFreeDrawTime(GlobalTime gTime, float dTime) {
auto &regions = Data.Worlds[p.Id].Regions;
auto obj = regions.find(p.Pos);
assert(obj != regions.end());
regions.erase(obj);
if(obj != regions.end()) {
regions.erase(obj);
auto &pair = changeOrAddList_removeList[p.Id];
std::get<1>(pair).insert(p.Pos);
auto &pair = changeOrAddList_removeList[p.Id];
std::get<1>(pair).insert(p.Pos);
}
}
}
@@ -583,7 +585,7 @@ coro<> ServerSession::rP_Content(Net::AsyncSocket &sock) {
co_return;
case ToClient::L2Content::RemoveRegion: {
WorldId_t wcId = co_await sock.read<uint8_t>();
WorldId_t wcId = co_await sock.read<WorldId_t>();
Pos::GlobalChunk pos;
pos.unpack(co_await sock.read<Pos::GlobalRegion::Pack>());

View File

@@ -14,6 +14,7 @@ namespace LV::Client::VK {
Получаемые вершины сначала пишутся в общий буфер, потом передаются на устройство
*/
// Нужна реализация индексного буфера
template<typename Vertex, uint16_t PerBlock = 1 << 10, uint16_t PerPool = 1 << 12>
class VertexPool {
static constexpr size_t HC_Buffer_Size = size_t(PerBlock)*size_t(PerPool);
@@ -63,8 +64,9 @@ private:
// Пишем в общий буфер, TasksWait
Vertex *ptr = HCPtr+WritePos;
std::copy(data.begin(), data.end(), ptr);
size_t count = data.size();
TasksWait.push({std::move(data), WritePos, poolId, blockId});
WritePos += data.size();
WritePos += count;
} else {
// Отложим запись на следующий такт
TasksPostponed.push(Task(std::move(data), -1, poolId, blockId));
@@ -219,7 +221,9 @@ public:
void update(VkCommandPool commandPool) {
if(TasksWait.empty())
return;
assert(WritePos);
VkCommandBufferAllocateInfo allocInfo {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
nullptr,
@@ -240,6 +244,28 @@ public:
vkBeginCommandBuffer(commandBuffer, &beginInfo);
VkBufferMemoryBarrier barrier = {
VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
nullptr,
VK_ACCESS_HOST_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
HostCoherent.getBuffer(),
0,
WritePos*sizeof(Vertex)
};
vkCmdPipelineBarrier(
commandBuffer,
VK_PIPELINE_STAGE_HOST_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
0, nullptr,
1, &barrier,
0, nullptr
);
while(!TasksWait.empty()) {
Task& task = TasksWait.front();

View File

@@ -7,6 +7,7 @@
#include "Client/ServerSession.hpp"
#include "Common/Async.hpp"
#include "Common/Net.hpp"
#include "TOSLib.hpp"
#include "assets.hpp"
#include "imgui.h"
#include <GLFW/glfw3.h>
@@ -216,6 +217,7 @@ void Vulkan::run()
} else if (err == VK_SUBOPTIMAL_KHR)
{
LOGGER.debug() << "VK_SUBOPTIMAL_KHR Pre";
continue;
} else if(err == VK_SUCCESS) {
Screen.State = DrawState::Drawing;
@@ -2079,6 +2081,17 @@ void Vulkan::gui_MainMenu() {
ImGui::InputText("Username", ConnectionProgress.Username, sizeof(ConnectionProgress.Username));
ImGui::InputText("Password", ConnectionProgress.Password, sizeof(ConnectionProgress.Password), ImGuiInputTextFlags_Password);
static bool flag = false;
if(!flag) {
flag = true;
Game.Server = std::make_unique<ServerObj>(IOC);
ConnectionProgress.Progress = "Сервер запущен на порту " + std::to_string(Game.Server->LS.getPort());
ConnectionProgress.InProgress = true;
ConnectionProgress.Cancel = false;
ConnectionProgress.Progress.clear();
co_spawn(ConnectionProgress.connect(IOC));
}
if(!ConnectionProgress.InProgress && !ConnectionProgress.Socket) {
if(ImGui::Button("Подключиться")) {
ConnectionProgress.InProgress = true;
@@ -3510,6 +3523,8 @@ void DynamicImage::changeData(int32_t x, int32_t y, uint16_t width, uint16_t hei
// Выполняем все команды
buffer.execute();
Time::sleep3(50);
// Удаляем не нужную картинку
vkDestroyImage(Instance->Graphics.Device, tempImage, nullptr);
vkFreeMemory(Instance->Graphics.Device, tempMemory, nullptr);

View File

@@ -197,12 +197,18 @@ void VulkanRenderSession::init(Vulkan *instance) {
return true;
});
{
uint16_t texId = VKCTX->MainTest.atlasAddTexture(2, 2);
uint32_t colors[4] = {0xfffffffful, 0x00fffffful, 0xffffff00ul, 0xff00fffful};
VKCTX->MainTest.atlasChangeTextureData(texId, (const uint32_t*) colors);
}
int width, height;
bool hasAlpha;
for(const char *path : {
"grass.png",
"tropical_rainforest_wood.png",
"willow_wood.png",
"tropical_rainforest_wood.png",
"xnether_blue_wood.png",
"xnether_purple_wood.png"
}) {
@@ -617,12 +623,6 @@ 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;
@@ -639,6 +639,7 @@ void VulkanRenderSession::onChunksChange(WorldId_t worldId, const std::unordered
}
std::vector<NodeVertexStatic> vertexs2 = generateMeshForNodeChunks(chunk.Nodes);
if(vertexs2.empty()) {
VKCTX->VertexPool_Nodes.dropVertexs(std::get<1>(buffers));
} else {
@@ -697,7 +698,7 @@ void VulkanRenderSession::drawWorld(GlobalTime gTime, float dTime, VkCommandBuff
// Сместить в координаты игрока, повернуть относительно взгляда проецировать на экран
// Изначально взгляд в z-1
PCO.ProjView = glm::mat4(1);
PCO.ProjView = glm::translate(PCO.ProjView, -glm::vec3(Pos)/float(Pos::Object_t::BS));
PCO.ProjView = glm::translate(PCO.ProjView, -glm::vec3(Pos.z, Pos.y, Pos.x)/float(Pos::Object_t::BS));
PCO.ProjView = proj*glm::mat4(Quat)*PCO.ProjView;
PCO.Model = glm::mat4(1);
@@ -771,7 +772,7 @@ void VulkanRenderSession::drawWorld(GlobalTime gTime, float dTime, VkCommandBuff
for(auto &pair : iterWorld->second) {
if(auto& nodes = std::get<1>(pair.second)) {
glm::vec3 cpos(pair.first.x, pair.first.y, pair.first.z);
glm::vec3 cpos(pair.first.z, pair.first.y, pair.first.x);
PCO.Model = glm::translate(orig, cpos*16.f);
auto [vkBuffer, offset] = VKCTX->VertexPool_Nodes.map(nodes);