Skip to main content
gamedev.net
🔒 Locked

CPU usage

Started by Crispy 7 replies 200+ views
Original Post
Crispy
Crispy
Hi, looking at most either commercial or otherwise finished products reveals that most of them have relatively low CPU usage (0 - 2%) - and I''m not talking about high-end games here. My programs, however, push this number up to 50-99% when using the standard program kernel - a simple do ... while(not_done) loop without any threading. How can I set my application''s priority in Windows'' priority queue? Furthermore, can this be done in (Windows) console applications? Thanks, Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
sphinx23
sphinx23
its ok that your game uses up to 99% of CPU time. Take a look at games like Quake (Win95-version), Quake II, Quake III Arena, ... (not only id-software games). The clue is that these games reduce CPU usage when they are not currently active. in this case they suspend their thread by some time (and wait for incoming messages?). Take a look at the Q2-Source somewhere at ftp.idsoftware.com. In the file named sys_win.c should be some stuff to show how to suspend a thread by some time.

[edited by - sphinx23 on February 24, 2003 9:50:29 AM]
Crispy
Crispy
That''s the whole point - I''m cool with games using top notch graphics running at a high CPU usage level - what I have in mind is simple Windows GUI applications with barely anything to do...

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
sphinx23
sphinx23
the point is the game loop:

while (1)
{
if (PeekMessage (...))
{
TranslateMessage
DispatchMessage
}

Update_Game ();
}

this game loop, in a whatever-you-want-to-have-game gives you ALWAYS 99% of CPU-Usage, because its a never exiting loop. Most, if not all, of today''s games (and most old) use this. What you possibly want to have is:

while (GetMessage (...))
{
TranslateMessage
DispatchMessage
}

This are the main loops app''s like ''notepad'' or the most of all out there use. they are not time-consuming, since they only react if a message is posted by windows or any other application
Crispy
Crispy
Ok, I see - thanks for the reply. What about Windows console applications - is there a way to set the priority given to those?

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Jan Wassenberg
Jan Wassenberg
CPU usage := 100 - time_spent_in_os_idle_loop / total_time
Even a low priority thread will eat up 100% CPU time if it can.

Guys, he''s talking about (console) apps.

For a Win app, you just use GetMessage; in a console app, you need to sleep periodically (Win32 and POSIX calls of the same name).
Example:

while(1)
check_input
...
sleep(1)

(only does stuff once a second => low CPU usage)

HTH
Jan

500x4
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Crispy
Crispy
Thanks Jan - didn''t think of that. Works nice now. It''s just that some computers might have such applications as Prime95 (calculates Mersenne numbers), one of those cure-for-cancer type of programs and such running in the background and I don''t want my teeny weeny little console app to eat up all of the resources it can find (especially considering it doesn''t need them at all).

Crispy

grr@500
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Thunder_Hawk
Thunder_Hawk
quote:
Original post by Jan Wassenberg
sleep(1)
(only does stuff once a second => low CPU usage)


sleep takes an arguement of milliseconds (in C/C++ anyway)

for (int i = 0; i < 21; i++) {
RequestPost();
cout << "Error 500" << endl;
Refresh();
}
Post();
cout << "No joke, it took this many tries!" << endl;
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Crispy
Crispy
quote:
Original post by Thunder_Hawk
sleep takes an arguement of milliseconds (in C/C++ anyway)



The dos function sleep(), defined in dos.h, takes seconds, the windows version Sleep() takes milliseconds. Otherwise both work identically.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.