Author Topic: FPS Limiter  (Read 5117 times)

0 Members and 1 Guest are viewing this topic.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
FPS Limiter
« on: May 04, 2006 »
Quote
rbraz
CBM 128

Posts: 187
(21/4/06 18:34)
Reply
  FPS Limiter
--------------------------------------------------------------------------------
 This is a code that I'm using to limit the max fps in C++/OGL and now converted it to FB, it use a high performance counter (QueryPerformanceCounter) and frequency performance (QueryPerformanceFrequency) to limit the max. frame rate. Feel free to use it in your next productions 

 

Code: [Select]
'----------------------
'   FPS Limiter
'----------------------
'   by Rbraz - 2006
'----------------------

Option Explicit

' Includes
#Include Once "windows.bi"

'Sub Routines
Declare Sub FPS_Count()
'FPS Counter
Dim Shared iFPS, bSettime,iSecStart,iFrameCount,iFrameStart as integer


'--------------------------------------------------
Const MAX_FPS = 60             'Max FPS Desired
Dim Freq    as LARGE_INTEGER
Dim cTimer1 as LARGE_INTEGER
Dim cTimer2 as LARGE_INTEGER
Dim Interval as double
'--------------------------------------------------

    QueryPerformanceFrequency(@Freq)                'Get Frequency
    Interval = CDBL(Freq.QuadPart) / CDBL(MAX_FPS)  'Calculate interval based on MAX_FPS and Frequency

'Main Loop
While Inkey$() <> Chr$( 27 )
       
    QueryPerformanceCounter(@cTimer2)
    if(cTimer2.QuadPart >= cTimer1.QuadPart + Interval) then
       
        QueryPerformanceCounter(@cTimer1)
               
        locate 8,30
        print "Desired FPS: " & MAX_FPS
        locate 10,30
        print "Current FPS: " & iFPS
   
        FPS_Count()
       
    end if
   
 
Wend
'End Main

Sub FPS_Count()
         If bSettime = 1 then
          iSecStart = Timer() * 1000.0
          iFrameStart = iFrameCount
          bSettime = 0
     EndIf 
     If (Timer()*1000.0) >= iSecStart + 1000 then
          iFPS = iFrameCount - iFrameStart
          bSettime = 1
     EndIf
     iFrameCount = iFrameCount + 1     
End Sub


 
Quote
5H0CKW4VE
 *Administrator*

Posts: 8015
(22/4/06 13:52)
Reply
ezSupporter

  Re: FPS Limiter
--------------------------------------------------------------------------------
 I may well pinch this, will credit you of course.. Thanks Rbraz 


--------------------------------------------------------------------------------


¤´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·`¤... SHOCKWAVE / DBF...¤

VISIT DARK BIT FACTORY INTERACTIVE! (please!)


Challenge Trophies Won: