[Gtk-sharp-list] A question about timers
Jeff Tickle
jeff at jefftickle.com
Mon Jun 13 23:55:54 EDT 2005
> I'm writting an RPG engine in my spare time, I dont hace experience
> writting games so I have a doubt... I have some objects which after
> doing an action, have a dynamic cooldown (based on its statistics)...
> should I use a main loop and check all the objects manually?.. cause
> I've placed a timer within each object.. and when its cooldown time is
> elapsed, it executes an action stored in the object's queue.
I don't have any gaming experience either, but just from programming
experience it sounds to me like that would work.
Obviously if your game is turn-based, you might want to forego the timer
in favor of some sort of counter that changes each time the turn does,
but it doesn't sound like you're doing that.
If you're concerned about having a lot of timers taking up memory and
thread space, you might consider instead having one central timer that,
for example, sends out a "tick" (event) at a regular interval that each
game object could pick up on, then act upon individually after a certain
number of ticks have been received. For example, if your tick frequency
is once per second and you need a creature to die after 3 seconds, you
could do something like this:
// in your program's initialization:
Timer t = new Timer(1000);
// in your object that needs to die after 3 seconds:
int ticks;
bool deathTick;
void onGlobalTick() {
if(deathTick) {
ticks++;
if(ticks < 3) return;
else die();
}
else ticks = 0;
}
Hope this helps or at least sparks an idea.
-Jeff
More information about the Gtk-sharp-list
mailing list