FPS-Limiter
Started by SlnC, Sep 15 2011 11:15 AM
12 replies to this topic
#1
Posted 15 September 2011 - 11:15 AM
Hey everyone,
how do i externally limit my FPS in a DirectX9 Game? ... The Game i mean gets horrible bugy with like more than 150fps.. I've already tried FPS_Limiter but i need to start that game with parameters and FPS_Limiter does not support that, i've also tried VSync but i get huge Input Laggs. So i started to google for some tutorials how to do this limiter on my own .. without success -.-. So i hope someone on this forum know how to do this or can give me an advice.
Greets SlnC
how do i externally limit my FPS in a DirectX9 Game? ... The Game i mean gets horrible bugy with like more than 150fps.. I've already tried FPS_Limiter but i need to start that game with parameters and FPS_Limiter does not support that, i've also tried VSync but i get huge Input Laggs. So i started to google for some tutorials how to do this limiter on my own .. without success -.-. So i hope someone on this forum know how to do this or can give me an advice.
Greets SlnC
#2
Posted 15 September 2011 - 11:25 AM
You can do it with timeGetTime in your main loop, if you want to limit it to 60fps, thats 16 milliseconds per frame, just make a Sleep() operation that makes sure it waits the extra few milliseconds it needs to to make 60 fps.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.
#3
Posted 15 September 2011 - 11:47 AM
the point is .. how do i do this without having acces to the source code of the game ^^ i think i need to hook DirectX while the game is running or at the start of the game .. but how do i do this .. and most importantly .. what do i have to do next ^^
#4
Posted 15 September 2011 - 11:59 AM
Oh sorry I didnt read properly... maybe there is some kind of fps limiter, im not sure of the exact name of it, but back in the old 486 days to play an 86 game you needed to limit the fps in exactly the same way... woops, sorry man.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.
#5
Posted 15 September 2011 - 12:06 PM
no problem :D
#6
Posted 15 September 2011 - 12:10 PM
It is quite bad design to make your game logic depend on the FPS.
#7
Posted 15 September 2011 - 02:49 PM
Like i metioned before, i have no access to the Source Code of the game ... i didnt write this game^^
#8
Posted 16 September 2011 - 08:12 AM
Basically you want to limit the FPS when playing any normal game, in most cases you just need to enable VSync as that "should" force the game to try and run at the same speed as your monitors refresh rate.
Failing that there are 3rd party programs that can do it, but as I've never used any of them I couldn't comment on there effectiveness, your best bet is to google search FPS Limiter and read up on them.
Failing that there are 3rd party programs that can do it, but as I've never used any of them I couldn't comment on there effectiveness, your best bet is to google search FPS Limiter and read up on them.
:) Skid :)
"Imagination is the only weapon in the war against reality."
"The polar opposite to Nintendo's bewilderingly name modestly powered little white cuboid is Sony's unoriginal titled monolithic black colossus the Playstation 3"
"Imagination is the only weapon in the war against reality."
"The polar opposite to Nintendo's bewilderingly name modestly powered little white cuboid is Sony's unoriginal titled monolithic black colossus the Playstation 3"
#9
Posted 16 September 2011 - 12:33 PM
SlnC said:
Hey everyone,
......... I've already tried FPS_Limiter but i need to start that game with parameters and FPS_Limiter does not support that, i've also tried VSync but i get huge Input Laggs. ......
Greets SlnC
......... I've already tried FPS_Limiter but i need to start that game with parameters and FPS_Limiter does not support that, i've also tried VSync but i get huge Input Laggs. ......
Greets SlnC
#10
Posted 16 September 2011 - 01:03 PM
Not sure this will help but maybe you get some more ideas from my input.
- If this is an old dos game you could try dosbox.
- You could also use fraps as a FPS limiter, but then you will always record a video. Not sure if you could loop and always override the last 30 sec or so, as to not fill up your hard drive.
- ATI has some ATI Tray Tools, which might help (if you have an ATI card, NVidia might have similar options).
- And then there is RivaTuner which allows you to make some tweaks. http://www.guru3d.co...?page=rivatuner
Also, generally you tend to get less input lags when your fps is slightly less than your monitors refresh rate. Maybe you could tweak VSync a bit to solve the problem.
- If this is an old dos game you could try dosbox.
- You could also use fraps as a FPS limiter, but then you will always record a video. Not sure if you could loop and always override the last 30 sec or so, as to not fill up your hard drive.
- ATI has some ATI Tray Tools, which might help (if you have an ATI card, NVidia might have similar options).
- And then there is RivaTuner which allows you to make some tweaks. http://www.guru3d.co...?page=rivatuner
Also, generally you tend to get less input lags when your fps is slightly less than your monitors refresh rate. Maybe you could tweak VSync a bit to solve the problem.
#11
Posted 27 January 2012 - 05:26 PM
*revive thread* 
So i hooked DirectX and tried to delay the Present() method by
i was successful at not going over the 120 fps.
but my fps got jumpy and is between ~90 and ~110.
(without the "limitation" i get like 350-400 fps so its not due to my hardware)
the problem is simple with my calculation i limit the Present()-method to be
executed max 120 times per second but did not take into account that the method
itself needs time to process. so i started to meassure(with QueryPerformanceCounter() )
the time the mehthod would need to be called again
so my Present()-Method looks like this now:
so now i get still jumpy fps (160-180) and iam way ove the 120
so dTimeDiff is too big to get me to my 120fps.
so my question is, is that the "usual" approach to limit the fps via hook?
If yes, is there something like a formula for the delay-time?
PS.: Sorry for my english, not my native language
EDIT: Used this tutorial for hooking: http://www.gamedev.n...hooking-sample/
So i hooked DirectX and tried to delay the Present() method by
//fps is loaded for an ini file( fps = 120 for example). DWORD delay = 1000/fps; Sleep(delay);
i was successful at not going over the 120 fps.
but my fps got jumpy and is between ~90 and ~110.
(without the "limitation" i get like 350-400 fps so its not due to my hardware)
the problem is simple with my calculation i limit the Present()-method to be
executed max 120 times per second but did not take into account that the method
itself needs time to process. so i started to meassure(with QueryPerformanceCounter() )
the time the mehthod would need to be called again
so my Present()-Method looks like this now:
//fps is loaded for an ini file( fps = 120 for example).
//g_CurentCount is first declared in the constructor
//(so naturally the first call is wrong but i dont realy care :) )
//and ignore the amount of casts :D
STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
{
QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
double dTimeDiff = (((double)(g_LastCount-g_CurentCount))/((double)g_Frequency)) * 1000;
double sleep = (1000/fps)-dTimeDiff;
if(sleep<=0){
sleep = 1;
}
Sleep((DWORD)sleep);
g_CurentCount = g_LastCount;
return m_device->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}
so now i get still jumpy fps (160-180) and iam way ove the 120
so dTimeDiff is too big to get me to my 120fps.
so my question is, is that the "usual" approach to limit the fps via hook?
If yes, is there something like a formula for the delay-time?
PS.: Sorry for my english, not my native language
EDIT: Used this tutorial for hooking: http://www.gamedev.n...hooking-sample/
#12
Posted 27 January 2012 - 08:56 PM
Both ATI and nVidia drivers allow you to forcefully enable vsync in games. Your current approach obviously has a lot of educational value, but I think just doing it in the display settings is the fastest and most effective
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#13
Posted 27 January 2012 - 10:33 PM
I thought I smelled a bit of necromancy 
SInC, in a nutshell that's pretty much how it's done, next to playing with VSync options of course. Keep in mind that sleeping is not an exact procedure. It only has millisecond accuracy at best, but in real cases it will delay a tiny bit longer than asked. You can check this article for details. If you aim for 60 FPS, or 16.66 MS per frame, then if your sleep timer is off by 4 milliseconds you can have up to 18 FPS difference. You also shouldn't force a sleep of 1 millisecond if you don't have to. In your code, if you're lagging behind the frame rate you are further delaying it by adding a 1 millisecond delay. That's like adding salt on a wound
SInC, in a nutshell that's pretty much how it's done, next to playing with VSync options of course. Keep in mind that sleeping is not an exact procedure. It only has millisecond accuracy at best, but in real cases it will delay a tiny bit longer than asked. You can check this article for details. If you aim for 60 FPS, or 16.66 MS per frame, then if your sleep timer is off by 4 milliseconds you can have up to 18 FPS difference. You also shouldn't force a sleep of 1 millisecond if you don't have to. In your code, if you're lagging behind the frame rate you are further delaying it by adding a 1 millisecond delay. That's like adding salt on a wound
http://www.nutty.ca - Being a nut has its advantages.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











