remove defunct splash screen code, add cl_idlefps to reduce cpu usage in "idle" situations

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3845 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2011-07-06 01:01:13 +00:00
parent 4a59ea5993
commit 7f1db63765
14 changed files with 84 additions and 125 deletions

View File

@ -1029,7 +1029,7 @@ void CL_AllowIndependantSendCmd(qboolean allow)
int CL_IndepPhysicsThread(void *param)
{
unsigned int sleeptime;
double sleeptime;
double fps;
double time, lasttime;
double spare;
@ -1058,7 +1058,7 @@ int CL_IndepPhysicsThread(void *param)
while (fps < 100)
fps*=2;
sleeptime = (1000*1000)/fps;
sleeptime = 1/fps;
Sys_Sleep(sleeptime);
}

View File

@ -48,6 +48,7 @@ cvar_t cl_shownet = SCVAR("cl_shownet","0"); // can be 0, 1, or 2
cvar_t cl_sbar = CVARFC("cl_sbar", "0", CVAR_ARCHIVE, CL_Sbar_Callback);
cvar_t cl_hudswap = CVARF("cl_hudswap", "0", CVAR_ARCHIVE);
cvar_t cl_maxfps = CVARF("cl_maxfps", "500", CVAR_ARCHIVE);
cvar_t cl_idlefps = CVARF("cl_idlefps", "0", CVAR_ARCHIVE);
cvar_t cl_nopext = CVARF("cl_nopext", "0", CVAR_ARCHIVE);
cvar_t cl_pext_mask = CVAR("cl_pext_mask", "0xffffffff");
cvar_t cl_nolerp = CVAR("cl_nolerp", "2");
@ -3001,6 +3002,7 @@ void CL_Init (void)
Cvar_Register (&cl_sbar, cl_screengroup);
Cvar_Register (&cl_hudswap, cl_screengroup);
Cvar_Register (&cl_maxfps, cl_screengroup);
Cvar_Register (&cl_idlefps, cl_screengroup);
Cvar_Register (&cl_timeout, cl_controlgroup);
Cvar_Register (&lookspring, cl_inputgroup);
Cvar_Register (&lookstrafe, cl_inputgroup);
@ -3349,7 +3351,7 @@ extern cvar_t cl_sparemsec;
int nopacketcount;
void SNDDMA_SetUnderWater(qboolean underwater);
float Host_Frame (double time)
double Host_Frame (double time)
{
static double time1 = 0;
static double time2 = 0;
@ -3360,6 +3362,7 @@ float Host_Frame (double time)
static double spare;
float maxfps;
qboolean maxfpsignoreserver;
qboolean idle;
RSpeedLocals();
@ -3401,6 +3404,22 @@ float Host_Frame (double time)
if (cl.paused)
cl.gametimemark += time;
idle = (cls.state == ca_disconnected) ||
UI_MenuState() != 0 ||
key_dest == key_menu ||
key_dest == key_editor ||
cl.paused;
// TODO: check if minimized or unfocused
if (idle && cl_idlefps.value > 0)
{
double idlesec = 1.0 / cl_idlefps.value;
if (idlesec > 0.1)
idlesec = 0.1; // limit to at least 10 fps
if ((realtime - oldrealtime) < idlesec)
return idlesec - (realtime - oldrealtime);
}
/*
if (cl_maxfps.value)
fps = cl_maxfps.value;//max(30.0, min(cl_maxfps.value, 72.0));
@ -3432,7 +3451,7 @@ float Host_Frame (double time)
realtime += spare/1000; //don't use it all!
spare = CL_FilterTime((realtime - oldrealtime)*1000, maxfps, maxfpsignoreserver);
if (!spare)
return 1;
return 0;
if (spare < 0 || cls.state < ca_onserver)
spare = 0; //uncapped.
if (spare > cl_sparemsec.ival)
@ -3473,7 +3492,7 @@ float Host_Frame (double time)
#ifndef CLIENTONLY
if (isDedicated) //someone changed it.
return true;
return 0;
#endif
cls.framecount++;

View File

@ -252,7 +252,7 @@ void Host_Shutdown(void);
NORETURN void VARGS Host_Error (char *error, ...) LIKEPRINTF(1);
NORETURN void VARGS Host_EndGame (char *message, ...) LIKEPRINTF(1);
qboolean Host_SimulationTime(float time);
float Host_Frame (double time);
double Host_Frame (double time);
void Host_Quit_f (void);
void VARGS Host_ClientCommands (char *fmt, ...) LIKEPRINTF(1);
void Host_ShutdownServer (qboolean crash);

View File

@ -988,16 +988,6 @@ q2colormap:
TRACE(("dbg: R_ApplyRenderer: Palette loaded\n"));
#ifdef _WIN32
#ifndef _SDL
if (hwnd_dialog)
{
DestroyWindow (hwnd_dialog);
hwnd_dialog = NULL;
}
#endif
#endif
if (newr)
if (!VID_Init(newr, host_basepal))
{

View File

@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <signal.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
@ -591,14 +592,6 @@ char *Sys_ConsoleInput(void)
return NULL;
}
void Sys_HighFPPrecision (void)
{
}
void Sys_LowFPPrecision (void)
{
}
int main (int c, const char **v)
{
double time, oldtime, newtime;
@ -639,6 +632,8 @@ int main (int c, const char **v)
oldtime = Sys_DoubleTime ();
while (1)
{
double sleeptime;
#ifdef __MACOSX__
//wow, not even windows was this absurd.
#ifdef RGLQUAKE
@ -654,8 +649,10 @@ int main (int c, const char **v)
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
Host_Frame(time);
sleeptime = Host_Frame(time);
oldtime = newtime;
Sys_Sleep(sleeptime);
}
}
@ -878,9 +875,15 @@ void Sys_DestroyConditional(void *condv)
free(cv->mutex);
free(cv);
}
void Sys_Sleep (unsigned int microseconds)
{
usleep(microseconds);
}
#endif
void Sys_Sleep (double seconds)
{
struct timespec ts;
ts.tv_sec = (time_t)seconds;
seconds -= ts.tv_sec;
ts.tv_nsec = seconds * 1000000000.0;
nanosleep(&ts, NULL);
}

View File

@ -423,9 +423,13 @@ int main(int argc, char **argv)
oldtime = Sys_DoubleTime ();
while(!(SetSignal(0, 0)&SIGBREAKF_CTRL_C))
{
double sleeptime;
newtime = Sys_DoubleTime ();
Host_Frame(newtime - oldtime);
sleeptime = Host_Frame(newtime - oldtime);
oldtime = newtime;
Sys_Sleep(sleeptime);
}
}
@ -468,14 +472,7 @@ qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refres
return false;
}
/* x86 crap */
void Sys_HighFPPrecision (void)
{
}
void Sys_LowFPPrecision (void)
{
}
#ifdef MULTITHREAD
/* Everything here is stubbed because I don't know MorphOS */
@ -496,6 +493,6 @@ qboolean Sys_ConditionWait(void *condv) { return false; }
qboolean Sys_ConditionSignal(void *condv) { return false; }
qboolean Sys_ConditionBroadcast(void *condv) { return false; }
void Sys_DestroyConditional(void *condv) {}
void Sys_Sleep(int microseconds) {}
#endif
void Sys_Sleep(double seconds) {}

View File

@ -542,14 +542,18 @@ int main(int argc, char **argv)
else
#endif
{
double sleeptime;
// yield the CPU for a little while when paused, minimized, or not the focus
if (!(SDL_GetAppState() & SDL_APPACTIVE))
SDL_Delay(1);
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
Host_Frame (time);
sleeptime = Host_Frame (time);
oldtime = newtime;
Sys_Sleep(sleeptime);
}
}
return 0;
@ -560,14 +564,6 @@ qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refres
return false;
}
void Sys_HighFPPrecision(void)
{
}
void Sys_LowFPPrecision(void)
{
}
@ -694,9 +690,9 @@ void Sys_DestroyConditional(void *condv)
free(cv);
}
void Sys_Sleep (unsigned int microseconds)
void Sys_Sleep (double seconds)
{
SDL_Delay(microseconds / 1000000);
SDL_Delay(seconds * 1000);
}
#endif

View File

@ -267,8 +267,6 @@ int starttime;
qboolean ActiveApp, Minimized;
qboolean WinNT;
HWND hwnd_dialog; // startup dialog box
static HANDLE hinput, houtput;
HANDLE qwclsemaphore;
@ -1063,11 +1061,6 @@ qboolean Sys_InitTerminal (void)
}
#endif
//if we still have the splash screen, kill it
if (hwnd_dialog)
DestroyWindow(hwnd_dialog);
hwnd_dialog = NULL;
SetConsoleCtrlHandler (HandlerRoutine, TRUE);
SetConsoleTitle (FULLENGINENAME " dedicated server");
hinput = GetStdHandle (STD_INPUT_HANDLE);
@ -1239,13 +1232,16 @@ void NPQTV_Sys_MainLoop(void)
else
{
#ifndef SERVERONLY
double sleeptime;
newtime = Sys_DoubleTime ();
duratrion = newtime - lastlooptime;
Host_Frame (duratrion);
sleeptime = Host_Frame (duratrion);
lastlooptime = newtime;
SetHookState(sys_disableWinKeys.ival);
Sys_Sleep(sleeptime);
// Sleep(0);
#else
Sys_Error("wut?");
@ -1595,35 +1591,10 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
if (isDedicated)
{
#if !defined(CLIENTONLY)
hwnd_dialog=NULL;
if (!Sys_InitTerminal())
Sys_Error ("Couldn't allocate dedicated server console");
#endif
}
#ifdef IDD_DIALOG1
else
hwnd_dialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, NULL);
if (hwnd_dialog)
{
RECT rect;
if (GetWindowRect (hwnd_dialog, &rect))
{
if (rect.left > (rect.top * 2))
{
SetWindowPos (hwnd_dialog, 0,
(rect.left / 2) - ((rect.right - rect.left) / 2),
rect.top, 0, 0,
SWP_NOZORDER | SWP_NOSIZE);
}
}
ShowWindow (hwnd_dialog, SW_SHOWDEFAULT);
UpdateWindow (hwnd_dialog);
SetForegroundWindow (hwnd_dialog);
}
#endif
if (!Sys_Startup_CheckMem(&parms))
Sys_Error ("Not enough memory free; check disk space\n");
@ -1715,7 +1686,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
else
{
#ifndef SERVERONLY
int sleeptime;
double sleeptime;
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
sleeptime = Host_Frame (time);
@ -1724,8 +1695,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
SetHookState(sys_disableWinKeys.ival);
/*sleep if its not yet time for a frame*/
//if (sleeptime > 0)
// Sleep(sleeptime);
Sys_Sleep(sleeptime);
#else
Sys_Error("wut?");
#endif
@ -1789,23 +1759,6 @@ qboolean Sys_GetDesktopParameters(int *width, int *height, int *bpp, int *refres
return true;
}
void Sys_HighFPPrecision (void)
{
}
void Sys_LowFPPrecision (void)
{
}
void VARGS Sys_SetFPCW (void)
{
}
void VARGS MaskExceptions (void)
{
}
#ifdef MULTITHREAD
/* Thread creation calls */
typedef struct threadwrap_s
@ -2050,9 +2003,9 @@ void Sys_DestroyConditional(void *condv)
DeleteCriticalSection(&cv->mainlock);
free(cv);
}
void Sys_Sleep (unsigned int microseconds)
{
Sleep(microseconds / 1000000);
}
#endif
void Sys_Sleep (double seconds)
{
Sleep(seconds * 1000);
}

