📄 host.c
字号:
/*
==================
Host_Frame
Runs all active servers
==================
*/
void _Host_Frame (float time)
{
static double time1 = 0;
static double time2 = 0;
static double time3 = 0;
int pass1, pass2, pass3;
if (setjmp (host_abortserver) )
return; // something bad happened, or the server disconnected
// keep the random time dependent
rand ();
// decide the simulation time
if (!Host_FilterTime (time))
return; // don't run too fast, or packets will flood out
// get new key events
Sys_SendKeyEvents ();
// allow mice or other external controllers to add commands
IN_Commands ();
// process console commands
Cbuf_Execute ();
NET_Poll();
// if running the server locally, make intentions now
if (sv.active)
CL_SendCmd ();
//-------------------
//
// server operations
//
//-------------------
// check for commands typed to the host
Host_GetConsoleCommands ();
if (sv.active)
Host_ServerFrame ();
//-------------------
//
// client operations
//
//-------------------
// if running the server remotely, send intentions now after
// the incoming messages have been read
if (!sv.active)
CL_SendCmd ();
host_time += host_frametime;
// fetch results from server
if (cls.state == ca_connected)
{
CL_ReadFromServer ();
}
// update video
if (host_speeds->value)
time1 = Sys_FloatTime ();
SCR_UpdateScreen ();
if (host_speeds->value)
time2 = Sys_FloatTime ();
// update audio
if (cls.signon == SIGNONS)
{
S_Update (r_origin, vpn, vright, vup);
CL_DecayLights ();
}
else
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
CDAudio_Update();
if (host_speeds->value)
{
pass1 = (time1 - time3)*1000;
time3 = Sys_FloatTime ();
pass2 = (time2 - time1)*1000;
pass3 = (time3 - time2)*1000;
Con_Printf ("%3i tot %3i server %3i gfx %3i snd\n",
pass1+pass2+pass3, pass1, pass2, pass3);
}
host_framecount++;
fps_count++; // 2001-11-31 FPS display by QuakeForge/Muff
}
void Host_Frame (float time)
{
double time1, time2;
static double timetotal;
static int timecount;
int i, c, m;
if (!serverprofile->value)
{
_Host_Frame (time);
return;
}
time1 = Sys_FloatTime ();
_Host_Frame (time);
time2 = Sys_FloatTime ();
timetotal += time2 - time1;
timecount++;
if (timecount < 1000)
return;
m = timetotal*1000/timecount;
timecount = 0;
timetotal = 0;
c = 0;
for (i=0 ; i<svs.maxclients ; i++)
{
if (svs.clients[i].active)
c++;
}
Con_Printf ("serverprofile: %2i clients %2i msec\n", c, m);
}
//============================================================================
extern int vcrFile;
#define VCR_SIGNATURE 0x56435231
// "VCR1"
void Host_InitVCR (quakeparms_t *parms)
{
int i, len, n;
char *p;
if (COM_CheckParm("-playback"))
{
if (com_argc != 2)
Sys_Error("No other parameters allowed with -playback\n");
Sys_FileOpenRead("quake.vcr", &vcrFile);
if (vcrFile == -1)
Sys_Error("playback file not found\n");
Sys_FileRead (vcrFile, &i, sizeof(int));
if (i != VCR_SIGNATURE)
Sys_Error("Invalid signature in vcr file\n");
Sys_FileRead (vcrFile, &com_argc, sizeof(int));
com_argv = malloc(com_argc * sizeof(char *));
com_argv[0] = parms->argv[0];
for (i = 0; i < com_argc; i++)
{
Sys_FileRead (vcrFile, &len, sizeof(int));
p = malloc(len);
Sys_FileRead (vcrFile, p, len);
com_argv[i+1] = p;
}
com_argc++; /* add one for arg[0] */
parms->argc = com_argc;
parms->argv = com_argv;
}
if ( (n = COM_CheckParm("-record")) != 0)
{
vcrFile = Sys_FileOpenWrite("quake.vcr");
i = VCR_SIGNATURE;
Sys_FileWrite(vcrFile, &i, sizeof(int));
i = com_argc - 1;
Sys_FileWrite(vcrFile, &i, sizeof(int));
for (i = 1; i < com_argc; i++)
{
if (i == n)
{
len = 10;
Sys_FileWrite(vcrFile, &len, sizeof(int));
Sys_FileWrite(vcrFile, "-playback", len);
continue;
}
len = strlen(com_argv[i]) + 1;
Sys_FileWrite(vcrFile, &len, sizeof(int));
Sys_FileWrite(vcrFile, com_argv[i], len);
}
}
}
// 2001-09-18 New cvar system by Maddes (Init) start
void COM_Init_Cvars ();
void Con_Init_Cvars ();
//TW void Key_Init_Cvars ();
void Mod_Init_Cvars();
void Chase_Init_Cvars ();
void SCR_Init_Cvars ();
void VID_Init_Cvars();
void V_Init_Cvars();
//TW void M_Init_Cvars ();
void R_Init_Cvars ();
//TW void Sbar_Init_Cvars ();
void CL_Init_Cvars ();
void S_Init_Cvars ();
void IN_Init_Cvars ();
void NET_Init_Cvars ();
void Host_InitLocal_Cvars ();
void PR_Init_Cvars();
void Draw_Init_Cvars();
//TW void CDAudio_Init_Cvars();
// 2001-09-18 New cvar system by Maddes (Init) end
/*
====================
Host_Init
====================
*/
void Host_Init (quakeparms_t *parms)
{
loadedfile_t *fileinfo; // 2001-09-12 Returning information about loaded file by Maddes
if (standard_quake)
minimum_memory = MINIMUM_MEMORY;
else
minimum_memory = MINIMUM_MEMORY_LEVELPAK;
if (COM_CheckParm ("-minmemory"))
parms->memsize = minimum_memory;
host_parms = *parms;
if (parms->memsize < minimum_memory)
Sys_Error ("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float)0x100000);
com_argc = parms->argc;
com_argv = parms->argv;
Memory_Init (parms->membase, parms->memsize);
Cvar_Init (); // 2001-09-18 New cvar system by Maddes
Cbuf_Init ();
Cmd_Init ();
// 2001-09-18 New cvar system by Maddes (Init) start
COM_Init_Cvars (); // initialize all filesystem related variables
Con_Init_Cvars (); // initialize all console related cvars
//TW Key_Init_Cvars (); // initialize all key related cvars
Mod_Init_Cvars(); // initialize all model related cvars
Chase_Init_Cvars (); // initialize all chase camera related cvars
SCR_Init_Cvars (); // initialize all screen(?) related cvars
VID_Init_Cvars(); // initialize all video related cvars
V_Init_Cvars(); // initialize all view related cvars
//TW M_Init_Cvars (); // initialize all menu related cvars
R_Init_Cvars (); // initialize all rendering system related cvars
//TW Sbar_Init_Cvars (); // initialize all statusbar related cvars
CL_Init_Cvars (); // initialize all cl_* related cvars
S_Init_Cvars (); // initialize all sound system related cvars
IN_Init_Cvars (); // initialize all input related cvars
NET_Init_Cvars (); // initialize all net related cvars
Host_InitLocal_Cvars (); // initialize all local host related cvars
PR_Init_Cvars(); // initialize all pr_* related cvars
NVS_Init_Cvars (); // 2000-04-30 NVS COMMON by Maddes
NVS_Init_Server_Cvars (); // 2000-04-30 NVS HANDSHAKE SRV<->QC/SRV<->CL by Maddes
NVS_Init_Client_Cvars (); // 2000-04-30 NVS HANDSHAKE SRV<->QC/SRV<->CL by Maddes
// 2001-09-18 New cvar system by Maddes (Init) end
V_Init ();
Chase_Init ();
Host_InitVCR (parms);
COM_Init (parms->basedir);
Host_InitLocal ();
W_LoadWadFile ("gfx.wad");
Key_Init ();
Con_Init ();
M_Init ();
PR_Init ();
Mod_Init ();
NET_Init ();
SV_Init ();
NVS_Init (); // 2000-04-30 NVS COMMON by Maddes
NVS_Init_Server (); // 2000-04-30 NVS HANDSHAKE SRV<->QC/SRV<->CL by Maddes
NVS_Init_Client (); // 2000-04-30 NVS HANDSHAKE SRV<->QC/SRV<->CL by Maddes
Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));
R_InitTextures (); // needed even for dedicated servers
if (cls.state != ca_dedicated)
{
// 2001-09-12 Returning information about loaded file by Maddes start
/*
host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp");
if (!host_basepal)
*/
fileinfo = COM_LoadHunkFile ("gfx/palette.lmp");
if (!fileinfo)
// 2001-09-12 Returning information about loaded file by Maddes end
Sys_Error ("Couldn't load gfx/palette.lmp");
host_basepal = fileinfo->data; // 2001-09-12 Returning information about loaded file by Maddes
// 2001-09-12 Returning information about loaded file by Maddes start
/*
host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp");
if (!host_colormap)
*/
fileinfo = COM_LoadHunkFile ("gfx/colormap.lmp");
if (!fileinfo)
// 2001-09-12 Returning information about loaded file by Maddes end
Sys_Error ("Couldn't load gfx/colormap.lmp");
host_colormap = fileinfo->data; // 2001-09-12 Returning information about loaded file by Maddes
// 2000-07-28 DOSQuake input init before video init fix by Norberto Alfredo Bensa start
//#ifndef _WIN32 // on non win32, mouse comes before video for security reasons
#if !defined(_WIN32) && !defined(DOSQUAKE) // on non dos/win32, mouse comes before video for security reasons
// 2000-07-28 DOSQuake input init before video init fix by Norberto Alfredo Bensa end
IN_Init ();
#endif
VID_Init (host_basepal);
Draw_Init_Cvars(); // 2001-09-18 New cvar system by Maddes (Init)
Draw_Init ();
SCR_Init ();
R_Init ();
#ifndef _WIN32
// on Win32, sound initialization has to come before video initialization, so we
// can put up a popup if the sound hardware is in use
S_Init ();
#else
#ifdef GLQUAKE
// FIXME: doesn't use the new one-window approach yet
S_Init ();
#endif
#endif // _WIN32
//TW CDAudio_Init_Cvars(); // 2001-09-18 New cvar system by Maddes (Init)
CDAudio_Init ();
Sbar_Init ();
CL_Init ();
// 2000-07-28 DOSQuake input init before video init fix by Norberto Alfredo Bensa start
//#ifdef _WIN32 // on non win32, mouse comes before video for security reasons
#if defined(_WIN32) || defined(DOSQUAKE) // on non dos/win32, mouse comes before video for security reasons
// 2000-07-28 DOSQuake input init before video init fix by Norberto Alfredo Bensa end
IN_Init ();
#endif
}
Cbuf_InsertText ("exec config.rc\n"); // 2001-09-18 New cvar system by Maddes
// this creates all missing variables
// some of them will be updated by config.cfg executed in quake.rc
// this way you can use a non-set-compatible engine without loosing your new cvars
Cbuf_InsertText ("exec quake.rc\n");
Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
host_hunklevel = Hunk_LowMark ();
host_initialized = true;
Sys_Printf ("========Quake Initialized=========\n");
}
/*
===============
Host_Shutdown
FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
to run quit through here before the final handoff to the sys code.
===============
*/
void Host_Shutdown(void)
{
static qboolean isdown = false;
if (isdown)
{
printf ("recursive shutdown\n");
return;
}
isdown = true;
// keep Con_Printf from trying to update the screen
scr_disabled_for_loading = true;
Host_WriteConfiguration ();
CDAudio_Shutdown ();
NET_Shutdown ();
S_Shutdown();
IN_Shutdown ();
if (cls.state != ca_dedicated)
{
VID_Shutdown();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -