aboutsummaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
authordarkrose <lisa@ltmnet.com>2012-07-17 23:00:04 +1000
committerPerttu Ahola <celeron55@gmail.com>2012-07-23 08:18:37 +0300
commitcd6becd442a50a6e2f7129108e1c2c495f885764 (patch)
tree9f013b53ff4ec7d4df6ee26769e397f3defee268 /src/environment.cpp
parent829f262c7954c4eb82eff3931d065fce8bc7809e (diff)
downloadminetest-cd6becd442a50a6e2f7129108e1c2c495f885764.tar.gz
minetest-cd6becd442a50a6e2f7129108e1c2c495f885764.tar.bz2
minetest-cd6becd442a50a6e2f7129108e1c2c495f885764.zip
Implement node timers
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index b55b3a6cf..02ca1f71b 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -774,10 +774,18 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
activateObjects(block);
// Run node timers
- std::map<v3s16, f32> elapsed_timers =
+ std::map<v3s16, NodeTimer> elapsed_timers =
block->m_node_timers.step((float)dtime_s);
- if(!elapsed_timers.empty())
- errorstream<<"Node timers don't work yet!"<<std::endl;
+ if(!elapsed_timers.empty()){
+ MapNode n;
+ for(std::map<v3s16, NodeTimer>::iterator
+ i = elapsed_timers.begin();
+ i != elapsed_timers.end(); i++){
+ n = block->getNodeNoEx(i->first);
+ if(scriptapi_node_on_timer(m_lua,i->first,n,i->second.elapsed))
+ block->setNodeTimer(i->first,NodeTimer(i->second.timeout,0));
+ }
+ }
/* Handle ActiveBlockModifiers */
ABMHandler abmhandler(m_abms, dtime_s, this, false);
@@ -1058,10 +1066,18 @@ void ServerEnvironment::step(float dtime)
"Timestamp older than 60s (step)");
// Run node timers
- std::map<v3s16, f32> elapsed_timers =
- block->m_node_timers.step(dtime);
- if(!elapsed_timers.empty())
- errorstream<<"Node timers don't work yet!"<<std::endl;
+ std::map<v3s16, NodeTimer> elapsed_timers =
+ block->m_node_timers.step((float)dtime);
+ if(!elapsed_timers.empty()){
+ MapNode n;
+ for(std::map<v3s16, NodeTimer>::iterator
+ i = elapsed_timers.begin();
+ i != elapsed_timers.end(); i++){
+ n = block->getNodeNoEx(i->first);
+ if(scriptapi_node_on_timer(m_lua,i->first,n,i->second.elapsed))
+ block->setNodeTimer(i->first,NodeTimer(i->second.timeout,0));
+ }
+ }
}
}