View File

@ -83,7 +83,6 @@ extern int window_center_x, window_center_y;
extern RECT window_rect;
extern qboolean mouseinitialized;
extern HWND hwnd_dialog;
//extern HANDLE hinput, houtput;

View File

@ -107,10 +107,10 @@ qboolean Sys_ConditionWait(void *condv);
qboolean Sys_ConditionSignal(void *condv);
qboolean Sys_ConditionBroadcast(void *condv);
void Sys_DestroyConditional(void *condv);
void Sys_Sleep(unsigned int microseconds);
#endif
void Sys_Sleep(double seconds);
#ifdef NPQTV
qboolean NPQTV_Sys_Startup(int argc, char *argv[]);
void NPQTV_Sys_MainLoop(void);

View File

@ -1881,9 +1881,6 @@ qboolean GLVID_Init (rendererstate_t *info, unsigned char *palette)
vid.colormap = host_colormap;
if (hwnd_dialog)
DestroyWindow (hwnd_dialog);
VID_SetPalette (palette);
if (!GLVID_SetMode (info, palette))

View File

@ -714,7 +714,7 @@ void WriteAsmStatements(progfuncs_t *progfuncs, progstate_t *progs, int num, int
break;
case ev_vector:
if (v->_vector[0] || v->_vector[1] || v->_vector[2])
writes(f, "\tlocal vector %s = '%f %f %f';\r\n", def->s_name, v->_vector[0], v->_vector[1], v->_vector[2]);
writes(f, "\tlocal vector %s = '%f %f %f';\r\n", progfuncs->stringtable+def->s_name, v->_vector[0], v->_vector[1], v->_vector[2]);
else
writes(f, "\tlocal %s %s;\r\n", "vector",progfuncs->stringtable+def->s_name);
ofs+=2; //skip floats;

View File

@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <time.h>
#ifdef MULTITHREAD
#include <pthread.h>
@ -1049,10 +1050,15 @@ void Sys_DestroyConditional(void *condv)
free(cv->mutex);
free(cv);
}
void Sys_Sleep (unsigned int microseconds)
{
usleep(microseconds);
}
#endif
void Sys_Sleep (double seconds)
{
struct timespec ts;
ts.tv_sec = (time_t)seconds;
seconds -= ts.tv_sec;
ts.tv_nsec = seconds * 1000000000.0;
nanosleep(&ts, NULL);
}

View File

@ -1634,11 +1634,10 @@ void Sys_DestroyConditional(void *condv)
DeleteCriticalSection(&cv->mainlock);
free(cv);
}
#endif
void Sys_Sleep (unsigned int microseconds)
void Sys_Sleep (double seconds)
{
Sleep(microseconds / 1000000);
Sleep(seconds * 1000);
}
#endif
#endif