From a1b84053d4da2bcb885e8f74bfad8977a24fdff3 Mon Sep 17 00:00:00 2001 From: DrSocalkwe3n Date: Tue, 2 Sep 2025 16:41:55 +0600 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=81=D1=83=D1=80=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Client/AssetsManager.cpp | 31 ++++++++++++++++++----- Src/Client/AssetsManager.hpp | 1 + Src/Client/ServerSession.cpp | 30 +++++++++++++--------- Src/Client/Vulkan/VulkanRenderSession.cpp | 2 ++ Src/Client/Vulkan/VulkanRenderSession.hpp | 12 +++++++++ Src/Server/RemoteClient.cpp | 4 +-- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/Src/Client/AssetsManager.cpp b/Src/Client/AssetsManager.cpp index fecf85a..22db1f0 100644 --- a/Src/Client/AssetsManager.cpp +++ b/Src/Client/AssetsManager.cpp @@ -342,16 +342,24 @@ void AssetsManager::readWriteThread(AsyncUseControl::Lock lock) { // TODO: добавить вычистку места при нехватке if(res.size() <= SMALL_RESOURCE) { - Hash_t hash = res.hash(); - sqlite3_bind_blob(STMT_INLINE_INSERT, 1, (const void*) hash.data(), 32, SQLITE_STATIC); - sqlite3_bind_int(STMT_INLINE_INSERT, 2, time(nullptr)); - sqlite3_bind_blob(STMT_INLINE_INSERT, 3, res.data(), res.size(), SQLITE_STATIC); - if(sqlite3_step(STMT_INLINE_INSERT) != SQLITE_DONE) { + Hash_t hash = res.hash(); + LOG.debug() << "Сохраняем ресурс " << hashToString(hash); + + try { + sqlite3_bind_blob(STMT_INLINE_INSERT, 1, (const void*) hash.data(), 32, SQLITE_STATIC); + sqlite3_bind_int(STMT_INLINE_INSERT, 2, time(nullptr)); + sqlite3_bind_blob(STMT_INLINE_INSERT, 3, res.data(), res.size(), SQLITE_STATIC); + if(sqlite3_step(STMT_INLINE_INSERT) != SQLITE_DONE) { + sqlite3_reset(STMT_INLINE_INSERT); + MAKE_ERROR("Не удалось выполнить подготовленный запрос STMT_INLINE_INSERT: " << sqlite3_errmsg(DB)); + } + sqlite3_reset(STMT_INLINE_INSERT); - MAKE_ERROR("Не удалось выполнить подготовленный запрос STMT_INLINE_INSERT: " << sqlite3_errmsg(DB)); + } catch(const std::exception& exc) { + LOG.error() << "Произошла ошибка при сохранении " << hashToString(hash); + throw; } - sqlite3_reset(STMT_INLINE_INSERT); } else { std::string hashKey; { @@ -395,4 +403,13 @@ void AssetsManager::readWriteThread(AsyncUseControl::Lock lock) { } } +std::string AssetsManager::hashToString(const Hash_t& hash) { + std::stringstream ss; + ss << std::hex << std::setfill('0'); + for (const auto& byte : hash) + ss << std::setw(2) << static_cast(byte); + + return ss.str(); +} + } \ No newline at end of file diff --git a/Src/Client/AssetsManager.hpp b/Src/Client/AssetsManager.hpp index 2ad541b..4ebb0d2 100644 --- a/Src/Client/AssetsManager.hpp +++ b/Src/Client/AssetsManager.hpp @@ -204,6 +204,7 @@ private: size_t maxCacheDatabaseSize, size_t maxLifeTime); void readWriteThread(AsyncUseControl::Lock lock); + std::string hashToString(const Hash_t& hash); }; } \ No newline at end of file diff --git a/Src/Client/ServerSession.cpp b/Src/Client/ServerSession.cpp index bd0df78..4607f0a 100644 --- a/Src/Client/ServerSession.cpp +++ b/Src/Client/ServerSession.cpp @@ -1080,21 +1080,27 @@ coro<> ServerSession::rP_Resource(Net::AsyncSocket &sock) { { Hash_t hash; co_await sock.read((std::byte*) hash.data(), hash.size()); - uint32_t size = co_await sock.read(); - AssetLoading& al = AsyncContext.AssetsLoading.at(hash); - if(al.Data.size()-al.Offset < size) - MAKE_ERROR("Несоответствие ожидаемого размера ресурса"); + try { + uint32_t size = co_await sock.read(); + assert(AsyncContext.AssetsLoading.contains(hash)); + AssetLoading& al = AsyncContext.AssetsLoading.at(hash); + if(al.Data.size()-al.Offset < size) + MAKE_ERROR("Несоответствие ожидаемого размера ресурса"); - co_await sock.read((std::byte*) al.Data.data() + al.Offset, size); - al.Offset += size; + co_await sock.read((std::byte*) al.Data.data() + al.Offset, size); + al.Offset += size; - if(al.Offset == al.Data.size()) { - // Ресурс полностью загружен - AsyncContext.LoadedAssets.lock()->emplace_back( - al.Type, al.Id, std::move(al.Domain), std::move(al.Key), std::move(al.Data) - ); + if(al.Offset == al.Data.size()) { + // Ресурс полностью загружен + AsyncContext.LoadedAssets.lock()->emplace_back( + al.Type, al.Id, std::move(al.Domain), std::move(al.Key), std::move(al.Data) + ); - AsyncContext.AssetsLoading.erase(AsyncContext.AssetsLoading.find(hash)); + AsyncContext.AssetsLoading.erase(AsyncContext.AssetsLoading.find(hash)); + } + } catch(const std::exception& exc) { + std::string err = exc.what(); + int g = 0; } co_return; diff --git a/Src/Client/Vulkan/VulkanRenderSession.cpp b/Src/Client/Vulkan/VulkanRenderSession.cpp index c028e2e..71dd985 100644 --- a/Src/Client/Vulkan/VulkanRenderSession.cpp +++ b/Src/Client/Vulkan/VulkanRenderSession.cpp @@ -1452,6 +1452,8 @@ void VulkanRenderSession::drawWorld(GlobalTime gTime, float dTime, VkCommandBuff PCO.Model = orig; } + + CP.pushFrame(); } void VulkanRenderSession::pushStage(EnumRenderStage stage) { diff --git a/Src/Client/Vulkan/VulkanRenderSession.hpp b/Src/Client/Vulkan/VulkanRenderSession.hpp index c06021f..22ed016 100644 --- a/Src/Client/Vulkan/VulkanRenderSession.hpp +++ b/Src/Client/Vulkan/VulkanRenderSession.hpp @@ -297,7 +297,19 @@ public: // Готовность кадров определяет когда можно удалять ненужные ресурсы, которые ещё используются в рендере void pushFrame() { + FrameRoulette = (FrameRoulette+1) % FRAME_COUNT_RESOURCE_LATENCY; + for(auto pointer : VPV_ToFree[FrameRoulette]) { + VertexPool_Voxels.dropVertexs(pointer); + } + + VPV_ToFree[FrameRoulette].clear(); + + for(auto pointer : VPN_ToFree[FrameRoulette]) { + VertexPool_Nodes.dropVertexs(pointer); + } + + VPN_ToFree[FrameRoulette].clear(); } // Выдаёт буферы для рендера в порядке от ближнего к дальнему. distance - радиус в регионах diff --git a/Src/Server/RemoteClient.cpp b/Src/Server/RemoteClient.cpp index 30bd4c6..1b5e98e 100644 --- a/Src/Server/RemoteClient.cpp +++ b/Src/Server/RemoteClient.cpp @@ -843,13 +843,13 @@ void RemoteClient::onUpdate() { p.write(res.data() + sended, willSend); sended += willSend; - if(sended == willSend) { + if(sended == res.size()) { hasFullSended = true; } } if(hasFullSended) { - for(ssize_t iter = toSend.size()-1; iter > 0; iter--) { + for(ssize_t iter = toSend.size()-1; iter >= 0; iter--) { if(std::get<4>(toSend[iter]).size() == std::get<5>(toSend[iter])) { toSend.erase(toSend.begin()+iter); }