Need help working with timers...

BlitzMax Forums/BlitzMax Beginners Area/Need help working with timers...

Apollonius(Posted 2007) [#1]
Ranting at the same time so bare with me.

Reading through the documentation, I was looking for something that could control the number of updates per seconds and maybe even frames per second. I came across CreateTimer,... I'm not sure I understand the hertz concept yet...

The way I'm currently coding my game allows me to separate the general values/controls update of the game from the graphical updates.

So basicly I was thinking of running a CreateTimer( 30 ) to update my game 30 times per second and run a Flip 0; and let the graphics update themselves as fast as possible..

I'm trying to code that right now and I just wanted inputs on this. I grant ranting permission ;)


H&K(Posted 2007) [#2]
http://www.blitzmax.com/codearcs/codearcs.php?code=1721


tonyg(Posted 2007) [#3]
Createtimer is a 'quick' way of setting a framerate.
The best way depends on the type of game you're running. You can try Frame Limiting , fixed-rate logic or Delta timing .
However, there have been 100's of posts which contain more code and discussion on which is best in which situation. Use the search function using 'timing'.


Apollonius(Posted 2007) [#4]
I'd be running real time game, like an RPG :P


tonyg(Posted 2007) [#5]
You could probably run any of them unless you have physics simulation in which case 'fixed-rate' is preferable.
Many people have been using Delta-time for years without any problems as well.Still... do those searches and you'll have the the information at your own fingertips.


Apollonius(Posted 2007) [#6]
Yeah I was looking for those topics you talked about after replying and somehow I came to the same conclusion.. delta seems good.

Although won't-I have problems with special effects? Forgot how its called something engine.. basicly it's an easy way to do explosions, smoke, fire.. ect. Since BM does not have that feature we have to make these effects by hand and I'm just wondering if delta will hinder that process?

BTW I wonder if there is such an engine already made for special effects, that'd save time :o
*goes look in the archives*

EDITED
Found the word, it's called a particle engine, although I found 2 in the archieves. They're only prototypes... And there's a very cool fire effect, it's just awesome!


tonyg(Posted 2007) [#7]
Delta would be OK but fixed-rate is pretty good at keeping physics updated. This is debated at length in those posts you read.
There's Smash Particle Engine and lots of source code from others if you use the search function.


Apollonius(Posted 2007) [#8]
I like the sample for the fixed-rate, however, it's not as easy to use as Delta, looking at it, I'm not sure what needs to be included and what commands has to be in my loop?

I'd say its at least less code then Delta


Apollonius(Posted 2007) [#9]
gotta say though... i just tried delta and it isnt working... i tried to set the FPS to 30 yet with flip 0 I get 150FPS++ and with flip i get 60... Whatever I put 1 fps to 150.. with the example.. i see no change either..

Something's wrong.. somewhere :x


Apollonius(Posted 2007) [#10]
Ok ok... after trying to understand /slash/ rewrite Fixed Timing, I started understanding how it works. So I made my own version, it might be coded wrong, since I'm as skilled as a Monkey with a broom. I would like some input, I'm gonna try to make a function to simplify it even more.

..graphical updates are pushed to the maximum your comp can support so basicly it should be smooth...

' Appollonius' Prototype testing based on fixed-rate
' I tried to make it as easy to understand as possible

Graphics 640,480

' REQUIRED
Global UPDATE_FREQUENCY:Int 	= 60
Global UPDATE_EVERY:Int			= 1000/UPDATE_FREQUENCY

Global UPDATE_MILLI:Int			= 0
Global LOOP_MILLI:Int			= 0
Global TOTAL_MILLI:Int			= 0 

' Circle Attributes
Global x:Int=0, y:Int=50, dir:String="right"

' Get milli since computer started
TOTAL_MILLI=MilliSecs()

Repeat
	' Calculate total milli minus current loop milli
	LOOP_MILLI=MilliSecs()-TOTAL_MILLI
	TOTAL_MILLI=MilliSecs()
	
	UPDATE_MILLI:+ LOOP_MILLI
	
	While UPDATE_MILLI >= UPDATE_EVERY
		UpdateIT()
		UPDATE_MILLI:-UPDATE_EVERY
	Wend
	
	DrawIT()
	Flip 0; Cls
	
Until KeyHit(KEY_ESCAPE)
End

' Display a moving circle
Function UpdateIT()
	If x < 0 	Then dir="right"
	If x > 640	Then dir="left"
	
	If dir="right" Then x:+1
	If dir="left" Then x:-1
End Function

Function DrawIT()
	DrawOval x, y, 50, 50
	DrawText "Update Milli-Seconds = " + UPDATE_MILLI,5,5
	DrawText "In Loop Milli-Seconds = " + LOOP_MILLI,5,20
	DrawText "Total Milli-Seconds = " + TOTAL_MILLI,5,35
End Function