#include <time_nl.h>
Inheritance diagram for NLMISC::CTime:
Nevrax France
Definition at line 57 of file time_nl.h.
Static Public Member Functions | |
TTime | getLocalTime () |
TTicks | getPerformanceTime () |
uint32 | getSecondsSince1970 () |
double | ticksToSecond (TTicks ticks) |
|
get the time in millisecond. It's a local time, it means that the value is different on 2 differents computers. Use the CUniTime to get a universal time that is the same on all computers.
Definition at line 55 of file time_nl.cpp. References getPerformanceTime(), nlerror, and NLMISC::TTime. Referenced by NLAIAGENT::CAgentWatchTimer::attach(), NLSOUND::CAudioMixerUser::curTime(), NL3D::CWaterModel::doSimpleRender(), NLSOUND::CComplexSource::getTime(), loadForm(), NLSOUND::CComplexSource::onEvent(), NLSOUND::CComplexSource::onUpdate(), NLSOUND::CComplexSource::playStuf(), NLAIAGENT::CAgentManagerTimer::CRunTimer::run(), NLAIAGENT::CAgentClockTimer::runActivity(), NLAIAGENT::CAgentWatchTimer::runActivity(), NL3D::CWaterModel::setupMaterialNVertexShader(), ticksToSecond(), NLSOUND::CSoundDriverDSound::TimerCallback(), NLSOUND::CSoundDriverDSound::update(), NLSOUND::CAudioMixerUser::update(), and NLSOUND::CBackgroundSoundManager::updateBackgroundStatus().
00056 { 00057 #ifdef NL_OS_WINDOWS 00058 00059 static bool byperfcounter; 00060 static bool initdone = false; 00061 00062 // Initialization 00063 if ( ! initdone ) 00064 { 00065 byperfcounter = (getPerformanceTime() != 0); 00066 initdone = true; 00067 } 00068 00069 /* Retrieve time is ms 00070 * Why do we prefer getPerformanceTime() to timeGetTime() ? Because on one dual-processor Win2k 00071 * PC, we have noticed that timeGetTime() slows down when the client is running !!! 00072 */ 00073 00074 00075 /* Now we have noticed that on all WinNT4 PC the getPerformanceTime can give us value that 00076 * are less than previous 00077 */ 00078 00079 //if ( byperfcounter ) 00080 //{ 00081 // return (TTime)(ticksToSecond(getPerformanceTime()) * 1000.0f); 00082 //} 00083 //else 00084 //{ 00085 return timeGetTime(); 00086 //} 00087 00088 #elif defined (NL_OS_UNIX) 00089 00090 struct timeval tv; 00091 00092 if ( gettimeofday( &tv, NULL) == -1 ) 00093 { 00094 nlerror ("Cannot get time of day."); 00095 } 00096 return (TTime)tv.tv_sec * (TTime)1000 + (TTime)tv.tv_usec / (TTime)1000; 00097 00098 #endif 00099 } |
|
get the time in processor ticks. Use it for profile purpose. Only implemented under windows for the time. If the performance time is not supported on this hardware, it returns 0. Definition at line 105 of file time_nl.cpp. References nlwarning, NLMISC::TTicks, and x. Referenced by getLocalTime(), NLMISC::CSystemInfo::getProcessorFrequency(), NLAIAGENT::CAgentScript::run(), NLAIAGENT::CAgentScript::sendMessage(), and ticksToSecond().
00106 { 00107 #ifdef NL_OS_WINDOWS 00108 LARGE_INTEGER ret; 00109 if (QueryPerformanceCounter (&ret)) 00110 return ret.QuadPart; 00111 else 00112 return 0; 00113 #else // NL_OS_WINDOWS 00114 00115 #ifdef HAVE_X86 00116 unsigned long long int x; 00117 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); 00118 return x; 00119 #else // HAVE_X86 00120 static bool firstWarn = true; 00121 if (firstWarn) 00122 { 00123 nlwarning ("TTicks CTime::getPerformanceTime () is not implemented for your processor, returning 0"); 00124 firstWarn = false; 00125 } 00126 return 0; 00127 #endif // HAVE_X86 00128 00129 #endif // NL_OS_WINDOWS 00130 } |
|
returns the number of second since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. This values is the same on all computer if computers are synchronized (with NTP for example). Definition at line 45 of file time_nl.cpp. References uint32. Referenced by NLAINIMAT::CMHiCSagent::CTemporaryPriority::CTemporaryPriority(), and NLAINIMAT::CMHiCSagent::learningComputation().
00046 { 00047 return (uint32) time (NULL); 00048 } |
|
convert a ticks count into second. If the performance time is not supported on this hardware, it returns 0.0. Definition at line 143 of file time_nl.cpp. References getLocalTime(), getPerformanceTime(), sint64, NLMISC::TTicks, and NLMISC::TTime. Referenced by NL3D::CScene::render().
00144 { 00145 #ifdef NL_OS_WINDOWS 00146 LARGE_INTEGER ret; 00147 if (QueryPerformanceFrequency(&ret)) 00148 { 00149 return (double)(sint64)ticks/(double)ret.QuadPart; 00150 } 00151 else 00152 #endif // NL_OS_WINDOWS 00153 { 00154 static bool benchFrequency = true; 00155 static sint64 freq = 0; 00156 if (benchFrequency) 00157 { 00158 // try to have an estimation of the cpu frequency 00159 00160 TTicks tickBefore = getPerformanceTime (); 00161 TTicks tickAfter = tickBefore; 00162 TTime timeBefore = getLocalTime (); 00163 TTime timeAfter = timeBefore; 00164 while (true) 00165 { 00166 if (timeAfter - timeBefore > 1000) 00167 break; 00168 timeAfter = getLocalTime (); 00169 tickAfter = getPerformanceTime (); 00170 } 00171 00172 TTime timeDelta = timeAfter - timeBefore; 00173 TTicks tickDelta = tickAfter - tickBefore; 00174 00175 freq = 1000 * tickDelta / timeDelta; 00176 benchFrequency = false; 00177 } 00178 00179 return (double)(sint64)ticks/(double)freq; 00180 } 00181 } |