Archived from groups: alt.games.neverwinter-nights (
More info?)
On Thu, 01 Jul 2004 17:29:35 +0000, Vellu wrote:
> Yes, sounds sensible enough...but in the menus aswell? Where absolutely
> nothing takes place (unless you click something). Not being a programmer
There's a swirling... thing in the background of some of the menus.
Besides, the menus presumably use the same input engine as the rest of the
game, and that can't block (sleep untill you press a key), otherwise
nothing could happen in the game until you pressed a key (because the loop
would be stuck on the "read user input" part and thus could not advance to
updating the gameworld and redrawing screen until it got some input)...
So what I'm trying to say is, that it would require explicitly telling the
OS to not run the game for a while (a few microseconds) to prevent it from
using 100% CPU. That would cause a performance hit, because each time the
loop was run the program would simply wait for a while, thus taking longer
to complete the loop and thus being unable to go through it as many times
per second...
> myself, I can't really say that I know what the procedure is that games use
> to always use/reserve as much of cpu power as they can, except the fact that
> it is in my opion a wise thing to do (game performance wise).
The game is using all the CPU it can get, which, as you pointed out, is a
wise thing to do, because the screen is redrawn once per loop, so loops
per second = frames per second.
But it's impossible for a program to reserve CPU beyond what it's actually
using. All CPU cycles must do something. That's why operating systems have
an "idle" task, a program which does nothing but loops endlessly; whenever
no other program can be run (because they're all sleeping or blocked),
this idle loop is run to waste time untill it's time to wake one of the
other programs or one of them unblocks, at which point execution jumps to
that program. If there's several runnable programs at the sime time, then
the execution jumps from program to program, executing each a short while
and then jumping to next, giving an illusion of concurrent execution. How
long each program is run depends on its priority: the higher the priority,
the longer the program is run before switching to the next one.
So, all a program needs to do to use all the CPU is to never sleep or
block, and have no other CPU intensive programs running at the same time.
It doesn't take any special procedure to use 100% CPU; it takes special
procedure (sleeping or blocking) to avoid that.
Most programs use little CPU while they're running, since they do nothing
but wait for you to press a (mouse)button, and block until you do. They do
use lots of CPU while starting up, because they are opening windows,
loading settings and other data and generally preparing for accepting
commands. A program that's working will always try to use 100% CPU (but
this work usually involves input and output, which are usually done in a
blocking manner, so the actual usage is most of the time be less, since
the program blocks occasionally), regardless of CPU speed, and will simply
get their task done quicker in a faster system.
I am a programmer, altought not a very good one
🙁.