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

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

game: get rid of milli_wait() and rewrite the fixed framerate handling.

File size: 1.7 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#if defined HAVE_CONFIG_H
22#   include "config.h"
23#endif
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <sys/time.h>
28#include <time.h>
29
30#include "timing.h"
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{
43    get_time();
44}
45
46//
47// get_time()
48// Get the current time
49//
50void time_marker::get_time()
51{
52    struct timeval tv = { 0, 0 };
53    gettimeofday( &tv, NULL );
54    seconds = tv.tv_sec;
55    micro_seconds = tv.tv_usec;
56}
57
58//
59// diff_time()
60// Find the time difference
61//
62double time_marker::diff_time( time_marker *other )
63{
64    return (double)(seconds - other->seconds) + (double)(micro_seconds - other->micro_seconds) / 1000000;
65}
66
Note: See TracBrowser for help on using the repository browser.