eliminate GetEdictFieldValue, mostly merge SV_AddGravity, and clean up

some whitespace in sv_phys.c
This commit is contained in:
Bill Currie 2002-02-25 07:44:17 +00:00
parent cd29f8b9a0
commit 9ea013888b
9 changed files with 75 additions and 110 deletions

View file

@ -206,19 +206,6 @@ ED_Free (progs_t * pr, edict_t *ed)
//=========================================================================== //===========================================================================
pr_type_t *
GetEdictFieldValue (progs_t * pr, edict_t *ed, const char *field)
{
ddef_t *def;
def = ED_FindField (pr, field);
if (!def)
return NULL;
return &ed->v[def->ofs];
}
/* /*
PR_ValueString PR_ValueString

View file

@ -1049,7 +1049,6 @@ Host_Give_f (void)
{ {
char *t; char *t;
int v; int v;
eval_t *val;
if (cmd_source == src_command) { if (cmd_source == src_command) {
Cmd_ForwardToServer (); Cmd_ForwardToServer ();
@ -1099,84 +1098,61 @@ Host_Give_f (void)
case 's': case 's':
if (rogue) { if (rogue) {
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_shells1"); SVfloat (sv_player, ammo_shells1) = v;
if (val)
val->_float = v;
} }
SVfloat (sv_player, ammo_shells) = v; SVfloat (sv_player, ammo_shells) = v;
break; break;
case 'n': case 'n':
if (rogue) { if (rogue) {
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_nails1"); SVfloat (sv_player, ammo_nails1) = v;
if (val) {
val->_float = v;
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING) if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
SVfloat (sv_player, ammo_nails) = v; SVfloat (sv_player, ammo_nails) = v;
}
} else { } else {
SVfloat (sv_player, ammo_nails) = v; SVfloat (sv_player, ammo_nails) = v;
} }
break; break;
case 'l': case 'l':
if (rogue) { if (rogue) {
val = SVfloat (sv_player, ammo_lava_nails) = v;
GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_lava_nails");
if (val) {
val->_float = v;
if (SVfloat (sv_player, weapon) > IT_LIGHTNING) if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
SVfloat (sv_player, ammo_nails) = v; SVfloat (sv_player, ammo_nails) = v;
} }
}
break; break;
case 'r': case 'r':
if (rogue) { if (rogue) {
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_rockets1"); SVfloat (sv_player, ammo_rockets1) = v;
if (val) {
val->_float = v;
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING) if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
SVfloat (sv_player, ammo_rockets) = v; SVfloat (sv_player, ammo_rockets) = v;
}
} else { } else {
SVfloat (sv_player, ammo_rockets) = v; SVfloat (sv_player, ammo_rockets) = v;
} }
break; break;
case 'm': case 'm':
if (rogue) { if (rogue) {
val = SVfloat (sv_player, ammo_multi_rockets) = 0;
GetEdictFieldValue (&sv_pr_state, sv_player,
"ammo_multi_rockets");
if (val) {
val->_float = v;
if (SVfloat (sv_player, weapon) > IT_LIGHTNING) if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
SVfloat (sv_player, ammo_rockets) = v; SVfloat (sv_player, ammo_rockets) = v;
} }
}
break; break;
case 'h': case 'h':
SVfloat (sv_player, health) = v; SVfloat (sv_player, health) = v;
break; break;
case 'c': case 'c':
if (rogue) { if (rogue) {
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_cells1"); SVfloat (sv_player, ammo_cells1) = v;
if (val) {
val->_float = v;
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING) if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
SVfloat (sv_player, ammo_cells) = v; SVfloat (sv_player, ammo_cells) = v;
}
} else { } else {
SVfloat (sv_player, ammo_cells) = v; SVfloat (sv_player, ammo_cells) = v;
} }
break; break;
case 'p': case 'p':
if (rogue) { if (rogue) {
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_plasma"); SVfloat (sv_player, ammo_plasma) = v;
if (val) {
val->_float = v;
if (SVfloat (sv_player, weapon) > IT_LIGHTNING) if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
SVfloat (sv_player, ammo_cells) = v; SVfloat (sv_player, ammo_cells) = v;
} }
}
break; break;
} }
} }

View file

@ -513,7 +513,6 @@ SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
{ {
int bits, items, i; int bits, items, i;
edict_t *other; edict_t *other;
pr_type_t *val;
// send a damage message // send a damage message
if (SVfloat (ent, dmg_take) || SVfloat (ent, dmg_save)) { if (SVfloat (ent, dmg_take) || SVfloat (ent, dmg_save)) {
@ -549,13 +548,12 @@ SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
// stuff the sigil bits into the high bits of items for sbar, or else // stuff the sigil bits into the high bits of items for sbar, or else
// mix in items2 // mix in items2
val = GetEdictFieldValue (&sv_pr_state, ent, "items2"); if (sv_fields.items2 != -1)
items = (int) SVfloat (ent, items) | ((int) SVfloat (ent, items2)
if (val) << 23);
items = (int) SVfloat (ent, items) | ((int) val->float_var << 23);
else else
items = (int) SVfloat (ent, items) | ((int) *sv_globals.serverflags << items = (int) SVfloat (ent, items) | ((int) *sv_globals.serverflags
28); << 28);
bits |= SU_ITEMS; bits |= SU_ITEMS;

View file

@ -354,11 +354,8 @@ SV_AddGravity (edict_t *ent)
{ {
float ent_gravity; float ent_gravity;
pr_type_t *val; if (sv_fields.gravity != -1 && SVfloat (ent, gravity))
ent_gravity = SVfloat (ent, gravity);
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
if (val && val->float_var)
ent_gravity = val->float_var;
else else
ent_gravity = 1.0; ent_gravity = 1.0;
SVvector (ent, velocity)[2] -= ent_gravity * sv_gravity->value * sv_frametime; SVvector (ent, velocity)[2] -= ent_gravity * sv_gravity->value * sv_frametime;
@ -382,8 +379,8 @@ SV_PushEntity (edict_t *ent, vec3_t push)
if (SVfloat (ent, movetype) == MOVETYPE_FLYMISSILE) if (SVfloat (ent, movetype) == MOVETYPE_FLYMISSILE)
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins), trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
SVvector (ent, maxs), end, MOVE_MISSILE, ent); SVvector (ent, maxs), end, MOVE_MISSILE, ent);
else if (SVfloat (ent, solid) == SOLID_TRIGGER || SVfloat (ent, solid) == else if (SVfloat (ent, solid) == SOLID_TRIGGER
SOLID_NOT) || SVfloat (ent, solid) == SOLID_NOT)
// only clip against bmodels // only clip against bmodels
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins), trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
SVvector (ent, maxs), end, MOVE_NOMONSTERS, ent); SVvector (ent, maxs), end, MOVE_NOMONSTERS, ent);
@ -665,8 +662,8 @@ SV_Physics_Toss (edict_t *ent)
// stop if on ground // stop if on ground
if (trace.plane.normal[2] > 0.7) { if (trace.plane.normal[2] > 0.7) {
if (SVvector (ent, velocity)[2] < 60 || SVfloat (ent, movetype) != if (SVvector (ent, velocity)[2] < 60
MOVETYPE_BOUNCE) { || SVfloat (ent, movetype) != MOVETYPE_BOUNCE) {
SVfloat (ent, flags) = (int) SVfloat (ent, flags) | FL_ONGROUND; SVfloat (ent, flags) = (int) SVfloat (ent, flags) | FL_ONGROUND;
SVentity (ent, groundentity) = EDICT_TO_PROG (&sv_pr_state, SVentity (ent, groundentity) = EDICT_TO_PROG (&sv_pr_state,
trace.ent); trace.ent);
@ -706,8 +703,7 @@ SV_Physics_Step (edict_t *ent)
SV_FlyMove (ent, sv_frametime, NULL); SV_FlyMove (ent, sv_frametime, NULL);
SV_LinkEdict (ent, true); SV_LinkEdict (ent, true);
if ((int) SVfloat (ent, flags) & FL_ONGROUND) // just hit ground if ((int) SVfloat (ent, flags) & FL_ONGROUND) { // just hit ground
{
if (hitsound) if (hitsound)
SV_StartSound (ent, 0, "demon/dland2.wav", 255, 1); SV_StartSound (ent, 0, "demon/dland2.wav", 255, 1);
} }

View file

@ -156,6 +156,9 @@ typedef struct
int glow_size; int glow_size;
int glow_color; int glow_color;
int colormod; int colormod;
int gravity;
int maxspeed;
} sv_fields_t; } sv_fields_t;
extern sv_fields_t sv_fields; extern sv_fields_t sv_fields;

View file

@ -350,7 +350,13 @@ SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
void void
SV_AddGravity (edict_t *ent) SV_AddGravity (edict_t *ent)
{ {
SVvector (ent, velocity)[2] -= movevars.gravity * sv_frametime; float ent_gravity;
if (sv_fields.gravity != -1 && SVfloat (ent, gravity))
ent_gravity = SVfloat (ent, gravity);
else
ent_gravity = 1.0;
SVvector (ent, velocity)[2] -= ent_gravity * movevars.gravity * sv_frametime;
} }
/* PUSHMOVE */ /* PUSHMOVE */
@ -371,8 +377,8 @@ SV_PushEntity (edict_t *ent, vec3_t push)
if (SVfloat (ent, movetype) == MOVETYPE_FLYMISSILE) if (SVfloat (ent, movetype) == MOVETYPE_FLYMISSILE)
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins), trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
SVvector (ent, maxs), end, MOVE_MISSILE, ent); SVvector (ent, maxs), end, MOVE_MISSILE, ent);
else if (SVfloat (ent, solid) == SOLID_TRIGGER || SVfloat (ent, solid) == else if (SVfloat (ent, solid) == SOLID_TRIGGER
SOLID_NOT) || SVfloat (ent, solid) == SOLID_NOT)
// only clip against bmodels // only clip against bmodels
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins), trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
SVvector (ent, maxs), end, MOVE_NOMONSTERS, ent); SVvector (ent, maxs), end, MOVE_NOMONSTERS, ent);
@ -672,8 +678,8 @@ SV_Physics_Toss (edict_t *ent)
// stop if on ground // stop if on ground
if (trace.plane.normal[2] > 0.7) { if (trace.plane.normal[2] > 0.7) {
if (SVvector (ent, velocity)[2] < 60 || SVfloat (ent, movetype) != if (SVvector (ent, velocity)[2] < 60
MOVETYPE_BOUNCE) { || SVfloat (ent, movetype) != MOVETYPE_BOUNCE) {
SVfloat (ent, flags) = (int) SVfloat (ent, flags) | FL_ONGROUND; SVfloat (ent, flags) = (int) SVfloat (ent, flags) | FL_ONGROUND;
SVentity (ent, groundentity) = EDICT_TO_PROG (&sv_pr_state, SVentity (ent, groundentity) = EDICT_TO_PROG (&sv_pr_state,
trace.ent); trace.ent);
@ -714,8 +720,7 @@ SV_Physics_Step (edict_t *ent)
SV_FlyMove (ent, sv_frametime, NULL); SV_FlyMove (ent, sv_frametime, NULL);
SV_LinkEdict (ent, true); SV_LinkEdict (ent, true);
if ((int) SVfloat (ent, flags) & FL_ONGROUND) // just hit ground if ((int) SVfloat (ent, flags) & FL_ONGROUND) { // just hit ground
{
if (hitsound) if (hitsound)
SV_StartSound (ent, 0, "demon/dland2.wav", 255, 1); SV_StartSound (ent, 0, "demon/dland2.wav", 255, 1);
} }
@ -812,8 +817,9 @@ SV_Physics (void)
SV_LinkEdict (ent, true); // force retouch even for stationary SV_LinkEdict (ent, true); // force retouch even for stationary
} }
if (i > 0 && i <= MAX_CLIENTS) if (i > 0 && i <= MAX_CLIENTS) {
continue; // clients are run directly from packets continue; // clients are run directly from packets
}
SV_RunEntity (ent); SV_RunEntity (ent);
SV_RunNewmis (); SV_RunNewmis ();

View file

@ -339,6 +339,9 @@ SV_LoadProgs (void)
sv_fields.glow_color = ED_GetFieldIndex (&sv_pr_state, "glow_color"); sv_fields.glow_color = ED_GetFieldIndex (&sv_pr_state, "glow_color");
sv_fields.colormod = ED_GetFieldIndex (&sv_pr_state, "colormod"); sv_fields.colormod = ED_GetFieldIndex (&sv_pr_state, "colormod");
sv_fields.gravity = ED_GetFieldIndex (&sv_pr_state, "gravity");
sv_fields.maxspeed = ED_GetFieldIndex (&sv_pr_state, "maxspeed");
def = PR_FindGlobal (&sv_pr_state, "current_skill"); def = PR_FindGlobal (&sv_pr_state, "current_skill");
if (def) if (def)
sv_globals.current_skill = (float *) &sv_pr_state.pr_globals[def->ofs]; sv_globals.current_skill = (float *) &sv_pr_state.pr_globals[def->ofs];

View file

@ -660,7 +660,6 @@ SV_UpdateToReliableMessages (void)
client_t *client; client_t *client;
edict_t *ent; edict_t *ent;
int i, j; int i, j;
pr_type_t *val;
// check for changes to be sent over the reliable streams to all clients // check for changes to be sent over the reliable streams to all clients
for (i = 0, host_client = svs.clients; i < MAX_CLIENTS; i++, host_client++) { for (i = 0, host_client = svs.clients; i < MAX_CLIENTS; i++, host_client++) {
@ -685,15 +684,15 @@ SV_UpdateToReliableMessages (void)
// maxspeed/entgravity changes // maxspeed/entgravity changes
ent = host_client->edict; ent = host_client->edict;
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity"); if (sv_fields.gravity != -1
if (val && host_client->entgravity != val->float_var) { && host_client->entgravity != SVfloat (ent, gravity)) {
host_client->entgravity = val->float_var; host_client->entgravity = SVfloat (ent, gravity);
ClientReliableWrite_Begin (host_client, svc_entgravity, 5); ClientReliableWrite_Begin (host_client, svc_entgravity, 5);
ClientReliableWrite_Float (host_client, host_client->entgravity); ClientReliableWrite_Float (host_client, host_client->entgravity);
} }
val = GetEdictFieldValue (&sv_pr_state, ent, "maxspeed"); if (sv_fields.maxspeed != -1
if (val && host_client->maxspeed != val->float_var) { && host_client->maxspeed != SVfloat (ent, maxspeed)) {
host_client->maxspeed = val->float_var; host_client->maxspeed = SVfloat (ent, maxspeed);
ClientReliableWrite_Begin (host_client, svc_maxspeed, 5); ClientReliableWrite_Begin (host_client, svc_maxspeed, 5);
ClientReliableWrite_Float (host_client, host_client->maxspeed); ClientReliableWrite_Float (host_client, host_client->maxspeed);
} }

View file

@ -333,7 +333,6 @@ SV_Spawn_f (void)
int i; int i;
client_t *client; client_t *client;
edict_t *ent; edict_t *ent;
pr_type_t *val;
int n; int n;
if (host_client->state != cs_connected) { if (host_client->state != cs_connected) {
@ -397,13 +396,11 @@ SV_Spawn_f (void)
SVstring (ent, netname) = PR_SetString (&sv_pr_state, host_client->name); SVstring (ent, netname) = PR_SetString (&sv_pr_state, host_client->name);
host_client->entgravity = 1.0; host_client->entgravity = 1.0;
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity"); if (sv_fields.gravity != -1)
if (val) SVfloat (ent, gravity) = 1.0;
val->float_var = 1.0;
host_client->maxspeed = sv_maxspeed->value; host_client->maxspeed = sv_maxspeed->value;
val = GetEdictFieldValue (&sv_pr_state, ent, "maxspeed"); if (sv_fields.maxspeed != -1)
if (val) SVfloat (ent, gravity) = sv_maxspeed->value;
val->float_var = sv_maxspeed->value;
// //
// force stats to be updated // force stats to be updated