Whats the difference between GetTickCount and TimeGetTime?
Ive never heard of TGT before
Whats the difference between GetTickCount and TimeGetTime?
Ive never heard of TGT before
From what I can gather timegettime is more reliable. Sadly my machine has something wrong...or something weird happening. Timegettime still gets time from number of millisecs since windows started.
You need to have MMsystem in your uses clause to use it. Wish I knew what is making my apps run so weird
Try the QueryPerformanceCounter. In fact, here's an example. It's VERY reliable and accurate down to the trillionths of a second.
Code:(****************************************************************************** * The contents of this file are subject to the Mozilla Public License * * Version 1.1 (the "License"); you may not use this file except in * * compliance with the License. You may obtain a copy of the License at * * http://www.mozilla.org/MPL/ * * * * Software distributed under the License is distributed on an "AS IS" * * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * * License for the specific language governing rights and limitations * * under the License. * * * * The Original Code is uQTimers.pas. * * * * The Initial Developer of the Original Code is Robert "The Wicked Flea" * * Kosek. Portions created by Robert Kosek are Copyright (C) May 2006. * * All Rights Reserved. * ******************************************************************************) unit uQTimers; interface uses Windows; type TQuickTimer = record Start, Stop: Int64; end; { Returns a number for the running timer. } function StartTimer: Integer; { When given a number the timer will be removed and the result will be the seconds elapsed. } function StopTimer(which: Integer): Extended; var ProcessorSpeed: Int64; QTimers: array of TQuickTimer; implementation function StartTimer: Integer; begin Result := length(QTimers); SetLength(QTimers,length(QTimers)+1); QueryPerformanceCounter(QTimers[Result].Start); end; function StopTimer(which: Integer): Extended; procedure RemoveIndex(Index: Integer); var i: integer; begin for i := Index to Length(QTimers)-1 do QTimers[i] := QTimers[i+1]; SetLength(QTimers,Length(QTimers)-1); end; begin QueryPerformanceCounter(QTimers[which].Stop); Result := (QTimers[which].Stop - QTimers[which].Start) / ProcessorSpeed; if which = length(QTimers) then SetLength(QTimers,length(QTimers)-1) else RemoveIndex(which); end; procedure KillTimers; begin SetLength(QTimers,0); end; initialization QueryPerformanceFrequency(ProcessorSpeed); finalization KillTimers; end.
That is some good code and will no doubt me very accurate. Sadly, something fundamentally wrong with directx, XP, my gcard (geforce 2), or delphix because even if I try that, the game will not run right if delphi is closed. The exe made will have whatever bug is operating incorporated into it.
I have concluded that it is not just the timers affected, it is alot of other directx things with delphix. I will change gcard soon, and see if there is any difference.
Why would the game work right when delphi is open and nopt work otherwise? What is wrong here? Very frustrating, and it seems only me with this bug?
I have changed the following but still the problem exists:
Processor, motherboard, directx version, memory, delphi version, Delphix version
I did not have these problems however when using win2000 a year ago. The only problem is I do not know if this problem is being compil;ed into the exe regardless. That is why I set out a test in the Delphix section of these forums to test.
maybe SP2 will save me? You think I should try it?
If your talking about XP SP2, then YES. It fixed ALOT of bugs in XP overall, and some of the performance counters were directly (and indirectly) affected.Originally Posted by seiferalmasy
- Jeremy
http://www.eonclash.com/
well sp2 was no go, it was bloody awful. half my programs no longer worked, slow down of OS and a host of other unwanted side effects. I have gone back to sp1a. SP2 did not correct the problem I have
I am seriously thinking it might be soley due to my geforce 2 and or the drivers. Tried latest drivers but they cause BSOD with the geforce 2, so they are no go
SP1a isnt going to be supported with security patches after october so mabey a format is in order to get SP2 going
I did format in the end
all went pearshaped anyway, so uninstalled bad evil sp2 , went back to 1a
Also, when my graphics drivers are not installed (or running in safe mode), the games and timers run correctly, so most likely is driver/nvidia related
not bothered about them security updates from microsoft, good ol Zone alarm does the trick usually (but now thats gone, and kaspersky kicks ass) The next OS I get will be in atleast another 2 years, prob a later form of Vista
isnt a OS issue (maybe I try win 98 too, just to eb sure). I have changed Graphic card to ATI X800, that wasn't it either. Isn't even a delphix issue.
Its a delphi issue. I have no idea what it is and have all but give in. Will get hold of borland delphi 2005 and see if that too has this strange "bug".
Delphi 7 no change from 4, the same. On idle loops exact the same as the timers. Somehow iterations are being limited. Its all messed up and crazy. I am stuck well and truly.
Will keep you posted
Edit:
Borland 2005, same problem. And my my what an AWFUL GUI 2005 has...I will never ever use that!
Cerianly not the processor. Even with affinity set to use 1 processor, still there (and HT is off on my machine). When I take the program to another persons house, 4 so far, the problem still exists. When I was using an athlon 1800+ with a completely different computer, the problem was the same.
It is very strange. I will now upload a new test file, since the other is dead. This one doesn't use timers. It uses a loop and unfortunately for me, the problem is STILL there.
This is not a timer problem at all....its worse. Seems that iterations are being limited?
It is possible maybe that maybe some hardware I have has affected the proper running of my computer. Even when all drivers were not installed however, the problem still existed.
The things I have never changed recently are:
Soundcard, Hauppauge 350, Pinnacle Studio 9 DV. Other than that my entire system has changed once including delphi version. I have used delphi 4, 7 and 2005, all same result I have used Win 2000 with SP4 and XP. Same result. Infact, the code below will show you that indeed there is something truly bizarre going on:
Code:While (Finished=False)do begin Currenttime:=Timegettime-StartTime If (CurrentTime>9)then begin inc(TheCounter); Starttime:=TimegetTime; end; Application.processmessages; end;
Explanation: When currenttime is greater than 9, the counter is incremented. This incremementation should be 100 times a second, since timegettime is the same as gettickcount.
What Happens: If dxdiag or msn messenger (to name 2) applications are not open on screen the result is wrong. What happens on my machines atleast (and then all machines I take the exe to) is the counter goes up 32 times a second..and not 100. All values in the place of 17 display erroneous results. If I set to 100, i would expect TheCounter to go up by 10 times a second but that is not what I get.
The Test:
My test is simple. I have a link below which basically has the code above. I want you people to test the following:
1. If the exe supplied with the program counts up 100 times a second.
2. Once YOU have compiled it, does it go up by 100 times a second.
3. Send me YOUR compiled exe so I can test it on my machine and other peoples machines
This will tell me:
1. If the problem is machine dependant
2. If the problem is soley because I am compiling the source
Thanks to all that participate but if this problem still exists on my test machines (4 of them) with YOUR exe's, then we have a major problem here.....
Please note that the program has a normal timer on the form. This counts TEN seconds and then gives you the number of seconds elaspsed when The Counter has reached 1000. In other words, the above example should give 1000 (100 a sec * 10 sec) after 10 seconds Smile If it does not...the result follows the pattern I am experiencing.
If it does not also try having dxdiag opened, or msn messenger open on screen (not in task bar).
---------
Bottom line:
Why the hell would dxdiag or msn messenger being opened sort the problem out temporrarily as long as they are open on my machine? (this "fix" doesn't seem to work on any machine I test the exe on so far apart from my own). The problem still exists when application.processmessages is not called, so that isn't it either
Seifer Almasy
THE TEST FILE WITH SOURCE.
MY FTP SERVER:
If you want to access through IE (note mozilla firefox cannot upload):
FTP://thetest@DLPB.kicks-ass.net:2121 (leave password box empty)
If you want to access through FTP client (recommended):
Server: DLPB.kicks-ass.net
Port 2121
Username: thetest (case sensitive)
Pass: (no password)
Remember please, to upload your own exe after compiling the source on your end. Upload back to my FTP server if you will (give it a unique name).
Thanks to all that participate, because of this problemis not just me, then all of us using idle loops etc for our delphi games are in trouble on atleast a significant amount of machines. Hopefully it is just me
Bookmarks