iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > frames per second


Reply
 
Thread Tools Display Modes
  #1  
Old 10-18-2002, 03:33 PM
Hellrector Hellrector is offline
Regular
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 50
Default frames per second

I read a lot of posts with people telling they are getting a surtain frame rate with there project.
My question is. How do you write a bullet proof piece of code to get your frame rate?
I'm new to game programming, so making a mistake in doing this could turn out possitive or negative. I just wanna be sure....
Reply With Quote
  #2  
Old 10-18-2002, 04:17 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Preferred language:
Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Hawaii, USA
Posts: 16,584
Default

Well, on the simplest level, having definite FPS comes from a Sleep loop that will wait until time has passed.
You'd usually use the GetTickCount to get a millisecond time and then Sleep to wait.

Then:
Code:
Const MaxFPS As Integer = 10 Dim L As Long, L2 As Long Do L = GetTickCount Call AVeryLongAndComplexProcedureThatIsTheBulkOfThisApp L2 = GetTickCount If L2 - L <= 1000 \ MaxFPS Then Sleep ((1000 \ MaxFPS) - (L2 - L)) End If Loop Until bEscape
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 10-18-2002, 04:22 PM
Hellrector Hellrector is offline
Regular
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 50
Default

If I read this write than would say
you take the tick count before the game actions
and afterwards and you have the result
tickcount 1000 = 1 sec ? nevermind... those are milli secs
I wouldn't need the sleep function as I don't wanna be limiting the speeds right now
Just want to know the speed how many frames are done per second without limitation
Reply With Quote
  #4  
Old 10-18-2002, 04:44 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Preferred language:
Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Hawaii, USA
Posts: 16,584
Default

To find your FPS:
Code:
L = GetTickCount Call AHotMess 'your game code L2 = GetTickCount FPS = 1000 / (L2 - L)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 10-18-2002, 05:07 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Preferred language:
Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

I normally just use a timer set to 1000 ms with a global (or module level) long counter called FPS.

Private FPS as Long

Main Code:
Code:
Do 'Main Loop code .... FPS = FPS + 1 'increment the frame counter Loop While Not bDone

Timer code:
Code:
Private Sub tmrFPS_Timer() me.Caption = "FPS: " & FPS FPS = 0 End Sub

It's simple, accurate, and gets the job done.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #6  
Old 10-18-2002, 05:19 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Preferred language:
Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

When choosing between the two methods presented, bear in mind:

Iceplugs method calculates the FPS for each individual frame. This is great but could lead to a fair amount of fluctuation. My way averages out the cycles over 1 second.

Iceplug can get FPS in fractional increments. My way is whole frames only.

Iceplug doesn't show how you display the FPS but you probably should NOT update the screen every frame....any kind of screen refreshing takes a lot of time and will decrease your frame rate. My way updates the screen once per second, not once per frame.

Iceplugs way is pure code (well, there is an API in there...). My way requires a timer control.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #7  
Old 10-19-2002, 02:29 PM
Hellrector Hellrector is offline
Regular
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 50
Default

thnxz works great
Reply With Quote
  #8  
Old 10-21-2002, 04:43 AM
antoney's Avatar
antoney antoney is offline
Freshman
 
Join Date: Jun 2002
Location: Australia QLD
Posts: 26
Default

Im lost with this..ehhh does anyone know a where i can find a tutorial for FPS, or better yet can someone explain (In simplest form!!) how i can write the code.
Reply With Quote
  #9  
Old 10-21-2002, 05:11 AM
Hellrector Hellrector is offline
Regular
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 50
Default

I think Billsoo's reply is self explaining
not much too it if you use his method.
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: