Подстройки кодекса

This commit is contained in:
2026-01-03 22:17:39 +06:00
parent 2540439bf0
commit 2759073bb3
13 changed files with 492 additions and 69 deletions

View File

@@ -4,7 +4,7 @@
namespace LV::Server {
ContentManager::ContentManager(AssetsPreloader &am)
ContentManager::ContentManager(AssetsPreloader& am)
: AM(am)
{
std::fill(std::begin(NextId), std::end(NextId), 1);

View File

@@ -1567,7 +1567,7 @@ void GameServer::init(fs::path worldPath) {
AssetsInit.Assets.push_back(mlt.LoadChain[index].Path / "assets");
}
Content.AM.applyResourceChange(Content.AM.recheckResourcesSync(AssetsInit));
Content.AM.applyResourceChange(Content.AM.reloadResources(AssetsInit));
LOG.info() << "Пре Инициализация";
@@ -1882,7 +1882,7 @@ void GameServer::stepModInitializations() {
void GameServer::reloadMods() {
LOG.info() << "Перезагрузка модов: ассеты и зависимости";
AssetsPreloader::ResourceChangeObj changes = Content.AM.recheckResourcesSync(AssetsInit);
AssetsPreloader::Out_reloadResources changes = Content.AM.reloadResources(AssetsInit);
AssetsPreloader::Out_applyResourceChange applied = Content.AM.applyResourceChange(changes);
size_t changedCount = 0;
@@ -2687,7 +2687,7 @@ void GameServer::stepSyncContent() {
full.uniq();
// Информируем о запрошенных ассетах
std::vector<std::tuple<EnumAssets, ResourceId, const std::string, const std::string, Resource>> resources;
std::vector<std::tuple<EnumAssets, ResourceId, std::string, std::string, Resource, std::u8string>> resources;
for(int type = 0; type < (int) EnumAssets::MAX_ENUM; type++) {
for(ResourceId resId : full.AssetsInfo[type]) {
const AssetsPreloader::MediaResource* media = Content.AM.getResource((EnumAssets) type, resId);
@@ -2695,7 +2695,7 @@ void GameServer::stepSyncContent() {
continue;
Resource resource(media->Resource->data(), media->Resource->size());
resources.emplace_back((EnumAssets) type, resId, media->Domain, media->Key, std::move(resource));
resources.emplace_back((EnumAssets) type, resId, media->Domain, media->Key, std::move(resource), media->Dependencies);
}
}
@@ -2705,8 +2705,8 @@ void GameServer::stepSyncContent() {
continue;
auto& [type, id, media] = *result;
Resource resource(media->Resource->data(), media->Resource->size());
resources.emplace_back(type, id, media->Domain, media->Key, std::move(resource));
Resource resource(*media->Resource);
resources.emplace_back(type, id, media->Domain, media->Key, std::move(resource), media->Header);
}
// Информируем о запрошенных профилях

View File

@@ -11,6 +11,7 @@
#include <boost/system/system_error.hpp>
#include <exception>
#include <Common/Packets.hpp>
#include "sha2.hpp"
namespace LV::Server {
@@ -562,13 +563,14 @@ ResourceRequest RemoteClient::pushPreparedPackets() {
return std::move(nextRequest);
}
void RemoteClient::informateAssets(const std::vector<std::tuple<EnumAssets, ResourceId, const std::string, const std::string, Resource>>& resources)
void RemoteClient::informateAssets(const std::vector<std::tuple<EnumAssets, ResourceId, std::string, std::string, Resource, std::vector<uint8_t>>>& resources)
{
std::vector<std::tuple<EnumAssets, ResourceId, const std::string, const std::string, Hash_t, size_t>> newForClient;
std::vector<std::tuple<EnumAssets, ResourceId, std::string, std::string, Hash_t, std::vector<uint8_t>>> newForClient;
static std::atomic<uint32_t> debugSendLogCount = 0;
for(auto& [type, resId, domain, key, resource] : resources) {
for(auto& [type, resId, domain, key, resource, header] : resources) {
auto hash = resource.hash();
Hash_t headerHash = sha2::sha256(header.data(), header.size());
auto lock = NetworkAndResource.lock();
// Проверка запрашиваемых клиентом ресурсов
@@ -613,12 +615,13 @@ void RemoteClient::informateAssets(const std::vector<std::tuple<EnumAssets, Reso
// Посмотрим что известно клиенту
if(auto iter = lock->ResUses.AssetsUse[(int) type].find(resId);
iter != lock->ResUses.AssetsUse[(int) type].end()
&& std::get<Hash_t>(iter->second) != hash
&& (iter->second.second.Hash != hash || iter->second.second.HeaderHash != headerHash)
) {
lock.unlock();
// Требуется перепривязать идентификатор к новому хешу
newForClient.push_back({(EnumAssets) type, resId, domain, key, hash, resource.size()});
std::get<Hash_t>(iter->second) = hash;
newForClient.push_back({(EnumAssets) type, resId, domain, key, hash, header});
iter->second.second.Hash = hash;
iter->second.second.HeaderHash = headerHash;
}
}
}
@@ -628,14 +631,19 @@ void RemoteClient::informateAssets(const std::vector<std::tuple<EnumAssets, Reso
assert(newForClient.size() < 65535*4);
auto lock = NetworkAndResource.lock();
lock->checkPacketBorder(2+1+4+newForClient.size()*(1+4+64+32));
lock->checkPacketBorder(2+1+4);
lock->NextPacket << (uint8_t) ToClient::L1::Resource // Оповещение
<< ((uint8_t) ToClient::L2Resource::Bind) << uint32_t(newForClient.size());
for(auto& [type, resId, domain, key, hash, size] : newForClient) {
for(auto& [type, resId, domain, key, hash, header] : newForClient) {
// TODO: может внести ограничение на длину домена и ключа?
const size_t entrySize = 1 + 4 + 2 + domain.size() + 2 + key.size() + 32 + 4 + header.size();
lock->checkPacketBorder(entrySize);
lock->NextPacket << uint8_t(type) << uint32_t(resId) << domain << key;
lock->NextPacket.write((const std::byte*) hash.data(), hash.size());
lock->NextPacket << uint32_t(header.size());
if(!header.empty())
lock->NextPacket.write((const std::byte*) header.data(), header.size());
}
}
}

View File

@@ -212,7 +212,11 @@ class RemoteClient {
struct ResUses_t {
// Счётчики использования двоичных кэшируемых ресурсов + хэш привязанный к идентификатору
// Хэш используется для того, чтобы исключить повторные объявления неизменившихся ресурсов
std::map<ResourceId, std::pair<uint32_t, Hash_t>> AssetsUse[(int) EnumAssets::MAX_ENUM];
struct AssetBindState {
Hash_t Hash;
Hash_t HeaderHash;
};
std::map<ResourceId, std::pair<uint32_t, AssetBindState>> AssetsUse[(int) EnumAssets::MAX_ENUM];
// Зависимость профилей контента от профилей ресурсов
// Нужно чтобы пересчитать зависимости к профилям ресурсов
@@ -426,8 +430,16 @@ public:
// Сюда приходят все обновления ресурсов движка
// Глобально их можно запросить в выдаче pushPreparedPackets()
// Нужно передавать клиенту информацию о новых привязках
// id -> домен+ключ
// id -> hash+header
// По запросу клиента отправлять нужные ресурсы по hash
/// TODO: новый void informateAssets();
// Оповещение о запрошенных (и не только) ассетах
void informateAssets(const std::vector<std::tuple<EnumAssets, ResourceId, const std::string, const std::string, Resource>>& resources);
void informateAssets(const std::vector<std::tuple<EnumAssets, ResourceId, std::string, std::string, Resource, std::vector<uint8_t>>>& resources);
// Игровые определения
void informateDefVoxel(const std::vector<std::pair<DefVoxelId, DefVoxel*>>& voxels) { NetworkAndResource.lock()->informateDefVoxel(voxels); }