Controlling FPS
Controlling FPS
Controlling FPS
Controlling FPS
Controlling FPS
Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS
Controlling FPS Controlling FPS
Controlling FPS
Go Back  Xtreme Visual Basic Talk > > > Controlling FPS


Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2008, 10:51 AM
sukasa sukasa is offline
Newcomer
 
Join Date: Sep 2006
Posts: 7
Post Controlling FPS


So, I've been working on a game, and I've run into a bit of a snag. The program is designed to run at a set FPS, however, I don't think my code works as well as it could- this is the code as it is now:


Code:
Do While InGame = True
DoEvents
 If fps <= GetTickCount Then 'IF the FPS counter says go, go
-snip-
fps = (GetTickCount + Int(1000 / MAX_FRAME_RATE))
End If
Loop
My problem is, if I change fps to just GetTickCount(), then the program runs anywhere from 180-200 FPS. However, if I add even 1 to fps (to make it fps = (GetTickCount + 1), it cuts down to only 65 FPS, which is lower than my target FPS. Obviously, this code doesn't work well enough, unless my FPS-reading code is completely off. My question is, can anyone point me in the direction of some better code I can look at and learn from so I can make mine work better?

As an addendum, here's the code that checks the FPS.

Code:
...
For a = 0 To UBound(fps2) - 1
            fps2(a) = fps2(a + 1)
        Next a
        fps2(UBound(fps2)) = GetTickCount
...
Set_FrameRate
...
Private Sub Set_FrameRate()
    On Error Resume Next
    If MessageTmr Mod 32 = 0 Then
        Label1.Caption = "FPS:" + Str(Int((1000 * (UBound(fps2) + 1)) / (GetTickCount - fps2(0))))
    End If
End Sub
The "..."s are just snipped-out non-FPS stuff. Basically, fps2() is there to average out the FPs over the last little bit. MessageTmr is increased every frame, as well, and wraps from 255 to 0.
Reply With Quote
  #2  
Old 05-08-2008, 05:16 PM
an5w3r's Avatar
an5w3r an5w3r is offline
Senior Contributor
 
Join Date: Jan 2004
Location: Romania
Posts: 1,342
Default

I remember reading something once upon the time.
It was something like this: if you want your program to work at a given FPS rate all you need to do is work it inside a loop and test it if in one second you have the desired FPS rate (if so ignore the rest of the code, if not do the drawing stuff) and reset the counter after each second passes. I don't know if this helps you, but this is the basic idea behind working on a constant FPS rate.
__________________
Fully customizable and easy to use .NET WPF charting library http://www.SoftwareGFX.com
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Controlling FPS
Controlling FPS
Controlling FPS Controlling FPS
Controlling FPS
Controlling FPS
Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS Controlling FPS
Controlling FPS
Controlling FPS
 
Controlling FPS
Controlling FPS
 
-->