aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/a02142.html
blob: 9ba0a993ab259b5d46a73812fda3695fbb488da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>NeL: NLMISC::CTime class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.6 -->
<div class="qindex">  <form class="search" action="search.php" method="get">
<a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a>  | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<h1>NLMISC::CTime Class Reference</h1><code>#include &lt;<a class="el" href="a06553.html">time_nl.h</a>&gt;</code>
<p>
<p>Inheritance diagram for NLMISC::CTime:
<p><center><img src="a02142.png" usemap="#NLMISC::CTime_map" border="0" alt=""></center>
<map name="NLMISC::CTime_map">
<area href="a02141.html" alt="NLNET::_CUniTime" shape="rect" coords="0,56,118,80">
</map>
<hr><a name="_details"></a><h2>Detailed Description</h2>
This class provide a independant local time system. <dl compact><dt><b>Author:</b></dt><dd>Vianney Lecroart <p>
Nevrax France </dd></dl>
<dl compact><dt><b>Date:</b></dt><dd>2000 </dd></dl>

<p>

<p>
Definition at line <a class="el" href="a06553.html#l00057">57</a> of file <a class="el" href="a06553.html">time_nl.h</a>.<table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
<tr><td colspan=2><br><h2>Static Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a05378.html#a242">TTime</a>&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee0">getLocalTime</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a05378.html#a243">TTicks</a>&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="a04558.html#a11">uint32</a>&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee2">getSecondsSince1970</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align=right valign=top>double&nbsp;</td><td class="memItemRight" valign=bottom><a class="el" href="a02142.html#NLMISC_1_1CTimee3">ticksToSecond</a> (<a class="el" href="a05378.html#a243">TTicks</a> ticks)</td></tr>

</table>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="NLMISC_1_1CTimee0" doxytag="NLMISC::CTime::getLocalTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> <a class="el" href="a05378.html#a242">TTime</a> NLMISC::CTime::getLocalTime </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [static]</code></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
get the time in millisecond. It's a <b>local</b> time, it means that the value is <b>different</b> on 2 differents computers. Use the CUniTime to get a universal time that is the same on all computers. <dl compact><dt><b>Warning:</b></dt><dd>On Windows, the value is on 32 bits only.</dd></dl>

<p>
Definition at line <a class="el" href="a06552.html#l00055">55</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a06552.html#l00105">getPerformanceTime()</a>, <a class="el" href="a05622.html#l00154">nlerror</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
Referenced by <a class="el" href="a05416.html#l00396">NLAIAGENT::CAgentWatchTimer::attach()</a>, <a class="el" href="a05466.html#l00565">NLSOUND::CAudioMixerUser::curTime()</a>, <a class="el" href="a06737.html#l01170">NL3D::CWaterModel::doSimpleRender()</a>, <a class="el" href="a05593.html#l00441">NLSOUND::CComplexSource::getTime()</a>, <a class="el" href="a05926.html#l00145">loadForm()</a>, <a class="el" href="a05593.html#l00577">NLSOUND::CComplexSource::onEvent()</a>, <a class="el" href="a05593.html#l00456">NLSOUND::CComplexSource::onUpdate()</a>, <a class="el" href="a05593.html#l00105">NLSOUND::CComplexSource::playStuf()</a>, <a class="el" href="a05416.html#l00140">NLAIAGENT::CAgentManagerTimer::CRunTimer::run()</a>, <a class="el" href="a05416.html#l00631">NLAIAGENT::CAgentClockTimer::runActivity()</a>, <a class="el" href="a05416.html#l00280">NLAIAGENT::CAgentWatchTimer::runActivity()</a>, <a class="el" href="a06737.html#l00831">NL3D::CWaterModel::setupMaterialNVertexShader()</a>, <a class="el" href="a06552.html#l00143">ticksToSecond()</a>, <a class="el" href="a06420.html#l00679">NLSOUND::CSoundDriverDSound::TimerCallback()</a>, <a class="el" href="a06420.html#l00703">NLSOUND::CSoundDriverDSound::update()</a>, <a class="el" href="a05465.html#l01268">NLSOUND::CAudioMixerUser::update()</a>, and <a class="el" href="a05471.html#l00861">NLSOUND::CBackgroundSoundManager::updateBackgroundStatus()</a>.
<p>
<div class="fragment"><pre>00056 {
00057 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
00058 <span class="preprocessor"></span>
00059         <span class="keyword">static</span> <span class="keywordtype">bool</span> byperfcounter;
00060         <span class="keyword">static</span> <span class="keywordtype">bool</span> initdone = <span class="keyword">false</span>;
00061 
00062         <span class="comment">// Initialization</span>
00063         <span class="keywordflow">if</span> ( ! initdone )
00064         {
00065                 byperfcounter = (<a class="code" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a>() != 0);
00066                 initdone = <span class="keyword">true</span>;
00067         }
00068 
00069         <span class="comment">/* Retrieve time is ms</span>
00070 <span class="comment">     * Why do we prefer getPerformanceTime() to timeGetTime() ? Because on one dual-processor Win2k</span>
00071 <span class="comment">         * PC, we have noticed that timeGetTime() slows down when the client is running !!!</span>
00072 <span class="comment">         */</span>
00073 
00074 
00075         <span class="comment">/* Now we have noticed that on all WinNT4 PC the getPerformanceTime can give us value that</span>
00076 <span class="comment">         * are less than previous</span>
00077 <span class="comment">         */</span>
00078 
00079         <span class="comment">//if ( byperfcounter )</span>
00080         <span class="comment">//{</span>
00081         <span class="comment">//      return (TTime)(ticksToSecond(getPerformanceTime()) * 1000.0f);</span>
00082         <span class="comment">//}</span>
00083         <span class="comment">//else</span>
00084         <span class="comment">//{</span>
00085                 <span class="keywordflow">return</span> timeGetTime();
00086         <span class="comment">//}</span>
00087 
00088 <span class="preprocessor">#elif defined (NL_OS_UNIX)</span>
00089 <span class="preprocessor"></span>
00090         <span class="keyword">struct </span>timeval tv;
00091 
00092         <span class="keywordflow">if</span> ( gettimeofday( &amp;tv, NULL) == -1 )
00093         {
00094                 <a class="code" href="a04199.html#a3">nlerror</a> (<span class="stringliteral">"Cannot get time of day."</span>);
00095         }
00096         <span class="keywordflow">return</span> (<a class="code" href="a05378.html#a242">TTime</a>)tv.tv_sec * (<a class="code" href="a05378.html#a242">TTime</a>)1000 + (<a class="code" href="a05378.html#a242">TTime</a>)tv.tv_usec / (<a class="code" href="a05378.html#a242">TTime</a>)1000;
00097 
00098 <span class="preprocessor">#endif</span>
00099 <span class="preprocessor"></span>}
</pre></div>    </td>
  </tr>
