|
Revision 13041, 2.8 kB
(checked in by robert, 14 months ago)
|
|
Ran script to remove trailing spaces and tabs
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <stdio.h> |
|---|
| 15 | #include <string.h> |
|---|
| 16 | |
|---|
| 17 | #include <osg/Timer> |
|---|
| 18 | #include <osg/Notify> |
|---|
| 19 | |
|---|
| 20 | using namespace osg; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | Timer* Timer::instance() |
|---|
| 30 | { |
|---|
| 31 | static Timer s_timer; |
|---|
| 32 | return &s_timer; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | #ifdef WIN32 |
|---|
| 36 | |
|---|
| 37 | #include <sys/types.h> |
|---|
| 38 | #include <fcntl.h> |
|---|
| 39 | #include <windows.h> |
|---|
| 40 | #include <winbase.h> |
|---|
| 41 | Timer::Timer() |
|---|
| 42 | { |
|---|
| 43 | LARGE_INTEGER frequency; |
|---|
| 44 | if(QueryPerformanceFrequency(&frequency)) |
|---|
| 45 | { |
|---|
| 46 | _secsPerTick = 1.0/(double)frequency.QuadPart; |
|---|
| 47 | } |
|---|
| 48 | else |
|---|
| 49 | { |
|---|
| 50 | _secsPerTick = 1.0; |
|---|
| 51 | OSG_NOTICE<<"Error: Timer::Timer() unable to use QueryPerformanceFrequency, "<<std::endl; |
|---|
| 52 | OSG_NOTICE<<"timing code will be wrong, Windows error code: "<<GetLastError()<<std::endl; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | setStartTick(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | Timer_t Timer::tick() const |
|---|
| 59 | { |
|---|
| 60 | LARGE_INTEGER qpc; |
|---|
| 61 | if (QueryPerformanceCounter(&qpc)) |
|---|
| 62 | { |
|---|
| 63 | return qpc.QuadPart; |
|---|
| 64 | } |
|---|
| 65 | else |
|---|
| 66 | { |
|---|
| 67 | OSG_NOTICE<<"Error: Timer::Timer() unable to use QueryPerformanceCounter, "<<std::endl; |
|---|
| 68 | OSG_NOTICE<<"timing code will be wrong, Windows error code: "<<GetLastError()<<std::endl; |
|---|
| 69 | return 0; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | #else |
|---|
| 74 | #include <unistd.h> |
|---|
| 75 | |
|---|
| 76 | Timer::Timer( void ) |
|---|
| 77 | { |
|---|
| 78 | _secsPerTick = (1.0 / (double) 1000000); |
|---|
| 79 | |
|---|
| 80 | setStartTick(); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | #if defined(_POSIX_TIMERS) && ( _POSIX_TIMERS > 0 ) && defined(_POSIX_MONOTONIC_CLOCK) |
|---|
| 84 | #include <time.h> |
|---|
| 85 | |
|---|
| 86 | Timer_t Timer::tick() const |
|---|
| 87 | { |
|---|
| 88 | struct timespec ts; |
|---|
| 89 | clock_gettime(CLOCK_MONOTONIC, &ts); |
|---|
| 90 | return ((osg::Timer_t)ts.tv_sec)*1000000+(osg::Timer_t)ts.tv_nsec/1000; |
|---|
| 91 | } |
|---|
| 92 | #else |
|---|
| 93 | #include <sys/time.h> |
|---|
| 94 | |
|---|
| 95 | Timer_t Timer::tick() const |
|---|
| 96 | { |
|---|
| 97 | struct timeval tv; |
|---|
| 98 | gettimeofday(&tv, NULL); |
|---|
| 99 | return ((osg::Timer_t)tv.tv_sec)*1000000+(osg::Timer_t)tv.tv_usec; |
|---|
| 100 | } |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | #endif |
|---|