[quake3] Python performance report

Neil Toronto ntoronto at cs.byu.edu
Thu Dec 14 13:40:51 EST 2006


Tony J. White wrote:
> On Wed, Dec 13, 2006 at 06:33:30PM -0700, Neil Toronto wrote:
>   
>> 1) I've implemented cg_latentSnaps (from Unlagged), and it was way easier than 
>> in 1.27. Somebody seriously cleaned up cg_snapshot.c. This cvar allows you to 
>> simulate lag. The client game simply requests snapshot number "current - 
>> cg_latentSnaps".
>>     
>
> Is this necessary now that cl_packetdelay and sv_packetdelay are in the
> engine?
>   

Holy behind the times Batman!

Very cool. Better granularity than mine, too. They only appear to work 
in a real client/server situation, though. I'll have to see if Eclipse 
will let me tweak my run script like that. Hmm...

(Eclipse, no kidding. With the C and Python plugins, I have the perfect 
IDE for this project.)

>   
>> 2) I've added com_laptop, which, if 1, causes Sys_Sleep(0) to be called at the 
>> end of the (busy-wait) rendering loop. It makes Quake 3 a little more 
>> laptop-friendly, and also lets you see the *real* amount of CPU Quake 3 takes 
>> on your performance meter. (Otherwise it's always 100%.)
>>     
>
> Is Sys_Sleep() just a wrapper for win32 Sleep() and posix usleep()?
> Does calling it with 0 just help in process scheduling?
>   

Yes, it's a wrapper. Calling the sleep function on either system with 0 
gives the process back to the scheduler so that it's free to let the CPU 
idle if it has nothing better to do. Here's the code from common.c:

    // we may want to spin here if things are going too fast
    if ( !com_dedicated->integer && com_maxfps->integer > 0 && 
!com_timedemo->integer ) {
        minMsec = 1000 / com_maxfps->integer;
    } else {
        minMsec = 1;
    }
    do {
        com_frameTime = Com_EventLoop();
        if ( lastTime > com_frameTime ) {
            lastTime = com_frameTime;        // possible on first frame
        }
        msec = com_frameTime - lastTime;
        if (com_laptop->integer && msec < minMsec) {
            // Mitigate the effects of this busy wait loop on the CPU
            Sys_Sleep(0);
        }
    } while ( msec < minMsec );
    Cbuf_Execute ();


It only calls Sys_Sleep(0) if the frame hasn't taken its allotted time. 
Now that I think about it, kicking the process off to the scheduler 
could alter the amount of time the loop took, which means msec should 
probably be recalculated.

Running the event loop in response to a timer event would be much more 
robust, but this code does so much I don't understand that I don't want 
to muck with it that much.

Neil




More information about the quake3 mailing list