LCOV - code coverage report
Current view: top level - src - nodetimer.h (source / functions) Hit Total Coverage
Test: report Lines: 2 20 10.0 %
Date: 2015-07-11 18:23:49 Functions: 2 9 22.2 %

          Line data    Source code
       1             : /*
       2             : Minetest
       3             : Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
       4             : 
       5             : This program is free software; you can redistribute it and/or modify
       6             : it under the terms of the GNU Lesser General Public License as published by
       7             : the Free Software Foundation; either version 2.1 of the License, or
       8             : (at your option) any later version.
       9             : 
      10             : This program is distributed in the hope that it will be useful,
      11             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             : GNU Lesser General Public License for more details.
      14             : 
      15             : You should have received a copy of the GNU Lesser General Public License along
      16             : with this program; if not, write to the Free Software Foundation, Inc.,
      17             : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             : */
      19             : 
      20             : #ifndef NODETIMER_HEADER
      21             : #define NODETIMER_HEADER
      22             : 
      23             : #include "irr_v3d.h"
      24             : #include <iostream>
      25             : #include <map>
      26             : 
      27             : /*
      28             :         NodeTimer provides per-node timed callback functionality.
      29             :         Can be used for:
      30             :         - Furnaces, to keep the fire burnin'
      31             :         - "activated" nodes that snap back to their original state
      32             :           after a fixed amount of time (mesecons buttons, for example)
      33             : */
      34             : 
      35             : class NodeTimer
      36             : {
      37             : public:
      38           0 :         NodeTimer(): timeout(0.), elapsed(0.) {}
      39           0 :         NodeTimer(f32 timeout_, f32 elapsed_):
      40           0 :                 timeout(timeout_), elapsed(elapsed_) {}
      41           0 :         ~NodeTimer() {}
      42             :         
      43             :         void serialize(std::ostream &os) const;
      44             :         void deSerialize(std::istream &is);
      45             :         
      46             :         f32 timeout;
      47             :         f32 elapsed;
      48             : };
      49             : 
      50             : /*
      51             :         List of timers of all the nodes of a block
      52             : */
      53             : 
      54             : class NodeTimerList
      55             : {
      56             : public:
      57         751 :         NodeTimerList() {}
      58         751 :         ~NodeTimerList() {}
      59             :         
      60             :         void serialize(std::ostream &os, u8 map_format_version) const;
      61             :         void deSerialize(std::istream &is, u8 map_format_version);
      62             :         
      63             :         // Get timer
      64           0 :         NodeTimer get(v3s16 p){
      65           0 :                 std::map<v3s16, NodeTimer>::iterator n = m_data.find(p);
      66           0 :                 if(n == m_data.end())
      67           0 :                         return NodeTimer();
      68           0 :                 return n->second;
      69             :         }
      70             :         // Deletes timer
      71           0 :         void remove(v3s16 p){
      72           0 :                 m_data.erase(p);
      73           0 :         }
      74             :         // Deletes old timer and sets a new one
      75           0 :         void set(v3s16 p, NodeTimer t){
      76           0 :                 m_data[p] = t;
      77           0 :         }
      78             :         // Deletes all timers
      79           0 :         void clear(){
      80           0 :                 m_data.clear();
      81           0 :         }
      82             : 
      83             :         // A step in time. Returns map of elapsed timers.
      84             :         std::map<v3s16, NodeTimer> step(float dtime);
      85             : 
      86             : private:
      87             :         std::map<v3s16, NodeTimer> m_data;
      88             : };
      89             : 
      90             : #endif
      91             : 

Generated by: LCOV version 1.11