BASIC

Author Topic: Multiple Realtime Timers Function!  (Read 5397 times)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Multiple Realtime Timers Function!
« on: 2004-Oct-21 »
Edited and UPDATED AUG. 5, 2008 for GLBasic Version 5+

Excellent Timer Function that keeps track of many timers that calculate seconds!
These return TRUE if the alloted time is reached!

Usage:
Code: GLBasic [Select]
onesecondelapsed=TTIMER(0,1) //returns TURE after 1 second
oneminuteelaped=TTIMER(1,60) //returns TRUE after 60 seconds
Function:
Code: GLBasic [Select]
FUNCTION TTIMER: TTNum, TTCountTo
//onesecondelapsed=TTIMER(0,1) //returns TURE after 1 second
//oneminuteelaped=TTIMER(1,60) //returns TRUE after 60 seconds
        STATIC  Init_TTTimer,NumOfTimers, CheckIt
        IF Init_TTTimer<>TRUE;
                NumOfTimers=100;
                Init_TTTimer=TRUE;
                DIM TIMETIMER[NumOfTimers][2];
                TIMETIMER[0][0]=-1;
                TIMETIMER[0][1]=-1;
                TIMETIMER[1][0]=-1;
                TIMETIMER[1][1]=-1;
        ENDIF
        IF TTNum>-1
                        TIMETIMER[TTNum][0]=GETTIMER()
                        TIMETIMER[TTNum][1]=TIMETIMER[TTNum][1]+TIMETIMER[TTNum][0]
                        CheckIt=TIMETIMER[TTNum][1]/1000
                        IF INTEGER(CheckIt)>=TTCountTo
                                        TIMETIMER[TTNum][0]=0
                                        TIMETIMER[TTNum][1]=0
                                        checkit=0
                                        RETURN TRUE
                                ELSE
                                        RETURN FALSE
                        ENDIF
        ENDIF
ENDFUNCTION

 
Quote
Tips:
1. becareful not to use too many timers,
2. reuse the id slots if they arent being used anymore.
3. More timers you se will result in less performance, dont use more than needed.
4. Do not use any single timer for multiple events! Watch those ID's!
Note:
Quote
Updated for use with current compiler: EDITED ON SEPT.23 2005
-Hemlos
« Last Edit: 2008-Aug-15 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Multiple Realtime Timers Function!
« Reply #1 on: 2004-Oct-21 »
Wow, that's handy!

rocko

  • Guest
Multiple Realtime Timers Function!
« Reply #2 on: 2006-May-09 »
Timers are good :D thank ya sir

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Multiple Realtime Timers Function!
« Reply #3 on: 2006-Oct-08 »
Youre welcome, check out my last post of the FPS and elapsed time function too
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Hb!

  • Guest
Multiple Realtime Timers Function!
« Reply #4 on: 2007-Oct-21 »
wow sounds good, thanks I gotta test em ,but if it makes the game extremely slow...I think ill have to use sprites instead ....