Line() function and frame rate behaviour

Blitz3D Forums/Blitz3D Beginners Area/Line() function and frame rate behaviour

1Garrett(Posted 2016) [#1]
The following code has one call to a Line() function; if the only row in the following cole with the Line() function is executed, the frame rate drops to a fluid 60hz frame rate per second (the code shows also the frame rate on screen). If that row with the Line() function is commented, the frame rate is not limited to 60hz (you can see clearly the ball rotating at more speed and, at least on my machine, frame rate is over 200 frames/second).

My question is why this behaviour? Can someone explain what does the Line() function and how can I control the frame rate? Next is the example code:

;setup graphics
Graphics 800, 600, 32, 2
SetBuffer BackBuffer()
	
;create ball image
o = CreateImage(25, 25)
Oval 0, 0, 25, 25
GrabImage o, 0, 0
MidHandle o


Ball1XPos# = 400.0
Ball1YPos# = 300.0

Ball1XPosNew# = 0.0
Ball1YPosNew# = 0.0

diameter# = 150


angle# = 0.0





	Repeat
		Cls
		Ball1XPosNew = (diameter * Cos(angle)) + Ball1XPos 
		Ball1YPosNew = (diameter * Sin(angle)) + Ball1YPos


		;here is the strange, the Line() function drops frame rate to 60hz 
		Line Ball1XPos, Ball1YPos - diameter, Ball1XPos, Ball1YPos + diameter

		;draw ball
		DrawImage o, Ball1XPosNew, Ball1YPosNew
		
		
		
		;fps counter
		 If MilliSecs()-settime>1000
		  getfps=setfps : setfps=0 : settime=MilliSecs()
		 Else
		  setfps=setfps+1
		 EndIf
		
		 Text 0,0,"FPS="+getfps		

		VWait
		Flip(False);


		
		;increment angle
		angle = angle + 0.5
		If (angle > 359) Then
			angle = 0;
		End If	
	
		
	;esc = exit	
	Until KeyHit(1)
	
	WaitKey()

	End


Hoping someone can explain this. Thanks a lot.


RemiD(Posted 2016) [#2]
The "locked" fps is not because of Line() or DrawImage() but because of VWait() (read the doc)

here is how i would write/structure the same code



1Garrett(Posted 2016) [#3]
Hi RemiD,

thank you very much for your answer, its clearer now even if I continue to not understand why, in my original code (and on my computer, at least), I obtain a perfect fixed 60fps/sec when the Line() function is not commented and about 300fps/sec when the Line() function is commented, while if I remove the both Line() and VWait() i get about 3500fps/sec, but commenting just the Line() i arrive at 8000fps/sec (or the line() function is particularly slow, or there is something wrong).

It seems that function has some code that fixes the frame rate, if in the code the VWait() is also added. However not important to enter for me too much in these tiny details...just one thing, in your posted code the fps counter seems not working, it displays always 1000fps/sec. Thanks again!


1Garrett(Posted 2016) [#4]
Sorry.. I get 8000fps/sec when Line() and VWait() are commented and 3500fps/sec when I uncomment the Line().


RemiD(Posted 2016) [#5]
The FPS counter seems to work correctly see with this example :