</table>
<a class="anchor" name="NLMISC_1_1CTimee1" doxytag="NLMISC::CTime::getPerformanceTime" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> <a class="el" href="a05378.html#a243">TTicks</a> NLMISC::CTime::getPerformanceTime </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [static]</code></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
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.
<p>
Definition at line <a class="el" href="a06552.html#l00105">105</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a05622.html#l00135">nlwarning</a>, <a class="el" href="a06553.html#l00048">NLMISC::TTicks</a>, and <a class="el" href="a05646.html#l00236">x</a>.
<p>
Referenced by <a class="el" href="a06552.html#l00055">getLocalTime()</a>, <a class="el" href="a06479.html#l00441">NLMISC::CSystemInfo::getProcessorFrequency()</a>, <a class="el" href="a05412.html#l01628">NLAIAGENT::CAgentScript::run()</a>, <a class="el" href="a05412.html#l01284">NLAIAGENT::CAgentScript::sendMessage()</a>, and <a class="el" href="a06552.html#l00143">ticksToSecond()</a>.
<p>
<div class="fragment"><pre>00106 {
00107 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
00108 <span class="preprocessor"></span>        LARGE_INTEGER ret;
00109         <span class="keywordflow">if</span> (QueryPerformanceCounter (&amp;ret))
00110                 <span class="keywordflow">return</span> ret.QuadPart;
00111         <span class="keywordflow">else</span>
00112                 <span class="keywordflow">return</span> 0;
00113 <span class="preprocessor">#else // NL_OS_WINDOWS</span>
00114 <span class="preprocessor"></span>
00115 <span class="preprocessor">#ifdef HAVE_X86</span>
00116 <span class="preprocessor"></span>        <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="a04223.html#a572">x</a>;
00117         __asm__ <span class="keyword">volatile</span> (<span class="stringliteral">".byte 0x0f, 0x31"</span> : <span class="stringliteral">"=A"</span> (<a class="code" href="a04223.html#a572">x</a>));
00118         <span class="keywordflow">return</span> <a class="code" href="a04223.html#a572">x</a>;
00119 <span class="preprocessor">#else // HAVE_X86</span>
00120 <span class="preprocessor"></span>        <span class="keyword">static</span> <span class="keywordtype">bool</span> firstWarn = <span class="keyword">true</span>;
00121         <span class="keywordflow">if</span> (firstWarn)
00122         {
00123                 <a class="code" href="a04199.html#a2">nlwarning</a> (<span class="stringliteral">"TTicks CTime::getPerformanceTime () is not implemented for your processor, returning 0"</span>);
00124                 firstWarn = <span class="keyword">false</span>;
00125         }
00126         <span class="keywordflow">return</span> 0;
00127 <span class="preprocessor">#endif // HAVE_X86</span>
00128 <span class="preprocessor"></span>
00129 <span class="preprocessor">#endif // NL_OS_WINDOWS</span>
00130 <span class="preprocessor"></span>}
</pre></div>    </td>
  </tr>
