NodeResolver: Perform callback immediately if node registration phase finished

Also add NodeResolver callbacks on the client
This commit is contained in:
kwolekr 2015-01-04 16:32:31 -05:00
parent 663e42ca3f
commit cd4d213ae0
4 changed files with 99 additions and 65 deletions

@ -2723,6 +2723,8 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
text = wgettext("Initializing nodes..."); text = wgettext("Initializing nodes...");
draw_load_screen(text, device, guienv, 0, 80); draw_load_screen(text, device, guienv, 0, 80);
m_nodedef->updateAliases(m_itemdef); m_nodedef->updateAliases(m_itemdef);
m_nodedef->setNodeRegistrationStatus(true);
m_nodedef->runNodeResolverCallbacks();
delete[] text; delete[] text;
// Update node textures and assign shaders to each tile // Update node textures and assign shaders to each tile

@ -402,6 +402,9 @@ public:
void serialize(std::ostream &os, u16 protocol_version); void serialize(std::ostream &os, u16 protocol_version);
void deSerialize(std::istream &is); void deSerialize(std::istream &is);
inline virtual bool getNodeRegistrationStatus() const;
inline virtual void setNodeRegistrationStatus(bool completed);
virtual void pendNodeResolve(NodeResolveInfo *nri); virtual void pendNodeResolve(NodeResolveInfo *nri);
virtual void cancelNodeResolve(NodeResolver *resolver); virtual void cancelNodeResolve(NodeResolver *resolver);
virtual void runNodeResolverCallbacks(); virtual void runNodeResolverCallbacks();
@ -441,6 +444,9 @@ private:
// List of node strings and node resolver callbacks to perform // List of node strings and node resolver callbacks to perform
std::list<NodeResolveInfo *> m_pending_node_lookups; std::list<NodeResolveInfo *> m_pending_node_lookups;
// True when all nodes have been registered
bool m_node_registration_complete;
}; };
@ -1268,10 +1274,28 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
} }
inline bool CNodeDefManager::getNodeRegistrationStatus() const
{
return m_node_registration_complete;
}
inline void CNodeDefManager::setNodeRegistrationStatus(bool completed)
{
m_node_registration_complete = completed;
}
void CNodeDefManager::pendNodeResolve(NodeResolveInfo *nri) void CNodeDefManager::pendNodeResolve(NodeResolveInfo *nri)
{ {
nri->resolver->m_ndef = this; nri->resolver->m_ndef = this;
m_pending_node_lookups.push_back(nri); if (m_node_registration_complete) {
nri->resolver->resolveNodeNames(nri);
nri->resolver->m_lookup_done = true;
delete nri;
} else {
m_pending_node_lookups.push_back(nri);
}
} }

@ -331,6 +331,9 @@ public:
virtual void serialize(std::ostream &os, u16 protocol_version)=0; virtual void serialize(std::ostream &os, u16 protocol_version)=0;
virtual bool getNodeRegistrationStatus() const=0;
virtual void setNodeRegistrationStatus(bool completed)=0;
virtual void pendNodeResolve(NodeResolveInfo *nri)=0; virtual void pendNodeResolve(NodeResolveInfo *nri)=0;
virtual void cancelNodeResolve(NodeResolver *resolver)=0; virtual void cancelNodeResolve(NodeResolver *resolver)=0;
virtual void runNodeResolverCallbacks()=0; virtual void runNodeResolverCallbacks()=0;
@ -380,6 +383,9 @@ public:
virtual void serialize(std::ostream &os, u16 protocol_version)=0; virtual void serialize(std::ostream &os, u16 protocol_version)=0;
virtual void deSerialize(std::istream &is)=0; virtual void deSerialize(std::istream &is)=0;
virtual bool getNodeRegistrationStatus() const=0;
virtual void setNodeRegistrationStatus(bool completed)=0;
virtual void pendNodeResolve(NodeResolveInfo *nri)=0; virtual void pendNodeResolve(NodeResolveInfo *nri)=0;
virtual void cancelNodeResolve(NodeResolver *resolver)=0; virtual void cancelNodeResolve(NodeResolver *resolver)=0;
virtual void runNodeResolverCallbacks()=0; virtual void runNodeResolverCallbacks()=0;

@ -340,6 +340,8 @@ Server::Server(
// Apply item aliases in the node definition manager // Apply item aliases in the node definition manager
m_nodedef->updateAliases(m_itemdef); m_nodedef->updateAliases(m_itemdef);
m_nodedef->setNodeRegistrationStatus(true);
// Perform pending node name resolutions // Perform pending node name resolutions
m_nodedef->runNodeResolverCallbacks(); m_nodedef->runNodeResolverCallbacks();