Who's Online:

  • [Bot]
Now online:
  • 3 guests
  • 1 robot

 

DBPRO CODE - Get Accurate Elapsed Time With PerfTimer and QueryPerformanceFrequency

Lets make the DBPro Perftimer useful. The global "elaspedTime" here works great for timer based movement. * This code snippet is ported over from my C++ code and gives same results.

 

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
` Get Accurate Elasped Time
` BY: Todd Riggins - ExoDev.Com - Nov 12,2010
 
 
Kernel32 =1
load dll "kernel32.dll",Kernel32
 
global freq as double integer
global elaspedTime as double float
global oldTime as double integer
oldTime = perftimer()
 
 memptr = make memory(16)
call dll Kernel32, "QueryPerformanceFrequency", memptr
 
freq = *memptr
 
set window on
sync on
sync rate 30
 
   make camera 1
   position camera 1,0,15,-400
   color backdrop 1, rgb(32,64,64)
 
repeat
   GetElapsedTime()
   text 10, 30, "freq: "+str$(freq)
   text 10, 50, "elaspedTime: "+str$(elaspedTime)
   text 10, 70, "perftimer(): "+str$(perftimer())
 
   sync
until escapekey()=1
 
end
 
Function GetElapsedTime()
   local current as double integer
   local loca as double float
   local locb as double float
   local locc as double float
   current = perftimer()
   loca=current
   locb=oldTime
   locc=freq
   elaspedTime = (loca-locb)/locc
   oldTime = perftimer()
   if elaspedTime<0.0 then elaspedTime = 0.0
EndFunction