0 Members and 1 Guest are viewing this topic.
rbrazCBM 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
'----------------------' FPS Limiter'----------------------' by Rbraz - 2006'----------------------Option Explicit' Includes#Include Once "windows.bi"'Sub RoutinesDeclare Sub FPS_Count()'FPS CounterDim Shared iFPS, bSettime,iSecStart,iFrameCount,iFrameStart as integer'--------------------------------------------------Const MAX_FPS = 60 'Max FPS DesiredDim Freq as LARGE_INTEGERDim cTimer1 as LARGE_INTEGERDim cTimer2 as LARGE_INTEGERDim Interval as double'-------------------------------------------------- QueryPerformanceFrequency(@Freq) 'Get Frequency Interval = CDBL(Freq.QuadPart) / CDBL(MAX_FPS) 'Calculate interval based on MAX_FPS and Frequency'Main LoopWhile 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 MainSub 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
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!)