\r
interface\r
\r
+{$ifdef win32}\r
+uses\r
+ ltimevalstuff;\r
+{$endif} \r
+\r
type\r
float=extended;\r
\r
\r
function oletounixfloat(t:float):float;\r
function oletounix(t:tdatetime):integer;\r
-function unixtoole(i:integer):tdatetime;\r
+function unixtoole(i:float):tdatetime;\r
\r
{$ifdef win32}\r
function mmtimefloat:float;\r
function qpctimefloat:float;\r
{$endif}\r
\r
+{$ifdef win32}\r
+procedure gettimeofday(var tv:ttimeval);\r
+{$endif}\r
+\r
+\r
const\r
mmtime_driftavgsize=32;\r
mmtime_warmupnum=4;\r
{$ifdef VER1_0}\r
linux,\r
{$else}\r
- baseunix,unix,unixutil, {needed for 2.0.2}\r
+ baseunix,unix,unixutil,sockets, {unixutil and sockets needed by unixstuff.inc on some compiler versions}\r
{$endif}\r
{$else}\r
windows,unitsettc,mmsystem,\r
result := trunc(oletounixfloat(t));\r
end;\r
\r
-function unixtoole(i:integer):tdatetime;\r
+function unixtoole(i:float):tdatetime;\r
begin\r
result := ((i)/86400)+daysdifference;\r
end;\r
{$else} {delphi 3}\r
{------------------------------ windows/delphi code to read time}\r
\r
+\r
+{simulate gettimeofday on windows so one can always use gettimeofday if preferred}\r
+\r
+procedure gettimeofday(var tv:ttimeval);\r
+var\r
+ e:extended;\r
+begin\r
+ e := unixtimefloat;\r
+ tv.tv_sec := round(int(e));\r
+ tv.tv_usec := trunc(frac(e)*1000000);\r
+ {just in case}\r
+ if (tv.tv_usec < 0) then tv.tv_usec := 0;\r
+ if (tv.tv_usec > 999999) then tv.tv_usec := 999999;\r
+end;\r
+\r
+\r
{\r
time float: gettickcount\r
resolution: 9x: ~55 ms NT: 1/64th of a second\r
f,g:float;\r
o:tosversioninfo;\r
isnt:boolean;\r
- is9x:boolean;\r
+{ is9x:boolean;}\r
begin\r
if (performancecountfreq = 0) then qpctimefloat;\r
ticks_freq_known := false;\r
o.dwOSVersionInfoSize := sizeof(o);\r
getversionex(o);\r
isnt := o.dwPlatformId = VER_PLATFORM_WIN32_NT;\r
- is9x := o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;\r
+{ is9x := o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;}\r
\r
ticks_freq2 := f;\r
mmtime_synchedqpc := false;\r
maxretries=5;\r
margin=0.002;\r
var\r
- jump:float;\r
- mm,f,qpc,newdrift,f1,f2:float;\r
+{ jump:float;}\r
+ mm,f,qpc,newdrift:float;\r
qpcjumped:boolean;\r
- a,b,c:integer;\r
- retrycount:integer;\r
+ a,b:integer;\r
+{ retrycount:integer;}\r
begin\r
if not ticks_freq_known then measure_ticks_freq;\r
- retrycount := maxretries;\r
+{ retrycount := maxretries;}\r
\r
qpc := qpctimefloat;\r
mm := mmtimefloat;\r
mmtime_prev_lastsyncqpc := mmtime_lastsyncqpc;\r
\r
mm := mmtimefloat;\r
- dec(retrycount);\r
+ { dec(retrycount);}\r
settc;\r
result := qpctimefloat;\r
f := mmtimefloat;\r
{ mmtime_drift := mmtime_drift + mmtime_driftavg[a];}\r
end;\r
{ mmtime_drift := mmtime_drift / b;}\r
+ a := 5;\r
if (b = 1) then a := 5 else if (b = 2) then a := 15 else if (b = 3) then a := 30 else if (b = 4) then a := 60 else if (b = 5) then a := 120 else if (b >= 5) then a := 120;\r
mmtime_nextdriftcorrection := qpc + a;\r
if (b >= 2) then warmup_finished := true;\r
qpc := qpctimefloat;\r
\r
result := (qpc - mmtime_lastsyncqpc) * mmtime_drift + mmtime_lastsyncmm;\r
- f := (qpc - mmtime_prev_lastsyncqpc) * mmtime_prev_drift + mmtime_prev_lastsyncmm;\r
\r
+ {f := (qpc - mmtime_prev_lastsyncqpc) * mmtime_prev_drift + mmtime_prev_lastsyncmm;\r
jump := result-f;\r
- {writeln('jump ',formatfloat('0.000000',jump),' drift ',formatfloat('0.00000000',mmtime_drift),' duration ',formatfloat('0.000',(mmtime_lastsyncqpc-mmtime_prev_lastsyncqpc)),' ',formatfloat('0.00000000',jump/(mmtime_lastsyncqpc-mmtime_prev_lastsyncqpc)));}\r
+ writeln('jump ',formatfloat('0.000000',jump),' drift ',formatfloat('0.00000000',mmtime_drift),' duration ',formatfloat('0.000',(mmtime_lastsyncqpc-mmtime_prev_lastsyncqpc)),' ',formatfloat('0.00000000',jump/(mmtime_lastsyncqpc-mmtime_prev_lastsyncqpc)));}\r
\r
f := result;\r
end;\r