|
This thread is locked; no one can reply to it. |
1
2
|
my game uses 90% CPU |
GullRaDriel
Member #3,861
September 2003
|
I never have problems building themon solaris, linux (debian) , windows xp ( pthread pack from source.redhat.org ) "Code is like shit - it only smells if it is not yours" |
Birdeeoh
Member #6,862
February 2006
|
I've been using Boost::threads for months now. I THINK they use pthreads on Unix but native on Windows (correct me if I'm wrong, too lazy to go check) but, regardless, it works great and easy, on either platform. [url http://developer.berlios.de/projects/openlayer/]OpenLayer[/url is an OpenGL accelerated 2D library for fast and easy graphics development under Allegro |
Milan Mimica
Member #3,877
September 2003
|
Quote: 1. Write a thread function for the timer thread, which sleeps for the desired amount of time, then sets an event. Something like this? while (true) { Sleep(20); //0.02 sec, 50 fps SetEvent(handle); }; Is this more accurate than using allegro timer?
-- |
Birdeeoh
Member #6,862
February 2006
|
Is this more accurate than using allegro timer? POSSIBLY/probably, but no guarantees. The allegro timers go for a 5ms resolution. Your snippet theoretically goes for 2ms resolution but, in reality, the documentation for all Sleep() style functions will say something like - Sleep( int ms ) - Puts the process to sleep for AT LEAST ms milliseconds Under a light load, you're likely to get pretty good results but there's no guarantee you will wake up right at 2ms everytime. Also, I wasn't following the ENTIRE event queue discussion, but asynchronous event delivery is also not usually guaranteed to work instantly. [url http://developer.berlios.de/projects/openlayer/]OpenLayer[/url is an OpenGL accelerated 2D library for fast and easy graphics development under Allegro |
Kitty Cat
Member #2,815
October 2002
|
Quote: Is this more accurate than using allegro timer? No. In fact, that could lead to time drifting. It takes a variable amount of time to call those functions and do whatever they're gonna do. You'd have to find a way to make the OS put the thread to sleep and wake it up at specific intervals. What you can try to do, is calculate the amount of time you need to sleep until the next tic should fire (using QPC/gettimeofday to track the current time vs. the next target time), sleep for that amount (via Sleep/usleep), wake up and do whatever, then repeat. This is basically what Allegro does for timers (though some jitter is introduced since all the timer functions run in the same thread/loop). int ms_to_sleep_for = one_second / tics_per_second; unsigned int current_time = get_time(); while(running) { signed int diff = current_time - get_time(); if(diff > 0) Sleep(diff); do_something(); current_time += ms_to_sleep_for; }
-- |
BAF
Member #2,981
December 2002
|
pthreads works fine on windows... I use it myself. |
Thomas Harte
Member #33
April 2000
|
Quote: What you can try to do, is calculate the amount of time you need to sleep until the next tic should fire (using QPC/gettimeofday to track the current time vs. the next target time) Of course this is exactly the same solution as the code I gave (guess I found the thread sooner!), it just doesn't devolve time counting to an Allegro timer. So I guess follow on questions are whether your use of Sleep rather than rest is a non-platform neutral oversight and whether anybody has a useful table of which high precision time functions are available on which OSs? [My site] [Tetrominoes] |
Kitty Cat
Member #2,815
October 2002
|
Quote: So I guess follow on questions are whether your use of Sleep rather than rest is a non-platform neutral oversight and whether anybody has a useful table of which high precision time functions are available on which OSs? Oversight, yes. I was going for psuedo-code and would've used sleep(), but that a real libc function. As for high precision time functions, sane OSs have gettimeofday, Windows has QueryPerformanceFrequency/QueryPerformanceCounter. If neither of those exist/work, the system isn't worth worrying about. -- |
Manfred D
Member #4,134
December 2003
|
I think it would be nice to have threads in Allegro. If I haven't misunderstood the universe, you need threads to fully enjoy the powers of dual core processors. And they are the future. |
CGamesPlay
Member #2,559
July 2002
|
I've picked up a timing method that I like very much, using Allegro timers:
The sem_wait causes the application to sleep for at least the right amount of time, but if it misses several ticks it simply won't sleep. -- Ryan Patterson - <http://cgamesplay.com/> |
|
1
2
|