more evil hacks to get nq's and qw's sv_phys.c similar.

This commit is contained in:
Bill Currie 2002-02-25 22:57:17 +00:00
parent 676527a0d3
commit 3e4c200430
10 changed files with 89 additions and 83 deletions

View file

@ -280,4 +280,6 @@ void SV_Progs_Init_Cvars (void);
void Cvar_Info (struct cvar_s *var); void Cvar_Info (struct cvar_s *var);
#define STOP_EPSILON 0.1
#endif // __server_h #endif // __server_h

View file

@ -67,6 +67,8 @@ typedef struct {
float *trace_inwater; float *trace_inwater;
int *msg_entity; int *msg_entity;
string_t *null; string_t *null;
int *newmis;
} sv_globals_t; } sv_globals_t;
extern sv_globals_t sv_globals; extern sv_globals_t sv_globals;
@ -177,9 +179,10 @@ typedef struct
int air_finished; //float int air_finished; //float
int pain_finished; //float int pain_finished; //float
int radsuit_finished; //float int radsuit_finished; //float
int speed; //Float int speed; //float
int rotated_bbox; //int int rotated_bbox; //int
int lastruntime; //float
} sv_fields_t; } sv_fields_t;
extern sv_fields_t sv_fields; extern sv_fields_t sv_fields;
@ -197,4 +200,6 @@ extern sv_fields_t sv_fields;
#define SVvector(e,f) SVFIELD (e, f, vector) #define SVvector(e,f) SVFIELD (e, f, vector)
#define SVinteger(e,f) SVFIELD (e, f, integer) #define SVinteger(e,f) SVFIELD (e, f, integer)
extern func_t EndFrame;
#endif // __sv_progs_h #endif // __sv_progs_h

View file

