This commit is contained in:
2025-09-14 10:07:23 +06:00
parent 55700c6939
commit 9cfae9c807
4 changed files with 51 additions and 5 deletions

View File

@@ -136,6 +136,8 @@ public:
}
for(const auto& [key, resource] : newOrChanged) {
result.push_back(key);
makeUnready(key);
ModelObject model;
std::string type = "unknown";
@@ -152,7 +154,6 @@ public:
for(const PreparedModel::Cuboid& cb : pm.Cuboids) {
glm::vec3 min = glm::min(cb.From, cb.To), max = glm::max(cb.From, cb.To);
for(const auto& [face, params] : cb.Faces) {
glm::vec2 from_uv = {params.UV[0], params.UV[1]}, to_uv = {params.UV[2], params.UV[3]};
@@ -246,6 +247,7 @@ public:
}
} catch(const std::exception& exc) {
LOG.warn() << "Не удалось распарсить модель " << type << ":\n\t" << exc.what();
continue;
}
Models.insert({key, std::move(model)});
@@ -386,8 +388,42 @@ public:
std::vector<AssetsNodestate> onNodestateChanges(std::vector<std::tuple<AssetsNodestate, Resource>> newOrChanged, std::vector<AssetsNodestate> lost, std::vector<AssetsModel> changedModels) {
std::vector<AssetsNodestate> result;
for(ResourceId lostId : lost) {
auto iterNodestate = Nodestates.find(lostId);
if(iterNodestate == Nodestates.end())
continue;
result.push_back(lostId);
Nodestates.erase(iterNodestate);
}
for(const auto& [key, resource] : newOrChanged) {
result.push_back(key);
PreparedNodeState nodestate;
std::string type = "unknown";
try {
std::u8string_view data((const char8_t*) resource.data(), resource.size());
if(data.starts_with((const char8_t*) "bn")) {
type = "InternalBinary";
// Компилированный nodestate внутреннего формата
nodestate = PreparedNodeState(data);
} else if(data.starts_with((const char8_t*) "{")) {
type = "InternalJson";
// nodestate в json формате
}
} catch(const std::exception& exc) {
LOG.warn() << "Не удалось распарсить nodestate " << type << ":\n\t" << exc.what();
continue;
}
Nodestates.insert({key, std::move(nodestate)});
}
std::sort(result.begin(), result.end());
auto eraseIter = std::unique(result.begin(), result.end());
result.erase(eraseIter, result.end());
return result;
}
@@ -402,7 +438,11 @@ public:
// statesInfo - Описание состояний ноды
// states - Текущие значения состояний ноды
std::vector<Model> getModelsForNode(AssetsNodestate id, const std::vector<StateInfo>& statesInfo, const std::unordered_map<std::string, int>& states) {
auto iterNodestate = Nodestates.find(id);
if(iterNodestate == Nodestates.end())
return {};
iterNodestate->second;
}
private:

View File

@@ -868,9 +868,11 @@ PreparedNodeState::PreparedNodeState(const std::string_view modid, const sol::ta
}
PreparedNodeState::PreparedNodeState(const std::u8string& data) {
PreparedNodeState::PreparedNodeState(const std::u8string_view data) {
Net::LinearReader lr(data);
lr.read<uint16_t>();
uint16_t size;
lr >> size;

View File

@@ -653,7 +653,7 @@ struct PreparedNodeState {
PreparedNodeState(const std::string_view modid, const js::object& profile);
PreparedNodeState(const std::string_view modid, const sol::table& profile);
PreparedNodeState(const std::u8string& data);
PreparedNodeState(const std::u8string_view data);
PreparedNodeState() = default;
PreparedNodeState(const PreparedNodeState&) = default;

View File

@@ -180,6 +180,10 @@ protected:
: Pos(pos), Input(input)
{}
LinearReader(const std::u8string_view input, size_t pos = 0)
: Pos(pos), Input(input)
{}
LinearReader(const LinearReader&) = delete;
LinearReader(LinearReader&&) = delete;
LinearReader& operator=(const LinearReader&) = delete;
@@ -226,7 +230,7 @@ protected:
private:
size_t Pos = 0;
const std::u8string& Input;
const std::u8string_view Input;
};
class SmartPacket : public Packet {