Quote:Original post by noooooon
Why a game should allways take 100% CPU if it doesn't need it ?
I didn't say that. I said that it should take 100% CPU if it *does* need it.
I said that we often want our games to run as smooth as possible. Which means the highest framerate possible, which again means 100% CPU usage.
And then I explained why this isn't harmful. You're right though, if you don't need to run "as fast as possible", then you definitely shouldn't use 100% CPU.
Quote:Quote:
You answered it yourself. They cap the framerate, so if a frame takes less than 1/60th to draw, they wait before drawing the next. Result: Framerate at 60, and on fast CPU's, less than 100% CPU usage.
Yes and how ? How do they wait ? That my question...
Use a timer to record the time at which you started rendering the current frame. Add 1/120th of a second to that, and you know when the next frame should start.
Once you've finished rendering the current frame, you take the current time, and check how far it is from the "next frame" time we computed.
Then you call Sleep(int) with the time difference.
At least, that's how I'd do it given the requirements you set.
Quote:
There are many reasons not to use 100% of CPU :
- The player may use other applications that also use some CPU while he plays (teamspeak, IM, ...)
Yes, and as I said, these other apps *do not get starved out* just because your game uses all the CPU time it can get. Instead, Windows makes sure they all get their fair share. Only the leftovers will be used by your app to reach higher CPU usage than that. If another app uses more of its own allocated CPU time, then there'll simply be less left over for your game, which then won't use 100% CPU. In other words, this particular argument doesn't generally hold. You don't need to worry about whether or not other apps get the CPU time they need. Windows does that for you.
Quote: - The player is on a laptop. CPU consume energy. He could play longer.
Yep. (Although most people only play games on their laptops while they're plugged into AC power. But it's still a valid point, and I agree)
Quote: - The player is a game developper or a tester in game studio. His CPU time could be use to make other things, like cross compilation for example.
See the above. Using "all available CPU time" does not starve out other processes.
Quote:
- your game is used inside another windows application. For example you have a windows application to edit your game levels. You have a viewport that shoes level created inside your game in real time. You dont want this application to use 100% CPU, since its a windows application.
I don't? Don't I want this viewport to update in realtime? And run somewhat smoothly? This particular argument seems to boil down to "you don't want to use 100% CPU because you don't want to use 100% CPU". If I have a viewport in a windows app which is supposed to show the game, then I may want it to run like the game. If I want it to be simpler than the actual game, then I may not need it to run smoothly, and I can use less CPU.
Quote:Now let me reverse the question. Why whould you use 100% CPU if you dont need to ?
Again, that's precisely the opposite of what I actually said. I said that you should use 100% CPU if you *did* need to. If you don't need it, you obviously shouldn't.
Hope that clarifies what I said a bit. I agree, in the case of Pong or other games that don't need much CPU to run smoothly, there's no point in using that much CPU... (You could just enable vsync though, and get a simpler solution. Then the game won't run faster than the monitor's refresh rate, and will automatically yield the CPU if it starts going too fast. This has the nice side bonus that it means the user can force vsync off, if he really wants to see how fast the game can go.)
I'm only saying that *in general*, there's nothing wrong with a game using all available resources, as long as the game can benefit from it. Windows makes sure that other apps won't be starved out, so unless you're writing a game for DOS, you don't really need to worry about that. (And if you're writing for DOS, there won't be other apps anyway, so the point is moot there)