virtual ~CNodeDefManager();
void clear();
virtual IWritableNodeDefManager *clone();
- virtual const ContentFeatures& get(content_t c) const;
- virtual const ContentFeatures& get(const MapNode &n) const;
+ inline virtual const ContentFeatures& get(content_t c) const;
+ inline virtual const ContentFeatures& get(const MapNode &n) const;
virtual bool getId(const std::string &name, content_t &result) const;
virtual content_t getId(const std::string &name) const;
virtual void getIds(const std::string &name, std::set<content_t> &result) const;
virtual void updateTextures(IGameDef *gamedef);
void serialize(std::ostream &os, u16 protocol_version);
void deSerialize(std::istream &is);
- virtual NodeResolver *getResolver();
+
+ virtual void pendNodeResolve(NodeResolveInfo *nri);
+ virtual void cancelNodeResolve(NodeResolver *resolver);
+ virtual void runNodeResolverCallbacks();
+
+ virtual bool getIdFromResolveInfo(NodeResolveInfo *nri,
+ const std::string &node_alt, content_t c_fallback, content_t &result);
+ virtual bool getIdsFromResolveInfo(NodeResolveInfo *nri,
+ std::vector<content_t> &result);
private:
void addNameIdMapping(content_t i, std::string name);
// Next possibly free id
content_t m_next_id;
- // NodeResolver to queue pending node resolutions
- NodeResolver m_resolver;
+ // List of node strings and node resolver callbacks to perform
+ std::list<NodeResolveInfo *> m_pending_node_lookups;
};
-CNodeDefManager::CNodeDefManager() :
- m_resolver(this)
+CNodeDefManager::CNodeDefManager()
{
clear();
}
}
-const ContentFeatures& CNodeDefManager::get(content_t c) const
+inline const ContentFeatures& CNodeDefManager::get(content_t c) const
{
- if (c < m_content_features.size())
- return m_content_features[c];
- else
- return m_content_features[CONTENT_UNKNOWN];
+ return c < m_content_features.size()
+ ? m_content_features[c] : m_content_features[CONTENT_UNKNOWN];
}
-const ContentFeatures& CNodeDefManager::get(const MapNode &n) const
+inline const ContentFeatures& CNodeDefManager::get(const MapNode &n) const
{
return get(n.getContent());
}
#ifndef SERVER
infostream << "CNodeDefManager::updateTextures(): Updating "
"textures in node definitions" << std::endl;
-
+
ITextureSource *tsrc = gamedef->tsrc();
IShaderSource *shdsrc = gamedef->getShaderSource();
scene::ISceneManager* smgr = gamedef->getSceneManager();
bool enable_shaders = g_settings->getBool("enable_shaders");
bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
+ bool enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
bool use_normal_texture = enable_shaders &&
(enable_bumpmapping || enable_parallax_occlusion);
f->tiledef_special[j].backface_culling, f->alpha, material_type);
}
- // Meshnode drawtype
- // Read the mesh and apply scale
if ((f->drawtype == NDT_MESH) && (f->mesh != "")) {
+ // Meshnode drawtype
+ // Read the mesh and apply scale
f->mesh_ptr[0] = gamedef->getMesh(f->mesh);
if (f->mesh_ptr[0]){
v3f scale = v3f(1.0, 1.0, 1.0) * BS * f->visual_scale;
scaleMesh(f->mesh_ptr[0], scale);
recalculateBoundingBox(f->mesh_ptr[0]);
+ meshmanip->recalculateNormals(f->mesh_ptr[0], true, false);
}
- }
-
- //Convert regular nodebox nodes to meshnodes
- //Change the drawtype and apply scale
- else if ((f->drawtype == NDT_NODEBOX) &&
+ } else if ((f->drawtype == NDT_NODEBOX) &&
((f->node_box.type == NODEBOX_REGULAR) ||
(f->node_box.type == NODEBOX_FIXED)) &&
(!f->node_box.fixed.empty())) {
+ //Convert regular nodebox nodes to meshnodes
+ //Change the drawtype and apply scale
f->drawtype = NDT_MESH;
f->mesh_ptr[0] = convertNodeboxNodeToMesh(f);
v3f scale = v3f(1.0, 1.0, 1.0) * f->visual_scale;
scaleMesh(f->mesh_ptr[0], scale);
recalculateBoundingBox(f->mesh_ptr[0]);
+ meshmanip->recalculateNormals(f->mesh_ptr[0], true, false);
}
- //Cache 6dfacedir rotated clones of meshes
- if (f->mesh_ptr[0] && (f->param_type_2 == CPT2_FACEDIR)) {
+ //Cache 6dfacedir and wallmounted rotated clones of meshes
+ if (enable_mesh_cache && f->mesh_ptr[0] && (f->param_type_2 == CPT2_FACEDIR)) {
for (u16 j = 1; j < 24; j++) {
f->mesh_ptr[j] = cloneMesh(f->mesh_ptr[0]);
rotateMeshBy6dFacedir(f->mesh_ptr[j], j);
recalculateBoundingBox(f->mesh_ptr[j]);
- meshmanip->recalculateNormals(f->mesh_ptr[j], false, false);
+ meshmanip->recalculateNormals(f->mesh_ptr[j], true, false);
}
+ } else if (enable_mesh_cache && f->mesh_ptr[0] && (f->param_type_2 == CPT2_WALLMOUNTED)) {
+ static const u8 wm_to_6d[6] = {20, 0, 16+1, 12+3, 8, 4+2};
+ for (u16 j = 1; j < 6; j++) {
+ f->mesh_ptr[j] = cloneMesh(f->mesh_ptr[0]);
+ rotateMeshBy6dFacedir(f->mesh_ptr[j], wm_to_6d[j]);
+ recalculateBoundingBox(f->mesh_ptr[j]);
+ meshmanip->recalculateNormals(f->mesh_ptr[j], true, false);
+ }
+ rotateMeshBy6dFacedir(f->mesh_ptr[0], wm_to_6d[0]);
+ recalculateBoundingBox(f->mesh_ptr[0]);
+ meshmanip->recalculateNormals(f->mesh_ptr[0], true, false);
}
}
#endif
tile->material_flags &= ~MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES;
} else {
std::ostringstream os(std::ios::binary);
+ tile->frames.resize(frame_count);
+
for (int i = 0; i < frame_count; i++) {
+
FrameSpec frame;
os.str("");
}
-NodeResolver *CNodeDefManager::getResolver()
-{
- return &m_resolver;
-}
-
-
IWritableNodeDefManager *createNodeDefManager()
{
return new CNodeDefManager();
writeU8(os, drowning);
writeU8(os, leveled);
writeU8(os, liquid_range);
- } else
+ } else
throw SerializationError("ContentFeatures::serialize(): "
"Unsupported version requested");
}
}
}
-/*
- NodeResolver
-*/
-NodeResolver::NodeResolver(INodeDefManager *ndef)
+void CNodeDefManager::pendNodeResolve(NodeResolveInfo *nri)
{
- m_ndef = ndef;
- m_is_node_registration_complete = false;
+ nri->resolver->m_ndef = this;
+ m_pending_node_lookups.push_back(nri);
}
-NodeResolver::~NodeResolver()
+void CNodeDefManager::cancelNodeResolve(NodeResolver *resolver)
{
- while (!m_pending_contents.empty()) {
- NodeResolveInfo *nri = m_pending_contents.front();
- m_pending_contents.pop_front();
- delete nri;
+ for (std::list<NodeResolveInfo *>::iterator
+ it = m_pending_node_lookups.begin();
+ it != m_pending_node_lookups.end();
+ ++it) {
+ NodeResolveInfo *nri = *it;
+ if (resolver == nri->resolver) {
+ it = m_pending_node_lookups.erase(it);
+ delete nri;
+ }
}
}
-int NodeResolver::addNode(std::string n_wanted, std::string n_alt,
- content_t c_fallback, content_t *content)
+void CNodeDefManager::runNodeResolverCallbacks()
{
- if (m_is_node_registration_complete) {
- if (m_ndef->getId(n_wanted, *content))
- return NR_STATUS_SUCCESS;
-
- if (n_alt == "")
- return NR_STATUS_FAILURE;
-
- return m_ndef->getId(n_alt, *content) ?
- NR_STATUS_SUCCESS : NR_STATUS_FAILURE;
- } else {
- NodeResolveInfo *nfi = new NodeResolveInfo;
- nfi->n_wanted = n_wanted;
- nfi->n_alt = n_alt;
- nfi->c_fallback = c_fallback;
- nfi->output = content;
-
- m_pending_contents.push_back(nfi);
-
- return NR_STATUS_PENDING;
+ while (!m_pending_node_lookups.empty()) {
+ NodeResolveInfo *nri = m_pending_node_lookups.front();
+ m_pending_node_lookups.pop_front();
+ nri->resolver->resolveNodeNames(nri);
+ nri->resolver->m_lookup_done = true;
+ delete nri;
}
}
-int NodeResolver::addNodeList(const char *nodename,
- std::vector<content_t> *content_vec)
+bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
+ const std::string &node_alt, content_t c_fallback, content_t &result)
{
- if (m_is_node_registration_complete) {
- std::set<content_t> idset;
- std::set<content_t>::iterator it;
-
- m_ndef->getIds(nodename, idset);
- for (it = idset.begin(); it != idset.end(); ++it)
- content_vec->push_back(*it);
-
- return idset.size() ? NR_STATUS_SUCCESS : NR_STATUS_FAILURE;
- } else {
- m_pending_content_vecs.push_back(
- std::make_pair(std::string(nodename), content_vec));
- return NR_STATUS_PENDING;
+ if (nri->nodenames.empty()) {
+ result = c_fallback;
+ errorstream << "Resolver empty nodename list" << std::endl;
+ return false;
}
-}
+ content_t c;
+ std::string name = nri->nodenames.front();
+ nri->nodenames.pop_front();
-bool NodeResolver::cancelNode(content_t *content)
-{
- bool found = false;
-
- std::list<NodeResolveInfo *>::iterator it = m_pending_contents.begin();
- while (it != m_pending_contents.end()) {
- NodeResolveInfo *nfi = *it;
- if (nfi->output == content) {
- it = m_pending_contents.erase(it);
- delete nfi;
- found = true;
- }
+ bool success = getId(name, c);
+ if (!success && node_alt != "") {
+ name = node_alt;
+ success = getId(name, c);
}
- return found;
-}
-
-
-int NodeResolver::cancelNodeList(std::vector<content_t> *content_vec)
-{
- int num_canceled = 0;
-
- std::list<std::pair<std::string, std::vector<content_t> *> >::iterator it;
- it = m_pending_content_vecs.begin();
- while (it != m_pending_content_vecs.end()) {
- if (it->second == content_vec) {
- it = m_pending_content_vecs.erase(it);
- num_canceled++;
- }
+ if (!success) {
+ errorstream << "Resolver: Failed to resolve node name '" << name
+ << "'." << std::endl;
+ c = c_fallback;
}
- return num_canceled;
+ result = c;
+ return success;
}
-int NodeResolver::resolveNodes()
+bool CNodeDefManager::getIdsFromResolveInfo(NodeResolveInfo *nri,
+ std::vector<content_t> &result)
{
- int num_failed = 0;
+ bool success = true;
- //// Resolve pending single node name -> content ID mappings
- while (!m_pending_contents.empty()) {
- NodeResolveInfo *nri = m_pending_contents.front();
- m_pending_contents.pop_front();
+ if (nri->nodelistinfo.empty()) {
+ errorstream << "Resolver: Empty nodelistinfo list" << std::endl;
+ return false;
+ }
- bool success = true;
- if (!m_ndef->getId(nri->n_wanted, *nri->output)) {
- success = (nri->n_alt != "") ?
- m_ndef->getId(nri->n_alt, *nri->output) : false;
- }
+ NodeListInfo listinfo = nri->nodelistinfo.front();
+ nri->nodelistinfo.pop_front();
- if (!success) {
- *nri->output = nri->c_fallback;
- num_failed++;
- errorstream << "NodeResolver::resolveNodes(): Failed to "
- "resolve '" << nri->n_wanted;
- if (nri->n_alt != "")
- errorstream << "' and '" << nri->n_alt;
- errorstream << "' to a content ID" << std::endl;
+ while (listinfo.length--) {
+ if (nri->nodenames.empty()) {
+ errorstream << "Resolver: Empty nodename list" << std::endl;
+ return false;
}
- delete nri;
- }
-
- //// Resolve pending node names and add to content_t vector
- while (!m_pending_content_vecs.empty()) {
- std::pair<std::string, std::vector<content_t> *> item =
- m_pending_content_vecs.front();
- m_pending_content_vecs.pop_front();
-
- std::string &name = item.first;
- std::vector<content_t> *output = item.second;
-
- std::set<content_t> idset;
- std::set<content_t>::iterator it;
-
- m_ndef->getIds(name, idset);
- for (it = idset.begin(); it != idset.end(); ++it)
- output->push_back(*it);
+ content_t c;
+ std::string name = nri->nodenames.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;
+ }
}
- //// Mark node registration as complete so future resolve
- //// requests are satisfied immediately
- m_is_node_registration_complete = true;
-
- return num_failed;
+ return success;
}