From e8026d9c7656c8395cd135492527fd3780560d79 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 31 May 2002 21:05:58 +0000 Subject: [PATCH] touch, think and blocked now support methods also a little whitespace cleanup --- nq/include/sv_progs.h | 51 ++++++++++++++++++++++++++++++++++++++++++ nq/source/host.c | 3 +-- nq/source/sv_cl_phys.c | 6 ++--- nq/source/sv_main.c | 6 ++--- nq/source/sv_phys.c | 20 +++++------------ nq/source/world.c | 4 +--- qw/include/sv_progs.h | 50 +++++++++++++++++++++++++++++++++++++++++ qw/source/sv_phys.c | 24 ++++++-------------- qw/source/sv_user.c | 19 +++++----------- qw/source/world.c | 4 +--- 10 files changed, 126 insertions(+), 61 deletions(-) diff --git a/nq/include/sv_progs.h b/nq/include/sv_progs.h index 8ee78f75a..ba099d44a 100644 --- a/nq/include/sv_progs.h +++ b/nq/include/sv_progs.h @@ -201,5 +201,56 @@ extern sv_fields_t sv_fields; #define SVinteger(e,f) SVFIELD (e, f, integer) extern func_t EndFrame; +extern progs_t sv_pr_state; + +static inline void +sv_pr_touch (edict_t *self, edict_t *other) +{ + int this; + + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); + *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); + if ((this = sv_pr_state.fields.this) != -1) { + P_INT (&sv_pr_state, 0) = E_var (self, this, integer); + P_INT (&sv_pr_state, 1) = 0; + P_INT (&sv_pr_state, 2) = E_var (other, this, integer); + } + PR_ExecuteProgram (&sv_pr_state, SVfunc (self, touch)); +} + +static inline void +sv_pr_use (edict_t *self, edict_t *other) +{ +} + +static inline void +sv_pr_think (edict_t *self) +{ + int this; + + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); + *sv_globals.other = 0; + if ((this = sv_pr_state.fields.this) != -1) { + P_INT (&sv_pr_state, 0) = E_var (self, this, integer); + P_INT (&sv_pr_state, 1) = 0; + P_INT (&sv_pr_state, 2) = 0; + } + PR_ExecuteProgram (&sv_pr_state, SVfunc (self, think)); +} + +static inline void +sv_pr_blocked (edict_t *self, edict_t *other) +{ + int this; + + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); + *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); + if ((this = sv_pr_state.fields.this) != -1) { + P_INT (&sv_pr_state, 0) = E_var (self, this, integer); + P_INT (&sv_pr_state, 1) = 0; + P_INT (&sv_pr_state, 2) = E_var (other, this, integer); + } + PR_ExecuteProgram (&sv_pr_state, SVfunc (self, blocked)); +} #endif // __sv_progs_h diff --git a/nq/source/host.c b/nq/source/host.c index c99ca8cdd..d966c116e 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -384,8 +384,7 @@ SV_DropClient (qboolean crash) saveSelf = *sv_globals.self; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, host_client->edict); - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.ClientDisconnect); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.ClientDisconnect); *sv_globals.self = saveSelf; } diff --git a/nq/source/sv_cl_phys.c b/nq/source/sv_cl_phys.c index 24211fec2..a7adc9daa 100644 --- a/nq/source/sv_cl_phys.c +++ b/nq/source/sv_cl_phys.c @@ -320,8 +320,7 @@ SV_Physics_Client (edict_t *ent, int num) // call standard client pre-think *sv_globals.time = sv.time; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.PlayerPreThink); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.PlayerPreThink); // do a move SV_CheckVelocity (ent); @@ -371,6 +370,5 @@ SV_Physics_Client (edict_t *ent, int num) *sv_globals.time = sv.time; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.PlayerPostThink); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.PlayerPostThink); } diff --git a/nq/source/sv_main.c b/nq/source/sv_main.c index f6f1da8a9..76149c3dc 100644 --- a/nq/source/sv_main.c +++ b/nq/source/sv_main.c @@ -274,8 +274,7 @@ SV_ConnectClient (int clientnum) memcpy (client->spawn_parms, spawn_parms, sizeof (spawn_parms)); else { // call the progs to get default spawn parms for the new client - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.SetNewParms); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.SetNewParms); for (i = 0; i < NUM_SPAWN_PARMS; i++) client->spawn_parms[i] = sv_globals.parms[i]; } @@ -889,8 +888,7 @@ SV_SaveSpawnparms (void) // call the progs to get default spawn parms for the new client *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, host_client->edict); - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.SetChangeParms); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.SetChangeParms); for (j = 0; j < NUM_SPAWN_PARMS; j++) host_client->spawn_parms[j] = sv_globals.parms[j]; diff --git a/nq/source/sv_phys.c b/nq/source/sv_phys.c index e9be69f73..388bd238e 100644 --- a/nq/source/sv_phys.c +++ b/nq/source/sv_phys.c @@ -152,9 +152,7 @@ SV_RunThink (edict_t *ent) // by a trigger with a local time. SVfloat (ent, nextthink) = 0; *sv_globals.time = thinktime; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, sv.edicts); - PR_ExecuteProgram (&sv_pr_state, SVfunc (ent, think)); + sv_pr_think (ent); if (ent->free) return false; @@ -178,15 +176,11 @@ SV_Impact (edict_t *e1, edict_t *e2) *sv_globals.time = sv.time; if (SVfunc (e1, touch) && SVfloat (e1, solid) != SOLID_NOT) { - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, e1); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, e2); - PR_ExecuteProgram (&sv_pr_state, SVfunc (e1, touch)); + sv_pr_touch (e1, e2); } if (SVfunc (e2, touch) && SVfloat (e2, solid) != SOLID_NOT) { - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, e2); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, e1); - PR_ExecuteProgram (&sv_pr_state, SVfunc (e2, touch)); + sv_pr_touch (e2, e1); } *sv_globals.self = old_self; @@ -484,9 +478,7 @@ 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 (SVfunc (pusher, blocked)) { - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, pusher); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, check); - PR_ExecuteProgram (&sv_pr_state, SVfunc (pusher, blocked)); + sv_pr_blocked (pusher, check); } // move back any entities we already moved for (i = 0; i < num_moved; i++) { @@ -537,9 +529,7 @@ SV_Physics_Pusher (edict_t *ent) if (thinktime > oldltime && thinktime <= SVfloat (ent, ltime)) { SVfloat (ent, nextthink) = 0; *sv_globals.time = sv.time; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, sv.edicts); - PR_ExecuteProgram (&sv_pr_state, SVfunc (ent, think)); + sv_pr_think (ent); if (ent->free) return; } diff --git a/nq/source/world.c b/nq/source/world.c index 233db15e5..aeeed83de 100644 --- a/nq/source/world.c +++ b/nq/source/world.c @@ -291,10 +291,8 @@ SV_TouchLinks (edict_t *ent, areanode_t *node) old_self = *sv_globals.self; old_other = *sv_globals.other; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, touch); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, ent); *sv_globals.time = sv.time; - PR_ExecuteProgram (&sv_pr_state, SVfunc (touch, touch)); + sv_pr_touch (touch, ent); *sv_globals.self = old_self; *sv_globals.other = old_other; diff --git a/qw/include/sv_progs.h b/qw/include/sv_progs.h index 1ab023aa2..1d15b8073 100644 --- a/qw/include/sv_progs.h +++ b/qw/include/sv_progs.h @@ -184,4 +184,54 @@ extern func_t SpectatorThink; extern func_t SpectatorDisconnect; extern func_t UserInfoCallback; +static inline void +sv_pr_touch (edict_t *self, edict_t *other) +{ + int this; + + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); + *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); + if ((this = sv_pr_state.fields.this) != -1) { + P_INT (&sv_pr_state, 0) = E_var (self, this, integer); + P_INT (&sv_pr_state, 1) = 0; + P_INT (&sv_pr_state, 2) = E_var (other, this, integer); + } + PR_ExecuteProgram (&sv_pr_state, SVfunc (self, touch)); +} + +static inline void +sv_pr_use (edict_t *self, edict_t *other) +{ +} + +static inline void +sv_pr_think (edict_t *self) +{ + int this; + + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); + *sv_globals.other = 0; + if ((this = sv_pr_state.fields.this) != -1) { + P_INT (&sv_pr_state, 0) = E_var (self, this, integer); + P_INT (&sv_pr_state, 1) = 0; + P_INT (&sv_pr_state, 2) = 0; + } + PR_ExecuteProgram (&sv_pr_state, SVfunc (self, think)); +} + +static inline void +sv_pr_blocked (edict_t *self, edict_t *other) +{ + int this; + + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, self); + *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, other); + if ((this = sv_pr_state.fields.this) != -1) { + P_INT (&sv_pr_state, 0) = E_var (self, this, integer); + P_INT (&sv_pr_state, 1) = 0; + P_INT (&sv_pr_state, 2) = E_var (other, this, integer); + } + PR_ExecuteProgram (&sv_pr_state, SVfunc (self, blocked)); +} + #endif // __sv_progs_h diff --git a/qw/source/sv_phys.c b/qw/source/sv_phys.c index 040704684..0d2a7c074 100644 --- a/qw/source/sv_phys.c +++ b/qw/source/sv_phys.c @@ -155,9 +155,7 @@ SV_RunThink (edict_t *ent) // by a trigger with a local time. SVfloat (ent, nextthink) = 0; *sv_globals.time = thinktime; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, sv.edicts); - PR_ExecuteProgram (&sv_pr_state, SVfunc (ent, think)); + sv_pr_think (ent); if (ent->free) return false; @@ -181,15 +179,11 @@ SV_Impact (edict_t *e1, edict_t *e2) *sv_globals.time = sv.time; if (SVfunc (e1, touch) && SVfloat (e1, solid) != SOLID_NOT) { - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, e1); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, e2); - PR_ExecuteProgram (&sv_pr_state, SVfunc (e1, touch)); + sv_pr_touch (e1, e2); } if (SVfunc (e2, touch) && SVfloat (e2, solid) != SOLID_NOT) { - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, e2); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, e1); - PR_ExecuteProgram (&sv_pr_state, SVfunc (e2, touch)); + sv_pr_touch (e2, e1); } *sv_globals.self = old_self; @@ -491,11 +485,9 @@ 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 (SVfunc (pusher, blocked)) { - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, pusher); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, check); - PR_ExecuteProgram (&sv_pr_state, SVfunc (pusher, blocked)); - } + if (SVfunc (pusher, blocked)) + sv_pr_blocked (pusher, check); + // move back any entities we already moved for (i = 0; i < num_moved; i++) { VectorCopy (moved_from[i], SVvector (moved_edict[i], origin)); @@ -548,9 +540,7 @@ SV_Physics_Pusher (edict_t *ent) VectorCopy (SVvector (ent, origin), oldorg); SVfloat (ent, nextthink) = 0; *sv_globals.time = sv.time; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, sv.edicts); - PR_ExecuteProgram (&sv_pr_state, SVfunc (ent, think)); + sv_pr_think (ent); if (ent->free) return; VectorSubtract (SVvector (ent, origin), oldorg, move); diff --git a/qw/source/sv_user.c b/qw/source/sv_user.c index a071d914d..35a0f0c6b 100644 --- a/qw/source/sv_user.c +++ b/qw/source/sv_user.c @@ -1526,10 +1526,8 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside) *sv_globals.frametime = sv_frametime; *sv_globals.time = sv.time; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, - sv_player); - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.PlayerPreThink); + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv_player); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.PlayerPreThink); SV_RunThink (sv_player); } @@ -1615,9 +1613,7 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside) ent = EDICT_NUM (&sv_pr_state, n); if (!SVfunc (ent, touch) || (playertouch[n / 8] & (1 << (n % 8)))) continue; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, ent); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, sv_player); - PR_ExecuteProgram (&sv_pr_state, SVfunc (ent, touch)); + sv_pr_touch (ent, sv_player); playertouch[n / 8] |= 1 << (n % 8); } } @@ -1635,15 +1631,12 @@ SV_PostRunCmd (void) if (!host_client->spectator) { *sv_globals.time = sv.time; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, - sv_player); - PR_ExecuteProgram (&sv_pr_state, - sv_funcs.PlayerPostThink); + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv_player); + PR_ExecuteProgram (&sv_pr_state, sv_funcs.PlayerPostThink); SV_RunNewmis (); } else if (SpectatorThink) { *sv_globals.time = sv.time; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, - sv_player); + *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv_player); PR_ExecuteProgram (&sv_pr_state, SpectatorThink); } } diff --git a/qw/source/world.c b/qw/source/world.c index 233db15e5..aeeed83de 100644 --- a/qw/source/world.c +++ b/qw/source/world.c @@ -291,10 +291,8 @@ SV_TouchLinks (edict_t *ent, areanode_t *node) old_self = *sv_globals.self; old_other = *sv_globals.other; - *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, touch); - *sv_globals.other = EDICT_TO_PROG (&sv_pr_state, ent); *sv_globals.time = sv.time; - PR_ExecuteProgram (&sv_pr_state, SVfunc (touch, touch)); + sv_pr_touch (touch, ent); *sv_globals.self = old_self; *sv_globals.other = old_other;