readability cleanup of vector comparisons to 0, now all such comparisons use VectorIsNull, and a little more whitespace cleanup in cl_pred.c

This commit is contained in:
Forest Hale 2001-03-16 12:27:11 +00:00
parent f922262b61
commit 05545350e7
6 changed files with 21 additions and 29 deletions

View file

@ -48,6 +48,9 @@ extern int nanmask;
#define VectorAdd(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];} #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
// LordHavoc: makes code more readable
#define VectorIsNull(a) ((a)[0] == 0 && (a)[1] == 0 && (a)[2] == 0)
/* /*
* VectorDistance, the distance between two points. * VectorDistance, the distance between two points.
* Yes, this is the same as sqrt(VectorSubtract then DotProduct), * Yes, this is the same as sqrt(VectorSubtract then DotProduct),

View file

@ -55,9 +55,7 @@ CL_PredictUsercmd (player_state_t * from, player_state_t * to, usercmd_t *u,
{ {
// Dabb: if there is no movement to start with, don't predict... // Dabb: if there is no movement to start with, don't predict...
if(cl_nostatpred->int_val && !from->velocity[0] if(cl_nostatpred->int_val && VectorIsNull(from->velocity)) {
&& !from->velocity[1]
&& !from->velocity[2]) {
VectorCopy (from->origin, to->origin); VectorCopy (from->origin, to->origin);
VectorCopy (u->angles, to->viewangles); VectorCopy (u->angles, to->viewangles);
VectorCopy (from->velocity, to->velocity); VectorCopy (from->velocity, to->velocity);
@ -123,7 +121,8 @@ CL_PredictMove (void)
if (cl.paused) if (cl.paused)
return; return;
cl.onground = 0; // assume on ground unless prediction says different // assume on ground unless prediction says different
cl.onground = 0;
cl.time = realtime - cls.latency - cl_pushlatency->value * 0.001; cl.time = realtime - cls.latency - cl_pushlatency->value * 0.001;
if (cl.time > realtime) if (cl.time > realtime)
@ -145,8 +144,8 @@ CL_PredictMove (void)
from = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK]; from = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK];
// we can now render a frame // we can now render a frame
if (cls.state == ca_onserver) { // first update is the final signon if (cls.state == ca_onserver) {
// stage // first update is the final signon stage
VID_SetCaption (cls.servername); VID_SetCaption (cls.servername);
cls.state = ca_active; cls.state = ca_active;
} }
@ -159,9 +158,8 @@ CL_PredictMove (void)
// Dabb: if there is no movement to start with, don't predict... // Dabb: if there is no movement to start with, don't predict...
if(cl_nostatpred->int_val && !from->playerstate[cl.playernum].velocity[0] if(cl_nostatpred->int_val
&& !from->playerstate[cl.playernum].velocity[1] && VectorIsNull(from->playerstate[cl.playernum].velocity)) {
&& !from->playerstate[cl.playernum].velocity[2]) {
VectorCopy (from->playerstate[cl.playernum].velocity, cl.simvel); VectorCopy (from->playerstate[cl.playernum].velocity, cl.simvel);
VectorCopy (from->playerstate[cl.playernum].origin, cl.simorg); VectorCopy (from->playerstate[cl.playernum].origin, cl.simorg);
return; return;
@ -176,8 +174,8 @@ CL_PredictMove (void)
for (i = 1; i < UPDATE_BACKUP - 1 && cls.netchan.incoming_sequence + i < for (i = 1; i < UPDATE_BACKUP - 1 && cls.netchan.incoming_sequence + i <
cls.netchan.outgoing_sequence; i++) { cls.netchan.outgoing_sequence; i++) {
to = &cl.frames[(cls.netchan.incoming_sequence + i) & UPDATE_MASK]; to = &cl.frames[(cls.netchan.incoming_sequence + i) & UPDATE_MASK];
CL_PredictUsercmd (&from->playerstate[cl.playernum] CL_PredictUsercmd (&from->playerstate[cl.playernum],
, &to->playerstate[cl.playernum], &to->cmd, &to->playerstate[cl.playernum], &to->cmd,
cl.spectator); cl.spectator);
cl.onground = onground; cl.onground = onground;
if (to->senttime >= cl.time) if (to->senttime >= cl.time)
@ -194,21 +192,13 @@ CL_PredictMove (void)
// now interpolate some fraction of the final frame // now interpolate some fraction of the final frame
if (to->senttime == from->senttime) if (to->senttime == from->senttime)
f = 0; f = 0;
else { else
f = (cl.time - from->senttime) / (to->senttime - from->senttime); f = bound(0, (cl.time - from->senttime) / (to->senttime - from->senttime), 1);
if (f < 0)
f = 0;
if (f > 1)
f = 1;
}
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
if (fabs if (fabs(from->playerstate[cl.playernum].origin[i] -
(from->playerstate[cl.playernum].origin[i] - to->playerstate[cl.playernum].origin[i]) > 128) {
to->playerstate[cl.playernum].origin[i]) > 128) { // teleported, // teleported, so don't lerp
// so don't
// lerp
VectorCopy (to->playerstate[cl.playernum].velocity, cl.simvel); VectorCopy (to->playerstate[cl.playernum].velocity, cl.simvel);
VectorCopy (to->playerstate[cl.playernum].origin, cl.simorg); VectorCopy (to->playerstate[cl.playernum].origin, cl.simorg);
return; return;

View file

@ -285,7 +285,7 @@ PM_GroundMove (void)
float downdist, updist; float downdist, updist;
pmove.velocity[2] = 0; pmove.velocity[2] = 0;
if (!pmove.velocity[0] && !pmove.velocity[1] && !pmove.velocity[2]) if (VectorIsNull(pmove.velocity))
return; return;
// first try just moving to the destination // first try just moving to the destination

View file

@ -442,8 +442,7 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum)
OPC->_float = !OPA->_float; OPC->_float = !OPA->_float;
break; break;
case OP_NOT_V: case OP_NOT_V:
OPC->_float = !OPA->vector[0] && !OPA->vector[1] OPC->_float = VectorIsNull(OPA->vector);
&& !OPA->vector[2];
break; break;
case OP_NOT_S: case OP_NOT_S:
OPC->_float = !OPA->string || !*PR_GetString (pr, OPA->string); OPC->_float = !OPA->string || !*PR_GetString (pr, OPA->string);

View file

@ -537,8 +537,7 @@ SV_PushMove (edict_t *pusher, float movetime)
int i; int i;
vec3_t move; vec3_t move;
if (!pusher->v.v.velocity[0] && !pusher->v.v.velocity[1] if (VectorIsNull(pusher->v.v.velocity)) {
&& !pusher->v.v.velocity[2]) {
pusher->v.v.ltime += movetime; pusher->v.v.ltime += movetime;
return; return;
} }

View file

@ -477,6 +477,7 @@ SV_ClipToLinks (areanode_t *node, moveclip_t * clip)
|| clip->boxmaxs[2] < touch->v.v.absmin[2]) || clip->boxmaxs[2] < touch->v.v.absmin[2])
continue; continue;
// LordHavoc: err... FIXME?? I decided not to touch this weird code...
if (clip->passedict != 0 && clip->passedict->v.v.size[0] if (clip->passedict != 0 && clip->passedict->v.v.size[0]
&& !touch->v.v.size[0]) continue; // points never interact && !touch->v.v.size[0]) continue; // points never interact