|
Two timers, one function |
Biznaga
Member #3,180
January 2003
|
Hi!
|
CGamesPlay
Member #2,559
July 2002
|
That's perfectly valid. Try it out [append] -- Ryan Patterson - <http://cgamesplay.com/> |
ReyBrujo
Moderator
January 2001
|
Remember that your function must be fast. If it is fast, then you should have no problems. -- |
Biznaga
Member #3,180
January 2003
|
I'll assume it's OK then. Thanks, guys! CGamesPlay said: Oh, well, it's valid, but the address of those two params goes out of scope when the functions return.
A minor detail ReyBrujo said: Remember that your function must be fast. That's the idea, it'll just update some flags. The point is I have this doubt mainly because I know nothing about interrupts and threads. I don't know if something weird happens with the stack or whatever when accessing the same function at the same time. My game is still in the design stage, so I don't want any weird bug later. |
ImLeftFooted
Member #3,935
October 2003
|
Quote: The point is I have this doubt mainly because I know nothing about interrupts and threads. I don't know if something weird happens with the stack or whatever when accessing the same function at the same time. My game is still in the design stage, so I don't want any weird bug later. In most cases they should be called from completely different stacks. Quote:
volatile int[MAX] params; The typical way to solve this problem is pass timer_func a pointer to a struct with all the data you need in it, instead of making global varaibles. Example:
|
Tobias Dammers
Member #2,604
August 2002
|
And again I say: Don't - use - allegro - timers! They're inaccurate, they eat (too) much cpu, and they require extra threads, without removing the need for constant polling (which is the only advantage of using threads after all). --- |
ReyBrujo
Moderator
January 2001
|
Unless you are making a 3D (especially a FPS), Allegro timers are fine and portable enough. -- |
Sirocco
Member #88
April 2000
|
I completely agree with Rey. I use Allegro timers (and lots of them) for all of my games, and they work perfectly. They exist for a reason, despite their few shortcomings, and if you understand how they work and how they are meant to be deployed you won't have any problems. If the situation demands a different approach (such as complex 3D systems), take it. Edited for clarity. --> |
BAF
Member #2,981
December 2002
|
If anybody had some framework for basic QPC/gettimeofday that can be reused easily, that would be nice. |
GullRaDriel
Member #3,861
September 2003
|
Baf said: If anybody had some framework for basic QPC/gettimeofday that can be reused easily, that would be nice. Search for timer in the forum and write your own. "Code is like shit - it only smells if it is not yours" |
Kitty Cat
Member #2,815
October 2002
|
Quote: timers [...] require extra threads All of Allegro's timers run on a single thread. And since some of Allegro's internals use timers, that thread is already created. -- |
Tobias Dammers
Member #2,604
August 2002
|
This is what I use: #ifndef TIMER_H #define TIMER_H void init_timer(bool use_qpc = false); void stop_timer(); void start_timer(int timer_ms); float get_timer_delta(); const char* get_timing_method_string(); float get_timer_accuracy(); #endif timer.cpp:
Uses QPC in windows if asked to, and falls back on allegro timers otherwise. --- |
ImLeftFooted
Member #3,935
October 2003
|
Baf said: If anybody had some framework for basic QPC/gettimeofday that can be reused easily, that would be nice.
Put it in my domain's temp folder. If you want to mirror it baf it would last longer: Usage: #include "timer.h" int main() { printf("%u seconds or %u milliseconds or %u microseconds since program start", timer.secs(), timer.msecs(), timer.usecs()); }
|
|