
-----------------------------------
Catalyst
Sat May 24, 2003 11:25 pm

FPS module
-----------------------------------
here an FPS module i wrote for something i am working on


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


-----------------------------------
Tony
Sat May 24, 2003 11:34 pm


-----------------------------------
thx Catalyst, I'll link this page from the FPS tutorial :)
+10Bits
