Отладка получения ресурсов

This commit is contained in:
2025-09-02 13:03:39 +06:00
parent 05570b0844
commit 4eef3ca211
10 changed files with 149 additions and 65 deletions

View File

@@ -498,6 +498,8 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
keyToIdDomain[key] = id;
data->emplace(lwt, resource, domain, key);
lock->HashToId[resource.hash()] = {(EnumAssets) type, id};
}
}
@@ -511,6 +513,39 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
std::set_difference(l.begin(), l.end(), noc.begin(), noc.end(), std::back_inserter(result.Lost[type]));
}
// Дамп ключей assets
{
std::stringstream result;
auto lock = LocalObj.lock();
for(int type = 0; type < (int) EnumAssets::MAX_ENUM; type++) {
if(type == 0)
result << "Nodestate:\n";
else if(type == 1)
result << "Particle:\n";
else if(type == 2)
result << "Animation:\n";
else if(type == 3)
result << "Model:\n";
else if(type == 4)
result << "Texture:\n";
else if(type == 5)
result << "Sound:\n";
else if(type == 6)
result << "Font:\n";
for(const auto& [domain, list] : lock->KeyToId[type]) {
result << "\t" << domain << ":\n";
for(const auto& [key, id] : list) {
result << "\t\t" << key << " = " << id << '\n';
}
}
}
LOG.debug() << "Дамп ассетов:\n" << result.str();
}
if(!orr.Nodestates.empty())
{
auto lock = LocalObj.lock();
@@ -617,6 +652,7 @@ AssetsManager::Out_applyResourceChange AssetsManager::applyResourceChange(const
}
}
entry.FullSubTextureDeps.append_range(entry.TextureDeps);
{
std::sort(entry.FullSubTextureDeps.begin(), entry.FullSubTextureDeps.end());
auto eraseIter = std::unique(entry.FullSubTextureDeps.begin(), entry.FullSubTextureDeps.end());

View File

@@ -105,6 +105,7 @@ private:
// Связь домены -> {ключ -> идентификатор}
std::unordered_map<std::string, std::unordered_map<std::string, ResourceId>> KeyToId[(int) EnumAssets::MAX_ENUM];
std::unordered_map<Hash_t, std::tuple<EnumAssets, ResourceId>> HashToId;
std::tuple<ResourceId, std::optional<DataEntry>&> nextId(EnumAssets type);
@@ -132,6 +133,28 @@ private:
return std::nullopt;
}
std::optional<std::tuple<Resource, const std::string&, const std::string&, EnumAssets, ResourceId>> getResource(const Hash_t& hash) {
auto iter = HashToId.find(hash);
if(iter == HashToId.end())
return std::nullopt;
auto [type, id] = iter->second;
std::optional<std::tuple<Resource, const std::string&, const std::string&>> res = getResource(type, id);
if(!res) {
HashToId.erase(iter);
return std::nullopt;
}
if(std::get<Resource>(*res).hash() == hash) {
auto& [resource, domain, key] = *res;
return std::tuple<Resource, const std::string&, const std::string&, EnumAssets, ResourceId>{resource, domain, key, type, id};
}
HashToId.erase(iter);
return std::nullopt;
}
const std::optional<std::vector<AssetsModel>>& getResourceNodestate(ResourceId id) {
assert(id < Table_NodeState.size()*TableEntry<DataEntry>::ChunkSize);
return Table_NodeState[id / TableEntry<DataEntry>::ChunkSize]
@@ -224,6 +247,11 @@ public:
return LocalObj.lock()->getResource(type, id);
}
// Выдаёт ресурс по хешу
std::optional<std::tuple<Resource, const std::string&, const std::string&, EnumAssets, ResourceId>> getResource(const Hash_t& hash) {
return LocalObj.lock()->getResource(hash);
}
// Выдаёт зависимости к ресурсам профиля ноды
std::tuple<AssetsNodestate, std::vector<AssetsModel>, std::vector<AssetsTexture>>
getNodeDependency(const std::string& domain, const std::string& key)

View File

@@ -806,14 +806,15 @@ void GameServer::BackingNoiseGenerator_t::run(int id) {
std::array<float, 64*64*64> data;
float *ptr = &data[0];
std::fill(ptr, ptr+64*64*64, 0);
for(int z = 0; z < 64; z++)
for(int y = 0; y < 64; y++)
for(int x = 0; x < 64; x++, ptr++) {
// *ptr = TOS::genRand();
*ptr = glm::perlin(glm::vec3(posNode.x+x, posNode.y+y, posNode.z+z) / 16.13f);
//*ptr = std::pow(*ptr, 0.75f)*1.5f;
}
// for(int z = 0; z < 64; z++)
// for(int y = 0; y < 64; y++)
// for(int x = 0; x < 64; x++, ptr++) {
// // *ptr = TOS::genRand();
// *ptr = glm::perlin(glm::vec3(posNode.x+x, posNode.y+y, posNode.z+z) / 16.13f);
// //*ptr = std::pow(*ptr, 0.75f)*1.5f;
// }
Output.lock()->push_back({key, std::move(data)});
}
@@ -1493,7 +1494,7 @@ void GameServer::init(fs::path worldPath) {
BackingNoiseGenerator.Threads[iter] = std::thread(&BackingNoiseGenerator_t::run, &BackingNoiseGenerator, iter);
}
BackingAsyncLua.Threads.resize(4);
BackingAsyncLua.Threads.resize(1);
for(size_t iter = 0; iter < BackingAsyncLua.Threads.size(); iter++) {
BackingAsyncLua.Threads[iter] = std::thread(&BackingAsyncLua_t::run, &BackingAsyncLua, iter);
}
@@ -1837,12 +1838,8 @@ void GameServer::stepGeneratorAndLuaAsync(IWorldSaveBackend::TickSyncInfo_Out db
// Обработка шума на стороне луа
{
std::vector<std::pair<BackingNoiseGenerator_t::NoiseKey, std::array<float, 64*64*64>>> calculatedNoise = BackingNoiseGenerator.tickSync(std::move(db.NotExisten));
if(!calculatedNoise.empty()) {
auto lock = BackingAsyncLua.NoiseIn.lock();
for(auto& pair : calculatedNoise)
lock->push(pair);
}
if(!calculatedNoise.empty())
BackingAsyncLua.NoiseIn.lock()->push_range(calculatedNoise);
calculatedNoise.clear();
@@ -2408,7 +2405,15 @@ void GameServer::stepSyncContent() {
auto& [resource, domain, key] = *result;
resources.emplace_back((EnumAssets) type, resId, domain, key, resource);
}
}
for(const Hash_t& hash : full.Hashes) {
std::optional<std::tuple<Resource, const std::string&, const std::string&, EnumAssets, ResourceId>> result = Content.AM.getResource(hash);
if(!result)
continue;
auto& [resource, domain, key, type, id] = *result;
resources.emplace_back(type, id, domain, key, resource);
}
// Информируем о запрошенных профилях

View File

@@ -192,7 +192,7 @@ class GameServer : public AsyncObject {
thread.join();
}
__attribute__((optimize("O3"))) void run(int id);
/* __attribute__((optimize("O3"))) */ void run(int id);
} BackingChunkPressure;
/*

View File

@@ -523,10 +523,12 @@ void RemoteClient::informateAssets(const std::vector<std::tuple<EnumAssets, Reso
auto it = std::lower_bound(AssetsInWork.OnClient.begin(), AssetsInWork.OnClient.end(), hash);
if(it == AssetsInWork.OnClient.end() || *it != hash)
if(it == AssetsInWork.OnClient.end() || *it != hash) {
AssetsInWork.OnClient.insert(it, hash);
AssetsInWork.ToSend.emplace_back(type, domain, key, resId, resource, 0);
AssetsInWork.ToSend.emplace_back(type, domain, key, resId, resource, 0);
} else {
LOG.warn() << "Клиент повторно запросил имеющийся у него ресурс";
}
lock = NetworkAndResource.lock();
}
@@ -552,13 +554,13 @@ void RemoteClient::informateAssets(const std::vector<std::tuple<EnumAssets, Reso
assert(newForClient.size() < 65535*4);
auto lock = NetworkAndResource.lock();
lock->checkPacketBorder(2+4+newForClient.size()*(1+4+32));
lock->checkPacketBorder(2+1+4+newForClient.size()*(1+4+64+32));
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) {
// TODO: может внести ограничение на длину домена и ключа?
lock->NextPacket << uint8_t(type) << uint32_t(resId) << domain << key << size;
lock->NextPacket << uint8_t(type) << uint32_t(resId) << domain << key;
lock->NextPacket.write((const std::byte*) hash.data(), hash.size());
}
}