mirror of
https://git.code.sf.net/p/quake/quakeforge-old
synced 2025-02-16 16:51:16 +00:00
host.c completions...might be able to link now. :)
This commit is contained in:
parent
44ec4f61d5
commit
74e0de143a
1 changed files with 184 additions and 86 deletions
268
common/host.c
268
common/host.c
|
@ -30,36 +30,28 @@
|
||||||
Boston, MA 02111-1307, USA.
|
Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
Host_EndGame
|
|
||||||
|
|
||||||
On clients and non-dedicated servers, close currently-running game and
|
|
||||||
drop to console. On dedicated servers, exit.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
#include "net.h"
|
#include <net.h>
|
||||||
#include "console.h"
|
#include <console.h>
|
||||||
#include "quakedef.h"
|
#include <quakedef.h>
|
||||||
#ifdef UQUAKE
|
#ifdef UQUAKE
|
||||||
#include "server.h"
|
#include <server.h>
|
||||||
#endif
|
#endif
|
||||||
#include "client.h"
|
#include <client.h>
|
||||||
#include "view.h"
|
#include <view.h>
|
||||||
#include "wad.h"
|
#include <wad.h>
|
||||||
#include "input.h"
|
#include <input.h>
|
||||||
#include "sound.h"
|
#include <sound.h>
|
||||||
#include "cdaudio.h"
|
#include <cdaudio.h>
|
||||||
#include "keys.h"
|
#include <keys.h>
|
||||||
#include "menu.h"
|
#include <menu.h>
|
||||||
#include "draw.h"
|
#include <draw.h>
|
||||||
#include "screen.h"
|
#include <screen.h>
|
||||||
#include "sbar.h"
|
#include <sbar.h>
|
||||||
#include "mathlib.h"
|
#include <mathlib.h>
|
||||||
#include "client.h"
|
|
||||||
|
|
||||||
extern int host_hunklevel;
|
extern int host_hunklevel;
|
||||||
|
|
||||||
|
@ -69,15 +61,16 @@ double realtime; // without any filtering or bounding
|
||||||
double oldrealtime; // last frame run
|
double oldrealtime; // last frame run
|
||||||
qboolean isDedicated;
|
qboolean isDedicated;
|
||||||
int fps_count;
|
int fps_count;
|
||||||
int vcrFile = -1;
|
int vcrFile = -1;
|
||||||
cvar_t serverprofile = {"serverprofile","0"};
|
|
||||||
cvar_t host_framerate = {"host_framerate","0"}; // set for slow motion
|
cvar_t serverprofile = {"serverprofile", "0"};
|
||||||
cvar_t samelevel = {"samelevel","0"};
|
cvar_t host_framerate = {"host_framerate", "0"}; // set for slow motion
|
||||||
cvar_t noexit = {"noexit","0",false,true};
|
cvar_t samelevel = {"samelevel", "0"};
|
||||||
cvar_t pausable = {"pausable","1"};
|
cvar_t noexit = {"noexit", "0", false, true};
|
||||||
cvar_t temp1 = {"temp1","0"};
|
cvar_t pausable = {"pausable", "1"};
|
||||||
/* Should server filter out \n & \r in player names ? */
|
cvar_t temp1 = {"temp1", "0"};
|
||||||
cvar_t sv_filter = {"sv_filter","1"};
|
cvar_t sv_filter = {"sv_filter", "1"}; // filter \n & \r in names?
|
||||||
|
|
||||||
#ifdef UQUAKE
|
#ifdef UQUAKE
|
||||||
client_t *host_client; // current client
|
client_t *host_client; // current client
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,6 +78,46 @@ client_t *host_client; // current client
|
||||||
void Host_InitLocal (void);
|
void Host_InitLocal (void);
|
||||||
void Host_FindMaxClients (void);
|
void Host_FindMaxClients (void);
|
||||||
|
|
||||||
|
#ifdef QUAKEWORLD
|
||||||
|
#define MAXTIME 0.2
|
||||||
|
#define MINTIME 0.0
|
||||||
|
#elif UQUAKE
|
||||||
|
#define MAXTIME 0.1
|
||||||
|
#define MINTIME 0.001
|
||||||
|
#endif
|
||||||
|
#define MAXFPS 72.0
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Host_ClearMemory
|
||||||
|
|
||||||
|
Clears all the memory used by both the client and server, but do not
|
||||||
|
reinitialize anything.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Host_ClearMemory (void)
|
||||||
|
{
|
||||||
|
Con_DPrintf ("Clearing memory\n");
|
||||||
|
D_FlushCaches ();
|
||||||
|
Mod_ClearAll ();
|
||||||
|
if (host_hunklevel)
|
||||||
|
Hunk_FreeToLowMark (host_hunklevel);
|
||||||
|
|
||||||
|
#ifdef UQUAKE
|
||||||
|
cls.signon = 0;
|
||||||
|
|
||||||
|
memset (&sv, 0, sizeof(sv));
|
||||||
|
#endif
|
||||||
|
memset (&cl, 0, sizeof(cl));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Host_EndGame
|
||||||
|
|
||||||
|
On clients and non-dedicated servers, close currently-running game and
|
||||||
|
drop to console. On dedicated servers, exit.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Host_EndGame ( char *message, ... )
|
Host_EndGame ( char *message, ... )
|
||||||
{
|
{
|
||||||
|
@ -115,46 +148,80 @@ Host_EndGame ( char *message, ... )
|
||||||
else
|
else
|
||||||
CL_Disconnect ();
|
CL_Disconnect ();
|
||||||
|
|
||||||
longjmp (host_abortserver, 1);
|
longjmp (host_abort, 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Host_FilterTime
|
||||||
|
|
||||||
|
Returns false if the time is too short to run a frame
|
||||||
|
*/
|
||||||
|
qboolean
|
||||||
|
Host_FilterTime ( float time )
|
||||||
|
{
|
||||||
|
float fps;
|
||||||
|
|
||||||
|
realtime += time;
|
||||||
|
if ( oldrealtime > realtime )
|
||||||
|
oldrealtime = 0;
|
||||||
|
|
||||||
|
if (cl_maxfps.value)
|
||||||
|
fps = max(30.0, min(cl_maxfps.value, MAXFPS));
|
||||||
|
else
|
||||||
|
#ifdef QUAKEWORLD
|
||||||
|
fps = max(30.0, min(rate.value/80.0, MAXFPS));
|
||||||
|
#elif UQUAKE
|
||||||
|
fps = MAXFPS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!cls.timedemo && realtime - oldrealtime < 1.0/fps)
|
||||||
|
return false; // framerate is too high
|
||||||
|
|
||||||
|
host_frametime = realtime - oldrealtime;
|
||||||
|
oldrealtime = realtime;
|
||||||
|
|
||||||
|
if (host_framerate.value > 0) {
|
||||||
|
host_frametime = host_framerate.value;
|
||||||
|
} else { // don't allow really long or short frames
|
||||||
|
host_frametime = min(MAXTIME, max(host_frametime, MINTIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
#ifdef QUAKEWORLD
|
||||||
|
int nopacketcount; // for Host_FrameMain
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
Host_FrameMain
|
Host_FrameMain
|
||||||
|
|
||||||
Run everything that happens on a per-frame basis
|
Run everything that happens on a per-frame basis
|
||||||
*/
|
*/
|
||||||
int nopacketcount;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Host_FrameMain (float time)
|
Host_FrameMain ( float time )
|
||||||
{
|
{
|
||||||
static double time1 = 0;
|
static double time1 = 0;
|
||||||
static double time2 = 0;
|
static double time2 = 0;
|
||||||
static double time3 = 0;
|
static double time3 = 0;
|
||||||
int pass1, pass2, pass3;
|
int pass1, pass2, pass3;
|
||||||
float fps;
|
|
||||||
if (setjmp (host_abort) )
|
#ifdef UQUAKE
|
||||||
|
cl_visedicts = cl_visedicts_list[0];
|
||||||
|
#endif
|
||||||
|
if ( setjmp(host_abort) )
|
||||||
return; // something bad happened, or the server disconnected
|
return; // something bad happened, or the server disconnected
|
||||||
|
|
||||||
|
#ifdef UQUAKE
|
||||||
|
// keep the random time dependent
|
||||||
|
rand ();
|
||||||
|
#endif
|
||||||
|
|
||||||
// decide the simulation time
|
// decide the simulation time
|
||||||
realtime += time;
|
if ( !Host_FilterTime(time) )
|
||||||
if (oldrealtime > realtime)
|
return;
|
||||||
oldrealtime = 0;
|
|
||||||
|
|
||||||
if (cl_maxfps.value)
|
|
||||||
fps = max(30.0, min(cl_maxfps.value, 72.0));
|
|
||||||
else
|
|
||||||
fps = max(30.0, min(rate.value/80.0, 72.0));
|
|
||||||
|
|
||||||
if (!cls.timedemo && realtime - oldrealtime < 1.0/fps)
|
|
||||||
return; // framerate is too high
|
|
||||||
|
|
||||||
host_frametime = realtime - oldrealtime;
|
|
||||||
oldrealtime = realtime;
|
|
||||||
if (host_frametime > 0.2)
|
|
||||||
host_frametime = 0.2;
|
|
||||||
|
|
||||||
// get new key events
|
// get new key events
|
||||||
Sys_SendKeyEvents ();
|
Sys_SendKeyEvents ();
|
||||||
|
@ -165,15 +232,21 @@ Host_FrameMain (float time)
|
||||||
// process console commands
|
// process console commands
|
||||||
Cbuf_Execute ();
|
Cbuf_Execute ();
|
||||||
|
|
||||||
// fetch results from server
|
// Poll server for results
|
||||||
|
#ifdef QUAKEWORLD
|
||||||
CL_ReadPackets ();
|
CL_ReadPackets ();
|
||||||
|
#elif UQUAKE
|
||||||
|
NET_Poll ();
|
||||||
|
#endif
|
||||||
|
|
||||||
// send intentions now
|
// send intentions now
|
||||||
|
#ifdef QUAKEWORLD
|
||||||
// resend a connection request if necessary
|
// resend a connection request if necessary
|
||||||
if (cls.state == ca_disconnected) {
|
if (cls.state == ca_disconnected) {
|
||||||
CL_CheckForResend ();
|
CL_CheckForResend ();
|
||||||
} else
|
} else {
|
||||||
CL_SendCmd ();
|
CL_SendCmd ();
|
||||||
|
}
|
||||||
|
|
||||||
// Set up prediction for other players
|
// Set up prediction for other players
|
||||||
CL_SetUpPlayerPrediction(false);
|
CL_SetUpPlayerPrediction(false);
|
||||||
|
@ -186,6 +259,31 @@ Host_FrameMain (float time)
|
||||||
|
|
||||||
// build a refresh entity list
|
// build a refresh entity list
|
||||||
CL_EmitEntities ();
|
CL_EmitEntities ();
|
||||||
|
#elif UQUAKE
|
||||||
|
// if running the server locally, make intentions now
|
||||||
|
if (sv.active)
|
||||||
|
CL_SendCmd ();
|
||||||
|
|
||||||
|
// check for commands typed to the host
|
||||||
|
Host_GetConsoleCommands ();
|
||||||
|
|
||||||
|
if (sv.active)
|
||||||
|
SV_Frame (); // Send frame to clients
|
||||||
|
|
||||||
|
/*
|
||||||
|
if running the server remotely, send intentions now after 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 ();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// update video
|
// update video
|
||||||
if (host_speeds.value)
|
if (host_speeds.value)
|
||||||
|
@ -197,8 +295,11 @@ Host_FrameMain (float time)
|
||||||
time2 = Sys_DoubleTime ();
|
time2 = Sys_DoubleTime ();
|
||||||
|
|
||||||
// update audio
|
// update audio
|
||||||
if (cls.state == ca_active)
|
#ifdef QUAKEWORLD
|
||||||
{
|
if (cls.state == ca_active) {
|
||||||
|
#elif UQUAKE
|
||||||
|
if (cls.signon == SIGNONS) {
|
||||||
|
#endif
|
||||||
S_Update (r_origin, vpn, vright, vup);
|
S_Update (r_origin, vpn, vright, vup);
|
||||||
CL_DecayLights ();
|
CL_DecayLights ();
|
||||||
}
|
}
|
||||||
|
@ -207,8 +308,7 @@ Host_FrameMain (float time)
|
||||||
|
|
||||||
CDAudio_Update();
|
CDAudio_Update();
|
||||||
|
|
||||||
if (host_speeds.value)
|
if (host_speeds.value) {
|
||||||
{
|
|
||||||
pass1 = (time1 - time3)*1000;
|
pass1 = (time1 - time3)*1000;
|
||||||
time3 = Sys_DoubleTime ();
|
time3 = Sys_DoubleTime ();
|
||||||
pass2 = (time2 - time1)*1000;
|
pass2 = (time2 - time1)*1000;
|
||||||
|
@ -309,7 +409,7 @@ Host_Error ( char *error, ... )
|
||||||
Sys_Error ("Host_Error: %s\n",string);
|
Sys_Error ("Host_Error: %s\n",string);
|
||||||
|
|
||||||
#ifdef UQUAKE
|
#ifdef UQUAKE
|
||||||
longjmp (host_abortserver, 1);
|
longjmp (host_abort, 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,23 +624,19 @@ Host_Shutdown( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===============
|
Host_WriteConfiguration
|
||||||
Host_WriteConfiguration
|
|
||||||
|
|
||||||
Writes key bindings and archived cvars to config.cfg
|
Write key bindings and archived cvars to config.cfg
|
||||||
===============
|
|
||||||
*/
|
*/
|
||||||
void Host_WriteConfiguration (void)
|
void
|
||||||
|
Host_WriteConfiguration ( void )
|
||||||
{
|
{
|
||||||
QFile *f;
|
QFile *f;
|
||||||
|
|
||||||
// dedicated servers initialize the host but don't parse and set the
|
// Only write cvars if we are non-dedicated
|
||||||
// config.cfg cvars
|
if (host_initialized & !isDedicated) {
|
||||||
if (host_initialized & !isDedicated)
|
|
||||||
{
|
|
||||||
f = Qopen (va("%s/config.cfg",com_gamedir), "w");
|
f = Qopen (va("%s/config.cfg",com_gamedir), "w");
|
||||||
if (!f)
|
if ( !f ) {
|
||||||
{
|
|
||||||
Con_Printf ("Couldn't write config.cfg.\n");
|
Con_Printf ("Couldn't write config.cfg.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -552,13 +648,15 @@ void Host_WriteConfiguration (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef UQUAKE
|
#ifdef UQUAKE
|
||||||
/*
|
/*
|
||||||
=======================
|
Host_InitLocal
|
||||||
Host_InitLocal
|
|
||||||
======================
|
(desc)
|
||||||
*/
|
*/
|
||||||
void Host_InitLocal (void)
|
void
|
||||||
|
Host_InitLocal ( void )
|
||||||
{
|
{
|
||||||
Host_InitCommands ();
|
Host_InitCommands ();
|
||||||
|
|
||||||
|
@ -581,16 +679,16 @@ void Host_InitLocal (void)
|
||||||
Cvar_RegisterVariable (&temp1);
|
Cvar_RegisterVariable (&temp1);
|
||||||
Cvar_RegisterVariable (&sv_filter);
|
Cvar_RegisterVariable (&sv_filter);
|
||||||
|
|
||||||
|
|
||||||
Host_FindMaxClients ();
|
Host_FindMaxClients ();
|
||||||
|
|
||||||
host_time = 1.0; // so a think at time 0 won't get called
|
host_time = 1.0; // so a think at time 0 won't get called
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
================
|
Host_FindMaxClients
|
||||||
Host_FindMaxClients
|
|
||||||
================
|
(desc)
|
||||||
*/
|
*/
|
||||||
void Host_FindMaxClients (void)
|
void Host_FindMaxClients (void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue