1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Cache liquid alternative IDs (#8053)

This commit is contained in:
Vitaliy 2020-05-21 00:52:10 +03:00 committed by GitHub
parent 42fcfb75e8
commit 82e4137893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 16 deletions

View file

@ -371,7 +371,9 @@ void ContentFeatures::reset()
leveled_max = LEVELED_MAX;
liquid_type = LIQUID_NONE;
liquid_alternative_flowing = "";
liquid_alternative_flowing_id = CONTENT_IGNORE;
liquid_alternative_source = "";
liquid_alternative_source_id = CONTENT_IGNORE;
liquid_viscosity = 0;
liquid_renewable = true;
liquid_range = LIQUID_LEVEL_MAX+1;
@ -1444,6 +1446,10 @@ void NodeDefManager::deSerialize(std::istream &is)
getNodeBoxUnion(f.selection_box, f, &m_selection_box_union);
fixSelectionBoxIntUnion();
}
// Since liquid_alternative_flowing_id and liquid_alternative_source_id
// are not sent, resolve them client-side too.
resolveCrossrefs();
}
@ -1504,15 +1510,28 @@ void NodeDefManager::resetNodeResolveState()
m_pending_resolve_callbacks.clear();
}
void NodeDefManager::mapNodeboxConnections()
static void removeDupes(std::vector<content_t> &list)
{
std::sort(list.begin(), list.end());
auto new_end = std::unique(list.begin(), list.end());
list.erase(new_end, list.end());
}
void NodeDefManager::resolveCrossrefs()
{
for (ContentFeatures &f : m_content_features) {
if (f.liquid_type != LIQUID_NONE) {
f.liquid_alternative_flowing_id = getId(f.liquid_alternative_flowing);
f.liquid_alternative_source_id = getId(f.liquid_alternative_source);
continue;
}
if (f.drawtype != NDT_NODEBOX || f.node_box.type != NODEBOX_CONNECTED)
continue;
for (const std::string &name : f.connects_to) {
getIds(name, f.connects_to_ids);
}
removeDupes(f.connects_to_ids);
}
}