codex-5.2: отладка передачи ресурсов (assets)
This commit is contained in:
@@ -591,12 +591,15 @@ AssetsManager::BindResult AssetsManager::bindServerResource(AssetType type, Asse
|
||||
{
|
||||
BindResult result;
|
||||
AssetId localFromDK = getOrCreateLocalId(type, domain, key);
|
||||
AssetId localFromServer = ensureServerLocalId(type, serverId);
|
||||
auto& map = ServerToLocal[static_cast<size_t>(type)];
|
||||
AssetId localFromServer = 0;
|
||||
if(serverId < map.size())
|
||||
localFromServer = map[serverId];
|
||||
|
||||
if(localFromServer != 0)
|
||||
unionLocalIds(type, localFromServer, localFromDK, &result.ReboundFrom);
|
||||
AssetId localId = resolveLocalIdMutable(type, localFromDK);
|
||||
|
||||
auto& map = ServerToLocal[static_cast<size_t>(type)];
|
||||
if(serverId >= map.size())
|
||||
map.resize(serverId + 1, 0);
|
||||
map[serverId] = localId;
|
||||
@@ -656,14 +659,26 @@ std::vector<uint8_t> AssetsManager::rebindHeader(AssetType type, const std::vect
|
||||
return {};
|
||||
|
||||
auto mapModelId = [&](AssetId id) -> AssetId {
|
||||
if(serverIds)
|
||||
return ensureServerLocalId(AssetType::Model, id);
|
||||
if(serverIds) {
|
||||
auto localId = getLocalIdFromServer(AssetType::Model, id);
|
||||
if(!localId) {
|
||||
assert(!"Missing server bind for model id");
|
||||
MAKE_ERROR("Нет бинда сервера для модели id=" << id);
|
||||
}
|
||||
return *localId;
|
||||
}
|
||||
return resolveLocalIdMutable(AssetType::Model, id);
|
||||
};
|
||||
|
||||
auto mapTextureId = [&](AssetId id) -> AssetId {
|
||||
if(serverIds)
|
||||
return ensureServerLocalId(AssetType::Texture, id);
|
||||
if(serverIds) {
|
||||
auto localId = getLocalIdFromServer(AssetType::Texture, id);
|
||||
if(!localId) {
|
||||
assert(!"Missing server bind for texture id");
|
||||
MAKE_ERROR("Нет бинда сервера для текстуры id=" << id);
|
||||
}
|
||||
return *localId;
|
||||
}
|
||||
return resolveLocalIdMutable(AssetType::Texture, id);
|
||||
};
|
||||
|
||||
@@ -893,10 +908,6 @@ AssetsManager::AssetId AssetsManager::getOrCreateLocalId(AssetType type, std::st
|
||||
return id;
|
||||
}
|
||||
|
||||
AssetsManager::AssetId AssetsManager::getOrCreateLocalFromServer(AssetType type, AssetId serverId) {
|
||||
return ensureServerLocalId(type, serverId);
|
||||
}
|
||||
|
||||
std::optional<AssetsManager::AssetId> AssetsManager::getLocalIdFromServer(AssetType type, AssetId serverId) const {
|
||||
const auto& map = ServerToLocal[static_cast<size_t>(type)];
|
||||
if(serverId >= map.size())
|
||||
@@ -935,15 +946,6 @@ AssetsManager::AssetId AssetsManager::allocateLocalId(AssetType type) {
|
||||
return id;
|
||||
}
|
||||
|
||||
AssetsManager::AssetId AssetsManager::ensureServerLocalId(AssetType type, AssetId serverId) {
|
||||
auto& map = ServerToLocal[static_cast<size_t>(type)];
|
||||
if(serverId >= map.size())
|
||||
map.resize(serverId + 1, 0);
|
||||
if(map[serverId] == 0)
|
||||
map[serverId] = allocateLocalId(type);
|
||||
return resolveLocalIdMutable(type, map[serverId]);
|
||||
}
|
||||
|
||||
AssetsManager::AssetId AssetsManager::resolveLocalIdMutable(AssetType type, AssetId localId) {
|
||||
if(localId == 0)
|
||||
return 0;
|
||||
|
||||
@@ -101,7 +101,6 @@ public:
|
||||
std::vector<std::pair<ResourceKey, std::optional<Resource>>> pullReads();
|
||||
|
||||
AssetId getOrCreateLocalId(AssetType type, std::string_view domain, std::string_view key);
|
||||
AssetId getOrCreateLocalFromServer(AssetType type, AssetId serverId);
|
||||
std::optional<AssetId> getLocalIdFromServer(AssetType type, AssetId serverId) const;
|
||||
|
||||
private:
|
||||
@@ -127,7 +126,6 @@ private:
|
||||
size_t maxCacheDirectorySize, size_t maxLifeTime);
|
||||
|
||||
AssetId allocateLocalId(AssetType type);
|
||||
AssetId ensureServerLocalId(AssetType type, AssetId serverId);
|
||||
AssetId resolveLocalIdMutable(AssetType type, AssetId localId);
|
||||
AssetId resolveLocalId(AssetType type, AssetId localId) const;
|
||||
void unionLocalIds(AssetType type, AssetId fromId, AssetId toId, std::optional<AssetId>* reboundFrom);
|
||||
|
||||
@@ -330,7 +330,13 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
|
||||
std::vector<Hash_t> needRequest;
|
||||
|
||||
for(auto& [key, res] : resources) {
|
||||
{
|
||||
bool cacheHit = false;
|
||||
Hash_t actualHash = {};
|
||||
if(res) {
|
||||
actualHash = res->hash();
|
||||
cacheHit = actualHash == key.Hash;
|
||||
}
|
||||
if(cacheHit) {
|
||||
auto& waitingByDomain = AsyncContext.ResourceWait[(int) key.Type];
|
||||
auto iterDomain = waitingByDomain.find(key.Domain);
|
||||
if(iterDomain != waitingByDomain.end()) {
|
||||
@@ -377,7 +383,6 @@ void ServerSession::update(GlobalTime gTime, float dTime) {
|
||||
needRequest.push_back(key.Hash);
|
||||
}
|
||||
} else {
|
||||
Hash_t actualHash = res->hash();
|
||||
if(actualHash != key.Hash) {
|
||||
auto iter = std::lower_bound(AsyncContext.AlreadyLoading.begin(), AsyncContext.AlreadyLoading.end(), key.Hash);
|
||||
if(iter == AsyncContext.AlreadyLoading.end() || *iter != key.Hash) {
|
||||
@@ -1341,12 +1346,14 @@ coro<> ServerSession::rP_AssetsBindHH(Net::AsyncSocket &sock) {
|
||||
std::vector<uint8_t> header(headerStr.begin(), headerStr.end());
|
||||
|
||||
auto& table = ServerIdToDK[typeIndex];
|
||||
assert(id <= table.size());
|
||||
if(id >= table.size()) {
|
||||
LOG.warn() << "AssetsBindHH without domain/key for id=" << id;
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& [domain, key] = table[id];
|
||||
assert(!domain.empty() && !key.empty());
|
||||
if(domain.empty() && key.empty()) {
|
||||
LOG.warn() << "AssetsBindHH missing domain/key for id=" << id;
|
||||
continue;
|
||||
|
||||
@@ -142,7 +142,7 @@ private:
|
||||
TickData ThisTickEntry;
|
||||
|
||||
// Сюда обращается ветка обновления IServerSession, накапливая данные до SyncTick
|
||||
// Ресурсы, ожидающие ответа от менеджера кеша
|
||||
// Ресурсы, ожидающие либо кеш, либо сервер; используются для сопоставления hash->domain/key
|
||||
std::unordered_map<std::string, std::vector<std::pair<std::string, Hash_t>>> ResourceWait[(int) EnumAssets::MAX_ENUM];
|
||||
// Полученные изменения связок в ожидании стадии синхронизации такта
|
||||
std::vector<AssetsBindsChange> Binds;
|
||||
|
||||
@@ -1600,7 +1600,8 @@ void GameServer::stepConnections() {
|
||||
AssetsPreloader::Out_fullSync fullSync = Content.AM.collectFullSync();
|
||||
std::array<std::vector<ResourceId>, static_cast<size_t>(EnumAssets::MAX_ENUM)> lost{};
|
||||
|
||||
std::vector<Net::Packet> packets = RemoteClient::makePackets_informateAssets_DK(fullSync.IdToDK);
|
||||
std::vector<Net::Packet> packets;
|
||||
packets.push_back(RemoteClient::makePacket_informateAssets_DK(fullSync.IdToDK));
|
||||
packets.push_back(RemoteClient::makePacket_informateAssets_HH(fullSync.HashHeaders, lost));
|
||||
|
||||
for(const std::shared_ptr<RemoteClient>& client : newClients) {
|
||||
@@ -1694,8 +1695,7 @@ void GameServer::reloadMods() {
|
||||
{
|
||||
AssetsPreloader::Out_bakeId baked = Content.AM.bakeIdTables();
|
||||
if(!baked.IdToDK.empty()) {
|
||||
std::vector<Net::Packet> dkPackets = RemoteClient::makePackets_informateAssets_DK(baked.IdToDK);
|
||||
packetsToSend.insert(packetsToSend.end(), dkPackets.begin(), dkPackets.end());
|
||||
packetsToSend.push_back(RemoteClient::makePacket_informateAssets_DK(baked.IdToDK));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2488,8 +2488,7 @@ void GameServer::stepSyncContent() {
|
||||
{
|
||||
AssetsPreloader::Out_bakeId baked = Content.AM.bakeIdTables();
|
||||
if(!baked.IdToDK.empty()) {
|
||||
std::vector<Net::Packet> dkPackets = RemoteClient::makePackets_informateAssets_DK(baked.IdToDK);
|
||||
packetsToAll.insert(packetsToAll.end(), dkPackets.begin(), dkPackets.end());
|
||||
packetsToAll.push_back(RemoteClient::makePacket_informateAssets_DK(baked.IdToDK));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ Net::Packet RemoteClient::makePacket_informateAssets_DK(
|
||||
|
||||
// Сжатие
|
||||
std::u8string compressed = compressLinear(pack.complite());
|
||||
pack.clear();
|
||||
pack << uint8_t(ToClient::AssetsBindDK) << (const std::string&) compressed;
|
||||
|
||||
return pack;
|
||||
|
||||
@@ -411,13 +411,6 @@ private:
|
||||
void protocolError();
|
||||
coro<> readPacket(Net::AsyncSocket &sock);
|
||||
coro<> rP_System(Net::AsyncSocket &sock);
|
||||
|
||||
// void incrementProfile(const std::vector<TextureId_t> &textures, const std::vector<ModelId_t> &model,
|
||||
// const std::vector<SoundId_t> &sounds, const std::vector<FontId_t> &font
|
||||
// );
|
||||
// void decrementProfile(std::vector<TextureId_t> &&textures, std::vector<ModelId_t> &&model,
|
||||
// std::vector<SoundId_t> &&sounds, std::vector<FontId_t> &&font
|
||||
// );
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user