From 584d00a01c4bcd359cc3e585dbcab5cada662348 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Tue, 30 Jan 2018 00:30:02 +0100 Subject: Add minetest.bulk_set_node call + optimize Environment::set_node call (#6958) * Add minetest.bulk_set_node call + experimental mod unittest * Optimize set_node function to prevent triple lookup on contentfeatures Do only one lookup for old, and try to merge old and new lookup if node is same than previous node * Add benchmark function + optimize vector population to have real results --- src/serverenvironment.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/serverenvironment.cpp') diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 47fcb6e5d..f949021f6 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -917,8 +917,10 @@ bool ServerEnvironment::setNode(v3s16 p, const MapNode &n) INodeDefManager *ndef = m_server->ndef(); MapNode n_old = m_map->getNodeNoEx(p); + const ContentFeatures &cf_old = ndef->get(n_old); + // Call destructor - if (ndef->get(n_old).has_on_destruct) + if (cf_old.has_on_destruct) m_script->node_on_destruct(p, n_old); // Replace node @@ -929,11 +931,15 @@ bool ServerEnvironment::setNode(v3s16 p, const MapNode &n) m_map->updateVManip(p); // Call post-destructor - if (ndef->get(n_old).has_after_destruct) + if (cf_old.has_after_destruct) m_script->node_after_destruct(p, n_old); + // Retrieve node content features + // if new node is same as old, reuse old definition to prevent a lookup + const ContentFeatures &cf_new = n_old == n ? cf_old : ndef->get(n); + // Call constructor - if (ndef->get(n).has_on_construct) + if (cf_new.has_on_construct) m_script->node_on_construct(p, n); return true; -- cgit v1.2.3