mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 06:10:56 +00:00
eliminate GetEdictFieldValue, mostly merge SV_AddGravity, and clean up
some whitespace in sv_phys.c
This commit is contained in:
parent
cd29f8b9a0
commit
9ea013888b
9 changed files with 75 additions and 110 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -1049,7 +1049,6 @@ Host_Give_f (void)
|
|||
{
|
||||
char *t;
|
||||
int v;
|
||||
eval_t *val;
|
||||
|
||||
if (cmd_source == src_command) {
|
||||
Cmd_ForwardToServer ();
|
||||
|
@ -1099,58 +1098,41 @@ Host_Give_f (void)
|
|||
|
||||
case 's':
|
||||
if (rogue) {
|
||||
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_shells1");
|
||||
if (val)
|
||||
val->_float = v;
|
||||
SVfloat (sv_player, ammo_shells1) = v;
|
||||
}
|
||||
|
||||
SVfloat (sv_player, ammo_shells) = v;
|
||||
break;
|
||||
case 'n':
|
||||
if (rogue) {
|
||||
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_nails1");
|
||||
if (val) {
|
||||
val->_float = v;
|
||||
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_nails) = v;
|
||||
}
|
||||
SVfloat (sv_player, ammo_nails1) = v;
|
||||
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_nails) = v;
|
||||
} else {
|
||||
SVfloat (sv_player, ammo_nails) = v;
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
if (rogue) {
|
||||
val =
|
||||
GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_lava_nails");
|
||||
if (val) {
|
||||
val->_float = v;
|
||||
if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_nails) = v;
|
||||
}
|
||||
SVfloat (sv_player, ammo_lava_nails) = v;
|
||||
if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_nails) = v;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (rogue) {
|
||||
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_rockets1");
|
||||
if (val) {
|
||||
val->_float = v;
|
||||
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_rockets) = v;
|
||||
}
|
||||
SVfloat (sv_player, ammo_rockets1) = v;
|
||||
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_rockets) = v;
|
||||
} else {
|
||||
SVfloat (sv_player, ammo_rockets) = v;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
if (rogue) {
|
||||
val =
|
||||
GetEdictFieldValue (&sv_pr_state, sv_player,
|
||||
"ammo_multi_rockets");
|
||||
if (val) {
|
||||
val->_float = v;
|
||||
if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_rockets) = v;
|
||||
}
|
||||
SVfloat (sv_player, ammo_multi_rockets) = 0;
|
||||
if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_rockets) = v;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
|
@ -1158,24 +1140,18 @@ Host_Give_f (void)
|
|||
break;
|
||||
case 'c':
|
||||
if (rogue) {
|
||||
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_cells1");
|
||||
if (val) {
|
||||
val->_float = v;
|
||||
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_cells) = v;
|
||||
}
|
||||
SVfloat (sv_player, ammo_cells1) = v;
|
||||
if (SVfloat (sv_player, weapon) <= IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_cells) = v;
|
||||
} else {
|
||||
SVfloat (sv_player, ammo_cells) = v;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if (rogue) {
|
||||
val = GetEdictFieldValue (&sv_pr_state, sv_player, "ammo_plasma");
|
||||
if (val) {
|
||||
val->_float = v;
|
||||
if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_cells) = v;
|
||||
}
|
||||
SVfloat (sv_player, ammo_plasma) = v;
|
||||
if (SVfloat (sv_player, weapon) > IT_LIGHTNING)
|
||||
SVfloat (sv_player, ammo_cells) = v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -513,7 +513,6 @@ SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
|
|||
{
|
||||
int bits, items, i;
|
||||
edict_t *other;
|
||||
pr_type_t *val;
|
||||
|
||||
// send a damage message
|
||||
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
|
||||
// mix in items2
|
||||
val = GetEdictFieldValue (&sv_pr_state, ent, "items2");
|
||||
|
||||
if (val)
|
||||
items = (int) SVfloat (ent, items) | ((int) val->float_var << 23);
|
||||
if (sv_fields.items2 != -1)
|
||||
items = (int) SVfloat (ent, items) | ((int) SVfloat (ent, items2)
|
||||
<< 23);
|
||||
else
|
||||
items = (int) SVfloat (ent, items) | ((int) *sv_globals.serverflags <<
|
||||
28);
|
||||
items = (int) SVfloat (ent, items) | ((int) *sv_globals.serverflags
|
||||
<< 28);
|
||||
|
||||
bits |= SU_ITEMS;
|
||||
|
||||
|
|
|
@ -228,14 +228,14 @@ ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
|
|||
#define MAX_CLIP_PLANES 5
|
||||
|
||||
/*
|
||||
SV_FlyMove
|
||||
SV_FlyMove
|
||||
|
||||
The basic solid body movement clip that slides along multiple planes
|
||||
Returns the clipflags if the velocity was modified (hit something solid)
|
||||
1 = floor
|
||||
2 = wall / step
|
||||
4 = dead stop
|
||||
If steptrace is not NULL, the trace of any vertical wall hit will be stored
|
||||
The basic solid body movement clip that slides along multiple planes
|
||||
Returns the clipflags if the velocity was modified (hit something solid)
|
||||
1 = floor
|
||||
2 = wall / step
|
||||
4 = dead stop
|
||||
If steptrace is not NULL, the trace of any vertical wall hit will be stored
|
||||
*/
|
||||
int
|
||||
SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
|
||||
|
@ -354,11 +354,8 @@ SV_AddGravity (edict_t *ent)
|
|||
{
|
||||
float ent_gravity;
|
||||
|
||||
pr_type_t *val;
|
||||
|
||||
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
|
||||
if (val && val->float_var)
|
||||
ent_gravity = val->float_var;
|
||||
if (sv_fields.gravity != -1 && SVfloat (ent, gravity))
|
||||
ent_gravity = SVfloat (ent, gravity);
|
||||
else
|
||||
ent_gravity = 1.0;
|
||||
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)
|
||||
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
|
||||
SVvector (ent, maxs), end, MOVE_MISSILE, ent);
|
||||
else if (SVfloat (ent, solid) == SOLID_TRIGGER || SVfloat (ent, solid) ==
|
||||
SOLID_NOT)
|
||||
else if (SVfloat (ent, solid) == SOLID_TRIGGER
|
||||
|| SVfloat (ent, solid) == SOLID_NOT)
|
||||
// only clip against bmodels
|
||||
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
|
||||
SVvector (ent, maxs), end, MOVE_NOMONSTERS, ent);
|
||||
|
@ -665,8 +662,8 @@ SV_Physics_Toss (edict_t *ent)
|
|||
|
||||
// stop if on ground
|
||||
if (trace.plane.normal[2] > 0.7) {
|
||||
if (SVvector (ent, velocity)[2] < 60 || SVfloat (ent, movetype) !=
|
||||
MOVETYPE_BOUNCE) {
|
||||
if (SVvector (ent, velocity)[2] < 60
|
||||
|| SVfloat (ent, movetype) != MOVETYPE_BOUNCE) {
|
||||
SVfloat (ent, flags) = (int) SVfloat (ent, flags) | FL_ONGROUND;
|
||||
SVentity (ent, groundentity) = EDICT_TO_PROG (&sv_pr_state,
|
||||
trace.ent);
|
||||
|
@ -706,8 +703,7 @@ SV_Physics_Step (edict_t *ent)
|
|||
SV_FlyMove (ent, sv_frametime, NULL);
|
||||
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)
|
||||
SV_StartSound (ent, 0, "demon/dland2.wav", 255, 1);
|
||||
}
|
||||
|
|
|
@ -156,6 +156,9 @@ typedef struct
|
|||
int glow_size;
|
||||
int glow_color;
|
||||
int colormod;
|
||||
|
||||
int gravity;
|
||||
int maxspeed;
|
||||
} sv_fields_t;
|
||||
|
||||
extern sv_fields_t sv_fields;
|
||||
|
|
|
@ -229,14 +229,14 @@ ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
|
|||
#define MAX_CLIP_PLANES 5
|
||||
|
||||
/*
|
||||
SV_FlyMove
|
||||
SV_FlyMove
|
||||
|
||||
The basic solid body movement clip that slides along multiple planes
|
||||
Returns the clipflags if the velocity was modified (hit something solid)
|
||||
1 = floor
|
||||
2 = wall / step
|
||||
4 = dead stop
|
||||
If steptrace is not NULL, the trace of any vertical wall hit will be stored
|
||||
The basic solid body movement clip that slides along multiple planes
|
||||
Returns the clipflags if the velocity was modified (hit something solid)
|
||||
1 = floor
|
||||
2 = wall / step
|
||||
4 = dead stop
|
||||
If steptrace is not NULL, the trace of any vertical wall hit will be stored
|
||||
*/
|
||||
int
|
||||
SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
|
||||
|
@ -350,7 +350,13 @@ SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
|
|||
void
|
||||
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 */
|
||||
|
@ -371,8 +377,8 @@ SV_PushEntity (edict_t *ent, vec3_t push)
|
|||
if (SVfloat (ent, movetype) == MOVETYPE_FLYMISSILE)
|
||||
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
|
||||
SVvector (ent, maxs), end, MOVE_MISSILE, ent);
|
||||
else if (SVfloat (ent, solid) == SOLID_TRIGGER || SVfloat (ent, solid) ==
|
||||
SOLID_NOT)
|
||||
else if (SVfloat (ent, solid) == SOLID_TRIGGER
|
||||
|| SVfloat (ent, solid) == SOLID_NOT)
|
||||
// only clip against bmodels
|
||||
trace = SV_Move (SVvector (ent, origin), SVvector (ent, mins),
|
||||
SVvector (ent, maxs), end, MOVE_NOMONSTERS, ent);
|
||||
|
@ -672,8 +678,8 @@ SV_Physics_Toss (edict_t *ent)
|
|||
|
||||
// stop if on ground
|
||||
if (trace.plane.normal[2] > 0.7) {
|
||||
if (SVvector (ent, velocity)[2] < 60 || SVfloat (ent, movetype) !=
|
||||
MOVETYPE_BOUNCE) {
|
||||
if (SVvector (ent, velocity)[2] < 60
|
||||
|| SVfloat (ent, movetype) != MOVETYPE_BOUNCE) {
|
||||
SVfloat (ent, flags) = (int) SVfloat (ent, flags) | FL_ONGROUND;
|
||||
SVentity (ent, groundentity) = EDICT_TO_PROG (&sv_pr_state,
|
||||
trace.ent);
|
||||
|
@ -714,8 +720,7 @@ SV_Physics_Step (edict_t *ent)
|
|||
SV_FlyMove (ent, sv_frametime, NULL);
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
||||
if (i > 0 && i <= MAX_CLIENTS)
|
||||
if (i > 0 && i <= MAX_CLIENTS) {
|
||||
continue; // clients are run directly from packets
|
||||
}
|
||||
|
||||
SV_RunEntity (ent);
|
||||
SV_RunNewmis ();
|
||||
|
|
|
@ -339,6 +339,9 @@ SV_LoadProgs (void)
|
|||
sv_fields.glow_color = ED_GetFieldIndex (&sv_pr_state, "glow_color");
|
||||
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");
|
||||
if (def)
|
||||
sv_globals.current_skill = (float *) &sv_pr_state.pr_globals[def->ofs];
|
||||
|
|
|
@ -660,7 +660,6 @@ SV_UpdateToReliableMessages (void)
|
|||
client_t *client;
|
||||
edict_t *ent;
|
||||
int i, j;
|
||||
pr_type_t *val;
|
||||
|
||||
// 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++) {
|
||||
|
@ -685,15 +684,15 @@ SV_UpdateToReliableMessages (void)
|
|||
// maxspeed/entgravity changes
|
||||
ent = host_client->edict;
|
||||
|
||||
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
|
||||
if (val && host_client->entgravity != val->float_var) {
|
||||
host_client->entgravity = val->float_var;
|
||||
if (sv_fields.gravity != -1
|
||||
&& host_client->entgravity != SVfloat (ent, gravity)) {
|
||||
host_client->entgravity = SVfloat (ent, gravity);
|
||||
ClientReliableWrite_Begin (host_client, svc_entgravity, 5);
|
||||
ClientReliableWrite_Float (host_client, host_client->entgravity);
|
||||
}
|
||||
val = GetEdictFieldValue (&sv_pr_state, ent, "maxspeed");
|
||||
if (val && host_client->maxspeed != val->float_var) {
|
||||
host_client->maxspeed = val->float_var;
|
||||
if (sv_fields.maxspeed != -1
|
||||
&& host_client->maxspeed != SVfloat (ent, maxspeed)) {
|
||||
host_client->maxspeed = SVfloat (ent, maxspeed);
|
||||
ClientReliableWrite_Begin (host_client, svc_maxspeed, 5);
|
||||
ClientReliableWrite_Float (host_client, host_client->maxspeed);
|
||||
}
|
||||
|
|
|
@ -333,7 +333,6 @@ SV_Spawn_f (void)
|
|||
int i;
|
||||
client_t *client;
|
||||
edict_t *ent;
|
||||
pr_type_t *val;
|
||||
int n;
|
||||
|
||||
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);
|
||||
|
||||
host_client->entgravity = 1.0;
|
||||
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
|
||||
if (val)
|
||||
val->float_var = 1.0;
|
||||
if (sv_fields.gravity != -1)
|
||||
SVfloat (ent, gravity) = 1.0;
|
||||
host_client->maxspeed = sv_maxspeed->value;
|
||||
val = GetEdictFieldValue (&sv_pr_state, ent, "maxspeed");
|
||||
if (val)
|
||||
val->float_var = sv_maxspeed->value;
|
||||
if (sv_fields.maxspeed != -1)
|
||||
SVfloat (ent, gravity) = sv_maxspeed->value;
|
||||
|
||||
//
|
||||
// force stats to be updated
|
||||
|
|
Loading…
Reference in a new issue