mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
edict field access type checking :) Currently forced on, but it will become a
configure option in the future
This commit is contained in:
parent
68220d1fb0
commit
10e6b7af84
9 changed files with 38 additions and 22 deletions
|
@ -33,7 +33,16 @@
|
|||
|
||||
#include "qtypes.h"
|
||||
|
||||
typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t;
|
||||
typedef enum {
|
||||
ev_void,
|
||||
ev_string,
|
||||
ev_float,
|
||||
ev_vector,
|
||||
ev_entity,
|
||||
ev_field,
|
||||
ev_func,
|
||||
ev_pointer
|
||||
} etype_t;
|
||||
|
||||
#define OFS_NULL 0
|
||||
#define OFS_RETURN 1
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef union pr_type_u {
|
|||
int int_var;
|
||||
string_t string_var;
|
||||
func_t func_var;
|
||||
int edict_var;
|
||||
int entity_var;
|
||||
float vector_var[1]; // really 3, but this structure must be 32 bits
|
||||
} pr_type_t;
|
||||
|
||||
|
|
|
@ -151,7 +151,11 @@ typedef struct
|
|||
|
||||
extern sv_fields_t sv_fields;
|
||||
|
||||
#if 1
|
||||
#define SVFIELD(e,f,t) ((ED_FindField (&sv_pr_state, #f)->type == ev_##t) ? E_var (e, sv_fields.f, t) : PR_Error (&sv_pr_state, "bad type access %s:%d", __FILE__, __LINE__), E_var (e, sv_fields.f, t))
|
||||
#else
|
||||
#define SVFIELD(e,f,t) E_var (e, sv_fields.f, t)
|
||||
#endif
|
||||
|
||||
#define PROGHEADER_CRC 54730
|
||||
|
||||
|
|
|
@ -138,11 +138,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 (SVFIELD (ent, origin, vector), move, neworg);
|
||||
enemy = PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, enemy, int));
|
||||
enemy = PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, enemy, entity));
|
||||
if (i == 0 && enemy != sv.edicts) {
|
||||
dz =
|
||||
SVFIELD (ent, origin, vector)[2] -
|
||||
SVFIELD (PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, enemy, int)), origin, vector)[2];
|
||||
SVFIELD (PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, enemy, entity)), origin, vector)[2];
|
||||
if (dz > 40)
|
||||
neworg[2] -= 8;
|
||||
if (dz < 30)
|
||||
|
@ -218,7 +218,7 @@ SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
|
|||
// Con_Printf ("back on ground\n");
|
||||
SVFIELD (ent, flags, float) = (int) SVFIELD (ent, flags, float) & ~FL_PARTIALGROUND;
|
||||
}
|
||||
SVFIELD (ent, groundentity, int) = EDICT_TO_PROG (&sv_pr_state, trace.ent);
|
||||
SVFIELD (ent, groundentity, entity) = EDICT_TO_PROG (&sv_pr_state, trace.ent);
|
||||
|
||||
// the move is ok
|
||||
if (relink)
|
||||
|
@ -385,7 +385,7 @@ SV_MoveToGoal (progs_t *pr)
|
|||
float dist;
|
||||
|
||||
ent = PROG_TO_EDICT (&sv_pr_state, *sv_globals.self);
|
||||
goal = PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, goalentity, int));
|
||||
goal = PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, goalentity, entity));
|
||||
dist = G_FLOAT (&sv_pr_state, OFS_PARM0);
|
||||
|
||||
if (!((int) SVFIELD (ent, flags, float) & (FL_ONGROUND | FL_FLY | FL_SWIM))) {
|
||||
|
@ -393,7 +393,7 @@ SV_MoveToGoal (progs_t *pr)
|
|||
return;
|
||||
}
|
||||
// if the next step hits the enemy, return immediately
|
||||
if (PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, enemy, int)) != sv.edicts
|
||||
if (PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, enemy, entity)) != sv.edicts
|
||||
&& SV_CloseEnough (ent, goal, dist)) return;
|
||||
|
||||
// bump around...
|
||||
|
|
|
@ -294,7 +294,7 @@ SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
|
|||
if ((SVFIELD (trace.ent, solid, float) == SOLID_BSP)
|
||||
|| (SVFIELD (trace.ent, movetype, float) == MOVETYPE_PPUSH)) {
|
||||
SVFIELD (ent, flags, float) = (int) SVFIELD (ent, flags, float) | FL_ONGROUND;
|
||||
SVFIELD (ent, groundentity, int) = EDICT_TO_PROG (&sv_pr_state, trace.ent);
|
||||
SVFIELD (ent, groundentity, entity) = EDICT_TO_PROG (&sv_pr_state, trace.ent);
|
||||
}
|
||||
}
|
||||
if (!trace.plane.normal[2]) {
|
||||
|
@ -464,7 +464,7 @@ SV_Push (edict_t *pusher, vec3_t move)
|
|||
// if the entity is standing on the pusher, it will definately be
|
||||
// moved
|
||||
if (!(((int) SVFIELD (check, flags, float) & FL_ONGROUND)
|
||||
&& PROG_TO_EDICT (&sv_pr_state, SVFIELD (check, groundentity, int)) == pusher)) {
|
||||
&& PROG_TO_EDICT (&sv_pr_state, SVFIELD (check, groundentity, entity)) == pusher)) {
|
||||
if (SVFIELD (check, absmin, vector)[0] >= maxs[0]
|
||||
|| SVFIELD (check, absmin, vector)[1] >= maxs[1]
|
||||
|| SVFIELD (check, absmin, vector)[2] >= maxs[2]
|
||||
|
@ -719,7 +719,7 @@ SV_Physics_Toss (edict_t *ent)
|
|||
if (trace.plane.normal[2] > 0.7) {
|
||||
if (SVFIELD (ent, velocity, vector)[2] < 60 || SVFIELD (ent, movetype, float) != MOVETYPE_BOUNCE) {
|
||||
SVFIELD (ent, flags, float) = (int) SVFIELD (ent, flags, float) | FL_ONGROUND;
|
||||
SVFIELD (ent, groundentity, int) = EDICT_TO_PROG (&sv_pr_state, trace.ent);
|
||||
SVFIELD (ent, groundentity, entity) = EDICT_TO_PROG (&sv_pr_state, trace.ent);
|
||||
VectorCopy (vec3_origin, SVFIELD (ent, velocity, vector));
|
||||
VectorCopy (vec3_origin, SVFIELD (ent, avelocity, vector));
|
||||
}
|
||||
|
|
|
@ -789,7 +789,7 @@ PF_findradius (progs_t *pr)
|
|||
if (Length (eorg) > rad)
|
||||
continue;
|
||||
|
||||
SVFIELD (ent, chain, int) = EDICT_TO_PROG (pr, chain);
|
||||
SVFIELD (ent, chain, entity) = EDICT_TO_PROG (pr, chain);
|
||||
chain = ent;
|
||||
}
|
||||
|
||||
|
@ -1055,7 +1055,7 @@ PF_droptofloor (progs_t *pr)
|
|||
VectorCopy (trace.endpos, SVFIELD (ent, origin, vector));
|
||||
SV_LinkEdict (ent, false);
|
||||
SVFIELD (ent, flags, float) = (int) SVFIELD (ent, flags, float) | FL_ONGROUND;
|
||||
SVFIELD (ent, groundentity, int) = EDICT_TO_PROG (pr, trace.ent);
|
||||
SVFIELD (ent, groundentity, entity) = EDICT_TO_PROG (pr, trace.ent);
|
||||
G_FLOAT (pr, OFS_RETURN) = 1;
|
||||
}
|
||||
}
|
||||
|
@ -1461,12 +1461,15 @@ PF_makestatic (progs_t *pr)
|
|||
{
|
||||
edict_t *ent;
|
||||
int i;
|
||||
char *model;
|
||||
|
||||
ent = G_EDICT (pr, OFS_PARM0);
|
||||
|
||||
MSG_WriteByte (&sv.signon, svc_spawnstatic);
|
||||
|
||||
MSG_WriteByte (&sv.signon, SV_ModelIndex (PR_GetString (pr, SVFIELD (ent, model, float))));
|
||||
model = PR_GetString (pr, SVFIELD (ent, model, string));
|
||||
//Con_Printf ("Model: %d %s\n", SVFIELD (ent, model, string), model);
|
||||
MSG_WriteByte (&sv.signon, SV_ModelIndex (model));
|
||||
|
||||
MSG_WriteByte (&sv.signon, SVFIELD (ent, frame, float));
|
||||
MSG_WriteByte (&sv.signon, SVFIELD (ent, colormap, float));
|
||||
|
|
|
@ -504,7 +504,7 @@ SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg)
|
|||
}
|
||||
// send a damage message if the player got hit this frame
|
||||
if (SVFIELD (ent, dmg_take, float) || SVFIELD (ent, dmg_save, float)) {
|
||||
other = PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, dmg_inflictor, int));
|
||||
other = PROG_TO_EDICT (&sv_pr_state, SVFIELD (ent, dmg_inflictor, entity));
|
||||
MSG_WriteByte (msg, svc_damage);
|
||||
MSG_WriteByte (msg, SVFIELD (ent, dmg_save, float));
|
||||
MSG_WriteByte (msg, SVFIELD (ent, dmg_take, float));
|
||||
|
|
|
@ -1008,7 +1008,7 @@ SV_PTrack_f (void)
|
|||
host_client->spec_track = 0;
|
||||
ent = EDICT_NUM (&sv_pr_state, host_client - svs.clients + 1);
|
||||
tent = EDICT_NUM (&sv_pr_state, 0);
|
||||
SVFIELD (ent, goalentity, int) = EDICT_TO_PROG (&sv_pr_state, tent);
|
||||
SVFIELD (ent, goalentity, entity) = EDICT_TO_PROG (&sv_pr_state, tent);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1019,14 +1019,14 @@ SV_PTrack_f (void)
|
|||
host_client->spec_track = 0;
|
||||
ent = EDICT_NUM (&sv_pr_state, host_client - svs.clients + 1);
|
||||
tent = EDICT_NUM (&sv_pr_state, 0);
|
||||
SVFIELD (ent, goalentity, int) = EDICT_TO_PROG (&sv_pr_state, tent);
|
||||
SVFIELD (ent, goalentity, entity) = EDICT_TO_PROG (&sv_pr_state, tent);
|
||||
return;
|
||||
}
|
||||
host_client->spec_track = i + 1; // now tracking
|
||||
|
||||
ent = EDICT_NUM (&sv_pr_state, host_client - svs.clients + 1);
|
||||
tent = EDICT_NUM (&sv_pr_state, i + 1);
|
||||
SVFIELD (ent, goalentity, int) = EDICT_TO_PROG (&sv_pr_state, tent);
|
||||
SVFIELD (ent, goalentity, entity) = EDICT_TO_PROG (&sv_pr_state, tent);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1287,7 +1287,7 @@ AddLinksToPmove (areanode_t *node)
|
|||
next = l->next;
|
||||
check = EDICT_FROM_AREA (l);
|
||||
|
||||
if (SVFIELD (check, owner, int) == pl)
|
||||
if (SVFIELD (check, owner, entity) == pl)
|
||||
continue; // player's own missile
|
||||
if (SVFIELD (check, solid, float) == SOLID_BSP
|
||||
|| SVFIELD (check, solid, float) == SOLID_BBOX || SVFIELD (check, solid, float) == SOLID_SLIDEBOX) {
|
||||
|
@ -1350,7 +1350,7 @@ AddAllEntsToPmove (void)
|
|||
check = NEXT_EDICT (&sv_pr_state, check)) {
|
||||
if (check->free)
|
||||
continue;
|
||||
if (SVFIELD (check, owner, int) == pl)
|
||||
if (SVFIELD (check, owner, entity) == pl)
|
||||
continue;
|
||||
if (SVFIELD (check, solid, float) == SOLID_BSP
|
||||
|| SVFIELD (check, solid, float) == SOLID_BBOX
|
||||
|
@ -1547,7 +1547,7 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside)
|
|||
SVFIELD (sv_player, watertype, float) = watertype;
|
||||
if (onground != -1) {
|
||||
SVFIELD (sv_player, flags, float) = (int) SVFIELD (sv_player, flags, float) | FL_ONGROUND;
|
||||
SVFIELD (sv_player, groundentity, int) =
|
||||
SVFIELD (sv_player, groundentity, entity) =
|
||||
EDICT_TO_PROG (&sv_pr_state, EDICT_NUM (&sv_pr_state, pmove.physents[onground].info));
|
||||
} else {
|
||||
SVFIELD (sv_player, flags, float) = (int) SVFIELD (sv_player, flags, float) & ~FL_ONGROUND;
|
||||
|
|
|
@ -724,9 +724,9 @@ SV_ClipToLinks (areanode_t *node, moveclip_t * clip)
|
|||
if (clip->trace.allsolid)
|
||||
return;
|
||||
if (clip->passedict) {
|
||||
if (PROG_TO_EDICT (&sv_pr_state, SVFIELD (touch, owner, int)) == clip->passedict)
|
||||
if (PROG_TO_EDICT (&sv_pr_state, SVFIELD (touch, owner, entity)) == clip->passedict)
|
||||
continue; // don't clip against own missiles
|
||||
if (PROG_TO_EDICT (&sv_pr_state, SVFIELD (clip->passedict, owner, int)) == touch)
|
||||
if (PROG_TO_EDICT (&sv_pr_state, SVFIELD (clip->passedict, owner, entity)) == touch)
|
||||
continue; // don't clip against owner
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue