Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / More precise Timer()

Author
Message
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 14th Jan 2003 13:13
Hi,
Is there any windows DLL I can use to access a more precise
timer() function ?
If any of you have ever tryed 'Truevision' which
is an kind of DBpro extension for VB, you may have
noticed it having a special timer() function that
returns time in (1/10.000). DBP timer() returns (1/1.000).
Thx for any help.
Ratty Rat
22
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 14th Jan 2003 14:01
Not that I know of, but it could be useful, looking at what the timer() function returns on my PC, in my current project it appears to return 0,8,10 constantly, and nothing in-between, which always seemed a bit odd.

It still seems accurate enogh to use to keep a constant speed in the game though.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jan 2003 14:54
I don't know what you want it for, but there is a high-resolution timer as a part of windows - most machines support it now.

I'm at work right now - I'll post the code later.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jan 2003 19:26
Ok, here it is:



You will get some strange and large numbers. On my laptop the frequency shown is 3579545 ticks per second.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jan 2003 19:54
Hmmm. Perhaps I should put a proper example together...
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jan 2003 20:07
I've added a new function call HiTimer that you can use to specify your own resolution to. In the example below, I've used 100000 - 100 times higher than the timer function - that should be good enough for you

Of course, at that type of resolution, you will find that function calls themselves start to affect the timings.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Jan 2003 00:05
Oops, forgot something. If you want to use this snippit without any changes, you will need my Third party command dll, or change it and use MrTAToads equivalent dll. It uses an 8 byte peek command to get the correct values from the timer routines.

http://www.matrix1.demon.co.uk/DBPro/Matrix1Utility.zip
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 15th Jan 2003 00:43
I heard that the timer is not very precise, and this is on a different programming language i mean. It must be the way computers are - or the DLLs on them..

xxxpetratxxx
B. R. W
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 15th Jan 2003 00:48
It depends on how often you read the timer - normally (well I read it anyway) from an interrupt, but unfortunately that cant be done...

The timer itself is very precise, but can be processor dependant.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 15th Jan 2003 02:31
Hi! sorry I couldn't reply any sooner
I tryed the snippet but it dindn't run

Dbp didn't recognize the function at line 1:
InitialiseKernel32DLL()

I d/l Matrix1Utility.dll to my plugins-user folder,restarted
pro , didnt help.

Then I dumped the names from the dll to a txt file to
check if i could find InitialiseKernel32DLL() there. nope!

a)Do I have to load one of billgates dll's prior to
executing 'InitialiseKernel32DLL()'???
b)Am I missing any other dll ? MrTAToad's 'Handles.dll' is also in.

IanM, I readed the article on you're pages about
frame independet adaptive rate system.
My system works very like yours, but i would like
to add or maybe even correct one aspect of your system.
You should not use screen fps() as a measurement coz it
return an average fps.
What u need is precise timing between each sync, that
u can get with dbp own timer() which returns the time
in ms. When u then apply this time measurement to the
motion equation the result is more reliable and precise.
If u need a demostration on what i'm talking about let
me know and I'll cook something together and post it.

So imagine how cool it would be if we could increase
this level of precision even further with an hi-res
timer. Frame adaptive rate system works great for me
even with the dbp timer(), but it do suffers when below
10 fps. I think an hi-res timer() would do the trick.

Another great benefit of hires timing is for debugging.
By timing different sections of u're game u can easely
track down were the program takes most time and therefore
slows most of u're fps. Then u can dump this stats to the
screen or a file which would look something like this:

| (all times in ms.) |
Name | Ave | Min | Max |calls| % of sync time |
------------------------------------------------------------------
AI update | 40 | 35 | 45 | 8 | 30%
Player update | 30 | 25 | 35 | 1 | 5%
Collision Detection | 20 | 18 | 22 | 32 | 40%
Physics | 30 | 28 | 32 | 8 | 20%
...
...
...
...


This way its easy to see if the for example the AI update is draining
to much time and that u should do something about it in order to keep
refresh up were they should be.

This is unfurtunately not posiible to some extent with dbp timer()
since it 'only' has 1/1000 precision to do reliable measurements.
Many routines even if advanced can perform well under 1ms, and that is
all well, but if u call it 60 times for each sync the times adds up.

Hope this stuff helps anybody, thx for the interestz!
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 15th Jan 2003 02:34
forum messed up my nice stat table ho well , hope u see
what i mean
mimesis
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Norway
Posted: 15th Jan 2003 03:33
Silly ME!!!
'InitialiseKernel32DLL()' = 'load dll "kernel32.dll",1'
It works! great! i'll have to test it more tomorrow tought.

I'll make sure to mention you in my credits

Cheers!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Jan 2003 14:55
Nope, its my fault.

I like to group my functions into seperate .dba files, and I'd already done that at the point of the timer example.

Just take the code from the original, remove all the code up to the InitialiseKernel32DLL function, and insert the last snippit at the top.

Also, I realised last night that the HiTimer is actually more than a hi-res timer - You can use it to get 'odd' timing intervals too, for example if you use a parameter of 30, you will get exactly 30 ticks per second - something that is not possible using the Timer function (because 1000/30=33.3333333...).
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Jan 2003 15:02
Now I've read the rest of your post I'll reply to that too.

The adaptive timing page was written over a year ago for DBv1, so the only things available were the frame rate and timer - neither of which are great for precision.

I agree, code profiling is another use for the HiTimer that was not possible with the standard timer, because the standard timer does not have the resolution.

Because I'm seeing more and more use for the HiTimer function, I think I'll put it into the utility dll, which will allow me to optimise it - it uses up far too much system time itself at the moment.
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 15th Jan 2003 23:19
u could not do this:



and expect the result to be one second coz it takes time to perform each command.

xxxpetratxxx
B. R. W

Login to post a reply

Server time is: 2025-05-18 21:50:09
Your offset time is: 2025-05-18 21:50:09