[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 | |
---|
| 21 | #include "config.h" |
---|
| 22 | |
---|
[2] | 23 | #include <stdio.h> |
---|
| 24 | #include <stdlib.h> |
---|
| 25 | #include <sys/time.h> |
---|
| 26 | #include <time.h> |
---|
[56] | 27 | |
---|
[481] | 28 | #include "timing.h" |
---|
[2] | 29 | |
---|
| 30 | #ifdef __APPLE__ |
---|
| 31 | // OSX 10.1 has nanosleep but no header for it! |
---|
| 32 | extern "C" { |
---|
| 33 | int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); |
---|
| 34 | } |
---|
| 35 | #endif |
---|
| 36 | |
---|
| 37 | // Constructor |
---|
| 38 | // |
---|
| 39 | time_marker::time_marker() |
---|
| 40 | { |
---|
[124] | 41 | get_time(); |
---|
[2] | 42 | } |
---|
| 43 | |
---|
| 44 | // |
---|
| 45 | // get_time() |
---|
| 46 | // Get the current time |
---|
| 47 | // |
---|
| 48 | void time_marker::get_time() |
---|
| 49 | { |
---|
[124] | 50 | struct timeval tv = { 0, 0 }; |
---|
| 51 | gettimeofday( &tv, NULL ); |
---|
| 52 | seconds = tv.tv_sec; |
---|
| 53 | micro_seconds = tv.tv_usec; |
---|
[2] | 54 | } |
---|
| 55 | |
---|
| 56 | // |
---|
| 57 | // diff_time() |
---|
| 58 | // Find the time difference |
---|
| 59 | // |
---|
| 60 | double time_marker::diff_time( time_marker *other ) |
---|
| 61 | { |
---|
[124] | 62 | return (double)(seconds - other->seconds) + (double)(micro_seconds - other->micro_seconds) / 1000000; |
---|
[2] | 63 | } |
---|
| 64 | |
---|
| 65 | void timer_init() |
---|
| 66 | { |
---|
[124] | 67 | /* Do Nothing */ |
---|
[2] | 68 | } |
---|
| 69 | |
---|
| 70 | void timer_uninit() |
---|
| 71 | { |
---|
[124] | 72 | /* Do Nothing */ |
---|
[2] | 73 | } |
---|
| 74 | |
---|
| 75 | void milli_wait( unsigned wait_time ) |
---|
| 76 | { |
---|
[124] | 77 | struct timespec ts = { 0, wait_time * 1000000 }; |
---|
| 78 | nanosleep( &ts, NULL ); |
---|
[2] | 79 | } |
---|
| 80 | |
---|