@ -552,28 +552,9 @@ Host_GetConsoleCommands (void)
Con_ProcessInput (); Con_ProcessInput ();
} }
#ifdef FPS_20
void
_Host_ServerFrame (void)
{
// run the world state
*sv_globals.frametime = host_frametime;
// read client messages
SV_RunClients ();
// move things around and think
// always pause in single player if in console or menus
if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game))
SV_Physics ();
}
void void
Host_ServerFrame (void) Host_ServerFrame (void)
{ {
float save_host_frametime, temp_host_frametime;
// run the world state // run the world state
*sv_globals.frametime = host_frametime; *sv_globals.frametime = host_frametime;
@ -583,49 +564,20 @@ Host_ServerFrame (void)
// check for new clients // check for new clients
SV_CheckForNewClients (); SV_CheckForNewClients ();
temp_host_frametime = save_host_frametime = host_frametime; // read client messages
while (temp_host_frametime > (1.0 / 72.0)) { SV_RunClients ();
if (temp_host_frametime > 0.05)
host_frametime = 0.05; // move things around and think
else // always pause in single player if in console or menus
host_frametime = temp_host_frametime; if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game)) {
temp_host_frametime -= host_frametime; SV_Physics ();
_Host_ServerFrame (); sv.time += host_frametime;
} }
host_frametime = save_host_frametime;
// send all messages to the clients // send all messages to the clients
SV_SendClientMessages (); SV_SendClientMessages ();
} }
#else
void
Host_ServerFrame (void)
{
// run the world state
*sv_globals.frametime = host_frametime;
// set the time and clear the general datagram
SV_ClearDatagram ();
// check for new clients
SV_CheckForNewClients ();
// read client messages
SV_RunClients ();
// move things around and think
// always pause in single player if in console or menus
if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game))
SV_Physics ();
// send all messages to the clients
SV_SendClientMessages ();
}
#endif
/* /*
Host_Frame Host_Frame

View file

@ -1025,7 +1025,9 @@ SV_SpawnServer (const char *server)
// run two frames to allow everything to settle // run two frames to allow everything to settle
host_frametime = 0.1; host_frametime = 0.1;
SV_Physics (); SV_Physics ();
sv.time += host_frametime;
SV_Physics (); SV_Physics ();
sv.time += host_frametime;
// create a baseline for more efficient communications // create a baseline for more efficient communications
SV_CreateBaseline (); SV_CreateBaseline ();

View file

@ -193,8 +193,6 @@ SV_Impact (edict_t *e1, edict_t *e2)
*sv_globals.other = old_other; *sv_globals.other = old_other;
} }
#define STOP_EPSILON 0.1
/* /*
ClipVelocity ClipVelocity
@ -727,6 +725,12 @@ SV_ProgStartFrame (void)
void void
SV_RunEntity (edict_t *ent) SV_RunEntity (edict_t *ent)
{ {
if (sv_fields.lastruntime != -1) {
if (SVfloat (ent, lastruntime) == (float) realtime)
return;
SVfloat (ent, lastruntime) = (float) realtime;
}
switch ((int) SVfloat (ent, movetype)) { switch ((int) SVfloat (ent, movetype)) {
case MOVETYPE_PUSH: case MOVETYPE_PUSH:
SV_Physics_Pusher (ent); SV_Physics_Pusher (ent);
@ -752,6 +756,21 @@ SV_RunEntity (edict_t *ent)
} }
} }
void
SV_RunNewmis (void)
{
edict_t *ent;
if (sv_fields.lastruntime == -1 || !sv_globals.newmis
|| !*sv_globals.newmis)
return;
ent = PROG_TO_EDICT (&sv_pr_state, *sv_globals.newmis);
sv_frametime = 0.05;
*sv_globals.newmis = 0;
SV_RunEntity (ent);
}
void void
SV_Physics (void) SV_Physics (void)
{ {
@ -775,11 +794,19 @@ SV_Physics (void)
SV_Physics_Client (ent, i); SV_Physics_Client (ent, i);
continue; continue;
} }
SV_RunEntity (ent); SV_RunEntity (ent);
SV_RunNewmis ();
} }
if (*sv_globals.force_retouch) if (*sv_globals.force_retouch)
(*sv_globals.force_retouch)--; (*sv_globals.force_retouch)--;
sv.time += sv_frametime; if (EndFrame) {
// let the progs know that the frame has ended
*sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv.edicts);
*sv_globals.other = EDICT_TO_PROG (&sv_pr_state, sv.edicts);
*sv_globals.time = sv.time;
PR_ExecuteProgram (&sv_pr_state, EndFrame);
}
} }

View file

@ -66,6 +66,8 @@ cvar_t *saved2;
cvar_t *saved3; cvar_t *saved3;
cvar_t *saved4; cvar_t *saved4;
func_t EndFrame;
static int static int
prune_edict (progs_t *pr, edict_t *ent) prune_edict (progs_t *pr, edict_t *ent)
{ {
@ -131,6 +133,9 @@ parse_field (progs_t *pr, const char *key, const char *value)
void void
SV_LoadProgs (void) SV_LoadProgs (void)
{ {
ddef_t *def;
dfunction_t *f;
PR_LoadProgs (&sv_pr_state, sv_progs->string, sv.max_edicts, 0); PR_LoadProgs (&sv_pr_state, sv_progs->string, sv.max_edicts, 0);
if (!sv_pr_state.progs) if (!sv_pr_state.progs)
Host_Error ("SV_LoadProgs: couldn't load %s", sv_progs->string); Host_Error ("SV_LoadProgs: couldn't load %s", sv_progs->string);
@ -304,6 +309,14 @@ SV_LoadProgs (void)
sv_fields.pitch_speed = ED_GetFieldIndex (&sv_pr_state, "pitch_speed"); sv_fields.pitch_speed = ED_GetFieldIndex (&sv_pr_state, "pitch_speed");
sv_fields.rotated_bbox = ED_GetFieldIndex (&sv_pr_state, "rotated_bbox"); sv_fields.rotated_bbox = ED_GetFieldIndex (&sv_pr_state, "rotated_bbox");
sv_fields.lastruntime = ED_GetFieldIndex (&sv_pr_state, "lastruntime");
def = PR_FindGlobal (&sv_pr_state, "newmis");
sv_globals.newmis = def ? &G_var (&sv_pr_state, def->ofs, entity) : 0;
EndFrame = 0;
if ((f = ED_FindFunction (&sv_pr_state, "EndFrame")) != NULL)
EndFrame = (func_t) (f - sv_pr_state.pr_functions);
} }
void void

View file

@ -269,6 +269,7 @@ typedef struct
int spawncount; // number of servers spawned since start, int spawncount; // number of servers spawned since start,
// used to check late spawns // used to check late spawns
client_t clients[MAX_CLIENTS]; client_t clients[MAX_CLIENTS];
int maxclients;
int num_clients; int num_clients;
int serverflags; // episode completion information int serverflags; // episode completion information

View file

@ -1863,8 +1863,21 @@ SV_Frame (float time)
SV_CleanIPList (); SV_CleanIPList ();
// move autonomous things around if enough time has passed // move autonomous things around if enough time has passed
if (!sv.paused) if (!sv.paused) {
SV_Physics (); static double old_time;
// don't bother running a frame if sys_ticrate seconds haven't passed
sv_frametime = realtime - old_time;
if (sv_frametime >= sv_mintic->value) {
if (sv_frametime > sv_maxtic->value)
sv_frametime = sv_maxtic->value;
old_time = realtime;
*sv_globals.frametime = sv_frametime;
SV_Physics ();
}
}
// get packets // get packets
SV_ReadPackets (); SV_ReadPackets ();
@ -2407,6 +2420,7 @@ SV_Init (void)
SV_Init_Memory (); SV_Init_Memory ();
svs.maxclients = MAX_CLIENTS;
svs.info = Info_ParseString ("", MAX_SERVERINFO_STRING); svs.info = Info_ParseString ("", MAX_SERVERINFO_STRING);
localinfo = Info_ParseString ("", 0); // unlimited localinfo = Info_ParseString ("", 0); // unlimited
SV_InitOperatorCommands (); SV_InitOperatorCommands ();

View file

@ -747,9 +747,11 @@ SV_ProgStartFrame (void)
void void
SV_RunEntity (edict_t *ent) SV_RunEntity (edict_t *ent)
{ {
if (SVfloat (ent, lastruntime) == (float) realtime) if (sv_fields.lastruntime != -1) {
return; if (SVfloat (ent, lastruntime) == (float) realtime)
SVfloat (ent, lastruntime) = (float) realtime; return;
SVfloat (ent, lastruntime) = (float) realtime;
}
switch ((int) SVfloat (ent, movetype)) { switch ((int) SVfloat (ent, movetype)) {
case MOVETYPE_PUSH: case MOVETYPE_PUSH:
@ -781,7 +783,8 @@ SV_RunNewmis (void)
{ {
edict_t *ent; edict_t *ent;
if (!*sv_globals.newmis) if (sv_fields.lastruntime == -1 || !sv_globals.newmis
|| !*sv_globals.newmis)
return; return;
ent = PROG_TO_EDICT (&sv_pr_state, *sv_globals.newmis); ent = PROG_TO_EDICT (&sv_pr_state, *sv_globals.newmis);
sv_frametime = 0.05; sv_frametime = 0.05;
@ -793,20 +796,9 @@ SV_RunNewmis (void)
void void
SV_Physics (void) SV_Physics (void)
{ {
static double old_time;
edict_t *ent; edict_t *ent;
int i; int i;
// don't bother running a frame if sys_ticrate seconds haven't passed
sv_frametime = realtime - old_time;
if (sv_frametime < sv_mintic->value)
return;
if (sv_frametime > sv_maxtic->value)
sv_frametime = sv_maxtic->value;
old_time = realtime;
*sv_globals.frametime = sv_frametime;
SV_ProgStartFrame (); SV_ProgStartFrame ();
// treat each object in turn // treat each object in turn
@ -820,8 +812,9 @@ SV_Physics (void)
SV_LinkEdict (ent, true); // force retouch even for stationary SV_LinkEdict (ent, true); // force retouch even for stationary
} }
if (i > 0 && i <= MAX_CLIENTS) { if (i > 0 && i <= svs.maxclients) {
continue; // clients are run directly from packets // clients are run directly from packets
continue;
} }
SV_RunEntity (ent); SV_RunEntity (ent);
@ -831,7 +824,6 @@ SV_Physics (void)
if (*sv_globals.force_retouch) if (*sv_globals.force_retouch)
(*sv_globals.force_retouch)--; (*sv_globals.force_retouch)--;
// 2000-01-02 EndFrame function by Maddes/FrikaC start
if (EndFrame) { if (EndFrame) {
// let the progs know that the frame has ended // let the progs know that the frame has ended
*sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv.edicts); *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv.edicts);
@ -839,7 +831,6 @@ SV_Physics (void)
*sv_globals.time = sv.time; *sv_globals.time = sv.time;
PR_ExecuteProgram (&sv_pr_state, EndFrame); PR_ExecuteProgram (&sv_pr_state, EndFrame);
} }
// 2000-01-02 EndFrame function by Maddes/FrikaC end
} }
void void

View file

@ -317,7 +317,7 @@ SV_LoadProgs (void)
// Zoid, find the spectator functions // Zoid, find the spectator functions
SpectatorConnect = SpectatorThink = SpectatorDisconnect = 0; SpectatorConnect = SpectatorThink = SpectatorDisconnect = 0;
UserInfoCallback = 0; EndFrame = UserInfoCallback = 0;
if ((f = ED_FindFunction (&sv_pr_state, "SpectatorConnect")) != NULL) if ((f = ED_FindFunction (&sv_pr_state, "SpectatorConnect")) != NULL)
SpectatorConnect = (func_t) (f - sv_pr_state.pr_functions); SpectatorConnect = (func_t) (f - sv_pr_state.pr_functions);
@ -329,7 +329,6 @@ SV_LoadProgs (void)
UserInfoCallback = (func_t) (f - sv_pr_state.pr_functions); UserInfoCallback = (func_t) (f - sv_pr_state.pr_functions);
// 2000-01-02 EndFrame function by Maddes/FrikaC // 2000-01-02 EndFrame function by Maddes/FrikaC
EndFrame = 0;
if ((f = ED_FindFunction (&sv_pr_state, "EndFrame")) != NULL) if ((f = ED_FindFunction (&sv_pr_state, "EndFrame")) != NULL)
EndFrame = (func_t) (f - sv_pr_state.pr_functions); EndFrame = (func_t) (f - sv_pr_state.pr_functions);