]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Timer.cc
more featureful sound class
[chaz/yoink] / src / Moof / Timer.cc
index 4eea488ad7f43d29af7280f63ea3371f2380f4b2..bc7aae220416687747de6f29bf07c39fc39a3f67 100644 (file)
 #include <ctime>
 #include <stdexcept>
 
+#include "Log.hh"
 #include "Timer.hh"
 
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <SDL/SDL.h>
+
 
 namespace Mf {
 
@@ -76,6 +79,22 @@ Scalar getTicks()
        return Scalar(ts.tv_sec - reference) + Scalar(ts.tv_nsec) / 1000000000.0;
 }
 
+void sleep(Scalar seconds, bool absolute)
+{
+       struct timespec ts;
+       int ret;
+
+       if (absolute) seconds -= getTicks();
+       ts.tv_sec = time_t(seconds);
+       ts.tv_nsec = long((seconds - Scalar(ts.tv_sec)) * 1000000000.0);
+
+       do
+       {
+               ret = nanosleep(&ts, &ts);
+       }
+       while (ret == -1 && errno == EINTR);
+}
+
 
 #else // ! HAVE_CLOCK_GETTIME
 
@@ -84,34 +103,20 @@ Scalar getTicks()
 // SDL only promises centisecond accuracy, but that's better than a kick in the
 // butt.
 
-#include <SDL/SDL.h>
-
 Scalar getTicks()
 {
        Uint32 ms = SDL_GetTicks();
        return Scalar(ms / 1000) + Scalar(ms % 1000) / 1000.0;
 }
 
-
-#endif // HAVE_CLOCK_GETTIME
-
-
 void sleep(Scalar seconds, bool absolute)
 {
-       struct timespec ts;
-       int ret;
-
        if (absolute) seconds -= getTicks();
-       ts.tv_sec = time_t(seconds);
-       ts.tv_nsec = long((seconds - Scalar(ts.tv_sec)) * 1000000000.0);
-
-       do
-       {
-               ret = nanosleep(&ts, &ts);
-       }
-       while (ret == -1 && errno == EINTR);
+       SDL_Delay(Uint32(cml::clamp(int(seconds * 1000.0), 0, 1000)));
 }
 
+#endif // HAVE_CLOCK_GETTIME
+
 
 } // namespace Mf
 
This page took 0.018818 seconds and 4 git commands to generate.