Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 FPS module
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Catalyst




PostPosted: Sat May 24, 2003 11:25 pm   Post subject: FPS module

here an FPS module i wrote for something i am working on

code:

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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat May 24, 2003 11:34 pm   Post subject: (No subject)

thx Catalyst, I'll link this page from the FPS tutorial Smile
+10Bits
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: