Post by bitshifter on Jul 30, 2011 5:05:06 GMT -5
This tutorial will show how we can lower the CPU usage while playing Quake2 on Win32.
Step 1) Open the file /qcommon/common.c and add the new global variable:
Step 2) Scroll down to the Qcommon_Init procedure and add this code:
Save and close the file.
Step 2) Open the file /qcommon/common.h and scroll down and add this to the MISC section:
Save and close the file.
Step 3) Open the file /win32/sys_win.c and add this code to the WinMain procedure:
Save and close the file.
Step 4) Compile your sources and go test it out
By default the share_cpu value is zero, causing it to be a CPU hog (like normal).
You can ask the console its current value by typing: share_cpu
You can set the value by typing: share_cpu 10
You can clear the value by typing: share_cpu 0
The value determines how long the task scheduler sleeps.
Of course we are trading FPS for CPU time, but on fast PC is no problem.
A steady 24 FPS is all you need to have smooth playable game.
On my 3+ ghz Pentium 4
share_cpu 10
CPU usage 50~60%
FPS 25
REF ref_soft
REZ 1024 768 FS
0 sets it to off
10 sleeps 10 milliseconds
...
20 sleeps 20 milliseconds
...
Any comments or criticism is greatly appreciated.
Have fun
PS: How do i define colors in code?
Step 1) Open the file /qcommon/common.c and add the new global variable:
...
cvar_t *showtrace;
cvar_t *dedicated;
cvar_t *share_cpu; /* ++ bitshifter */
...
Step 2) Scroll down to the Qcommon_Init procedure and add this code:
...
#ifdef DEDICATED_ONLY
dedicated = Cvar_Get ("dedicated", "1", CVAR_NOSET);
#else
dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET);
#endif
/* ++ bitshifter */
share_cpu = Cvar_Get ("share_cpu", "0", CVAR_ARCHIVE);
...
Save and close the file.
Step 2) Open the file /qcommon/common.h and scroll down and add this to the MISC section:
...
extern cvar_t *share_cpu; /* ++ bitshifter */
extern cvar_t *developer;
extern cvar_t *dedicated;
extern cvar_t *host_speeds;
extern cvar_t *log_stats;
...
Save and close the file.
Step 3) Open the file /win32/sys_win.c and add this code to the WinMain procedure:
...
while (PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if (!GetMessage(&msg,NULL,0,0))
Com_Quit();
sys_msg_time = msg.time;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (share_cpu->value) /* ++ bitshifter */
Sleep((DWORD)share_cpu->value);
do
{
newtime = Sys_Milliseconds();
time = newtime - oldtime;
} while (time < 1);
...
Save and close the file.
Step 4) Compile your sources and go test it out
By default the share_cpu value is zero, causing it to be a CPU hog (like normal).
You can ask the console its current value by typing: share_cpu
You can set the value by typing: share_cpu 10
You can clear the value by typing: share_cpu 0
The value determines how long the task scheduler sleeps.
Of course we are trading FPS for CPU time, but on fast PC is no problem.
A steady 24 FPS is all you need to have smooth playable game.
On my 3+ ghz Pentium 4
share_cpu 10
CPU usage 50~60%
FPS 25
REF ref_soft
REZ 1024 768 FS
0 sets it to off
10 sleeps 10 milliseconds
...
20 sleeps 20 milliseconds
...
Any comments or criticism is greatly appreciated.
Have fun
PS: How do i define colors in code?