Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ivko

Limiting FPS and conserving CPU usage

This topic is 6015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I make my game run at a certain FPS and not take 100% CPU usage while it''s idling? The while(GetTickCount().. method wouldn''t work for me because it consumes all CPU power.

Share this post


Link to post
Share on other sites
Advertisement
The easiest way in my opinion would be to use multimedia timers and run your graphics through a callback. The associated functions are:
timeBeginPeriod
timeEndPeriod
timeGetDevCaps
timeGetSystemTime
timeGetTime
timeKillEvent
TimeProc
timeSetEvent

These can be looked up in MSDN for explanations and usage.
Good luck! =]

Share this post


Link to post
Share on other sites
Thanks, I'll look into those.. I think also that I remember there being a function which you call in such times when you're doing nothing that will transfer the CPU over to another application.. Anyone know if I'm imagining things or if there's such a function?

Just for clarification, this is MSVC++6 and a windows app.

Edited by - Ivko on December 30, 2001 1:54:26 PM

Share this post


Link to post
Share on other sites
Try Sleep(1). That will give up your remaining timeslice. Or if you have an idea of how many milliseconds you need to burn, just to Sleep(milliseconds). Remember though that no timer function is going to be exact, so err on the side of caution. Also, GetTickCount() has a granularity of 10ms.


-Brannon

Share this post


Link to post
Share on other sites
I guess my first question would be what are you saving the CPU for? Unless you are running under an operating system that is not pre-emptive or you have to pay for the CPU you use or your boss is monitoring how much CPU you are using then I don''t see the point. Use it or lose it. Running at 50% for a week doesn''t mean you can run at 150% the next week.

Share this post


Link to post
Share on other sites
Even under a pre-emptive OS, if your process is constantly trying to run, it can still "choke out" other processes. There are a finite number of timeslices per second. The OS can only do so much to try to give each process enough time..

Ivko, you have the right idea .. if you aren''t going to use the timeslice, give it up for another process/thread to use. Be a good citizen.


-Brannon

Share this post


Link to post
Share on other sites
Tell me. The last time you played a real-time game what important task were you running in the background? Hum, maybe you were defraging the hard drive. That is I/O bound, not CPU bound, but would you seriously do that while playing a game?

Share this post


Link to post
Share on other sites
Thanks for your input. What would I do? Play mp3s, use IRC, and be able to switch tasks to do something quick without the system grinding to a halt. It's just good practice, at the moment my game does nothing other than run the main loop and it takes up 100% CPU usage. There's no reason not to do it, and it just doesn't seem right. Another example is if I decided later to make something that's not a fullscreen game, I don't want it wasting all CPU power.

Thanks all, I'll try the Sleep method.

Edit: That's just what I was working for, thanks

Edited by - Ivko on December 31, 2001 10:45:13 PM

Share this post


Link to post
Share on other sites
That´s strange...My game uses 0% of the CPU...Perhaps it´s XP =/

BTW, it´s a good thing NOT to have 100% CPU-use a all time, since it strains the CPU very hard, increases the temperature in the computer and so on...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!