Ресурсы

This commit is contained in:
2025-09-02 16:41:55 +06:00
parent 4eef3ca211
commit a1b84053d4
6 changed files with 59 additions and 21 deletions

View File

@@ -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<int>(byte);
return ss.str();
}
}

View File

@@ -204,6 +204,7 @@ private:
size_t maxCacheDatabaseSize, size_t maxLifeTime);
void readWriteThread(AsyncUseControl::Lock lock);
std::string hashToString(const Hash_t& hash);
};
}

View File

@@ -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<uint32_t>();
AssetLoading& al = AsyncContext.AssetsLoading.at(hash);
if(al.Data.size()-al.Offset < size)
MAKE_ERROR("Несоответствие ожидаемого размера ресурса");
try {
uint32_t size = co_await sock.read<uint32_t>();
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;

View File

@@ -1452,6 +1452,8 @@ void VulkanRenderSession::drawWorld(GlobalTime gTime, float dTime, VkCommandBuff
PCO.Model = orig;
}
CP.pushFrame();
}
void VulkanRenderSession::pushStage(EnumRenderStage stage) {

View File

@@ -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 - радиус в регионах

View File

@@ -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);
}