1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-23 08:08:47 -05:00

Set fallback content if resolving content vector requires everything

This commit is contained in:
kwolekr 2014-12-27 22:20:04 -05:00
parent b67f37f27e
commit 08d259cf41
4 changed files with 48 additions and 25 deletions

View File

@ -248,7 +248,7 @@ bool Schematic::loadSchematicFromFile(const char *filename,
nri->nodenames.push_back(name); nri->nodenames.push_back(name);
} }
nri->nodename_sizes.push_back(nidmapcount); nri->nodelistinfo.push_back(NodeListInfo(nidmapcount, CONTENT_AIR));
ndef->pendNodeResolve(nri); ndef->pendNodeResolve(nri);
size_t nodecount = size.X * size.Y * size.Z; size_t nodecount = size.X * size.Y * size.Z;

View File

@ -1308,8 +1308,7 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
{ {
if (nri->nodenames.empty()) { if (nri->nodenames.empty()) {
result = c_fallback; result = c_fallback;
errorstream << "CNodeDefManager::getIdFromResolveInfo: empty " errorstream << "Resolver empty nodename list" << std::endl;
"nodenames list" << std::endl;
return false; return false;
} }
@ -1324,8 +1323,8 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
} }
if (!success) { if (!success) {
errorstream << "CNodeDefManager::getIdFromResolveInfo: Failed to " errorstream << "Resolver: Failed to resolve node name '" << name
"resolve node name '" << name << "'." << std::endl; << "'." << std::endl;
c = c_fallback; c = c_fallback;
} }
@ -1337,31 +1336,35 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
bool CNodeDefManager::getIdsFromResolveInfo(NodeResolveInfo *nri, bool CNodeDefManager::getIdsFromResolveInfo(NodeResolveInfo *nri,
std::vector<content_t> &result) std::vector<content_t> &result)
{ {
if (nri->nodename_sizes.empty()) { bool success = true;
errorstream << "CNodeDefManager::getIdsFromResolveInfo: empty "
"nodename_sizes list" << std::endl; if (nri->nodelistinfo.empty()) {
errorstream << "Resolver: Empty nodelistinfo list" << std::endl;
return false; return false;
} }
size_t nitems = nri->nodename_sizes.front(); NodeListInfo listinfo = nri->nodelistinfo.front();
nri->nodename_sizes.pop_front(); nri->nodelistinfo.pop_front();
while (nitems--) { while (listinfo.length--) {
if (nri->nodenames.empty()) { if (nri->nodenames.empty()) {
errorstream << "" << std::endl; errorstream << "Resolver: Empty nodename list" << std::endl;
return false; return false;
} }
content_t c; content_t c;
if (getId(nri->nodenames.front(), c)) { std::string name = nri->nodenames.front();
result.push_back(c);
} else {
errorstream << "CNodeDefManager::getIdsFromResolveInfo: empty "
"nodenames list" << std::endl;
}
nri->nodenames.pop_front(); nri->nodenames.pop_front();
if (getId(name, c)) {
result.push_back(c);
} else if (listinfo.all_required) {
errorstream << "Resolver: Failed to resolve node name '" << name
<< "'." << std::endl;
result.push_back(listinfo.c_fallback);
success = false;
}
} }
return true; return success;
} }

View File

@ -285,6 +285,26 @@ struct ContentFeatures
class NodeResolver; class NodeResolver;
class INodeDefManager; class INodeDefManager;
struct NodeListInfo {
NodeListInfo(u32 len)
{
length = len;
all_required = false;
c_fallback = CONTENT_IGNORE;
}
NodeListInfo(u32 len, content_t fallback)
{
length = len;
all_required = true;
c_fallback = fallback;
}
u32 length;
bool all_required;
content_t c_fallback;
};
struct NodeResolveInfo { struct NodeResolveInfo {
NodeResolveInfo(NodeResolver *nr) NodeResolveInfo(NodeResolver *nr)
{ {
@ -292,7 +312,7 @@ struct NodeResolveInfo {
} }
std::list<std::string> nodenames; std::list<std::string> nodenames;
std::list<size_t> nodename_sizes; std::list<NodeListInfo> nodelistinfo;
NodeResolver *resolver; NodeResolver *resolver;
}; };

View File

@ -508,7 +508,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
//// Get node name(s) to place decoration on //// Get node name(s) to place decoration on
std::vector<const char *> place_on_names; std::vector<const char *> place_on_names;
getstringlistfield(L, index, "place_on", place_on_names); getstringlistfield(L, index, "place_on", place_on_names);
nri->nodename_sizes.push_back(place_on_names.size()); nri->nodelistinfo.push_back(NodeListInfo(place_on_names.size()));
for (size_t i = 0; i != place_on_names.size(); i++) for (size_t i = 0; i != place_on_names.size(); i++)
nri->nodenames.push_back(place_on_names[i]); nri->nodenames.push_back(place_on_names[i]);
@ -585,7 +585,7 @@ bool ModApiMapgen::regDecoSimple(lua_State *L,
"defined" << std::endl; "defined" << std::endl;
return false; return false;
} }
nri->nodename_sizes.push_back(deco_names.size()); nri->nodelistinfo.push_back(NodeListInfo(deco_names.size()));
for (size_t i = 0; i != deco_names.size(); i++) for (size_t i = 0; i != deco_names.size(); i++)
nri->nodenames.push_back(deco_names[i]); nri->nodenames.push_back(deco_names[i]);
@ -596,7 +596,7 @@ bool ModApiMapgen::regDecoSimple(lua_State *L,
" but num_spawn_by specified" << std::endl; " but num_spawn_by specified" << std::endl;
return false; return false;
} }
nri->nodename_sizes.push_back(spawnby_names.size()); nri->nodelistinfo.push_back(NodeListInfo(spawnby_names.size()));
for (size_t i = 0; i != spawnby_names.size(); i++) for (size_t i = 0; i != spawnby_names.size(); i++)
nri->nodenames.push_back(spawnby_names[i]); nri->nodenames.push_back(spawnby_names[i]);
@ -691,7 +691,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
std::vector<const char *> wherein_names; std::vector<const char *> wherein_names;
getstringlistfield(L, index, "wherein", wherein_names); getstringlistfield(L, index, "wherein", wherein_names);
nri->nodename_sizes.push_back(wherein_names.size()); nri->nodelistinfo.push_back(NodeListInfo(wherein_names.size()));
for (size_t i = 0; i != wherein_names.size(); i++) for (size_t i = 0; i != wherein_names.size(); i++)
nri->nodenames.push_back(wherein_names[i]); nri->nodenames.push_back(wherein_names[i]);