</table>
<a class="anchor" name="NLMISC_1_1CTimee2" doxytag="NLMISC::CTime::getSecondsSince1970" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> <a class="el" href="a04558.html#a11">uint32</a> NLMISC::CTime::getSecondsSince1970 </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [static]</code></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
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).
<p>
Definition at line <a class="el" href="a06552.html#l00045">45</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a05981.html#l00100">uint32</a>.
<p>
Referenced by <a class="el" href="a06033.html#l00258">NLAINIMAT::CMHiCSagent::CTemporaryPriority::CTemporaryPriority()</a>, and <a class="el" href="a06032.html#l01219">NLAINIMAT::CMHiCSagent::learningComputation()</a>.
<p>
<div class="fragment"><pre>00046 {
00047         <span class="keywordflow">return</span> (<a class="code" href="a04558.html#a11">uint32</a>) time (NULL);
00048 }
</pre></div>    </td>
  </tr>
</table>
<a class="anchor" name="NLMISC_1_1CTimee3" doxytag="NLMISC::CTime::ticksToSecond" ></a><p>
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> double NLMISC::CTime::ticksToSecond </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top"><a class="el" href="a05378.html#a243">TTicks</a>&nbsp;</td>
          <td class="mdname1" valign="top" nowrap> <em>ticks</em>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [static]</code></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
convert a ticks count into second. If the performance time is not supported on this hardware, it returns 0.0.
<p>
Definition at line <a class="el" href="a06552.html#l00143">143</a> of file <a class="el" href="a06552.html">time_nl.cpp</a>.
<p>
References <a class="el" href="a06552.html#l00055">getLocalTime()</a>, <a class="el" href="a06552.html#l00105">getPerformanceTime()</a>, <a class="el" href="a05981.html#l00101">sint64</a>, <a class="el" href="a06553.html#l00048">NLMISC::TTicks</a>, and <a class="el" href="a06553.html#l00047">NLMISC::TTime</a>.
<p>
Referenced by <a class="el" href="a06348.html#l00300">NL3D::CScene::render()</a>.
<p>
<div class="fragment"><pre>00144 {
00145 <span class="preprocessor">#ifdef NL_OS_WINDOWS</span>
00146 <span class="preprocessor"></span>        LARGE_INTEGER ret;
00147         <span class="keywordflow">if</span> (QueryPerformanceFrequency(&amp;ret))
00148         {
00149                 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<a class="code" href="a04558.html#a12">sint64</a>)ticks/(<span class="keywordtype">double</span>)ret.QuadPart;
00150         }
00151         <span class="keywordflow">else</span>
00152 <span class="preprocessor">#endif // NL_OS_WINDOWS</span>
00153 <span class="preprocessor"></span>        {
00154                 <span class="keyword">static</span> <span class="keywordtype">bool</span> benchFrequency = <span class="keyword">true</span>;
00155                 <span class="keyword">static</span> <a class="code" href="a04558.html#a12">sint64</a> freq = 0;
00156                 <span class="keywordflow">if</span> (benchFrequency)
00157                 {
00158                         <span class="comment">// try to have an estimation of the cpu frequency</span>
00159 
00160                         <a class="code" href="a05378.html#a243">TTicks</a> tickBefore = <a class="code" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a> ();
00161                         <a class="code" href="a05378.html#a243">TTicks</a> tickAfter = tickBefore;
00162                         <a class="code" href="a05378.html#a242">TTime</a> timeBefore = <a class="code" href="a02142.html#NLMISC_1_1CTimee0">getLocalTime</a> ();
00163                         <a class="code" href="a05378.html#a242">TTime</a> timeAfter = timeBefore;
00164                         <span class="keywordflow">while</span> (<span class="keyword">true</span>)
00165                         {
00166                                 <span class="keywordflow">if</span> (timeAfter - timeBefore &gt; 1000)
00167                                         <span class="keywordflow">break</span>;
00168                                 timeAfter = <a class="code" href="a02142.html#NLMISC_1_1CTimee0">getLocalTime</a> ();
00169                                 tickAfter = <a class="code" href="a02142.html#NLMISC_1_1CTimee1">getPerformanceTime</a> ();
00170                         }
00171 
00172                         <a class="code" href="a05378.html#a242">TTime</a> timeDelta = timeAfter - timeBefore;
00173                         <a class="code" href="a05378.html#a243">TTicks</a> tickDelta = tickAfter - tickBefore;
00174 
00175                         freq = 1000 * tickDelta / timeDelta;
00176                         benchFrequency = <span class="keyword">false</span>;
00177                 }
00178 
00179                 <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(<a class="code" href="a04558.html#a12">sint64</a>)ticks/(<span class="keywordtype">double</span>)freq;
00180         }
00181 }
</pre></div>    </td>
  </tr>
</table>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="a06553.html">time_nl.h</a><li><a class="el" href="a06552.html">time_nl.cpp</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Tue Mar 16 13:37:31 2004 for NeL by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 > 
</a>1.3.6 </small></address>
</body>
</html>