Skip to content
This repository
tree: adc37f5741
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 25 lines (19 sloc) 0.581 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <Gosu/Timing.hpp>
#include <unistd.h>
#include <sys/time.h>

void Gosu::sleep(unsigned milliseconds)
{
usleep(milliseconds * 1000);
}

unsigned long Gosu::milliseconds()
{
static unsigned long start = 0;

    timeval tp;
    gettimeofday(&tp, NULL);

if (!start)
start = tp.tv_usec / 1000UL + tp.tv_sec * 1000UL;

    // Truncate to 2^30, C++ users shouldn't mind and Ruby users will
    // have a happy GC on 32-bit systems.
    // No, don't ask why this is an unsigned long then :)
    return (tp.tv_usec / 1000UL + tp.tv_sec * 1000UL - start) & 0x1fffffff;
}
Something went wrong with that request. Please try again.