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

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