views:

228

answers:

3

Trying to find a way to limit the framerate of programs/games externally in a similar fashion to VSync, but to a specified number (instead of screen refresh rate). A perfect example of what I am aiming for can be seen in FRAPS, when recording a video the framerate is limited to the recording rate. The reason is for fast pace games which aren't graphically intensive to stop the "screen lag" induced by large changes in framerate, however VSync isn't suitable as oddly it increases latency between keyboard/mouse (both are polling at high rates so not a hardware issue).

Looking ideally for some advice in C/++, honestly not sure where to start.

+2  A: 

I'm not sure if you understand what you're asking about.

The way an FPS game operates is, it paints the screen, does keyboard/mouse/etc handling and game logic, then it paints the screen again. In a tight loop.

The faster it can paint the screen (this is mainly a matter of your graphics adapter) and the faster it can get its logic busywork done, the faster the frame rate will be. Because that's literally all that's happening.

The frame rate doesn't slow processing down, it's the other way around. If you put pauses between screen paints, you'd be running your CPU a bit cooler but not accomplishing anything else.


Stated differently: Frame rate is an effect, not a cause. Your PC spends every spare microsecond doing screen updates because it has nothing better to do.

When you see lag, that's your PC being really bogged down with massive memory moves, disk reads, screen calculation (think 1000 enemies flying at you) or choking on Internet delays. Lag is not caused by screen repaints.


UPDATE:

I have trouble believing what you're saying, but I'm just the answer man here. If you really want to lower your frame rate, give your CPU(s) something to do. Run a Linux kernel compile. No wait, gamez = Windowz. Pull up Calc.exe and ask the scientific mode for the factorial of a large number. See what happens. If frame rate doesn't drop, do it with 2 or 3 instances of Calc in parallel.

Carl Smotricz
Thanks for the reply.I understand how graphics is processed, however the game I am on about specifically (GunZ) gives serious issues outside of the 250-350 fps realms. If above or below this number the game feels very sluggish and when I have enabled VSync it has taken as long as .5 seconds to actually do anything.Hopefully this gives a little more insight into my odd request :)
Auraomega
I wish I had your problems! My system is doing well if it hits 60 FPS. Since anything over about 80 FPS is completely indiscernible to even a fast eye and thus a waste of CPU/GPU power, I would say that any software that REQUIRES 250 FPS is badly broken.
Carl Smotricz
My system has a problem reaching anything above 5fps on modern games, this game was developed years ago. I think I understand what you are saying, but the game really does have this effect, over clocking my card to reach 500 and it becomes really difficult to get it to do what I wish, whether or not it's logical, it happens, under clocking the card helps, but is an annoyance. As for the huge changes in frame rate, ask any gamer what dropping from, say, 150 to 75 fps would do, you see the change as calculations are based off of framerate (at least, they are in this game and most I've played).
Auraomega
OK, so we're talking about a game with poorly implemented scene update calculation. Did you catch my update and advice for slowing your CPU down? I shudder to suggest this but it might actually help your game experience at a very moderate investment of effort.
Carl Smotricz
I just noticed it, I'll give that an attempt now, however I fear that it won't be enough (considering the 400fps reached easily on my 8500gt and soon to be upgrading to a 5850), I will come back and see if has help any. And yes, very badly implemented (infact, the game has become primarily based around exploiting bugs in the physics engine), but the game is really rather addictive even if it's a monument to poor development.
Auraomega
Nice attempt, however it keeps giving me a nag screen asking if I want to continue (typical Microsoft), and didn't help any. According to friends with more powerful cards they have similar issues at higher framerates too, I really can't understand why this happens :/
Auraomega
2 more things to try: First, if you can overclock your GPU, can't you just turn it down?
Carl Smotricz
2nd: If this game isn't strongly copy protected it can probably be hacked with tools like a debugger. One could, for instance, hijack a system call made in the main loop and delay it a bit on its way back. But this isn't the kind of thing easily done by remote control. Nor am I very good at it. I've written some successful bots but have been away from Windows for some years.
Carl Smotricz
I have been underclocking, yes, it just gets tedious and an all-in-one solution would be nice (theres no doubt other games out there with similar issues, even if I haven't found them yet). The game itself is free, but has a lot of "hack prevention" software with it, it wouldn't be too hard to bypass this, but again a labour to do it after each update (god mode unfortunately is in abundance and the game is updated regular to attempt to stifle those hacks).
Auraomega
Auraomega, if underclocking works, use a simple "slow down" utility. If you have problems getting that to work, take your question to SuperUser.
Georg Fritzsche
A: 

kkapture (open source) does this for demos. I don't know if it can be modified for your purpose. It creates a proxy video driver, but it's probably too hardcore to deal with.

neoneye
Thanks for the reply, I'll take a look at the code and see what I can deduce.
Auraomega
+1  A: 

Use the threading API to suspend the game's threads for a few ms, then resume them. This article (C++) on CodeProject and this stack (although C#) goes into some detail on this.

Cecil Has a Name