]> Dogcows Code - chaz/yoink/blobdiff - src/moof/timer.cc
mesh and other random adjustments
[chaz/yoink] / src / moof / timer.cc
index b5c55ff528f6f3c6205afbb128a8615acc882f09..74acc1c203a9bc45b7cb894835e55b9e760162fc 100644 (file)
@@ -9,7 +9,7 @@
 *
 **************************************************************************/
 
-#include "../config.h"
+#include "config.h"
 
 #include <cerrno>
 #include <ctime>
@@ -113,7 +113,7 @@ scalar timer::find_next_expiration()
        scalar next_fire = std::numeric_limits<scalar>::max();
 
        hash<unsigned,timer*,hash_function>::iterator it;
-       for (it = timers_.begin(); it != timers_.end(); ++it)
+       for (it = timers_.begin(); it.valid(); ++it)
        {
                scalar absolute = (*it).second->absolute_;
                if (absolute < next_fire) next_fire = absolute;
@@ -139,25 +139,22 @@ bool timer::is_repeating() const
 }
 
 
-void timer::fire_expired_timers()
-{
-       fire_expired_timers(ticks());
-}
-
 void timer::fire_expired_timers(scalar t)
 {
        if (next_expiration_ > t) return;
 
        hash<unsigned,timer*,hash_function>::iterator it;
-       for (it = timers_.begin(); it != timers_.end(); ++it)
+       for (it = timers_.begin(); it.valid(); ++it)
        {
                timer* timer = (*it).second;
                if (timer->is_expired()) timer->fire();
+
+               if (it.end()) break;
        }
 }
 
 
-#if HAVE_CLOCK_GETTIME
+#if USE_CLOCK_GETTIME
 
 // Since the monotonic clock will provide us with the time since the
 // computer started, the number of seconds since that time could easily
@@ -189,7 +186,7 @@ scalar timer::ticks()
        ASSERT(result == 0 && "cannot access clock");
 
        return scalar(ts.tv_sec - reference_) +
-                  scalar(ts.tv_nsec) / 1000000000.0;
+                  scalar(ts.tv_nsec) * SCALAR(0.000000001);
 }
 
 void timer::sleep(scalar seconds, mode mode)
@@ -199,7 +196,7 @@ void timer::sleep(scalar seconds, mode mode)
 
        if (mode == absolute) seconds -= ticks();
        ts.tv_sec = time_t(seconds);
-       ts.tv_nsec = long((seconds - scalar(ts.tv_sec)) * 1000000000.0);
+       ts.tv_nsec = long((seconds - scalar(ts.tv_sec)) * SCALAR(1000000000.0));
 
        do
        {
@@ -209,7 +206,7 @@ void timer::sleep(scalar seconds, mode mode)
 }
 
 
-#else // ! HAVE_CLOCK_GETTIME
+#else // ! USE_CLOCK_GETTIME
 
 
 // If we don't have posix timers, we'll have to use a different timing
@@ -219,16 +216,16 @@ void timer::sleep(scalar seconds, mode mode)
 scalar timer::ticks()
 {
        Uint32 ms = SDL_GetTicks();
-       return scalar(ms / 1000) + scalar(ms % 1000) / 1000.0;
+       return scalar(ms / 1000) + scalar(ms % 1000) * SCALAR(0.001);
 }
 
 void timer::sleep(scalar seconds, mode mode)
 {
        if (mode == absolute) seconds -= ticks();
-       SDL_Delay(Uint32(clamp(int(seconds * 1000.0), 0, 1000)));
+       SDL_Delay(Uint32(clamp(Uint32(seconds * SCALAR(1000.0)), 0, 1000)));
 }
 
-#endif // HAVE_CLOCK_GETTIME
+#endif // USE_CLOCK_GETTIME
 
 
 } // namespace moof
This page took 0.023384 seconds and 4 git commands to generate.