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

Last change on this file since 555 was 555, checked in by Sam Hocevar, 11 years ago

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

File size: 1.9 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]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
[555]21#if defined HAVE_CONFIG_H
22#   include "config.h"
23#endif
[56]24
[2]25#include <stdio.h>
26#include <stdlib.h>
27#include <sys/time.h>
28#include <time.h>
[56]29
[481]30#include "timing.h"
[2]31
32#ifdef __APPLE__
33// OSX 10.1 has nanosleep but no header for it!
34extern "C" {
35int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
36}
37#endif
38
39// Constructor
40//
41time_marker::time_marker()
42{
[124]43    get_time();
[2]44}
45
46//
47// get_time()
48// Get the current time
49//
50void time_marker::get_time()
51{
[124]52    struct timeval tv = { 0, 0 };
53    gettimeofday( &tv, NULL );
54    seconds = tv.tv_sec;
55    micro_seconds = tv.tv_usec;
[2]56}
57
58//
59// diff_time()
60// Find the time difference
61//
62double time_marker::diff_time( time_marker *other )
63{
[124]64    return (double)(seconds - other->seconds) + (double)(micro_seconds - other->micro_seconds) / 1000000;
[2]65}
66
67void timer_init()
68{
[124]69    /* Do Nothing */
[2]70}
71
72void timer_uninit()
73{
[124]74    /* Do Nothing */
[2]75}
76
77void milli_wait( unsigned wait_time )
78{
[124]79    struct timespec ts = { 0, wait_time * 1000000 };
80    nanosleep( &ts, NULL );
[2]81}
82
Note: See TracBrowser for help on using the repository browser.