PDA

View Full Version : WA and the main game timer?


Dando
12 Oct 2006, 19:49
Yeah I just want to ask someone, possibily deadcode what WA uses as its main timing. That is, when I create small games I usually use TimeGettime (mmsystem), rarely gettickcount. Other include Queryperformancecounter. (I.e. the windows internal millisecond timer/CPU ticks)

Just wondering what WA uses in its main timer procedure, if any of the above?

CyberShadow
12 Oct 2006, 20:21
Hi,

Before v3.6.19.17, W:A used GetTickCount for waiting for frames. In v3.6.19.17, Deadcode added code which uses QueryPerformanceCounter (when possible). I believe this caused problems later on, and was made optional with the TimerWorkaround_On/Off.reg files.

Dando
12 Oct 2006, 20:44
Thankyou

timegettime uses internal windows millisecond timer like gettickcount but is in my tests (and those of a programming forum) is more reliable. So if you still using gettickcount, better give timegettime some thought.

Yeah, queryperformancecounter can have micro (and maybe nano) second accuracy but it is sometimes unreliable and also depends on hardware (hence as you say "when possible").

(actually to get 1ms accuracy in windows you have to invoke timebeginperiod(1) cause default is 10-15 ms...which I found annoying)

Deadcode
14 Oct 2006, 00:59
(actually to get 1ms accuracy in windows you have to invoke timebeginperiod(1) cause default is 10-15 ms...which I found annoying)According to MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_timegettime.asp), this is only true in Windows NT/2000. It doesn't specify how XP behaves, but I'm running XP and the default precision for me is 1 ms.

Indeed, this is better than GetTickCount() for those systems that don't support QueryPerformanceCounter().

Strangely, I've found that both GetTickCount() and timeGetTime() are being expressed in units of 1/999.929 second on my system, if QueryPerformanceFrequency() is to be trusted. I guess I need to compare them against something outside of my computer.

Dando
14 Oct 2006, 01:19
Certainly in my tests atleast, default for all OS above 98 was 10-15ms (actually it was always 15) until I used timebeginperiod(1).

XP default was in my tests no different. I use delphi to program (obviously you are using the better language to create games C++) so maybe this is different somehow but can't see how...

In my frustrating travels I found this a good source>>>

http://www.geisswerks.com/ryan/FAQS/timing.html

Nice to see you back deadcode, whilst I will never be able to create games or program on your level...even at my basic level I can appreciate your work:) Thanks.

ps yeah you are right -in order to get best result you need to have a control time outside of the system and that is not easy ;) I think you can trust queryperformancecounter though, I made a stopwatch program with Tiemgettime and it does go out by a few seconds every few days so your results are probably correct. The timing is usually said to be ~1ms...so I suspect it is never actually VERY near 1ms all of the time, if ever:) Infact the above source says it has dropped to as much as 2ms in some cases

Edit:
1/999.929 seems to be consistent with the drop in time I get using my stopwatch program. I may go into this further at a later date. I did read somewhere that the internal timer of windows can be affected by large CPU activity also...though I don't know if this is at all true. Also what I found slightly baffling was that the integer value of win time is 32 bit signed meaning it can only hold ~ 25 days of milliseconds before turning negative. (I could prob work around this, but I don't know many people that keep windows running 25 days anyway;) )

I would like to see what woudl happen to some programs after that period...i suspect not all would work 100%

edit2: Finished my test. Flucuated between 1/999.1-1/999.9, average 1/999.5, although it went out by 89ms in 5 hours. (seems to not be constant results but still reasonably accurate to 1ms)

Plutonic
14 Oct 2006, 18:03
But I don't know many people that keep windows running 25 days anyway

I do, my server is never turned off, and my main PC, well same realy - well apart from powercuts...

Dando
14 Oct 2006, 20:16
cool...and no unwanted effects after 25 days? Especially timer programs that may turn negative? (though most will probably take the "problem" into account)

Plutonic
14 Oct 2006, 20:34
none that i've noticed, although can't say I have ever realy tested the matter.

Dando
15 Oct 2006, 03:16
yeah, seems I was mistaken? The storage is an *unsigned* 32 bit value meaning that it wraps around after just under 50 days instead (and remains positive obviously). (not that it matters) :) Looking around, in windows vista, microsoft have made a new function gettickcount64 (and probably timegettime64) which store values as 64 bit integer. That will keep us going 292 million years.....

Muzer
15 Oct 2006, 08:09
Um... wouldn't that logically be 100 days?

Plutonic
15 Oct 2006, 12:31
um, no. switching from signed to unsigned doubles the amount of positive numbers available.

switching from 32 to 64 bit multiplies it be a thurnther 2^32

Dando
15 Oct 2006, 14:02
which is also why there is a massive increase in security from 40 bit encryption AES to 128 and beyond;) Because the number of possible keys exponentially increases. 2^40 = 1099511627776, 2^128 = 340000000000000000000000000000000000000 keys. My computer can process 1000000 a second (and i broke a 40 bit encryption in about 10 days, average 6). As for 128 forget it, would take me millions and millions of years

I went off topic a bit there...but thats the meat of it....

CyberShadow
20 Oct 2006, 05:56
cool...and no unwanted effects after 25 days? Especially timer programs that may turn negative? (though most will probably take the "problem" into account)
Actually, Windows 95 and 98 seem to have had problems regarding this. A normal installation of Windows 95 or 98 will hang after 49.7 days. (Microsoft KB article (http://support.microsoft.com/?id=216641)).

Dando
20 Oct 2006, 06:13
hmm so them OS's themselves hung after the 50 day wrap-around (i corrected my 25 day mistake earlier in thread)....cool! But also bad on MS part..they should have accounted for this long before they released win95....

Seita
20 Oct 2006, 08:17
Not sure they had any reason to keep a computer running for so long, at that time.

franpa
20 Oct 2006, 08:45
exactly seita... back then a reboot was required for win95 every 5 days or so ;)

Seita
20 Oct 2006, 15:16
Not that a reboot was "required", but nobody was sitting in front of a computer more than 20 hours a day, so I was simply shut down the rest of the time.

franpa
21 Oct 2006, 09:42
well, maybe.... microsoft wasnt as screwed back then... so maybe windows 95 is stabler then my memory recalls...

Dando
21 Oct 2006, 10:28
That is never the point;) A good system always employs upper limits which are not feasibly possible to reach. Phone companies made a big mistake here in the UK and made us all add numbers to the beginning of the main number, when phone-numbers started "running out". That is poor planning and poor foresight.

Same with MS, they should have known that 50 Days was not good enough. Really it is a fault with an easy fix I feel they were prob too lazy or worse, didnt even see it coming