source: abuse/trunk/src/sdlport/timing.cpp @ 2

Last change on this file since 2 was 2, checked in by Sam Hocevar, 14 years ago
  • imported original 0.7.0 tarball
File size: 919 bytes
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <sys/time.h>
4#include <time.h>
5#include "timing.hpp"
6
7#ifdef __APPLE__
8// OSX 10.1 has nanosleep but no header for it!
9extern "C" {
10int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
11}
12#endif
13
14// Constructor
15//
16time_marker::time_marker()
17{
18        get_time();
19}
20
21//
22// get_time()
23// Get the current time
24//
25void time_marker::get_time()
26{
27        struct timeval tv = { 0, 0 };
28        gettimeofday( &tv, NULL );
29        seconds = tv.tv_sec;
30        micro_seconds = tv.tv_usec;
31}
32
33//
34// diff_time()
35// Find the time difference
36//
37double time_marker::diff_time( time_marker *other )
38{
39        return (double)(seconds - other->seconds) + (double)(micro_seconds - other->micro_seconds) / 1000000;
40}
41
42void timer_init()
43{
44        /* Do Nothing */
45}
46
47void timer_uninit()
48{
49        /* Do Nothing */
50}
51
52void milli_wait( unsigned wait_time )
53{
54        struct timespec ts = { 0, wait_time * 1000000 };
55        nanosleep( &ts, NULL );
56}
57
Note: See TracBrowser for help on using the repository browser.