Game Timer

Blitz3D Forums/Blitz3D Beginners Area/Game Timer

Trader3564(Posted 2007) [#1]
Hi,

I know that a good game uses its own timer.
My question is how do i write timebased movement and routines and things?
And how do i limit FPS.
I think its not a good idea to block a whole loop,
as done in the B3D example.

Any comments welcome :)


Trader3564(Posted 2007) [#2]
xD


b32(Posted 2007) [#3]
As for timebased movements, I know this method:

To limit the FPS, I believe the castle demo (in the samples 'mak' folder) has frame limiting code. I'm not sure if that is the example you mentioned ?


Matty(Posted 2007) [#4]
In my games now what I usually do is the following:


;Core game Loop

LogicTime=Millisecs()-1
LogicTimeDelay=20 ;50fps
GraphicTimeDelay=15 ;60fps (approx)
repeat

CurTime=Millisecs()
If CurTime>LogicTime then 
     Delta#=1.0+Float(CurTime-LogicTime)/Float(LogicTimeDelay)
LogicTime=CurTime+LogicTimeDelay

UpdateCamera(Delta#)
UpdateUnits(Delta#)
UpdateBullets(Delta#)
UpdateParticles(Delta#) ;and so on for all the logic related  functions that manage all the stuff in the game

UpdateWorld Delta#
endif 

If CurTime>GraphicTime then 
GraphicTime=CurTime+GraphicTimeDelay

;do all rendering stuff in here
renderworld
text 0,0,"FPS:"+str(fps)
vwait
flip false

endif 

fpscount=fpscount+1
if millisecs()>fpstime then 
fps=fpscount
fpstime=millisecs()+1000
fpscount=0
endif 

forever




and in those functions I do the following:

for example:


;any changes in position, velocity,acceleration which are ;additive I do as follows:such as with particles

;I haven't defined the ParticleObject type but you should get the general idea

For P.ParticleObject=each ParticleObject

P\positionx=P\positionx+p\velocityx*Delta#
P\velocityx=P\velocityx+p\accelerationx*Delta#
;same for y and z

P\Scale=P\Scale+P\ScaleFactor^Delta
;Any values which are multiplied by a factor you simply take that factor and raise it to the power of Delta.  Assumes that these scaling factors are not negative, but may be any value from 0 upwards.
next



Trader3564(Posted 2007) [#5]
wauw, thats some neat stuff. im going to check this out!