HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

A thought on timers

01-25-2007, 04:02 AM#1
Vexorian
We created 10 different ways to attach or link information to a timer, just noticed that those efforts are not needed at all and that attaching is simply the wrong approach.

let me put it this way (pseudo code)

current approach:
    //start timer:
    t=create timer
    attach data to timer
    start timer


    //expire event:
    t= expired timer
    data = get attached data from timer
    if (process data determines destroy time)
        destroy timer
    else
        restart timer


better approach:
    //init
    N=0
    t= create timer


    //start timer:
    if (t is paused) restart t
    N=N+1
    data[N] = create data

    // when timer expires:
    for i=1 to N do (if process data[i] decides destruction)
    {
        remove data[N] from array (swap data[i] with data[N] and decrease N)
    }
    if (N is now 0) pause timer

It is as multi instance (unless you want more than 8190 instances at the same time), and it does not require attaching or getting attached data so it is certainly faster...

Anyways this is far from being anything new at all, but I think that we really have the tools now to make it official.
01-25-2007, 04:27 AM#2
PipeDream
Doh! Great idea.

----

I think it can be made dynamic with respect to time intervals and synchronization by using two timers and a heap.
Heap: Top is the next event, and the game time at which it should happen
Timer 1: Tracks game time
Timer 2: Time until next event, non periodic.

Periodic events would add themselves back into the queue after they run

To add an event to the queue, first check if the event should occur before the top event. If this is the case, reset timer 2. Otherwise add it to the heap.

When timer 2 elapses, it runs the top event, pops the heap, and resets itself to fire at the next event by checking timer 1 for the current game time and comparing it to the desired firing time.

This has probably all been implemented already by anitarf/infrane in their cine system.
01-25-2007, 02:41 PM#3
Doomhammer
I still can't get my head around this idea idea of taking and returning timers from a stack. I mean, it sounds fine as theory, but how does it look like concretely? Here I'm missing a bit the examples (1 would be enough, in it: how to declare the additional globals, and how could it look like in use for a simple spell) I'd also like to see an example of a periodic timer running not more than n passes.
01-25-2007, 02:47 PM#4
Vexorian
If you want an example check the caster system's missile engine. The basic is not really about an stack.