FPS Limiting

Blitz3D Forums/Blitz3D Programming/FPS Limiting

darklordz(Posted 2004) [#1]
i use the following code
While Not KeyHit(1)
	Repeat
		ELAPSED% = MilliSecs() - TIME%
	Until ELAPSED%

	TICKS% = ELAPSED%/PERIOD%
	TWEEN# = Float(ELAPSED% Mod PERIOD%)/Float(PERIOD%)

	For C = 1 To TICKS%
		If C = TICKS% Then CaptureWorld
		TIME% = TIME% + PERIOD%
		Sadjuk_Updateworld%() ; all math n updates here...
		UpdateWorld
	Next
	
	Sadjuk_UpdateFX%() ; mo blur
	RenderWorld TWEEN#
	
	Sadjuk_DrawHUD%() ; 2d text operations
	Flip
Wend


fps is set to 60. but still people with gforce 4 or higher get a higher fps? how?


Chi3f Stadi(Posted 2004) [#2]
Check what monitor frequency they use since you use flip vwait !


Hotcakes(Posted 2004) [#3]
Nah that defies the whole purpose of the timing code above it Chief =]

darklordz, sorry to state the obvious but I presume PERIOD and TIME are previously initialised? ;]

Also remember that the expression 'Until ELAPSED%' will only wait so long as ELAPSED% is not 0 - is it possible that TIME%=TIME%+PERIOD% could ever give a greater number than MilliSecs()? I'd use 'Until ELAPSED%>0' to be sure.


Chi3f Stadi(Posted 2004) [#4]
@Hotcakes
Just test it with different monitor frequencies and you'll see i'm right !


darklordz(Posted 2004) [#5]
ermmm Hotcakes check this...
http://www.blitzbasic.com/codearcs/codearcs.php?code=9


DJWoodgate(Posted 2004) [#6]
Works fine here guys. I think you are under a misapprehension about what it is supposed to limit. It aims to run your game logic at the desired framerate. The rendering may be faster or slower and this will depend on hardware, monitor refresh rates at a given resolution and so on. Any glitches this might cause are smoothed out by the clever tweening stuff.


darklordz(Posted 2004) [#7]
But framelimiting code is supposed to lock the amount of frames rendered (in my case @ 60 fps). Correct me if im wrong. This will help speed problems on faster machines. (that the game runs faster then it's supposed to.) But on a gf 4 my game runs @ 70 fps whil it's limited to 60 how come <- my original question...


Zethrax(Posted 2004) [#8]
Framelimiting is the wrong term to be using. Think game speed limiting instead.

If a frame takes twice as long to render as the previous one then your frame rate will naturally drop by half (more or less). Your main concern should be in regulating the speed that objects move and other game processes execute at irregardless of the frame rate.


darklordz(Posted 2004) [#9]
Hmmm you are right but how can i control something not to render faster then it should?


Abomination(Posted 2004) [#10]
This is my game-speed limiter (more or less)
Perhaps usefull to someone...

Function Game_update_limit()
CGU=0 ;count game updates
Repeat
CGU=CGU+1
Update_Game ()
If CGU=1
While ETPU=>(MilliSecs() ;expected time for next update
;wait if GU was too fast
Wend
EndIf
ETPU=ETPU+TPU ;TPU is Target Time per Update
Until ETPU=>(MilliSecs() ;Do GU again if GU was too slow
End Function