+ void remove(v3s16 p) {
+ std::map<v3s16, std::multimap<double, NodeTimer>::iterator>::iterator n =
+ m_iterators.find(p);
+ if(n != m_iterators.end()) {
+ double removed_time = n->second->first;
+ m_timers.erase(n->second);
+ m_iterators.erase(n);
+ // Yes, this is float equality, but it is not a problem
+ // since we only test equality of floats as an ordered type
+ // and thus we never lose precision
+ if (removed_time == m_next_trigger_time) {
+ if (m_timers.empty())
+ m_next_trigger_time = -1.;
+ else
+ m_next_trigger_time = m_timers.begin()->first;
+ }
+ }
+ }
+ // Undefined behavior if there already is a timer
+ void insert(const NodeTimer &timer) {
+ v3s16 p = timer.position;
+ double trigger_time = m_time + (double)(timer.timeout - timer.elapsed);
+ std::multimap<double, NodeTimer>::iterator it = m_timers.emplace(trigger_time, timer);
+ m_iterators.emplace(p, it);
+ if (m_next_trigger_time == -1. || trigger_time < m_next_trigger_time)
+ m_next_trigger_time = trigger_time;