now only svs is reverenced where it shouldn't be, and that's to set info

strings (skybox and *progs). skybox is easy to take care of (aditional parse
functions), but I haven't yet decided what to do with *progs. Also, progs code
needs a bit of a cleanup, but that will come later.
This commit is contained in:
Bill Currie 2001-01-02 03:22:46 +00:00
parent ff89f60c74
commit 2debf6f669
13 changed files with 160 additions and 135 deletions

View file

@ -93,22 +93,22 @@ ddef_t *ED_FindField (struct progs_s *pr, char *name);
dfunction_t *ED_FindFunction (struct progs_s *pr, char *name);
//define EDICT_NUM(p,n) ((edict_t *)(sv.edicts+ (n)*(p)->pr_edict_size))
//define NUM_FOR_EDICT(p,e) (((byte *)(e) - sv.edicts)/(p)->pr_edict_size)
//define EDICT_NUM(p,n) ((edict_t *)(*(p)->edicts+ (n)*(p)->pr_edict_size))
//define NUM_FOR_EDICT(p,e) (((byte *)(e) - *(p)->edicts)/(p)->pr_edict_size)
edict_t *EDICT_NUM(struct progs_s *pr, int n);
int NUM_FOR_EDICT(struct progs_s *pr, edict_t *e);
#define NEXT_EDICT(p,e) ((edict_t *)( (byte *)e + (p)->pr_edict_size))
#define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts)
#define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e))
#define EDICT_TO_PROG(p,e) ((byte *)e - (byte *)*(p)->edicts)
#define PROG_TO_EDICT(p,e) ((edict_t *)((byte *)*(p)->edicts + e))
//============================================================================
#define G_FLOAT(p,o) ((p)->pr_globals[o])
#define G_INT(p,o) (*(int *)&(p)->pr_globals[o])
#define G_EDICT(p,o) ((edict_t *)((byte *)sv.edicts+ *(int *)&(p)->pr_globals[o]))
#define G_EDICT(p,o) ((edict_t *)((byte *)*(p)->edicts+ *(int *)&(p)->pr_globals[o]))
#define G_EDICTNUM(p,o) NUM_FOR_EDICT(p,G_EDICT(p, o))
#define G_VECTOR(p,o) (&(p)->pr_globals[o])
#define G_STRING(p,o) (PR_GetString(pr,*(string_t *)&(p)->pr_globals[o]))
@ -137,6 +137,11 @@ void PR_RunError (struct progs_s *pr, char *error, ...) __attribute__((format(pr
void ED_PrintEdicts (struct progs_s *pr);
void ED_PrintNum (struct progs_s *pr, int ent);
void ED_Count (struct progs_s *pr);
void ED_PrintEdict_f (void);
void ED_PrintEdicts_f (void);
void ED_Count_f (void);
void PR_Profile (struct progs_s *pr);
eval_t *GetEdictFieldValue(struct progs_s *pr, edict_t *ed, char *field);
@ -185,6 +190,11 @@ typedef struct progs_s {
int localstack[LOCALSTACK_SIZE];
int localstack_used;
edict_t **edicts;
int *num_edicts;
double *time;
int null_bad;
} progs_t;
#endif // _PROGS_H

View file

@ -404,6 +404,7 @@ extern progs_t sv_progs;
void SV_Error (char *error, ...) __attribute__((format(printf,1,2)));
void SV_Init (void);
void SV_Progs_Init (void);
void Con_Printf (char *fmt, ...) __attribute__((format(printf,1,2)));
void Con_DPrintf (char *fmt, ...) __attribute__((format(printf,1,2)));

View file

@ -38,7 +38,7 @@
#include "world.h"
#include "va.h"
#define RETURN_EDICT(p, e) (((int *)(p)->pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
#define RETURN_EDICT(p, e) (((int *)(p)->pr_globals)[OFS_RETURN] = EDICT_TO_PROG(p, e))
#define RETURN_STRING(p, s) (((int *)(p)->pr_globals)[OFS_RETURN] = PR_SetString((p), s))
/*
@ -81,7 +81,7 @@ PF_error (progs_t *pr)
s = PF_VarString (pr, 0);
Con_Printf ("======SERVER ERROR in %s:\n%s\n",
PR_GetString (pr, pr->pr_xfunction->s_name), s);
ed = PROG_TO_EDICT (pr->pr_global_struct->self);
ed = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
ED_Print (pr, ed);
SV_Error ("Program error");
@ -104,7 +104,7 @@ PF_objerror (progs_t *pr)
s = PF_VarString (pr, 0);
Con_Printf ("======OBJECT ERROR in %s:\n%s\n",
PR_GetString (pr, pr->pr_xfunction->s_name), s);
ed = PROG_TO_EDICT (pr->pr_global_struct->self);
ed = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
ED_Print (pr, ed);
ED_Free (pr, ed);
@ -529,9 +529,9 @@ PF_traceline (progs_t *pr)
VectorCopy (trace.plane.normal, pr->pr_global_struct->trace_plane_normal);
pr->pr_global_struct->trace_plane_dist = trace.plane.dist;
if (trace.ent)
pr->pr_global_struct->trace_ent = EDICT_TO_PROG (trace.ent);
pr->pr_global_struct->trace_ent = EDICT_TO_PROG (pr, trace.ent);
else
pr->pr_global_struct->trace_ent = EDICT_TO_PROG (sv.edicts);
pr->pr_global_struct->trace_ent = EDICT_TO_PROG (pr, sv.edicts);
}
/*
@ -636,7 +636,7 @@ PF_checkclient (progs_t *pr)
return;
}
// if current entity can't possibly see the check entity, return 0
self = PROG_TO_EDICT (pr->pr_global_struct->self);
self = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
VectorAdd (self->v.origin, self->v.view_ofs, view);
leaf = Mod_PointInLeaf (view, sv.worldmodel);
l = (leaf - sv.worldmodel->leafs) - 1;
@ -786,7 +786,7 @@ PF_findradius (progs_t *pr)
if (Length (eorg) > rad)
continue;
ent->v.chain = EDICT_TO_PROG (chain);
ent->v.chain = EDICT_TO_PROG (pr, chain);
chain = ent;
}
@ -1000,7 +1000,7 @@ PF_walkmove (progs_t *pr)
dfunction_t *oldf;
int oldself;
ent = PROG_TO_EDICT (pr->pr_global_struct->self);
ent = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
yaw = G_FLOAT (pr, OFS_PARM0);
dist = G_FLOAT (pr, OFS_PARM1);
@ -1039,7 +1039,7 @@ PF_droptofloor (progs_t *pr)
vec3_t end;
trace_t trace;
ent = PROG_TO_EDICT (pr->pr_global_struct->self);
ent = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
VectorCopy (ent->v.origin, end);
end[2] -= 256;
@ -1052,7 +1052,7 @@ PF_droptofloor (progs_t *pr)
VectorCopy (trace.endpos, ent->v.origin);
SV_LinkEdict (ent, false);
ent->v.flags = (int) ent->v.flags | FL_ONGROUND;
ent->v.groundentity = EDICT_TO_PROG (trace.ent);
ent->v.groundentity = EDICT_TO_PROG (pr, trace.ent);
G_FLOAT (pr, OFS_RETURN) = 1;
}
}
@ -1262,7 +1262,7 @@ PF_changeyaw (progs_t *pr)
edict_t *ent;
float ideal, current, move, speed;
ent = PROG_TO_EDICT (pr->pr_global_struct->self);
ent = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
current = anglemod (ent->v.angles[1]);
ideal = ent->v.ideal_yaw;
speed = ent->v.yaw_speed;
@ -1315,7 +1315,7 @@ WriteDest (progs_t *pr)
case MSG_ONE:
SV_Error ("Shouldn't be at MSG_ONE");
#if 0
ent = PROG_TO_EDICT (pr->pr_global_struct->msg_entity);
ent = PROG_TO_EDICT (pr, pr->pr_global_struct->msg_entity);
entnum = NUM_FOR_EDICT (pr, ent);
if (entnum < 1 || entnum > MAX_CLIENTS)
PR_RunError (pr, "WriteDest: not a client");
@ -1348,7 +1348,7 @@ Write_GetClient (progs_t *pr)
int entnum;
edict_t *ent;
ent = PROG_TO_EDICT (pr->pr_global_struct->msg_entity);
ent = PROG_TO_EDICT (pr, pr->pr_global_struct->msg_entity);
entnum = NUM_FOR_EDICT (pr, ent);
if (entnum < 1 || entnum > MAX_CLIENTS)
PR_RunError (pr, "Write_GetClient: not a client");

View file

@ -105,11 +105,11 @@ ED_Alloc (progs_t *pr)
int i;
edict_t *e;
for (i = MAX_CLIENTS + 1; i < sv.num_edicts; i++) {
for (i = MAX_CLIENTS + 1; i < *(pr)->num_edicts; i++) {
e = EDICT_NUM (pr, i);
// the first couple seconds of server time can involve a lot of
// freeing and allocating, so relax the replacement policy
if (e->free && (e->freetime < 2 || sv.time - e->freetime > 0.5)) {
if (e->free && (e->freetime < 2 || *(pr)->time - e->freetime > 0.5)) {
ED_ClearEdict (pr, e);
return e;
}
@ -121,7 +121,7 @@ ED_Alloc (progs_t *pr)
e = EDICT_NUM (pr, i);
SV_UnlinkEdict (e);
} else
sv.num_edicts++;
(*(pr)->num_edicts)++;
e = EDICT_NUM (pr, i);
ED_ClearEdict (pr, e);
@ -151,7 +151,7 @@ ED_Free (progs_t *pr, edict_t *ed)
ed->v.nextthink = -1;
ed->v.solid = 0;
ed->freetime = sv.time;
ed->freetime = *(pr)->time;
}
//===========================================================================
@ -292,7 +292,7 @@ PR_ValueString (progs_t *pr, etype_t type, eval_t *val)
break;
case ev_entity:
snprintf (line, sizeof (line), "entity %i",
NUM_FOR_EDICT (pr, PROG_TO_EDICT (val->edict)));
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->edict)));
break;
case ev_function:
f = pr->pr_functions + val->function;
@ -344,7 +344,7 @@ PR_UglyValueString (progs_t *pr, etype_t type, eval_t *val)
break;
case ev_entity:
snprintf (line, sizeof (line), "%i",
NUM_FOR_EDICT (pr, PROG_TO_EDICT (val->edict)));
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->edict)));
break;
case ev_function:
f = pr->pr_functions + val->function;
@ -534,32 +534,12 @@ ED_PrintEdicts (progs_t *pr)
{
int i;
Con_Printf ("%i entities\n", sv.num_edicts);
for (i = 0; i < sv.num_edicts; i++) {
Con_Printf ("%i entities\n", *(pr)->num_edicts);
for (i = 0; i < *(pr)->num_edicts; i++) {
Con_Printf ("\nEDICT %i:\n", i);
ED_PrintNum (pr, i);
}
}
void
ED_PrintEdicts_f (void)
{
ED_PrintEdicts (&sv_progs);
}
/*
ED_PrintEdict_f
For debugging, prints a single edicy
*/
void
ED_PrintEdict_f (void)
{
int i;
i = atoi (Cmd_Argv (1));
Con_Printf ("\n EDICT %i:\n", i);
ED_PrintNum (&sv_progs, i);
}
/*
ED_Count
@ -574,7 +554,7 @@ ED_Count (progs_t *pr)
int active, models, solid, step;
active = models = solid = step = 0;
for (i = 0; i < sv.num_edicts; i++) {
for (i = 0; i < *(pr)->num_edicts; i++) {
ent = EDICT_NUM (pr, i);
if (ent->free)
continue;
@ -587,7 +567,7 @@ ED_Count (progs_t *pr)
step++;
}
Con_Printf ("num_edicts:%3i\n", sv.num_edicts);
Con_Printf ("num_edicts:%3i\n", *(pr)->num_edicts);
Con_Printf ("active :%3i\n", active);
Con_Printf ("view :%3i\n", models);
Con_Printf ("touch :%3i\n", solid);
@ -595,12 +575,6 @@ ED_Count (progs_t *pr)
}
void
ED_Count_f (void)
{
ED_Count (&sv_progs);
}
/*
==============================================================================
@ -750,7 +724,7 @@ ED_ParseEpair (progs_t *pr, void *base, ddef_t *key, char *s)
break;
case ev_entity:
*(int *) d = EDICT_TO_PROG (EDICT_NUM (pr, atoi (s)));
*(int *) d = EDICT_TO_PROG (pr, EDICT_NUM (pr, atoi (s)));
break;
case ev_field:
@ -795,7 +769,7 @@ ED_ParseEdict (progs_t *pr, char *data, edict_t *ent)
init = false;
// clear it
if (ent != sv.edicts) // hack
if (ent != *(pr)->edicts) // hack
memset (&ent->v, 0, pr->progs->entityfields * 4);
// go through all the dictionary pairs
@ -896,7 +870,7 @@ ED_LoadFromFile (progs_t *pr, char *data)
ent = NULL;
inhibit = 0;
pr->pr_global_struct->time = sv.time;
pr->pr_global_struct->time = *(pr)->time;
// parse ents
while (1) {
@ -938,7 +912,7 @@ ED_LoadFromFile (progs_t *pr, char *data)
continue;
}
pr->pr_global_struct->self = EDICT_TO_PROG (ent);
pr->pr_global_struct->self = EDICT_TO_PROG (pr, ent);
PR_ExecuteProgram (pr, func - pr->pr_functions);
SV_FlushSignon ();
}
@ -1186,7 +1160,7 @@ EDICT_NUM (progs_t *pr, int n)
{
if (n < 0 || n >= MAX_EDICTS)
SV_Error ("EDICT_NUM: bad number %i", n);
return (edict_t *) ((byte *) sv.edicts + (n) * pr->pr_edict_size);
return (edict_t *) ((byte *) *(pr)->edicts + (n) * pr->pr_edict_size);
}
int
@ -1194,10 +1168,10 @@ NUM_FOR_EDICT (progs_t *pr, edict_t *e)
{
int b;
b = (byte *) e - (byte *) sv.edicts;
b = (byte *) e - (byte *) *(pr)->edicts;
b = b / pr->pr_edict_size;
if (b < 0 || b >= sv.num_edicts)
if (b < 0 || b >= *(pr)->num_edicts)
SV_Error ("NUM_FOR_EDICT: bad pointer");
return b;
}

View file

@ -226,13 +226,6 @@ PR_Profile (progs_t *pr)
} while (best);
}
void
PR_Profile_f (void)
{
PR_Profile (&sv_progs);
}
/*
PR_RunError
@ -354,7 +347,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
if (!fnum || fnum >= pr->progs->numfunctions) {
if (pr->pr_global_struct->self)
ED_Print (pr, PROG_TO_EDICT (pr->pr_global_struct->self));
ED_Print (pr, PROG_TO_EDICT (pr, pr->pr_global_struct->self));
SV_Error ("PR_ExecuteProgram: NULL function");
}
@ -457,7 +450,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
OPC->_float = !OPA->function;
break;
case OP_NOT_ENT:
OPC->_float = (PROG_TO_EDICT (OPA->edict) == sv.edicts);
OPC->_float = (PROG_TO_EDICT (pr, OPA->edict) == *pr->edicts);
break;
case OP_EQ_F:
OPC->_float = OPA->_float == OPB->_float;
@ -525,14 +518,14 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
return;
}
if (pr_boundscheck->int_val && (OPB->_int % pr->pr_edict_size <
((byte *) & sv.edicts->v -
(byte *) sv.edicts))) {
((byte *) & (*pr->edicts)->v -
(byte *) *pr->edicts))) {
pr->pr_xstatement = st - pr->pr_statements;
PR_RunError
(pr, "Progs attempted to write to an engine edict field\n");
return;
}
ptr = (eval_t *) ((byte *) sv.edicts + OPB->_int);
ptr = (eval_t *) ((byte *) *pr->edicts + OPB->_int);
ptr->_int = OPA->_int;
break;
case OP_STOREP_V:
@ -543,7 +536,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
(pr, "Progs attempted to write to an out of bounds edict\n");
return;
}
ptr = (eval_t *) ((byte *) sv.edicts + OPB->_int);
ptr = (eval_t *) ((byte *) *pr->edicts + OPB->_int);
ptr->vector[0] = OPA->vector[0];
ptr->vector[1] = OPA->vector[1];
ptr->vector[2] = OPA->vector[2];
@ -557,7 +550,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
return;
}
if (pr_boundscheck->int_val
&& (OPA->edict == 0 && sv.state == ss_active)) {
&& (OPA->edict == 0 && pr->null_bad)) {
pr->pr_xstatement = st - pr->pr_statements;
PR_RunError (pr, "assignment to world entity");
return;
@ -569,9 +562,9 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
(pr, "Progs attempted to address an invalid field in an edict\n");
return;
}
ed = PROG_TO_EDICT (OPA->edict);
ed = PROG_TO_EDICT (pr, OPA->edict);
OPC->_int =
(byte *) ((int *) &ed->v + OPB->_int) - (byte *) sv.edicts;
(byte *) ((int *) &ed->v + OPB->_int) - (byte *) *pr->edicts;
break;
case OP_LOAD_F:
case OP_LOAD_FLD:
@ -592,7 +585,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
(pr, "Progs attempted to read an invalid field in an edict\n");
return;
}
ed = PROG_TO_EDICT (OPA->edict);
ed = PROG_TO_EDICT (pr, OPA->edict);
OPC->_int = ((eval_t *) ((int *) &ed->v + OPB->_int))->_int;
break;
case OP_LOAD_V:
@ -610,7 +603,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
(pr, "Progs attempted to read an invalid field in an edict\n");
return;
}
ed = PROG_TO_EDICT (OPA->edict);
ed = PROG_TO_EDICT (pr, OPA->edict);
OPC->vector[0] =
((eval_t *) ((int *) &ed->v + OPB->_int))->vector[0];
OPC->vector[1] =
@ -671,7 +664,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
return; // all done
break;
case OP_STATE:
ed = PROG_TO_EDICT (pr->pr_global_struct->self);
ed = PROG_TO_EDICT (pr, pr->pr_global_struct->self);
ed->v.nextthink = pr->pr_global_struct->time + 0.1;
ed->v.frame = OPA->_float;
ed->v.think = OPB->function;
@ -840,13 +833,13 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
}
if (pr_boundscheck->int_val
&& (OPB->_int % pr->pr_edict_size <
((byte *) & sv.edicts->v - (byte *) sv.edicts))) {
((byte *) & (*pr->edicts)->v - (byte *) *pr->edicts))) {
pr->pr_xstatement = st - pr->pr_statements;
PR_RunError
(pr, "Progs attempted to write to an engine edict field\n");
return;
}
ptr = (eval_t *) ((byte *) sv.edicts + OPB->_int);
ptr = (eval_t *) ((byte *) *pr->edicts + OPB->_int);
ptr->_int = OPA->_int;
break;
case OP_LOAD_I:
@ -864,7 +857,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
(pr, "Progs attempted to read an invalid field in an edict\n");
return;
}
ed = PROG_TO_EDICT (OPA->edict);
ed = PROG_TO_EDICT (pr, OPA->edict);
OPC->_int = ((eval_t *) ((int *) &ed->v + OPB->_int))->_int;
break;

View file

@ -192,7 +192,7 @@ SV_SaveSpawnparms (void)
host_client->state = cs_connected;
// call the progs to get default spawn parms for the new client
sv_progs.pr_global_struct->self = EDICT_TO_PROG (host_client->edict);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, host_client->edict);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->SetChangeParms);
for (j = 0; j < NUM_SPAWN_PARMS; j++)
host_client->spawn_parms[j] = (&sv_progs.pr_global_struct->parm1)[j];
@ -316,6 +316,7 @@ SV_SpawnServer (char *server)
// restarted
sv.state = ss_dead;
sv_progs.null_bad = 0;
Mod_ClearAll ();
Hunk_FreeToLowMark (host_hunklevel);
@ -391,6 +392,7 @@ SV_SpawnServer (char *server)
// precache and static commands can be issued during
// map initialization
sv.state = ss_loading;
sv_progs.null_bad = 0;
ent = EDICT_NUM (&sv_progs, 0);
ent->free = false;
@ -415,6 +417,7 @@ SV_SpawnServer (char *server)
// all spawning is completed, any further precache statements
// or prog writes to the signon message are errors
sv.state = ss_active;
sv_progs.null_bad = 1;
// run two frames to allow everything to settle
sv_frametime = 0.1;

View file

@ -250,12 +250,12 @@ SV_DropClient (client_t *drop)
if (!drop->spectator) {
// call the prog function for removing a client
// this will set the body to a dead frame, among other things
sv_progs.pr_global_struct->self = EDICT_TO_PROG (drop->edict);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, drop->edict);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->ClientDisconnect);
} else if (SpectatorDisconnect) {
// call the prog function for removing a client
// this will set the body to a dead frame, among other things
sv_progs.pr_global_struct->self = EDICT_TO_PROG (drop->edict);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, drop->edict);
PR_ExecuteProgram (&sv_progs, SpectatorDisconnect);
}
}
@ -1907,6 +1907,7 @@ SV_Init (void)
COM_Init ();
PR_Init ();
SV_Progs_Init ();
Mod_Init ();
SV_InitNet ();

View file

@ -140,11 +140,11 @@ SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
// try one move with vertical motion, then one without
for (i = 0; i < 2; i++) {
VectorAdd (ent->v.origin, move, neworg);
enemy = PROG_TO_EDICT (ent->v.enemy);
enemy = PROG_TO_EDICT (&sv_progs, ent->v.enemy);
if (i == 0 && enemy != sv.edicts) {
dz =
ent->v.origin[2] -
PROG_TO_EDICT (ent->v.enemy)->v.origin[2];
PROG_TO_EDICT (&sv_progs, ent->v.enemy)->v.origin[2];
if (dz > 40)
neworg[2] -= 8;
if (dz < 30)
@ -220,7 +220,7 @@ SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
// Con_Printf ("back on ground\n");
ent->v.flags = (int) ent->v.flags & ~FL_PARTIALGROUND;
}
ent->v.groundentity = EDICT_TO_PROG (trace.ent);
ent->v.groundentity = EDICT_TO_PROG (&sv_progs, trace.ent);
// the move is ok
if (relink)
@ -402,8 +402,8 @@ SV_MoveToGoal (progs_t *pr)
edict_t *ent, *goal;
float dist;
ent = PROG_TO_EDICT (sv_progs.pr_global_struct->self);
goal = PROG_TO_EDICT (ent->v.goalentity);
ent = PROG_TO_EDICT (&sv_progs, sv_progs.pr_global_struct->self);
goal = PROG_TO_EDICT (&sv_progs, ent->v.goalentity);
dist = G_FLOAT (&sv_progs, OFS_PARM0);
if (!((int) ent->v.flags & (FL_ONGROUND | FL_FLY | FL_SWIM))) {
@ -411,7 +411,7 @@ SV_MoveToGoal (progs_t *pr)
return;
}
// if the next step hits the enemy, return immediately
if (PROG_TO_EDICT (ent->v.enemy) != sv.edicts
if (PROG_TO_EDICT (&sv_progs, ent->v.enemy) != sv.edicts
&& SV_CloseEnough (ent, goal, dist)) return;
// bump around...

View file

@ -163,8 +163,8 @@ SV_RunThink (edict_t *ent)
// by a trigger with a local time.
ent->v.nextthink = 0;
sv_progs.pr_global_struct->time = thinktime;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, sv.edicts);
PR_ExecuteProgram (&sv_progs, ent->v.think);
if (ent->free)
@ -191,14 +191,14 @@ SV_Impact (edict_t *e1, edict_t *e2)
sv_progs.pr_global_struct->time = sv.time;
if (e1->v.touch && e1->v.solid != SOLID_NOT) {
sv_progs.pr_global_struct->self = EDICT_TO_PROG (e1);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (e2);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, e1);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, e2);
PR_ExecuteProgram (&sv_progs, e1->v.touch);
}
if (e2->v.touch && e2->v.solid != SOLID_NOT) {
sv_progs.pr_global_struct->self = EDICT_TO_PROG (e2);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (e1);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, e2);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, e1);
PR_ExecuteProgram (&sv_progs, e2->v.touch);
}
@ -309,7 +309,7 @@ SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
if ((trace.ent->v.solid == SOLID_BSP)
|| (trace.ent->v.movetype == MOVETYPE_PPUSH)) {
ent->v.flags = (int) ent->v.flags | FL_ONGROUND;
ent->v.groundentity = EDICT_TO_PROG (trace.ent);
ent->v.groundentity = EDICT_TO_PROG (&sv_progs, trace.ent);
}
}
if (!trace.plane.normal[2]) {
@ -491,7 +491,7 @@ SV_Push (edict_t *pusher, vec3_t move)
// if the entity is standing on the pusher, it will definately be
// moved
if (!(((int) check->v.flags & FL_ONGROUND)
&& PROG_TO_EDICT (check->v.groundentity) == pusher)) {
&& PROG_TO_EDICT (&sv_progs, check->v.groundentity) == pusher)) {
if (check->v.absmin[0] >= maxs[0]
|| check->v.absmin[1] >= maxs[1]
|| check->v.absmin[2] >= maxs[2]
@ -541,8 +541,8 @@ SV_Push (edict_t *pusher, vec3_t move)
// if the pusher has a "blocked" function, call it
// otherwise, just stay in place until the obstacle is gone
if (pusher->v.blocked) {
sv_progs.pr_global_struct->self = EDICT_TO_PROG (pusher);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (check);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, pusher);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, check);
PR_ExecuteProgram (&sv_progs, pusher->v.blocked);
}
// move back any entities we already moved
@ -616,8 +616,8 @@ SV_Physics_Pusher (edict_t *ent)
VectorCopy (ent->v.origin, oldorg);
ent->v.nextthink = 0;
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, sv.edicts);
PR_ExecuteProgram (&sv_progs, ent->v.think);
if (ent->free)
return;
@ -764,7 +764,7 @@ SV_Physics_Toss (edict_t *ent)
if (trace.plane.normal[2] > 0.7) {
if (ent->v.velocity[2] < 60 || ent->v.movetype != MOVETYPE_BOUNCE) {
ent->v.flags = (int) ent->v.flags | FL_ONGROUND;
ent->v.groundentity = EDICT_TO_PROG (trace.ent);
ent->v.groundentity = EDICT_TO_PROG (&sv_progs, trace.ent);
VectorCopy (vec3_origin, ent->v.velocity);
VectorCopy (vec3_origin, ent->v.avelocity);
}
@ -881,8 +881,8 @@ SV_PPushMove (edict_t *pusher, float movetime) // player push
// Stage 4: Yes, it must be. Fail the move.
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Revert
if (pusher->v.blocked) { // Blocked func?
sv_progs.pr_global_struct->self = EDICT_TO_PROG (pusher);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (check);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, pusher);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, check);
PR_ExecuteProgram (&sv_progs, pusher->v.blocked);
}
@ -918,8 +918,8 @@ SV_Physics_PPusher (edict_t *ent)
if (thinktime > oldltime && thinktime <= ent->v.ltime) {
ent->v.nextthink = 0;
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, sv.edicts);
PR_ExecuteProgram (&sv_progs, ent->v.think);
if (ent->free)
return;
@ -932,8 +932,8 @@ void
SV_ProgStartFrame (void)
{
// let the progs know that a new frame has started
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv.edicts);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, sv.edicts);
sv_progs.pr_global_struct->time = sv.time;
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->StartFrame);
}
@ -991,7 +991,7 @@ SV_RunNewmis (void)
if (!sv_progs.pr_global_struct->newmis)
return;
ent = PROG_TO_EDICT (sv_progs.pr_global_struct->newmis);
ent = PROG_TO_EDICT (&sv_progs, sv_progs.pr_global_struct->newmis);
sv_frametime = 0.05;
sv_progs.pr_global_struct->newmis = 0;
@ -1049,8 +1049,8 @@ SV_Physics (void)
// 2000-01-02 EndFrame function by Maddes/FrikaC start
if (EndFrame) {
// let the progs know that the frame has ended
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (sv.edicts);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv.edicts);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, sv.edicts);
sv_progs.pr_global_struct->time = sv.time;
PR_ExecuteProgram (&sv_progs, EndFrame);
}

View file

@ -30,7 +30,9 @@
# include "config.h"
#endif
#include "cmd.h"
#include "progs.h"
#include "server.h"
int eval_alpha, eval_scale, eval_glowsize, eval_glowcolor, eval_colormod;
progs_t sv_progs;
@ -67,4 +69,45 @@ FindEdictFieldOffsets (progs_t *pr)
eval_glowcolor = FindFieldOffset (&sv_progs, "glow_color");
eval_colormod = FindFieldOffset (&sv_progs, "colormod");
}
};
}
void
SV_Progs_Init (void)
{
sv_progs.edicts = &sv.edicts;
sv_progs.num_edicts = &sv.num_edicts;
sv_progs.time = &sv.time;
}
void
ED_PrintEdicts_f (void)
{
ED_PrintEdicts (&sv_progs);
}
/*
ED_PrintEdict_f
For debugging, prints a single edicy
*/
void
ED_PrintEdict_f (void)
{
int i;
i = atoi (Cmd_Argv (1));
Con_Printf ("\n EDICT %i:\n", i);
ED_PrintNum (&sv_progs, i);
}
void
ED_Count_f (void)
{
ED_Count (&sv_progs);
}
void
PR_Profile_f (void)
{
PR_Profile (&sv_progs);
}

View file

@ -527,7 +527,7 @@ SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg)
}
// send a damage message if the player got hit this frame
if (ent->v.dmg_take || ent->v.dmg_save) {
other = PROG_TO_EDICT (ent->v.dmg_inflictor);
other = PROG_TO_EDICT (&sv_progs, ent->v.dmg_inflictor);
MSG_WriteByte (msg, svc_damage);
MSG_WriteByte (msg, ent->v.dmg_save);
MSG_WriteByte (msg, ent->v.dmg_take);

View file

@ -498,7 +498,7 @@ SV_Begin_f (void)
// call the spawn function
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, SpectatorConnect);
}
} else {
@ -508,12 +508,12 @@ SV_Begin_f (void)
// call the spawn function
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->ClientConnect);
// actually spawn the player
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->PutClientInServer);
}
@ -946,7 +946,7 @@ SV_Kill_f (void)
}
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->ClientKill);
}
@ -1054,7 +1054,7 @@ SV_PTrack_f (void)
host_client->spec_track = 0;
ent = EDICT_NUM (&sv_progs, host_client - svs.clients + 1);
tent = EDICT_NUM (&sv_progs, 0);
ent->v.goalentity = EDICT_TO_PROG (tent);
ent->v.goalentity = EDICT_TO_PROG (&sv_progs, tent);
return;
}
@ -1065,14 +1065,14 @@ SV_PTrack_f (void)
host_client->spec_track = 0;
ent = EDICT_NUM (&sv_progs, host_client - svs.clients + 1);
tent = EDICT_NUM (&sv_progs, 0);
ent->v.goalentity = EDICT_TO_PROG (tent);
ent->v.goalentity = EDICT_TO_PROG (&sv_progs, tent);
return;
}
host_client->spec_track = i + 1; // now tracking
ent = EDICT_NUM (&sv_progs, host_client - svs.clients + 1);
tent = EDICT_NUM (&sv_progs, i + 1);
ent->v.goalentity = EDICT_TO_PROG (tent);
ent->v.goalentity = EDICT_TO_PROG (&sv_progs, tent);
}
@ -1324,7 +1324,7 @@ AddLinksToPmove (areanode_t *node)
int i;
physent_t *pe;
pl = EDICT_TO_PROG (sv_player);
pl = EDICT_TO_PROG (&sv_progs, sv_player);
// touch linked edicts
for (l = node->solid_edicts.next; l != &node->solid_edicts; l = next) {
@ -1390,7 +1390,7 @@ AddAllEntsToPmove (void)
physent_t *pe;
int pl;
pl = EDICT_TO_PROG (sv_player);
pl = EDICT_TO_PROG (&sv_progs, sv_player);
check = NEXT_EDICT (&sv_progs, sv.edicts);
for (e = 1; e < sv.num_edicts; e++, check = NEXT_EDICT (&sv_progs, check)) {
if (check->free)
@ -1534,7 +1534,7 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside)
sv_progs.pr_global_struct->frametime = sv_frametime;
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->PlayerPreThink);
SV_RunThink (sv_player);
@ -1591,7 +1591,7 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside)
if (onground != -1) {
sv_player->v.flags = (int) sv_player->v.flags | FL_ONGROUND;
sv_player->v.groundentity =
EDICT_TO_PROG (EDICT_NUM (&sv_progs, pmove.physents[onground].info));
EDICT_TO_PROG (&sv_progs, EDICT_NUM (&sv_progs, pmove.physents[onground].info));
} else {
sv_player->v.flags = (int) sv_player->v.flags & ~FL_ONGROUND;
}
@ -1619,8 +1619,8 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside)
ent = EDICT_NUM (&sv_progs, n);
if (!ent->v.touch || (playertouch[n / 8] & (1 << (n % 8))))
continue;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, ent);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, ent->v.touch);
playertouch[n / 8] |= 1 << (n % 8);
}
@ -1640,12 +1640,12 @@ SV_PostRunCmd (void)
if (!host_client->spectator) {
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, sv_progs.pr_global_struct->PlayerPostThink);
SV_RunNewmis ();
} else if (SpectatorThink) {
sv_progs.pr_global_struct->time = sv.time;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (sv_player);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, sv_player);
PR_ExecuteProgram (&sv_progs, SpectatorThink);
}
}

View file

@ -316,8 +316,8 @@ SV_TouchLinks (edict_t *ent, areanode_t *node)
old_self = sv_progs.pr_global_struct->self;
old_other = sv_progs.pr_global_struct->other;
sv_progs.pr_global_struct->self = EDICT_TO_PROG (touch);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (ent);
sv_progs.pr_global_struct->self = EDICT_TO_PROG (&sv_progs, touch);
sv_progs.pr_global_struct->other = EDICT_TO_PROG (&sv_progs, ent);
sv_progs.pr_global_struct->time = sv.time;
PR_ExecuteProgram (&sv_progs, touch->v.touch);
@ -777,9 +777,9 @@ SV_ClipToLinks (areanode_t *node, moveclip_t * clip)
if (clip->trace.allsolid)
return;
if (clip->passedict) {
if (PROG_TO_EDICT (touch->v.owner) == clip->passedict)
if (PROG_TO_EDICT (&sv_progs, touch->v.owner) == clip->passedict)
continue; // don't clip against own missiles
if (PROG_TO_EDICT (clip->passedict->v.owner) == touch)
if (PROG_TO_EDICT (&sv_progs, clip->passedict->v.owner) == touch)
continue; // don't clip against owner
}