X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FTimer.cc;fp=src%2FMoof%2FTimer.cc;h=fb17f1d66e1ac3a89c99c95a4cec94d9412c0dde;hp=4eea488ad7f43d29af7280f63ea3371f2380f4b2;hb=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc;hpb=50c1239917f5e443b8ec91773c85ceb3db7da67b diff --git a/src/Moof/Timer.cc b/src/Moof/Timer.cc index 4eea488..fb17f1d 100644 --- a/src/Moof/Timer.cc +++ b/src/Moof/Timer.cc @@ -76,6 +76,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 @@ -92,26 +108,15 @@ Scalar 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(seconds * 1000.0)); } +#endif // HAVE_CLOCK_GETTIME + } // namespace Mf