![]() |
|
get_milliseconds function |
CGamesPlay
Member #2,559
July 2002
![]() |
This post is in reply to this one, and also is related to an AD post with the same subject. My method adds a get_milliseconds function to Allegro, and puts the call in the TIMER_DRIVER vtable. That means that it does require a call to install_timer. Quote: I'd also suggest adding something like al_get_time_delta() on top of it, which would return zero on first call and time delta in milliseconds on all next calls. I thought about it, but it's just too trivial to merit its own function. Besides, it encourages use of global variables and isn't thread-safe. Quote: These points were made for QPC/QPF, but probably apply to timeGetTime() too Seeing as how QPC and timeGetTime use completely separate metrics for measuring time, I'd like a little more proof that they "probably" apply, especially since the docs don't make that conclusion. The patch I've created is attached. -- Ryan Patterson - <http://cgamesplay.com/> |
Matt Smith
Member #783
November 2000
|
There is already an al_current_time() in the 4.3 event code which returns milliseconds. Have a look at that to see if it's the same thing. I agree about the QPC being a special case of thread-unsafety, because it's a register in the cpu core, whereas there's always only one system clock. |
X-G
Member #856
December 2000
![]() |
Note if you're using QPC: Make sure to restrict CPU affinity to just one core to avoid timing fuckups. -- |
Krzysztof Kluczek
Member #4,191
January 2004
![]() |
Quote: I agree about the QPC being a special case of thread-unsafety, because it's a register in the cpu core, whereas there's always only one system clock. QPC/timeGetTime doesn't directly return contents of CPU tick count register and makes proper corrections taking CPU speed changes into accout (namely CPU clock changes when idle). The problem is when there are two separate CPUs/cores in the system that change speed independently and time chcecks are called from various processors. System clock (eg. GetTickCount) shouldn't have such problems, but it has lower resolution (IIRC 5ms), which isn't enough for smooth animation and will produce quite big time aliasing on standard refresh ratios (eg. for 80Hz you'll randomly get 10ms and 15ms deltas between frames). ________ |
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: QPC/timeGetTime doesn't directly return contents of CPU tick count register and makes proper corrections taking CPU speed changes into accout (namely CPU clock changes when idle). timeGetTime doesn't return the CPU tick count at all. It returns the number of milliseconds since the system was started. Quote:
System clock (eg. GetTickCount) shouldn't have such problems, but it has lower resolution (IIRC 5ms), which isn't enough for smooth animation and will produce quite big time aliasing on standard refresh ratios (eg. for 80Hz you'll randomly get 10ms and 15ms deltas between frames). Read the MSDN link from my first post, please. -- Ryan Patterson - <http://cgamesplay.com/> |
Krzysztof Kluczek
Member #4,191
January 2004
![]() |
OK, so timeGetTime() should be safe to use. Now only somebody with knowledge about Allegro timer system should add emulation of this function. And here are my points from Minorhack thread: - I'd also suggest adding something like al_get_time_delta() on top of it, which would return zero on first call and time delta in milliseconds on all next calls (which would effectively make coding delta-based logic with Allegro a breeze). ________ |
CGamesPlay
Member #2,559
July 2002
![]() |
Quote: - al_get_milliseconds could require install_timer() call on all platforms to encourage portable coding. - I'd also suggest adding something like al_get_time_delta() on top of it, which would return zero on first call and time delta in milliseconds on all next calls (which would effectively make coding delta-based logic with Allegro a breeze). Both of those are already addressed in my first post, if you have anything further to comment on... -- Ryan Patterson - <http://cgamesplay.com/> |
Elias
Member #358
May 2000
|
Anything wrong with al_get_time (from 4.9)? Someone might want to compare to the implementation there, then send a complete patch to the mailing list if this one is better. -- |
Krzysztof Kluczek
Member #4,191
January 2004
![]() |
Quote:
Quote: I thought about it, but it's just too trivial to merit its own function. Besides, it encourages use of global variables and isn't thread-safe.
We already have get_mouse_mickeys, so getting time delta won't be much different. ________ |
CGamesPlay
Member #2,559
July 2002
![]() |
The mouse's movement delta is fundamentally different from the mouse's position. You can't simply subtract mouse_x from mouse_old_x to find the difference. [append] In other words, get_mouse_mickeys adds functionality that couldn't be added without a specialized function. Adding a function to return a time delta is an exact replicate of al_get_milliseconds, which returns a time delta as well, just from a different reference point. -- Ryan Patterson - <http://cgamesplay.com/> |
GullRaDriel
Member #3,861
September 2003
![]() |
I finally got it working, please some other Windows owner, test it ! attached are the good versions in a 7z archive ) I tried your version, compiled fine (attached are the modified dll and extimer). But looks like it does not work. I am searching why get_milliseconds always return 0 EDIT: I see that the new get_milliseconds rely on timeGetTime: So I think that the problem is near that. I am testing timeGetTime lonely in a sample code to see if it is my system who's buggy. EDIT: It is working when using directly timeGetTime. So the implementation should be messed up.
This code returns 1000, and as told in msdn, testing show me that the default granularity is 5 ms on WinXp. EDIT: Modified test to set granularity to 1 ms
This code works fine, it returns me 1 or 2 ms ( a for loop with a rest(1) inside gave me these results ) EDIT: More investigation if ((timer_driver) && (timer_driver->get_milliseconds)) { return timer_driver->get_milliseconds(); } else return 0; The problem is here. It always return 0 EDIT: Some more test around, I added the following to extimer.c
Result: EDIT: After searching a little, it looks like tim_win32_get_milliseconds is not implemented in the driver list, which cause the get_milliseconds function to always return 0 testing with tim_win32_get_milliseconds implemented:
"Code is like shit - it only smells if it is not yours" |
BAF
Member #2,981
December 2002
![]() |
There isn't a gettimeofday on Mac that you can use to provide Mac compatibility? |
GullRaDriel
Member #3,861
September 2003
![]() |
http://www.hmug.org/man/2/gettimeofday.php says yes. unix.c says ALLEGRO_MACOSX sometimes. So I guess it already uses gettimeofday "Code is like shit - it only smells if it is not yours" |
|