]> Dogcows Code - chaz/yoink/blobdiff - src/moof/timer.cc
testing new non-autotools build system
[chaz/yoink] / src / moof / timer.cc
index 273625640ab4a78dedfda47a691981972a98d7cf..e31e49fdfb23a567ff857e46c4932e483d921fe3 100644 (file)
 
 #include <SDL/SDL.h>
 
-#include "log.hh"
+#include "debug.hh"
 #include "timer.hh"
 
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 
 namespace moof {
 
 
-scalar timer::gNextFire = std::numeric_limits<scalar>::max();
-std::map<unsigned,timer*> timer::gTimers;
+scalar timer::next_expiration_ = std::numeric_limits<scalar>::max();
+hash<unsigned,timer*,hash_function> timer::timers_;
 
 
 unsigned timer::new_identifier()
@@ -58,9 +54,9 @@ void timer::init(const function& function, scalar seconds, mode mode)
                }
 
                id_ = new_identifier();
-               gTimers.insert(std::pair<unsigned,timer*>(id_, this));
+               timers_.insert(std::pair<unsigned,timer*>(id_, this));
 
-               if (absolute_ < gNextFire) gNextFire = absolute_;
+               if (absolute_ < next_expiration_) next_expiration_ = absolute_;
        }
 }
 
@@ -74,10 +70,13 @@ void timer::invalidate()
 {
        if (mode_ != invalid)
        {
-               gTimers.erase(id_);
+               timers_.erase(id_);
                mode_ = invalid;
 
-               if (is_equal(absolute_, gNextFire)) gNextFire = find_next_expiration();
+               if (is_equal(absolute_, next_expiration_))
+               {
+                       next_expiration_ = find_next_expiration();
+               }
        }
 }
 
@@ -95,7 +94,10 @@ void timer::fire()
                if (is_equal(absolute_, t, 1.0)) absolute_ += interval_;
                else absolute_ = interval_ + t;
 
-               if (is_equal(absolute, gNextFire)) gNextFire = find_next_expiration();
+               if (is_equal(absolute, next_expiration_))
+               {
+                       next_expiration_ = find_next_expiration();
+               }
        }
        else
        {
@@ -106,16 +108,16 @@ void timer::fire()
 
 scalar timer::find_next_expiration()
 {
-       std::map<unsigned,timer*>::iterator it;
-       scalar nextFire = std::numeric_limits<scalar>::max();
+       scalar next_fire = std::numeric_limits<scalar>::max();
 
-       for (it = gTimers.begin(); it != gTimers.end(); ++it)
+       hash<unsigned,timer*,hash_function>::iterator it;
+       for (it = timers_.begin(); it != timers_.end(); ++it)
        {
                scalar absolute = (*it).second->absolute_;
-               if (absolute < nextFire) nextFire = absolute;
+               if (absolute < next_fire) next_fire = absolute;
        }
 
-       return nextFire;
+       return next_fire;
 }
 
 
@@ -142,11 +144,10 @@ void timer::fire_expired_timers()
 
 void timer::fire_expired_timers(scalar t)
 {
-       std::map<unsigned,timer*>::iterator it;
-
-       if (gNextFire > t) return;
+       if (next_expiration_ > t) return;
 
-       for (it = gTimers.begin(); it != gTimers.end(); ++it)
+       hash<unsigned,timer*,hash_function>::iterator it;
+       for (it = timers_.begin(); it != timers_.end(); ++it)
        {
                timer* timer = (*it).second;
                if (timer->is_expired()) timer->fire();
@@ -175,7 +176,7 @@ static time_t set_reference()
        return ts.tv_sec;
 }
 
-static const time_t reference = set_reference();
+static const time_t reference_ = set_reference();
 
 
 scalar timer::ticks()
@@ -185,7 +186,7 @@ scalar timer::ticks()
        int result = clock_gettime(CLOCK_MONOTONIC, &ts);
        ASSERT(result == 0 && "cannot access clock");
 
-       return scalar(ts.tv_sec - reference) +
+       return scalar(ts.tv_sec - reference_) +
                   scalar(ts.tv_nsec) / 1000000000.0;
 }
 
@@ -211,7 +212,7 @@ void timer::sleep(scalar seconds, mode mode)
 
 // If we don't have posix timers, we'll have to use a different timing
 // method.  SDL only promises centisecond accuracy, but that's better than
-// a kick in the pants.
+// a kick in the pants.  
 
 scalar timer::ticks()
 {
This page took 0.022225 seconds and 4 git commands to generate.