summaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
index f2f3018df..19946354c 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -2015,6 +2015,35 @@ inline core::aabbox3d<f32> getNodeBox(v3s16 p, float d)
);
}
+class IntervalLimiter
+{
+public:
+ IntervalLimiter():
+ m_accumulator(0)
+ {
+ }
+ /*
+ dtime: time from last call to this method
+ wanted_interval: interval wanted
+ return value:
+ true: action should be skipped
+ false: action should be done
+ */
+ bool step(float dtime, float wanted_interval)
+ {
+ m_accumulator += dtime;
+ if(m_accumulator < wanted_interval)
+ {
+ dtime = 0;
+ return true;
+ }
+ m_accumulator -= wanted_interval;
+ return false;
+ }
+protected:
+ float m_accumulator;
+};
+
#endif