Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/timer.cc @ 8932

Last change on this file since 8932 was 7919, checked in by bensch, 18 years ago

orxonox/trunk: merged the gui branche back
merged with command:
https://svn.orxonox.net/orxonox/branches/gui
no conflicts

File size: 975 bytes
RevLine 
[7899]1/**
2 * @file timer.cc
3 * @brief A Timer class, that handles all about time.
4 *
5 * code taken from audiere.
6 */
7
8#include "timer.h"
9
10
11#include <time.h>
12#include <sys/time.h>
13
[7909]14#ifdef __WIN32__
15#include <windows.h>
16int gettimeofday
17      (struct timeval* tp, void* tzp) {
18    DWORD t;
19    t = timeGetTime();
20    tp->tv_sec = t / 1000;
21    tp->tv_usec = 1000 * (t % 1000 );
22    /* 0 indicates success. */
23    return 0;
24}
25#endif
26
[7900]27/**
28 * @returns the current time in Second exact to the micro-second
29 */
[7899]30double Timer::getNow() {
31
32#if HAVE_CLOCK_GETTIME
[7909]33
[7899]34   // use the POSIX realtime clock to get the current time
35    struct timespec tp;
36    int result = clock_gettime(CLOCK_REALTIME, &tp);
37    if (result == 0) {
38      return tp.tv_sec * tp.tv_nsec / 1000000000.0;
39    }
40#endif
41
42    // can't use realtime clock!  Try to use gettimeofday
43    struct timeval tv;
44    gettimeofday(&tv, 0);
45    return tv.tv_sec + tv.tv_usec / 1000000.0;
46}
Note: See TracBrowser for help on using the repository browser.