what is more accurate than sleep ?
Posted on 2002-03-13 11:36:12 by eko
You could code your own wait loop using rdtsc or high-performance
timers, I guess... this has higher impact on system than Sleep()
(since Sleep()ing threads aren't scheduled, while "your own loop"
delayed threads are).
Posted on 2002-03-13 11:42:42 by f0dder
Uhh!, I have no idea besides using a multimedia timer.

Solution: 1

- Create a loop while calling timeGetTime inside the loop while setting the start time before the loop.


timeGetTime()
mov timeStart, eax

loop:
timeGetTime()
subtract the current time from the timeStart...
check...
if not >= loop back

Solution: 2

- Use the multimedia timer functions such as timeBeginPeriod and timeEndPeriod

Solution: 3

- Check out the waitTableTimer

:)
Posted on 2002-03-13 11:47:07 by stryker
Note the problem with using any non-native windows function, you are at the mercy of windows task switcher.

Also using rdtsc you are not time dependant, but processors speed dependant (you can fall into the trap old 386 games fell into, you ever tried playing them on the later 486s or Pentiums?).

Mirno
Posted on 2002-03-13 12:23:53 by Mirno
Stryker - I tried method one once and it ate all available cpu cycles. i had to "End Task" it. Do you have a working example of how to do this without eating up all available resources? Also method two had the same effect.

Is there a way to get your process called every time a vertical or horizontal refresh is done. This would be more effeceint and more accurate I think (Refresh being hardware triggered?). Maybe a method using DirectX I checked out MSDN but found nothing. Maybe I dont know what to search for. Could anyone point me in the right direction?
Posted on 2002-03-13 15:05:24 by emonk
:) sorry to hear about that, but it was just an example that came out of my mind instantly. :) I can't think of any, aside from the ones I mentioned.

Maybe we could do something like this.




;beginning of the program

timeGetTime()
mov timeStart, eax

;Main loop of the program

timeGetTime()
subtract the current time from the timeStart...
check...
if not >= x jmp hello
else do something...
hello:


Just another lame idea. :)


But it did delay your computer. :) -> stupid comments
Posted on 2002-03-13 15:33:29 by stryker
Using rdtsc you would of course have to compensate for CPU speed.
As for a manual delay loop taking up all CPU cycles... run it in a
separate thread and let your main thread do the message handling
(and perhaps boost your delay-counter-thingy to "high" priority).
Worth a try anyway.
Posted on 2002-03-13 16:31:30 by f0dder