Game Timer

Blitz3D Forums/Blitz3D Beginners Area/Game Timer

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 :)

xD

As for timebased movements, I know this method:

Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

camera = CreateCamera()
MoveEntity camera, 0, 0, -15

cube = CreateCube()

prev = MilliSecs()

Repeat
        ;calculate how much time has passed since the prev. frame
	elapsed = (now - prev)
	prev = now
	now = MilliSecs()
	
        ;move cube, based on the time passed
	MoveEntity cube, elapsed * 0.01, 0, 0
	
	RenderWorld()
	Flip

Until KeyHit(1)

End

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 ?

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


wauw, thats some neat stuff. im going to check this out!