From 3b85dd08f96dcc8675c2dbf609532bcd1fbb688c Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Fri, 6 Dec 2019 15:46:22 -0500 Subject: [PATCH] various safety and optimization changes --- source/common.h | 1 - source/gl_model.h | 5 -- source/host.c | 6 +- source/host_cmd.c | 10 +-- source/mathlib.c | 113 ------------------------- source/mathlib.h | 164 ++++++++++++++++++++++++++++------- source/pr_cmds.c | 52 ++++++------ source/pr_edict.c | 9 +- source/pr_exec.c | 207 +++++++++++++++++---------------------------- source/pr_string.c | 12 +-- source/progs.h | 43 ++++++---- source/sv_main.c | 16 ++-- source/sv_move.c | 12 +-- source/sv_phys.c | 50 +++++------ source/world.c | 24 +++--- 15 files changed, 334 insertions(+), 390 deletions(-) diff --git a/source/common.h b/source/common.h index 687a4c6..2fe0ad2 100644 --- a/source/common.h +++ b/source/common.h @@ -178,7 +178,6 @@ int32_t Q_strncmp(const char *s1, const char *s2, int32_t count); int32_t Q_atoi(const char *str); float Q_atof(const char *str); - #include "strl_fn.h" /* locale-insensitive strcasecmp replacement functions: */ diff --git a/source/gl_model.h b/source/gl_model.h index 4b26afa..00a8878 100644 --- a/source/gl_model.h +++ b/source/gl_model.h @@ -53,7 +53,6 @@ BRUSH MODELS // // in memory representation // -// !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct { vec3_t position; @@ -65,7 +64,6 @@ typedef struct // plane_t structure -// !!! if this is changed, it must be changed in asm_i386.h too !!! typedef struct mplane_s { vec3_t normal; @@ -114,7 +112,6 @@ typedef struct texture_s #define SURF_DRAWTELE 0x1000 #define SURF_DRAWWATER 0x2000 -// !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct { uint32_t v[2]; @@ -224,7 +221,6 @@ typedef struct mclipnode_s } mclipnode_t; //johnfitz -// !!! if this is changed, it must be changed in asm_i386.h too !!! typedef struct { mclipnode_t *clipnodes; //johnfitz -- was dclipnode_t @@ -332,7 +328,6 @@ typedef struct maliasgroupframedesc_t frames[1]; } maliasgroup_t; -// !!! if this is changed, it must be changed in asm_draw.h too !!! typedef struct mtriangle_s { int32_t facesfront; diff --git a/source/host.c b/source/host.c index 4faf74e..8718788 100644 --- a/source/host.c +++ b/source/host.c @@ -420,10 +420,10 @@ void SV_DropClient(bool crash) { // call the prog function for removing a client // this will set the body to a dead frame, among other things - saveSelf = G_INT(GBL_self); - G_INT(GBL_self) = EDICT_TO_PROG(host_client->edict); + saveSelf = G_PEDICT(GBL_self); + G_PEDICT(GBL_self) = EDICT_TO_PROG(host_client->edict); PR_ExecuteProgram(G_FUNC(GBL_ClientDisconnect)); - G_INT(GBL_self) = saveSelf; + G_PEDICT(GBL_self) = saveSelf; } Sys_Printf("Client %s removed\n", host_client->name); diff --git a/source/host_cmd.c b/source/host_cmd.c index 7b5a6f3..1be599c 100644 --- a/source/host_cmd.c +++ b/source/host_cmd.c @@ -1546,7 +1546,7 @@ void Host_Kill_f(void) } G_FLOAT(GBL_time) = sv.time; - G_INT(GBL_self) = EDICT_TO_PROG(sv_player); + G_PEDICT(GBL_self) = EDICT_TO_PROG(sv_player); PR_ExecuteProgram(G_FUNC(GBL_ClientKill)); } @@ -1579,11 +1579,11 @@ void Host_Pause_f(void) if(sv.paused) { - SV_BroadcastPrintf("%s paused the game\n", PR_GetString(ED_RSTRING(sv_player, ED_netname))); + SV_BroadcastPrintf("%s paused the game\n", ED_STRING(sv_player, ED_netname)); } else { - SV_BroadcastPrintf("%s unpaused the game\n", PR_GetString(ED_RSTRING(sv_player, ED_netname))); + SV_BroadcastPrintf("%s unpaused the game\n", ED_STRING(sv_player, ED_netname)); } // send notification to all clients @@ -1665,7 +1665,7 @@ void Host_Spawn_f(void) (&G_FLOAT(GBL_parm1))[i] = host_client->spawn_parms[i]; // call the spawn function G_FLOAT(GBL_time) = sv.time; - G_INT(GBL_self) = EDICT_TO_PROG(sv_player); + G_PEDICT(GBL_self) = EDICT_TO_PROG(sv_player); PR_ExecuteProgram(G_FUNC(GBL_ClientConnect)); if((Sys_DoubleTime() - NET_QSocketGetTime(host_client->netconnection)) <= sv.time) @@ -2092,7 +2092,7 @@ edict_t *FindViewthing(void) for(i = 0 ; i < sv.num_edicts ; i++) { e = EDICT_NUM(i); - if(!strcmp(PR_GetString(ED_RSTRING(e, ED_classname)), "viewthing")) + if(!strcmp(ED_STRING(e, ED_classname), "viewthing")) return e; } Con_Printf("No viewthing on map\n"); diff --git a/source/mathlib.c b/source/mathlib.c index 0ccc05a..02fd306 100644 --- a/source/mathlib.c +++ b/source/mathlib.c @@ -164,20 +164,6 @@ int32_t BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p) return sides; } -//johnfitz -- the opposite of AngleVectors. this takes forward and generates pitch yaw roll -//TODO: take right and up vectors to properly set yaw and roll -void VectorAngles(const vec3_t forward, vec3_t angles) -{ - vec3_t temp; - - temp[0] = forward[0]; - temp[1] = forward[1]; - temp[2] = 0; - angles[PITCH] = -atan2(forward[2], VectorLength(temp)) / PI_DIV_180; - angles[YAW] = atan2(forward[1], forward[0]) / PI_DIV_180; - angles[ROLL] = 0; -} - void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) { float angle; @@ -204,105 +190,6 @@ void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) up[2] = cr * cp; } -int32_t VectorCompare(vec3_t v1, vec3_t v2) -{ - int32_t i; - - for(i = 0 ; i < 3 ; i++) - if(v1[i] != v2[i]) - return 0; - - return 1; -} - -void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc) -{ - vecc[0] = veca[0] + scale * vecb[0]; - vecc[1] = veca[1] + scale * vecb[1]; - vecc[2] = veca[2] + scale * vecb[2]; -} - - -vec_t _DotProduct(vec3_t v1, vec3_t v2) -{ - return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; -} - -void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out) -{ - out[0] = veca[0] - vecb[0]; - out[1] = veca[1] - vecb[1]; - out[2] = veca[2] - vecb[2]; -} - -void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out) -{ - out[0] = veca[0] + vecb[0]; - out[1] = veca[1] + vecb[1]; - out[2] = veca[2] + vecb[2]; -} - -void _VectorCopy(vec3_t in, vec3_t out) -{ - out[0] = in[0]; - out[1] = in[1]; - out[2] = in[2]; -} - -void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross) -{ - cross[0] = v1[1] * v2[2] - v1[2] * v2[1]; - cross[1] = v1[2] * v2[0] - v1[0] * v2[2]; - cross[2] = v1[0] * v2[1] - v1[1] * v2[0]; -} - -vec_t VectorLength(vec3_t v) -{ - return sqrt(DotProduct(v, v)); -} - -float VectorNormalize(vec3_t v) -{ - float length, ilength; - - length = sqrt(DotProduct(v, v)); - - if(length) - { - ilength = 1 / length; - v[0] *= ilength; - v[1] *= ilength; - v[2] *= ilength; - } - - return length; - -} - -void VectorInverse(vec3_t v) -{ - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; -} - -void VectorScale(vec3_t in, vec_t scale, vec3_t out) -{ - out[0] = in[0] * scale; - out[1] = in[1] * scale; - out[2] = in[2] * scale; -} - - -int32_t Q_log2(int32_t val) -{ - int32_t answer = 0; - while(val >>= 1) - answer++; - return answer; -} - - /* ================ R_ConcatRotations diff --git a/source/mathlib.h b/source/mathlib.h index bcebe32..63424b2 100644 --- a/source/mathlib.h +++ b/source/mathlib.h @@ -24,57 +24,157 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef spingle__mathlib_h #define spingle__mathlib_h -// mathlib.h - #include #define PI 3.14159265358979323846 #define PI_DIV_180 (PI / 180.0) //johnfitz +#define Q_rint(x) _Generic((x), float: Q_rintf, double: Q_rintd)(x) + struct mplane_s; extern vec3_t vec3_origin; -#define Q_rint(x) ((x) > 0 ? (int32_t)((x) + 0.5) : (int32_t)((x) - 0.5)) +void TurnVector(vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz -#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2]) -#define DoublePrecisionDotProduct(x,y) ((double)x[0]*y[0]+(double)x[1]*y[1]+(double)x[2]*y[2]) -#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];} -#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];} -#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];} +static inline int32_t Q_rintf(float x) +{ + return x > 0 ? (int32_t)(x + 0.5) : (int32_t)(x - 0.5); +} + +static inline int32_t Q_rintd(double x) +{ + return x > 0 ? (int32_t)(x + 0.5) : (int32_t)(x - 0.5); +} + +static inline vec_t DotProduct(vec3_t const v1, vec3_t const v2) +{ + return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; +} + +static inline vec_t DoublePrecisionDotProduct(vec3_t const v1, vec3_t const v2) +{ + return (double)v1[0] * v2[0] + (double)v1[1] * v2[1] + (double)v1[2] * v2[2]; +} +static inline void VectorSubtract(vec3_t const veca, vec3_t const vecb, vec3_t out) +{ + out[0] = veca[0] - vecb[0]; + out[1] = veca[1] - vecb[1]; + out[2] = veca[2] - vecb[2]; +} + +static inline void VectorAdd(vec3_t const veca, vec3_t const vecb, vec3_t out) +{ + out[0] = veca[0] + vecb[0]; + out[1] = veca[1] + vecb[1]; + out[2] = veca[2] + vecb[2]; +} + +static inline void VectorCopy(vec3_t const in, vec3_t out) +{ + out[0] = in[0]; + out[1] = in[1]; + out[2] = in[2]; +} + +static inline void VectorInverse(vec3_t v) +{ + v[0] = -v[0]; + v[1] = -v[1]; + v[2] = -v[2]; +} + +static inline void VectorScale(vec3_t const in, vec_t scale, vec3_t out) +{ + out[0] = in[0] * scale; + out[1] = in[1] * scale; + out[2] = in[2] * scale; +} //johnfitz -- courtesy of lordhavoc // QS: To avoid strict aliasing violations, use a float/int32_t union instead of type punning. // [agw] NO YOU FOOL THAT'S UNDEFINED BEHAVIOUR -#define VectorNormalizeFast(_v) \ -{ \ - union { float f; uint32_t i; } _y, _number; \ - _number.f = DotProduct(_v, _v); \ - if(_number.f != 0.0) \ - { \ - _y.i = 0x5f3759df - (_number.i >> 1); \ - _y.f = _y.f * (1.5f - (_number.f * 0.5f * _y.f * _y.f)); \ - VectorScale(_v, _y.f, _v); \ - } \ +static inline void VectorNormalizeFast(vec3_t v) +{ + union { float f; uint32_t i; } y, number; + number.f = DotProduct(v, v); + if(number.f != 0.0) + { + y.i = 0x5f3759df - (number.i >> 1); + y.f = y.f * (1.5f - (number.f * 0.5f * y.f * y.f)); + VectorScale(v, y.f, v); + } } -void TurnVector(vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz -void VectorAngles(const vec3_t forward, vec3_t angles); //johnfitz +static inline int32_t VectorCompare(vec3_t v1, vec3_t v2) +{ + int32_t i; -void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc); + for(i = 0 ; i < 3 ; i++) + if(v1[i] != v2[i]) + return 0; -vec_t _DotProduct(vec3_t v1, vec3_t v2); -void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out); -void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out); -void _VectorCopy(vec3_t in, vec3_t out); + return 1; +} -int32_t VectorCompare(vec3_t v1, vec3_t v2); -vec_t VectorLength(vec3_t v); -void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross); -float VectorNormalize(vec3_t v); // returns vector length -void VectorInverse(vec3_t v); -void VectorScale(vec3_t in, vec_t scale, vec3_t out); -int32_t Q_log2(int32_t val); +static inline void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc) +{ + vecc[0] = veca[0] + scale * vecb[0]; + vecc[1] = veca[1] + scale * vecb[1]; + vecc[2] = veca[2] + scale * vecb[2]; +} + +static inline void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross) +{ + cross[0] = v1[1] * v2[2] - v1[2] * v2[1]; + cross[1] = v1[2] * v2[0] - v1[0] * v2[2]; + cross[2] = v1[0] * v2[1] - v1[1] * v2[0]; +} + +static inline vec_t VectorLength(vec3_t v) +{ + return sqrt(DotProduct(v, v)); +} + +static inline float VectorNormalize(vec3_t v) +{ + float length, ilength; + + length = sqrt(DotProduct(v, v)); + + if(length) + { + ilength = 1 / length; + v[0] *= ilength; + v[1] *= ilength; + v[2] *= ilength; + } + + return length; + +} + +static inline int32_t Q_log2(int32_t val) +{ + int32_t answer = 0; + while(val >>= 1) + answer++; + return answer; +} + +//johnfitz -- the opposite of AngleVectors. this takes forward and generates pitch yaw roll +//TODO: take right and up vectors to properly set yaw and roll +static inline void VectorAngles(const vec3_t forward, vec3_t angles) +{ + vec3_t temp; + + temp[0] = forward[0]; + temp[1] = forward[1]; + temp[2] = 0; + angles[PITCH] = -atan2(forward[2], VectorLength(temp)) / PI_DIV_180; + angles[YAW] = atan2(forward[1], forward[0]) / PI_DIV_180; + angles[ROLL] = 0; +} void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]); void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]); diff --git a/source/pr_cmds.c b/source/pr_cmds.c index 76b6c09..04f6ee6 100644 --- a/source/pr_cmds.c +++ b/source/pr_cmds.c @@ -32,7 +32,7 @@ static char *PR_GetTempString(void) return pr_string_temp[(STRINGTEMP_BUFFERS - 1) & ++pr_string_tempindex]; } -#define RETURN_EDICT(e) (G_INT(GBL_RETURN) = EDICT_TO_PROG(e)) +#define RETURN_EDICT(e) (G_PEDICT(GBL_RETURN) = EDICT_TO_PROG(e)) #define MSG_BROADCAST 0 // unreliable to all #define MSG_ONE 1 // reliable to one (msg_entity) @@ -94,7 +94,7 @@ static void PF_error(void) s = PF_VarString(0); Con_Printf("======SERVER ERROR in %s:\n%s\n", PR_GetString(pr_xfunction->s_name), s); - ed = PROG_TO_EDICT(G_INT(GBL_self)); + ed = PROG_TO_EDICT(G_PEDICT(GBL_self)); ED_Print(ed); Host_Error("Program error"); @@ -118,7 +118,7 @@ static void PF_objerror(void) s = PF_VarString(0); Con_Printf("======OBJECT ERROR in %s:\n%s\n", PR_GetString(pr_xfunction->s_name), s); - ed = PROG_TO_EDICT(G_INT(GBL_self)); + ed = PROG_TO_EDICT(G_PEDICT(GBL_self)); ED_Print(ed); ED_Free(ed); @@ -714,9 +714,9 @@ static void PF_traceline(void) VectorCopy(trace.plane.normal, G_VECTOR(GBL_trace_plane_normal)); G_FLOAT(GBL_trace_plane_dist) = trace.plane.dist; if(trace.ent) - G_INT(GBL_trace_ent) = EDICT_TO_PROG(trace.ent); + G_PEDICT(GBL_trace_ent) = EDICT_TO_PROG(trace.ent); else - G_INT(GBL_trace_ent) = EDICT_TO_PROG(sv.edicts); + G_PEDICT(GBL_trace_ent) = EDICT_TO_PROG(sv.edicts); } //============================================================================ @@ -824,7 +824,7 @@ static void PF_checkclient(void) } // if current entity can't possibly see the check entity, return 0 - self = PROG_TO_EDICT(G_INT(GBL_self)); + self = PROG_TO_EDICT(G_PEDICT(GBL_self)); VectorAdd(ED_VECTOR(self, ED_origin), ED_VECTOR(self, ED_view_ofs), view); leaf = Mod_PointInLeaf(view, sv.worldmodel); l = (leaf - sv.worldmodel->leafs) - 1; @@ -953,7 +953,7 @@ static void PF_findradius(void) if(VectorLength(eorg) > rad) continue; - ED_INT(ent, ED_chain) = EDICT_TO_PROG(chain); + ED_PEDICT(ent, ED_chain) = EDICT_TO_PROG(chain); chain = ent; } @@ -981,7 +981,7 @@ static void PF_ftos(void) sprintf(s, "%" PRIi32 "", (int32_t)v); else sprintf(s, "%5.1f", v); - G_INT(GBL_RETURN) = PR_SetEngineString(s); + G_RSTRING(GBL_RETURN) = PR_SetEngineString(s); } static void PF_fabs(void) @@ -997,7 +997,7 @@ static void PF_vtos(void) s = PR_GetTempString(); sprintf(s, "'%5.1f %5.1f %5.1f'", G_VECTOR(GBL_PARM0)[0], G_VECTOR(GBL_PARM0)[1], G_VECTOR(GBL_PARM0)[2]); - G_INT(GBL_RETURN) = PR_SetEngineString(s); + G_RSTRING(GBL_RETURN) = PR_SetEngineString(s); } static void PF_spawn(void) @@ -1022,12 +1022,12 @@ static void PF_remove(void) static void PF_find(void) { int32_t e; - int32_t f; + pfield_t f; const char *s, *t; edict_t *ed; e = G_EDICTNUM(GBL_PARM0); - f = G_INT(GBL_PARM1); + f = G_PFIELD(GBL_PARM1); s = G_STRING(GBL_PARM2); if(!s) PR_RunError("PF_find: bad search string"); @@ -1037,7 +1037,7 @@ static void PF_find(void) ed = EDICT_NUM(e); if(ed->free) continue; - t = PR_GetString(ED_RSTRING(ed, f)); + t = ED_STRING(ed, f); if(!t) continue; if(!strcmp(t, s)) @@ -1059,7 +1059,7 @@ static void PR_CheckEmptyString(const char *s) static void PF_precache_file(void) { // precache_file is only used to copy files with qcc, it does nothing - G_INT(GBL_RETURN) = G_INT(GBL_PARM0); + G_RSTRING(GBL_RETURN) = G_RSTRING(GBL_PARM0); } static void PF_precache_sound(void) @@ -1071,7 +1071,7 @@ static void PF_precache_sound(void) PR_RunError("PF_Precache_*: Precache can only be done in spawn functions"); s = G_STRING(GBL_PARM0); - G_INT(GBL_RETURN) = G_INT(GBL_PARM0); + G_RSTRING(GBL_RETURN) = G_RSTRING(GBL_PARM0); PR_CheckEmptyString(s); for(i = 0; i < MAX_SOUNDS; i++) @@ -1096,7 +1096,7 @@ static void PF_precache_model(void) PR_RunError("PF_Precache_*: Precache can only be done in spawn functions"); s = G_STRING(GBL_PARM0); - G_INT(GBL_RETURN) = G_INT(GBL_PARM0); + G_RSTRING(GBL_RETURN) = G_RSTRING(GBL_PARM0); PR_CheckEmptyString(s); for(i = 0; i < MAX_MODELS; i++) @@ -1149,7 +1149,7 @@ static void PF_walkmove(void) dfunction_t *oldf; int32_t oldself; - ent = PROG_TO_EDICT(G_INT(GBL_self)); + ent = PROG_TO_EDICT(G_PEDICT(GBL_self)); yaw = G_FLOAT(GBL_PARM0); dist = G_FLOAT(GBL_PARM1); @@ -1167,14 +1167,14 @@ static void PF_walkmove(void) // save program state, because SV_movestep may call other functions oldf = pr_xfunction; - oldself = G_INT(GBL_self); + oldself = G_PEDICT(GBL_self); G_FLOAT(GBL_RETURN) = SV_movestep(ent, move, true); // restore program state pr_xfunction = oldf; - G_INT(GBL_self) = oldself; + G_PEDICT(GBL_self) = oldself; } /* @@ -1190,7 +1190,7 @@ static void PF_droptofloor(void) vec3_t end; trace_t trace; - ent = PROG_TO_EDICT(G_INT(GBL_self)); + ent = PROG_TO_EDICT(G_PEDICT(GBL_self)); VectorCopy(ED_VECTOR(ent, ED_origin), end); end[2] -= 256; @@ -1204,7 +1204,7 @@ static void PF_droptofloor(void) VectorCopy(trace.endpos, ED_VECTOR(ent, ED_origin)); SV_LinkEdict(ent, false); ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND; - ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); + ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); G_FLOAT(GBL_RETURN) = 1; } } @@ -1422,7 +1422,7 @@ void PF_changeyaw(void) edict_t *ent; float ideal, current, move, speed; - ent = PROG_TO_EDICT(G_INT(GBL_self)); + ent = PROG_TO_EDICT(G_PEDICT(GBL_self)); current = anglemod(ED_VECTOR(ent, ED_angles)[1]); ideal = ED_FLOAT(ent, ED_ideal_yaw); speed = ED_FLOAT(ent, ED_yaw_speed); @@ -1475,7 +1475,7 @@ static sizebuf_t *WriteDest(void) return &sv.datagram; case MSG_ONE: - ent = PROG_TO_EDICT(G_INT(GBL_msg_entity)); + ent = PROG_TO_EDICT(G_PEDICT(GBL_msg_entity)); entnum = NUM_FOR_EDICT(ent); if(entnum < 1 || entnum > svs.maxclients) PR_RunError("WriteDest: not a client"); @@ -1556,7 +1556,7 @@ static void PF_makestatic(void) //johnfitz -- PROTOCOL_FITZQUAKE if(sv.protocol == PROTOCOL_NETQUAKE) { - if(SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model))) & 0xFF00 || (int32_t)(ED_FLOAT(ent, ED_frame)) & 0xFF00) + if(SV_ModelIndex(ED_STRING(ent, ED_model)) & 0xFF00 || (int32_t)(ED_FLOAT(ent, ED_frame)) & 0xFF00) { ED_Free(ent); return; //can't display the correct model & frame, so don't show it at all @@ -1564,7 +1564,7 @@ static void PF_makestatic(void) } else { - if(SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model))) & 0xFF00) + if(SV_ModelIndex(ED_STRING(ent, ED_model)) & 0xFF00) bits |= B_LARGEMODEL; if((int32_t)(ED_FLOAT(ent, ED_frame)) & 0xFF00) bits |= B_LARGEFRAME; @@ -1581,9 +1581,9 @@ static void PF_makestatic(void) MSG_WriteByte(&sv.signon, svc_spawnstatic); if(bits & B_LARGEMODEL) - MSG_WriteShort(&sv.signon, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model)))); + MSG_WriteShort(&sv.signon, SV_ModelIndex(ED_STRING(ent, ED_model))); else - MSG_WriteByte(&sv.signon, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model)))); + MSG_WriteByte(&sv.signon, SV_ModelIndex(ED_STRING(ent, ED_model))); if(bits & B_LARGEFRAME) MSG_WriteShort(&sv.signon, ED_FLOAT(ent, ED_frame)); diff --git a/source/pr_edict.c b/source/pr_edict.c index f9c9cfc..5fa7236 100644 --- a/source/pr_edict.c +++ b/source/pr_edict.c @@ -311,7 +311,6 @@ void ED_Print(edict_t *ed) // if the value is still all 0, skip the field type = d->type & ~DEF_SAVEGLOBAL; - for(j = 0; j < type_size[type]; j++) { if(v[j]) @@ -842,7 +841,7 @@ void ED_LoadFromFile(const char *data) } // look for the spawn function - func = ED_FindFunction(PR_GetString(ED_RSTRING(ent, ED_classname))); + func = ED_FindFunction(ED_STRING(ent, ED_classname)); if(!func) { @@ -852,7 +851,7 @@ void ED_LoadFromFile(const char *data) continue; } - G_INT(GBL_self) = EDICT_TO_PROG(ent); + G_PEDICT(GBL_self) = EDICT_TO_PROG(ent); PR_ExecuteProgram(func - pr_functions); } @@ -879,14 +878,14 @@ edict_t *EDICT_NUM(int32_t n) { if(n < 0 || n >= sv.max_edicts) Host_Error("EDICT_NUM: bad number %" PRIi32 "", n); - return (edict_t *)((byte *)sv.edicts + (n) * pr_edict_size); + return (edict_t *)PROG_TO_EDICT(n * pr_edict_size); } int32_t NUM_FOR_EDICT(edict_t *e) { int32_t b; - b = (byte *)e - (byte *)sv.edicts; + b = EDICT_TO_PROG(e); b = b / pr_edict_size; if(b < 0 || b >= sv.num_edicts) diff --git a/source/pr_exec.c b/source/pr_exec.c index 344e72a..7b52d2f 100644 --- a/source/pr_exec.c +++ b/source/pr_exec.c @@ -350,13 +350,8 @@ PR_ExecuteProgram The interpretation main loop ==================== */ -#define OPA G_EVAL((uint16_t)st->a) -#define OPB G_EVAL((uint16_t)st->b) -#define OPC G_EVAL((uint16_t)st->c) - void PR_ExecuteProgram(func_t fnum) { - eval_t *ptr; dstatement_t *st; dfunction_t *f, *newf; int32_t profile, startprofile; @@ -365,8 +360,8 @@ void PR_ExecuteProgram(func_t fnum) if(!fnum || fnum >= progs.numfunctions) { - if(G_INT(GBL_self)) - ED_Print(PROG_TO_EDICT(G_INT(GBL_self))); + if(G_PEDICT(GBL_self)) + ED_Print(PROG_TO_EDICT(G_PEDICT(GBL_self))); Host_Error("PR_ExecuteProgram: NULL function"); } @@ -396,141 +391,103 @@ void PR_ExecuteProgram(func_t fnum) switch(st->op) { - case OP_ADD_F: - OPC->_float = OPA->_float + OPB->_float; - break; - case OP_ADD_V: - OPC->vector[0] = OPA->vector[0] + OPB->vector[0]; - OPC->vector[1] = OPA->vector[1] + OPB->vector[1]; - OPC->vector[2] = OPA->vector[2] + OPB->vector[2]; +#define OPA G_EVAL((uint16_t)st->a) +#define OPB G_EVAL((uint16_t)st->b) +#define OPC G_EVAL((uint16_t)st->c) +#define PTR ((eval_t *)PROG_TO_EDICT(OPB->edict)) + +#define MakeOpArithF(op, exp) \ + case op: \ + OPC->_float = OPA->_float exp OPB->_float; \ break; - case OP_SUB_F: - OPC->_float = OPA->_float - OPB->_float; - break; - case OP_SUB_V: - OPC->vector[0] = OPA->vector[0] - OPB->vector[0]; - OPC->vector[1] = OPA->vector[1] - OPB->vector[1]; - OPC->vector[2] = OPA->vector[2] - OPB->vector[2]; +#define MakeOpArithV(op, exp) \ + case op: \ + OPC->vec[0] = OPA->vec[0] exp OPB->vec[0]; \ + OPC->vec[1] = OPA->vec[1] exp OPB->vec[1]; \ + OPC->vec[2] = OPA->vec[2] exp OPB->vec[2]; \ break; - case OP_MUL_F: - OPC->_float = OPA->_float * OPB->_float; - break; - case OP_MUL_V: - OPC->_float = OPA->vector[0] * OPB->vector[0] + - OPA->vector[1] * OPB->vector[1] + - OPA->vector[2] * OPB->vector[2]; - break; - case OP_MUL_FV: - OPC->vector[0] = OPA->_float * OPB->vector[0]; - OPC->vector[1] = OPA->_float * OPB->vector[1]; - OPC->vector[2] = OPA->_float * OPB->vector[2]; - break; - case OP_MUL_VF: - OPC->vector[0] = OPB->_float * OPA->vector[0]; - OPC->vector[1] = OPB->_float * OPA->vector[1]; - OPC->vector[2] = OPB->_float * OPA->vector[2]; +#define MakeOpArithB(op, exp) \ + case op: \ + OPC->_float = (int32_t)OPA->_float exp (int32_t)OPB->_float; \ break; - case OP_DIV_F: - OPC->_float = OPA->_float / OPB->_float; - break; + MakeOpArithF(OP_ADD_F, +) + MakeOpArithF(OP_SUB_F, -) + MakeOpArithF(OP_MUL_F, *) + MakeOpArithF(OP_DIV_F, /) - case OP_BITAND: - OPC->_float = (int32_t)OPA->_float & (int32_t)OPB->_float; - break; + MakeOpArithV(OP_ADD_V, +) + MakeOpArithV(OP_SUB_V, -) - case OP_BITOR: - OPC->_float = (int32_t)OPA->_float | (int32_t)OPB->_float; - break; + MakeOpArithB(OP_BITAND, &) + MakeOpArithB(OP_BITOR, |) - case OP_GE: OPC->_float = OPA->_float >= OPB->_float; break; - case OP_LE: OPC->_float = OPA->_float <= OPB->_float; break; - case OP_GT: OPC->_float = OPA->_float > OPB->_float; break; - case OP_LT: OPC->_float = OPA->_float < OPB->_float; break; - case OP_AND: OPC->_float = OPA->_float && OPB->_float; break; - case OP_OR: OPC->_float = OPA->_float || OPB->_float; break; + case OP_MUL_V: OPC->_float = DotProduct(OPA->vec, OPB->vec); break; + case OP_MUL_FV: VectorScale(OPB->vec, OPA->_float, OPC->vec); break; + case OP_MUL_VF: VectorScale(OPA->vec, OPB->_float, OPC->vec); break; + + MakeOpArithF(OP_GE, >=) + MakeOpArithF(OP_LE, <=) + MakeOpArithF(OP_GT, >) + MakeOpArithF(OP_LT, <) + MakeOpArithF(OP_AND, &&) + MakeOpArithF(OP_OR, ||) + MakeOpArithF(OP_EQ_F, ==) + MakeOpArithF(OP_NE_F, !=) case OP_NOT_F: OPC->_float = !OPA->_float; break; case OP_NOT_V: - OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2]; + OPC->_float = !OPA->vec[0] && !OPA->vec[1] && !OPA->vec[2]; break; case OP_NOT_S: OPC->_float = !OPA->string || !*PR_GetString(OPA->string); break; case OP_NOT_FNC: - OPC->_float = !OPA->function; + OPC->_float = !OPA->func; break; case OP_NOT_ENT: - OPC->_float = (PROG_TO_EDICT(OPA->edict) == sv.edicts); + OPC->_float = PROG_TO_EDICT(OPA->edict) == sv.edicts; break; - case OP_EQ_F: - OPC->_float = OPA->_float == OPB->_float; - break; case OP_EQ_V: - OPC->_float = (OPA->vector[0] == OPB->vector[0]) && - (OPA->vector[1] == OPB->vector[1]) && - (OPA->vector[2] == OPB->vector[2]); + OPC->_float = OPA->vec[0] == OPB->vec[0] && + OPA->vec[1] == OPB->vec[1] && + OPA->vec[2] == OPB->vec[2]; break; case OP_EQ_S: OPC->_float = !strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string)); break; - case OP_EQ_E: - OPC->_float = OPA->_int == OPB->_int; - break; - case OP_EQ_FNC: - OPC->_float = OPA->function == OPB->function; - break; + case OP_EQ_E: OPC->_float = OPA->edict == OPB->edict; break; + case OP_EQ_FNC: OPC->_float = OPA->func == OPB->func; break; - case OP_NE_F: - OPC->_float = OPA->_float != OPB->_float; - break; case OP_NE_V: - OPC->_float = (OPA->vector[0] != OPB->vector[0]) || - (OPA->vector[1] != OPB->vector[1]) || - (OPA->vector[2] != OPB->vector[2]); + OPC->_float = OPA->vec[0] != OPB->vec[0] || + OPA->vec[1] != OPB->vec[1] || + OPA->vec[2] != OPB->vec[2]; break; case OP_NE_S: OPC->_float = strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string)); break; - case OP_NE_E: - OPC->_float = OPA->_int != OPB->_int; - break; - case OP_NE_FNC: - OPC->_float = OPA->function != OPB->function; - break; + case OP_NE_E: OPC->_float = OPA->edict != OPB->edict; break; + case OP_NE_FNC: OPC->_float = OPA->func != OPB->func; break; - case OP_STORE_F: - case OP_STORE_ENT: - case OP_STORE_FLD: - case OP_STORE_S: - case OP_STORE_FNC: - OPB->_int = OPA->_int; - break; - case OP_STORE_V: - OPB->vector[0] = OPA->vector[0]; - OPB->vector[1] = OPA->vector[1]; - OPB->vector[2] = OPA->vector[2]; - break; + case OP_STORE_F: OPB->_float = OPA->_float; break; + case OP_STORE_ENT: OPB->edict = OPA->edict; break; + case OP_STORE_FLD: OPB->field = OPA->field; break; + case OP_STORE_S: OPB->string = OPA->string; break; + case OP_STORE_FNC: OPB->func = OPA->func; break; + case OP_STORE_V: VectorCopy(OPA->vec, OPB->vec); break; - case OP_STOREP_F: - case OP_STOREP_ENT: - case OP_STOREP_FLD: // integers - case OP_STOREP_S: - case OP_STOREP_FNC: // pointers - ptr = (eval_t *)((byte *)sv.edicts + OPB->_int); - ptr->_int = OPA->_int; - break; - case OP_STOREP_V: - ptr = (eval_t *)((byte *)sv.edicts + OPB->_int); - ptr->vector[0] = OPA->vector[0]; - ptr->vector[1] = OPA->vector[1]; - ptr->vector[2] = OPA->vector[2]; - break; + case OP_STOREP_F: PTR->_float = OPA->_float; break; + case OP_STOREP_ENT: PTR->edict = OPA->edict; break; + case OP_STOREP_FLD: PTR->field = OPA->field; break; + case OP_STOREP_S: PTR->string = OPA->string; break; + case OP_STOREP_FNC: PTR->func = OPA->func; break; + case OP_STOREP_V: VectorCopy(OPA->vec, PTR->vec); break; case OP_ADDRESS: ed = PROG_TO_EDICT(OPA->edict); @@ -542,7 +499,7 @@ void PR_ExecuteProgram(func_t fnum) pr_xstatement = st - pr_statements; PR_RunError("assignment to world entity"); } - OPC->_int = (byte *)&ED_INT(ed, OPB->_int) - (byte *)sv.edicts; + OPC->field = EDICT_TO_PROG(&ED_PFIELD(ed, OPB->field)); break; case OP_LOAD_F: @@ -550,22 +507,22 @@ void PR_ExecuteProgram(func_t fnum) case OP_LOAD_ENT: case OP_LOAD_S: case OP_LOAD_FNC: - ed = PROG_TO_EDICT(OPA->edict); -#if defined(PARANOID) - NUM_FOR_EDICT(ed); // Make sure it's in range -#endif - OPC->_int = ED_EVAL(ed, OPB->_int)->_int; - break; - case OP_LOAD_V: ed = PROG_TO_EDICT(OPA->edict); #if defined(PARANOID) NUM_FOR_EDICT(ed); // Make sure it's in range #endif - ptr = ED_EVAL(ed, OPB->_int); - OPC->vector[0] = ptr->vector[0]; - OPC->vector[1] = ptr->vector[1]; - OPC->vector[2] = ptr->vector[2]; + switch(st->op) + { + case OP_LOAD_F: OPC->_float = ED_FLOAT(ed, OPB->field); break; + case OP_LOAD_FLD: OPC->field = ED_PFIELD(ed, OPB->field); break; + case OP_LOAD_ENT: OPC->edict = ED_PEDICT(ed, OPB->field); break; + case OP_LOAD_S: OPC->string = ED_RSTRING(ed, OPB->field); break; + case OP_LOAD_FNC: OPC->func = ED_FUNC(ed, OPB->field); break; + case OP_LOAD_V: + VectorCopy(ED_VECTOR(ed, OPB->field), OPC->vec); + break; + } break; case OP_IFNOT: if(!OPA->_int) st += st->b - 1; break; @@ -585,9 +542,9 @@ void PR_ExecuteProgram(func_t fnum) startprofile = profile; pr_xstatement = st - pr_statements; pr_argc = st->op - OP_CALL0; - if(!OPA->function) + if(!OPA->func) PR_RunError("NULL function"); - newf = &pr_functions[OPA->function]; + newf = &pr_functions[OPA->func]; if(newf->first_statement < 0) { // Built-in function @@ -611,17 +568,14 @@ void PR_ExecuteProgram(func_t fnum) G_FLOAT(GBL_RETURN + 2) = G_FLOAT((uint16_t)st->a + 2); st = &pr_statements[PR_LeaveFunction()]; if(pr_depth == exitdepth) - { - // Done return; - } break; case OP_STATE: - ed = PROG_TO_EDICT(G_INT(GBL_self)); + ed = PROG_TO_EDICT(G_PEDICT(GBL_self)); ED_FLOAT(ed, ED_nextthink) = G_FLOAT(GBL_time) + 0.1; ED_FLOAT(ed, ED_frame) = OPA->_float; - ED_FUNC(ed, ED_think) = OPB->function; + ED_FUNC(ed, ED_think) = OPB->func; break; default: @@ -630,7 +584,4 @@ void PR_ExecuteProgram(func_t fnum) } } } -#undef OPA -#undef OPB -#undef OPC diff --git a/source/pr_string.c b/source/pr_string.c index 168e6b5..2697ea6 100644 --- a/source/pr_string.c +++ b/source/pr_string.c @@ -53,11 +53,11 @@ const char *PR_ValueString(int32_t type, eval_t *val) sprintf(line, "entity %" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); break; case ev_function: - f = pr_functions + val->function; + f = pr_functions + val->func; sprintf(line, "%s()", PR_GetString(f->s_name)); break; case ev_field: - def = ED_FieldAtOfs(val->_int); + def = ED_FieldAtOfs(val->field); sprintf(line, ".%s", PR_GetString(def->s_name)); break; case ev_void: @@ -67,7 +67,7 @@ const char *PR_ValueString(int32_t type, eval_t *val) sprintf(line, "%5.1f", val->_float); break; case ev_vector: - sprintf(line, "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]); + sprintf(line, "'%5.1f %5.1f %5.1f'", val->vec[0], val->vec[1], val->vec[2]); break; case ev_pointer: sprintf(line, "pointer"); @@ -106,11 +106,11 @@ const char *PR_UglyValueString(int32_t type, eval_t *val) sprintf(line, "%" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); break; case ev_function: - f = pr_functions + val->function; + f = pr_functions + val->func; sprintf(line, "%s", PR_GetString(f->s_name)); break; case ev_field: - def = ED_FieldAtOfs(val->_int); + def = ED_FieldAtOfs(val->field); sprintf(line, "%s", PR_GetString(def->s_name)); break; case ev_void: @@ -120,7 +120,7 @@ const char *PR_UglyValueString(int32_t type, eval_t *val) sprintf(line, "%f", val->_float); break; case ev_vector: - sprintf(line, "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); + sprintf(line, "%f %f %f", val->vec[0], val->vec[1], val->vec[2]); break; default: sprintf(line, "bad type %" PRIi32 "", type); diff --git a/source/progs.h b/source/progs.h index 9a19f18..8d9dc7d 100644 --- a/source/progs.h +++ b/source/progs.h @@ -27,14 +27,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define PROGHEADER_CRC 5927 +typedef uint32_t pedict_t; +typedef uint32_t pfield_t; +typedef uint32_t prptr_t; + typedef union eval_s { - string_t string; float _float; - float vector[3]; - func_t function; + vec3_t vec; + func_t func; int32_t _int; - int32_t edict; + pedict_t edict; + pfield_t field; + string_t string; + prptr_t ptr; } eval_t; #define MAX_ENT_LEAFS 32 @@ -56,14 +62,19 @@ typedef struct edict_s } edict_t; #define EDICT_FROM_AREA(l) (edict_t *)((byte *)(l) - offsetof(edict_t, area)) -#define ED_VARS(e) ((entvars_t *)e->fields) -#define ED_FLOAT(e, o) (((float *)e->fields)[o]) -#define ED_INT(e, o) (((int32_t *)e->fields)[o]) -#define ED_VECTOR(e, o) (&ED_FLOAT(e, o)) -#define ED_EVAL(e, o) ((eval_t *)&ED_FLOAT(e, o)) -#define ED_RSTRING(e, o) (*(string_t *)&ED_INT(e, o)) -#define ED_FUNC(e, o) (*(func_t *)&ED_INT(e, o)) +#define ED_FLOAT(e, o) (((float *)e->fields)[o]) +#define ED_INT(e, o) (((int32_t *)e->fields)[o]) +#define ED_EDICT(e, o) PROG_TO_EDICT(ED_INT(e, o)) +#define ED_EDICTNUM(e, o) NUM_FOR_EDICT(ED_EDICT(e, o)) +#define ED_VECTOR(e, o) (&ED_FLOAT(e, o)) +#define ED_STRING(e, o) PR_GetString(ED_RSTRING(e, o)) +#define ED_RSTRING(e, o) (*(string_t *)&ED_INT(e, o)) +#define ED_FUNC(e, o) (*(func_t *)&ED_INT(e, o)) +#define ED_PEDICT(e, o) (*(pedict_t *)&ED_INT(e, o)) +#define ED_PFIELD(e, o) (*(pfield_t *)&ED_INT(e, o)) +#define ED_EVAL(e, o) ((eval_t *)&ED_INT(e, o)) +#define ED_VOID(e, o) ((void *)&ED_INT(o)) //============================================================================ @@ -125,14 +136,16 @@ int32_t NUM_FOR_EDICT(edict_t *e); #define G_FLOAT(o) (((float *)pr_global_data)[o]) #define G_INT(o) (((int32_t *)pr_global_data)[o]) -#define G_EDICT(o) ((edict_t *)(&((byte *)sv.edicts)[G_INT(o)])) +#define G_EDICT(o) PROG_TO_EDICT(G_INT(o)) #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o)) #define G_VECTOR(o) (&G_FLOAT(o)) -#define G_STRING(o) (PR_GetString(G_RSTRING(o))) +#define G_STRING(o) PR_GetString(G_RSTRING(o)) #define G_RSTRING(o) (*(string_t *)&G_INT(o)) #define G_FUNC(o) (*(func_t *)&G_INT(o)) -#define G_EVAL(o) ((eval_t *)&G_FLOAT(o)) -#define G_VOID(o) ((void *)&G_FLOAT(o)) +#define G_PEDICT(o) (*(pedict_t *)&G_INT(o)) +#define G_PFIELD(o) (*(pfield_t *)&G_INT(o)) +#define G_EVAL(o) ((eval_t *)&G_INT(o)) +#define G_VOID(o) ((void *)&G_INT(o)) typedef void (*builtin_t)(void); diff --git a/source/sv_main.c b/source/sv_main.c index 8b6afd4..0a55b37 100644 --- a/source/sv_main.c +++ b/source/sv_main.c @@ -306,7 +306,7 @@ void SV_SendServerinfo(client_t *client) else MSG_WriteByte(&client->message, GAME_COOP); - MSG_WriteString(&client->message, PR_GetString(ED_RSTRING(sv.edicts, ED_message))); + MSG_WriteString(&client->message, ED_STRING(sv.edicts, ED_message)); //johnfitz -- only send the first 256 model and sound precaches if protocol is 15 for(i = 0, s = sv.model_precache + 1 ; *s; s++, i++) @@ -574,7 +574,7 @@ void SV_WriteEntitiesToClient(edict_t *clent, sizebuf_t *msg) if(ent != clent) // clent is ALLWAYS sent { // ignore ents without visible models - if(!ED_FLOAT(ent, ED_modelindex) || !PR_GetString(ED_RSTRING(ent, ED_model))[0]) + if(!ED_FLOAT(ent, ED_modelindex) || !ED_STRING(ent, ED_model)[0]) continue; //johnfitz -- don't send model>255 entities if protocol is 15 @@ -782,7 +782,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) // if(ED_FLOAT(ent, ED_dmg_take) || ED_FLOAT(ent, ED_dmg_save)) { - other = PROG_TO_EDICT(ED_INT(ent, ED_dmg_inflictor)); + other = PROG_TO_EDICT(ED_PEDICT(ent, ED_dmg_inflictor)); MSG_WriteByte(msg, svc_damage); MSG_WriteByte(msg, ED_FLOAT(ent, ED_dmg_save)); MSG_WriteByte(msg, ED_FLOAT(ent, ED_dmg_take)); @@ -852,7 +852,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) //johnfitz -- PROTOCOL_FITZQUAKE if(sv.protocol != PROTOCOL_NETQUAKE) { - if(bits & SU_WEAPON && SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_weaponmodel))) & 0xFF00) bits |= SU_WEAPON2; + if(bits & SU_WEAPON && SV_ModelIndex(ED_STRING(ent, ED_weaponmodel)) & 0xFF00) bits |= SU_WEAPON2; if((int32_t)ED_FLOAT(ent, ED_armorvalue) & 0xFF00) bits |= SU_ARMOR2; if((int32_t)ED_FLOAT(ent, ED_currentammo) & 0xFF00) bits |= SU_AMMO2; if((int32_t)ED_FLOAT(ent, ED_ammo_shells) & 0xFF00) bits |= SU_SHELLS2; @@ -898,7 +898,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) if(bits & SU_ARMOR) MSG_WriteByte(msg, ED_FLOAT(ent, ED_armorvalue)); if(bits & SU_WEAPON) - MSG_WriteByte(msg, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_weaponmodel)))); + MSG_WriteByte(msg, SV_ModelIndex(ED_STRING(ent, ED_weaponmodel))); MSG_WriteShort(msg, ED_FLOAT(ent, ED_health)); MSG_WriteByte(msg, ED_FLOAT(ent, ED_currentammo)); @@ -925,7 +925,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) //johnfitz -- PROTOCOL_FITZQUAKE if(bits & SU_WEAPON2) - MSG_WriteByte(msg, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_weaponmodel))) >> 8); + MSG_WriteByte(msg, SV_ModelIndex(ED_STRING(ent, ED_weaponmodel)) >> 8); if(bits & SU_ARMOR2) MSG_WriteByte(msg, (int32_t)ED_FLOAT(ent, ED_armorvalue) >> 8); if(bits & SU_AMMO2) @@ -1191,7 +1191,7 @@ void SV_CreateBaseline(void) else { svent->baseline.colormap = 0; - svent->baseline.modelindex = SV_ModelIndex(PR_GetString(ED_RSTRING(svent, ED_model))); + svent->baseline.modelindex = SV_ModelIndex(ED_STRING(svent, ED_model)); svent->baseline.alpha = svent->alpha; //johnfitz -- alpha support } @@ -1304,7 +1304,7 @@ void SV_SaveSpawnparms(void) continue; // call the progs to get default spawn parms for the new client - G_INT(GBL_self) = EDICT_TO_PROG(host_client->edict); + G_PEDICT(GBL_self) = EDICT_TO_PROG(host_client->edict); PR_ExecuteProgram(G_FUNC(GBL_SetChangeParms)); for(j = 0 ; j < NUM_SPAWN_PARMS ; j++) host_client->spawn_parms[j] = (&G_FLOAT(GBL_parm1))[j]; diff --git a/source/sv_move.c b/source/sv_move.c index 54cef0b..c43546c 100644 --- a/source/sv_move.c +++ b/source/sv_move.c @@ -128,10 +128,10 @@ bool SV_movestep(edict_t *ent, vec3_t move, bool relink) for(i = 0 ; i < 2 ; i++) { VectorAdd(ED_VECTOR(ent, ED_origin), move, neworg); - enemy = PROG_TO_EDICT(ED_INT(ent, ED_enemy)); + enemy = PROG_TO_EDICT(ED_PEDICT(ent, ED_enemy)); if(i == 0 && enemy != sv.edicts) { - dz = ED_VECTOR(ent, ED_origin)[2] - ED_VECTOR(PROG_TO_EDICT(ED_INT(ent, ED_enemy)), ED_origin)[2]; + dz = ED_VECTOR(ent, ED_origin)[2] - ED_VECTOR(PROG_TO_EDICT(ED_PEDICT(ent, ED_enemy)), ED_origin)[2]; if(dz > 40) neworg[2] -= 8; if(dz < 30) @@ -212,7 +212,7 @@ bool SV_movestep(edict_t *ent, vec3_t move, bool relink) // Con_Printf ("back on ground\n"); ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) & ~FL_PARTIALGROUND; } - ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); + ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); // the move is ok if(relink) @@ -399,8 +399,8 @@ void SV_MoveToGoal(void) edict_t *ent, *goal; float dist; - ent = PROG_TO_EDICT(G_INT(GBL_self)); - goal = PROG_TO_EDICT(ED_INT(ent, ED_goalentity)); + ent = PROG_TO_EDICT(G_PEDICT(GBL_self)); + goal = PROG_TO_EDICT(ED_PEDICT(ent, ED_goalentity)); dist = G_FLOAT(GBL_PARM0); if(!((int32_t)ED_FLOAT(ent, ED_flags) & (FL_ONGROUND | FL_FLY | FL_SWIM))) @@ -410,7 +410,7 @@ void SV_MoveToGoal(void) } // if the next step hits the enemy, return immediately - if(PROG_TO_EDICT(ED_INT(ent, ED_enemy)) != sv.edicts && SV_CloseEnough(ent, goal, dist)) + if(PROG_TO_EDICT(ED_PEDICT(ent, ED_enemy)) != sv.edicts && SV_CloseEnough(ent, goal, dist)) return; // bump around... diff --git a/source/sv_phys.c b/source/sv_phys.c index 3e1aa44..251da69 100644 --- a/source/sv_phys.c +++ b/source/sv_phys.c @@ -95,12 +95,12 @@ void SV_CheckVelocity(edict_t *ent) { if(isnan(ED_VECTOR(ent, ED_velocity)[i])) { - Con_Printf("Got a NaN velocity on %s\n", PR_GetString(ED_RSTRING(ent, ED_classname))); + Con_Printf("Got a NaN velocity on %s\n", ED_STRING(ent, ED_classname)); ED_VECTOR(ent, ED_velocity)[i] = 0; } if(isnan(ED_VECTOR(ent, ED_origin)[i])) { - Con_Printf("Got a NaN origin on %s\n", PR_GetString(ED_RSTRING(ent, ED_classname))); + Con_Printf("Got a NaN origin on %s\n", ED_STRING(ent, ED_classname)); ED_VECTOR(ent, ED_origin)[i] = 0; } if(ED_VECTOR(ent, ED_velocity)[i] > sv_maxvelocity.value) @@ -139,8 +139,8 @@ bool SV_RunThink(edict_t *ent) ED_FLOAT(ent, ED_nextthink) = 0; G_FLOAT(GBL_time) = thinktime; - G_INT(GBL_self) = EDICT_TO_PROG(ent); - G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts); + G_PEDICT(GBL_self) = EDICT_TO_PROG(ent); + G_PEDICT(GBL_other) = EDICT_TO_PROG(sv.edicts); PR_ExecuteProgram(ED_FUNC(ent, ED_think)); //johnfitz -- PROTOCOL_FITZQUAKE @@ -167,28 +167,28 @@ Two entities have touched, so run their touch functions */ void SV_Impact(edict_t *e1, edict_t *e2) { - int32_t old_self, old_other; + pedict_t old_self, old_other; - old_self = G_INT(GBL_self); - old_other = G_INT(GBL_other); + old_self = G_PEDICT(GBL_self); + old_other = G_PEDICT(GBL_other); G_FLOAT(GBL_time) = sv.time; if(ED_FUNC(e1, ED_touch) && ED_FLOAT(e1, ED_solid) != SOLID_NOT) { - G_INT(GBL_self) = EDICT_TO_PROG(e1); - G_INT(GBL_other) = EDICT_TO_PROG(e2); + G_PEDICT(GBL_self) = EDICT_TO_PROG(e1); + G_PEDICT(GBL_other) = EDICT_TO_PROG(e2); PR_ExecuteProgram(ED_FUNC(e1, ED_touch)); } if(ED_FUNC(e2, ED_touch) && ED_FLOAT(e2, ED_solid) != SOLID_NOT) { - G_INT(GBL_self) = EDICT_TO_PROG(e2); - G_INT(GBL_other) = EDICT_TO_PROG(e1); + G_PEDICT(GBL_self) = EDICT_TO_PROG(e2); + G_PEDICT(GBL_other) = EDICT_TO_PROG(e1); PR_ExecuteProgram(ED_FUNC(e2, ED_touch)); } - G_INT(GBL_self) = old_self; - G_INT(GBL_other) = old_other; + G_PEDICT(GBL_self) = old_self; + G_PEDICT(GBL_other) = old_other; } @@ -301,7 +301,7 @@ int32_t SV_FlyMove(edict_t *ent, float time, trace_t *steptrace) if(ED_FLOAT(trace.ent, ED_solid) == SOLID_BSP) { ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND; - ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); + ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); } } if(!trace.plane.normal[2]) @@ -500,7 +500,7 @@ void SV_PushMove(edict_t *pusher, float movetime) // if the entity is standing on the pusher, it will definately be moved if(!(((int32_t)ED_FLOAT(check, ED_flags) & FL_ONGROUND) - && PROG_TO_EDICT(ED_INT(check, ED_groundentity)) == pusher)) + && PROG_TO_EDICT(ED_PEDICT(check, ED_groundentity)) == pusher)) { if(ED_VECTOR(check, ED_absmin)[0] >= maxs[0] || ED_VECTOR(check, ED_absmin)[1] >= maxs[1] @@ -555,8 +555,8 @@ void SV_PushMove(edict_t *pusher, float movetime) // otherwise, just stay in place until the obstacle is gone if(ED_FUNC(pusher, ED_blocked)) { - G_INT(GBL_self) = EDICT_TO_PROG(pusher); - G_INT(GBL_other) = EDICT_TO_PROG(check); + G_PEDICT(GBL_self) = EDICT_TO_PROG(pusher); + G_PEDICT(GBL_other) = EDICT_TO_PROG(check); PR_ExecuteProgram(ED_FUNC(pusher, ED_blocked)); } @@ -608,8 +608,8 @@ void SV_Physics_Pusher(edict_t *ent) { ED_FLOAT(ent, ED_nextthink) = 0; G_FLOAT(GBL_time) = sv.time; - G_INT(GBL_self) = EDICT_TO_PROG(ent); - G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts); + G_PEDICT(GBL_self) = EDICT_TO_PROG(ent); + G_PEDICT(GBL_other) = EDICT_TO_PROG(sv.edicts); PR_ExecuteProgram(ED_FUNC(ent, ED_think)); if(ent->free) return; @@ -913,7 +913,7 @@ void SV_WalkMove(edict_t *ent) if(ED_FLOAT(ent, ED_solid) == SOLID_BSP) { ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND; - ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(downtrace.ent); + ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(downtrace.ent); } } else @@ -943,7 +943,7 @@ void SV_Physics_Client(edict_t *ent, int32_t num) // call standard client pre-think // G_FLOAT(GBL_time) = sv.time; - G_INT(GBL_self) = EDICT_TO_PROG(ent); + G_PEDICT(GBL_self) = EDICT_TO_PROG(ent); PR_ExecuteProgram(G_FUNC(GBL_PlayerPreThink)); // @@ -997,7 +997,7 @@ void SV_Physics_Client(edict_t *ent, int32_t num) SV_LinkEdict(ent, true); G_FLOAT(GBL_time) = sv.time; - G_INT(GBL_self) = EDICT_TO_PROG(ent); + G_PEDICT(GBL_self) = EDICT_TO_PROG(ent); PR_ExecuteProgram(G_FUNC(GBL_PlayerPostThink)); } @@ -1137,7 +1137,7 @@ void SV_Physics_Toss(edict_t *ent) if(ED_VECTOR(ent, ED_velocity)[2] < 60 || ED_FLOAT(ent, ED_movetype) != MOVETYPE_BOUNCE) { ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND; - ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); + ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent); VectorCopy(vec3_origin, ED_VECTOR(ent, ED_velocity)); VectorCopy(vec3_origin, ED_VECTOR(ent, ED_avelocity)); } @@ -1212,8 +1212,8 @@ void SV_Physics(void) edict_t *ent; // let the progs know that a new frame has started - G_INT(GBL_self) = EDICT_TO_PROG(sv.edicts); - G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts); + G_PEDICT(GBL_self) = EDICT_TO_PROG(sv.edicts); + G_PEDICT(GBL_other) = EDICT_TO_PROG(sv.edicts); G_FLOAT(GBL_time) = sv.time; PR_ExecuteProgram(G_FUNC(GBL_StartFrame)); diff --git a/source/world.c b/source/world.c index 6e364ea..dac5525 100644 --- a/source/world.c +++ b/source/world.c @@ -142,13 +142,13 @@ hull_t *SV_HullForEntity(edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset) // explicit hulls in the BSP model if(ED_FLOAT(ent, ED_movetype) != MOVETYPE_PUSH) Host_Error("SOLID_BSP without MOVETYPE_PUSH (%s at %f %f %f)", - PR_GetString(ED_RSTRING(ent, ED_classname)), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]); + ED_STRING(ent, ED_classname), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]); model = sv.models[(int32_t)ED_FLOAT(ent, ED_modelindex) ]; if(!model || model->type != mod_brush) Host_Error("SOLID_BSP with a non bsp model (%s at %f %f %f)", - PR_GetString(ED_RSTRING(ent, ED_classname)), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]); + ED_STRING(ent, ED_classname), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]); VectorSubtract(maxs, mins, size); if(size[0] < 3) @@ -364,16 +364,16 @@ void SV_TouchLinks(edict_t *ent) || ED_VECTOR(ent, ED_absmax)[1] < ED_VECTOR(touch, ED_absmin)[1] || ED_VECTOR(ent, ED_absmax)[2] < ED_VECTOR(touch, ED_absmin)[2]) continue; - old_self = G_INT(GBL_self); - old_other = G_INT(GBL_other); + old_self = G_PEDICT(GBL_self); + old_other = G_PEDICT(GBL_other); - G_INT(GBL_self) = EDICT_TO_PROG(touch); - G_INT(GBL_other) = EDICT_TO_PROG(ent); + G_PEDICT(GBL_self) = EDICT_TO_PROG(touch); + G_PEDICT(GBL_other) = EDICT_TO_PROG(ent); G_FLOAT(GBL_time) = sv.time; PR_ExecuteProgram(ED_FUNC(touch, ED_touch)); - G_INT(GBL_self) = old_self; - G_INT(GBL_other) = old_other; + G_PEDICT(GBL_self) = old_self; + G_PEDICT(GBL_other) = old_other; } // free hunk-allocated edicts array @@ -820,10 +820,10 @@ void SV_ClipToLinks(areanode_t *node, moveclip_t *clip) return; if(clip->passedict) { - if(PROG_TO_EDICT(ED_INT(touch, ED_owner)) == clip->passedict) - continue; // don't clip against own missiles - if(PROG_TO_EDICT(ED_INT(clip->passedict, ED_owner)) == touch) - continue; // don't clip against owner + if(PROG_TO_EDICT(ED_PEDICT(touch, ED_owner)) == clip->passedict) + continue; // don't clip against own missiles + if(PROG_TO_EDICT(ED_PEDICT(clip->passedict, ED_owner)) == touch) + continue; // don't clip against owner } if((int32_t)ED_FLOAT(touch, ED_flags) & FL_MONSTER)