module FPS
export StartClock, StopClock, SetFont, SetFrameCap, DisplayFPS, GetFPS
var oldTime, newTime : int := 0
var capFrame : boolean := false
var frameLimit : int := 60
var currentFPS : real
var dispFont, dispColor : int
dispFont := Font.New ("verdana:10:bold")
dispColor := 0
proc SetFont (font : int, c : int)
dispFont := font
dispColor := c
end SetFont
proc SetFrameCap (n : int)
capFrame := true
frameLimit := n
end SetFrameCap
proc StartClock
clock (oldTime)
end StartClock
proc StopClock
clock (newTime)
currentFPS := 1000 / (newTime - oldTime)
if capFrame then
if currentFPS > frameLimit then
delay (round ((1000 / frameLimit) - (1000 / currentFPS)))
currentFPS := frameLimit
end if
end if
end StopClock
function GetFPS : real
result currentFPS
end GetFPS
proc DisplayFPS (x, y : int)
Font.Draw ("FPS: " + realstr (round(currentFPS), 0), x, y, dispFont, dispColor)
end DisplayFPS
end FPS
|