Exemple #1
0
double Timer::getTimeSinceEpoch()
{
    // The timer period (reciprocal of the frequency.)
    static const double timerPeriod = getTimerPeriod();

#if defined(LOVE_LINUX)
    double mt;
    // Check for POSIX timers and monotonic clocks. If not supported, use the gettimeofday fallback.
#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) \
&& (defined(CLOCK_MONOTONIC_RAW) || defined(CLOCK_MONOTONIC))
    timespec t;
#ifdef CLOCK_MONOTONIC_RAW
    clockid_t clk_id = CLOCK_MONOTONIC_RAW;
#else
    clockid_t clk_id = CLOCK_MONOTONIC;
#endif
    if (clock_gettime(clk_id, &t) == 0)
        mt = (double) t.tv_sec + (double) t.tv_nsec / 1000000000.0;
    else
#endif
        mt = getTimeOfDay();
    return mt;
#elif defined(LOVE_MACOSX) || defined(LOVE_IOS)
    return (double) mach_absolute_time() * timerPeriod;
#elif defined(LOVE_WINDOWS)
    LARGE_INTEGER microTime;
    QueryPerformanceCounter(&microTime);
    return (double) microTime.QuadPart * timerPeriod;
#endif
}
Exemple #2
0
Timer::Timer()
    : currTime(0)
    , prevFpsUpdate(0)
    , fps(0)
    , averageDelta(0)
    , fpsUpdateFrequency(1)
    , frames(0)
    , dt(0)
    , timerPeriod(getTimerPeriod())
{
    // Init the SDL timer system (needed for SDL_Delay.)
    if (SDL_InitSubSystem(SDL_INIT_TIMER) < 0)
        throw love::Exception("%s", SDL_GetError());

    prevFpsUpdate = currTime = getTime();
}