codex-5.2: отладка передачи ресурсов (assets)

This commit is contained in:
2026-01-04 22:30:06 +06:00
parent 6dd1f93221
commit 5904fe6853
7 changed files with 37 additions and 37 deletions

View File

@@ -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];
unionLocalIds(type, localFromServer, localFromDK, &result.ReboundFrom);
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;

View File

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

View File

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

View File

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