FrameTime# ( )
Parameters
| None. |
Description
|
Returns the milliseconds between the two most recent Flip calls. FrameTime measures the whole frame from the player's point of view: it is the time between entering the previous Flip and entering the latest one, so it includes your game logic, rendering, and any waiting done for VSync or a frame limit. 1000.0/FrameTime() gives the current frames per second; at a smooth 60 FPS you will read around 16.7. Its best trick is telling you which side of the fence a slowdown lives on, together with RenderCPUTime and RenderGPUTime: if FrameTime is large but the render times are small, the frame is being spent in your own code (or simply waiting on VSync); if the render times are large too, the scene itself is heavy. It returns -1 until two Flips have happened, so guard the first frames of your loop. The value is a measurement of the last completed frame, not a promise about the next one - expect it to jump around a little and smooth it over several frames before showing it off. Requires Extended mode. See also: RenderCPUTime, RenderGPUTime, RenderTriangles, DrawRenderStats. |
Example
; FrameTime Example ; ----------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,3,-14 light=CreateLight() RotateEntity light,45,45,0 ; An asteroid ring the player can switch off to lighten the frame hub=CreatePivot() Dim rocks(29) For n=0 To 29 rocks(n)=CreateSphere(24) ScaleEntity rocks(n),0.6,0.6,0.6 PositionEntity rocks(n),6*Cos(n*12),2*Sin(n*47),6*Sin(n*12) EntityParent rocks(n),hub EntityColor rocks(n),130,120,110 Next heavy=True While Not KeyDown(1) ; Space toggles the asteroid ring on and off If KeyHit(57) Then heavy=Not heavy For n=0 To 29 If heavy Then ShowEntity rocks(n) Else HideEntity rocks(n) Next EndIf TurnEntity hub,0,0.5,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld ; FrameTime measures the gap between the two most recent Flips ms#=FrameTime() Text 0,0,"Arrow keys: move camera Space: toggle asteroids Esc: exit" Text 0,20,"FrameTime() = "+ms+" ms" If ms>0 Then Text 0,40,"That is about "+Int(1000.0/ms)+" frames per second" Flip Wend End
Index