weird cpu usage

Started by
4 comments, last by jollyjeffers 16 years, 2 months ago
I am building a 2d game engine in with c# and direct3D and when I check the cpu usage of my programs using this engine I noticed something weird. When my application doesn't have focus the cpu usage jumps up to 50% and when it does have focus the cpu usage is 5% or lower. does anyone know what is causing this? Im using a peekmessage handler for my gameloop, maybe that is causing this, or it's just directX trying to get focus again or something like that. thanks in advance. id.
Advertisement
Yup, could well be that your application is going into a very tight 'busy waiting' loop. It's not unreasonable or uncommon to put something like Sleep(10) into your loop when you're either minimized or inactive - play fair with the other applications and all that [wink]

The other common one is with some apps that change the timer frequency (media players tend to do this) so you can actually get a performance boost by having WMP running at the same time as your app [lol]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Quote:Original post by jollyjeffers
It's not unreasonable or uncommon to put something like Sleep(10) into your loop when you're either minimized or inactive - play fair with the other applications and all that [wink]


thanks I'll try that.
Quote:Original post by jollyjeffers
The other common one is with some apps that change the timer frequency (media players tend to do this) so you can actually get a performance boost by having WMP running at the same time as your app [lol]

hth
Jack


So if i was 2 run something like Crysis with Win Media Player on, it would give me a performance boost?
Quote:Original post by Firecore
Quote:Original post by jollyjeffers
The other common one is with some apps that change the timer frequency (media players tend to do this) so you can actually get a performance boost by having WMP running at the same time as your app [lol]

hth
Jack


So if i was 2 run something like Crysis with Win Media Player on, it would give me a performance boost?


I doubt it. :p


Something you could also do is when you go inactive call WaitMessage when there are no messages, this will of course completely suspend your game when it's out of focus, but you'll use zero CPU. ;)
Quote:Original post by Firecore
So if i was 2 run something like Crysis with Win Media Player on, it would give me a performance boost?
Something like Crysis would be designed to do the same thing that WMP does. All that media player does is override the default timing interval to be more accurate, your app can do this as well but by default most people don't bother.

It would be nice if there were a MakeApplicationFaster() function [smile]

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement