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

Last change on this file since 551 was 494, checked in by Sam Hocevar, 12 years ago

style: remove trailing spaces, fix copyright statements.

File size: 1.8 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This program is free software; you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation; either version 2 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software Foundation,
18 *  Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 */
20
21#include "config.h"
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <sys/time.h>
26#include <time.h>
27
28#include "timing.h"
29
30#ifdef __APPLE__
31// OSX 10.1 has nanosleep but no header for it!
32extern "C" {
33int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
34}
35#endif
36
37// Constructor
38//
39time_marker::time_marker()
40{
41    get_time();
42}
43
44//
45// get_time()
46// Get the current time
47//
48void time_marker::get_time()
49{
50    struct timeval tv = { 0, 0 };
51    gettimeofday( &tv, NULL );
52    seconds = tv.tv_sec;
53    micro_seconds = tv.tv_usec;
54}
55
56//
57// diff_time()
58// Find the time difference
59//
60double time_marker::diff_time( time_marker *other )
61{
62    return (double)(seconds - other->seconds) + (double)(micro_seconds - other->micro_seconds) / 1000000;
63}
64
65void timer_init()
66{
67    /* Do Nothing */
68}
69
70void timer_uninit()
71{
72    /* Do Nothing */
73}
74
75void milli_wait( unsigned wait_time )
76{
77    struct timespec ts = { 0, wait_time * 1000000 };
78    nanosleep( &ts, NULL );
79}
80
Note: See TracBrowser for help on using the repository browser.