|
-
Apr 19th, 2009, 10:10 AM
#1
Thread Starter
Addicted Member
Limiting FPS to screen refresh?
Hi,
I have made a game (real time strategy) and it is running rather fast on my 3 GHz quad 8800 GTX, namely, it runs around 200 FPS usually when there are like 80 units and tanks in a forest fighting.
I would like to limit the FPS. So far my limitation code is pretty buggy... it does limit, but wrongly:
Code:
Private Sub LoopGame()
Do While GameIsNotPaused
FPS += 1
If Math.Abs(Environment.TickCount - LastTick) >= 1000 / DesiredFrameRate Then
... draw ...
LastTick = Environment.TickCount
FPS = 0
End If
Application.DoEvents()
Loop
End Sub
I set desiredframerate to 90, and this code:
Code:
Public Class Framerate
Private Shared lastTick As Integer
Private Shared lastFrameRate As Integer
Private Shared frameRate As Integer
Public Shared Function CalculateFrameRate() As Integer
frameRate += 1
If Math.Abs(System.Environment.TickCount - lastTick) >= 1000 Then
lastFrameRate = CType(frameRate * 1000 / Math.Abs(Environment.TickCount - lastTick), Integer)
frameRate = 0
lastTick = System.Environment.TickCount
End If
Return lastFrameRate
End Function
End Class
Tells me that the game is running 64 FPS 
Why 64, why not 90? What is wrong with that...
Also, after I solve this weird issue, should I set the value to monitor's refresh value which is usually 60 Hz on LCDs? Or should I set it to 30 or what ?
-
Apr 20th, 2009, 09:28 AM
#2
Re: Limiting FPS to screen refresh?
Environment.TickCount does not get updated as often as you'd like.
Why not let the FPS go as fast as it can? There's no detriment to doing so, beyond eating up the CPU availability (most games run as fast as they can). DirectX may have a way of actually limiting FPS if necessary, but haven't really played with that so could be totally wrong.
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
-
Apr 20th, 2009, 09:31 AM
#3
Thread Starter
Addicted Member
Re: Limiting FPS to screen refresh?
Because certain things are not supposed to go as fast as possible. For instance, handling keyboard events is crazy if the keyboard event is polled 500 times a second...
Another thing is that I do not want the screen to tear. I want it to be sync'ed with the monitor's Hz.
Additional FPS burns GPU for nothing.
-
Apr 21st, 2009, 06:40 AM
#4
Re: Limiting FPS to screen refresh?
If you use DirectX you don't have to worry about screen tearing. Just run it as fast as you can and the video card should display it as appropriate for the monitor.
I would think you'd be using directX if you are thinking of such high animation rates...
Although, it's not clear what you mean by 'certain things are not supposed to go as fast as possible'. I think the question may be, are you using DX or not?
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
-
Apr 21st, 2009, 06:48 AM
#5
Thread Starter
Addicted Member
Re: Limiting FPS to screen refresh?
Yes I am using DirectX and my real time strategy game sometimes runs as fast as 7000 FPS... my GPU is literally screaming and it's getting at 74C and my entire PC is getting warm... and all this for... 7000 FPS? Dude, I have 60 Hz monitor... I won't even be able to detect any changes beyond 60 FPS.
By FPS I am referring to the number of times the screen is drawn. The game logic is separated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|