SV_CheckVelocity() fix (cvar SV_MAXVELOCITY)

This commit is contained in:
Maddes Buecher 2000-08-16 20:49:06 +00:00
parent e5581c8373
commit b62172b915

View file

@ -78,7 +78,8 @@ void SV_Physics_Toss (edict_t *ent);
SV_CheckAllEnts
================
*/
void SV_CheckAllEnts (void)
void
SV_CheckAllEnts ( void )
{
int e;
edict_t *check;
@ -104,9 +105,11 @@ void SV_CheckAllEnts (void)
SV_CheckVelocity
================
*/
void SV_CheckVelocity (edict_t *ent)
void
SV_CheckVelocity ( edict_t *ent )
{
int i;
float wishspeed; // 1999-10-18 SV_MAXVELOCITY fix by Maddes
//
// bound velocity
@ -123,11 +126,15 @@ void SV_CheckVelocity (edict_t *ent)
Con_Printf ("Got a NaN origin on %s\n", PR_GetString(ent->v.classname));
ent->v.origin[i] = 0;
}
if (ent->v.velocity[i] > sv_maxvelocity->value)
ent->v.velocity[i] = sv_maxvelocity->value;
else if (ent->v.velocity[i] < -sv_maxvelocity->value)
ent->v.velocity[i] = -sv_maxvelocity->value;
}
// 1999-10-18 SV_MAXVELOCITY fix by Maddes start
wishspeed = Length(ent->v.velocity);
if (wishspeed > sv_maxvelocity->value)
{
VectorScale (ent->v.velocity, sv_maxvelocity->value/wishspeed, ent->v.velocity);
}
// 1999-10-18 SV_MAXVELOCITY fix by Maddes end
}
/*
@ -140,7 +147,8 @@ in a frame. Not used for pushmove objects, because they must be exact.
Returns false if the entity removed itself.
=============
*/
qboolean SV_RunThink (edict_t *ent)
qboolean
SV_RunThink ( edict_t *ent )
{
float thinktime;
@ -176,7 +184,8 @@ SV_Impact
Two entities have touched, so run their touch functions
==================
*/
void SV_Impact (edict_t *e1, edict_t *e2)
void
SV_Impact ( edict_t *e1, edict_t *e2 )
{
int old_self, old_other;
@ -213,7 +222,8 @@ returns the blocked flags (1 = floor, 2 = step / wall)
*/
#define STOP_EPSILON 0.1
int ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
int
ClipVelocity ( vec3_t in, vec3_t normal, vec3_t out, float overbounce )
{
float backoff;
float change;
@ -252,7 +262,8 @@ If steptrace is not NULL, the trace of any vertical wall hit will be stored
============
*/
#define MAX_CLIP_PLANES 5
int SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
int
SV_FlyMove ( edict_t *ent, float time, trace_t *steptrace )
{
int bumpcount, numbumps;
vec3_t dir;
@ -304,7 +315,7 @@ int SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
if (trace.plane.normal[2] > 0.7)
{
blocked |= 1; // floor
if ((trace.ent->v.solid == SOLID_BSP) || (trace.ent->v.movetype == MOVETYPE_PPUSH))
if ((trace.ent->v.solid == SOLID_BSP) || (trace.ent->v.movetype == MOVETYPE_PPUSH))
{
ent->v.flags = (int)ent->v.flags | FL_ONGROUND;
ent->v.groundentity = EDICT_TO_PROG(trace.ent);
@ -391,7 +402,8 @@ SV_AddGravity
============
*/
void SV_AddGravity (edict_t *ent, float scale)
void
SV_AddGravity ( edict_t *ent, float scale )
{
ent->v.velocity[2] -= scale * movevars.gravity * sv_frametime;
}
@ -411,7 +423,8 @@ SV_PushEntity
Does not change the entities velocity at all
============
*/
trace_t SV_PushEntity (edict_t *ent, vec3_t push)
trace_t
SV_PushEntity ( edict_t *ent, vec3_t push )
{
trace_t trace;
vec3_t end;
@ -442,7 +455,8 @@ SV_Push
============
*/
qboolean SV_Push (edict_t *pusher, vec3_t move)
qboolean
SV_Push ( edict_t *pusher, vec3_t move )
{
int i, e;
edict_t *check, *block;
@ -475,7 +489,7 @@ qboolean SV_Push (edict_t *pusher, vec3_t move)
continue;
if (check->v.movetype == MOVETYPE_PUSH
|| check->v.movetype == MOVETYPE_NONE
|| check->v.movetype == MOVETYPE_PPUSH
|| check->v.movetype == MOVETYPE_PPUSH
|| check->v.movetype == MOVETYPE_NOCLIP)
continue;
@ -571,7 +585,8 @@ SV_PushMove
============
*/
void SV_PushMove (edict_t *pusher, float movetime)
void
SV_PushMove ( edict_t *pusher, float movetime )
{
int i;
vec3_t move;
@ -596,13 +611,14 @@ SV_Physics_Pusher
================
*/
void SV_Physics_Pusher (edict_t *ent)
void
SV_Physics_Pusher ( edict_t *ent )
{
float thinktime;
float oldltime;
float movetime;
vec3_t oldorg, move;
float l;
vec3_t oldorg, move;
float l;
oldltime = ent->v.ltime;
@ -623,7 +639,7 @@ float l;
if (thinktime > oldltime && thinktime <= ent->v.ltime)
{
VectorCopy (ent->v.origin, oldorg);
VectorCopy (ent->v.origin, oldorg);
ent->v.nextthink = 0;
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(ent);
@ -631,18 +647,16 @@ VectorCopy (ent->v.origin, oldorg);
PR_ExecuteProgram (ent->v.think);
if (ent->free)
return;
VectorSubtract (ent->v.origin, oldorg, move);
l = Length(move);
if (l > 1.0/64)
{
// Con_Printf ("**** snap: %f\n", Length (l));
VectorCopy (oldorg, ent->v.origin);
SV_Push (ent, move);
}
VectorSubtract (ent->v.origin, oldorg, move);
l = Length(move);
if (l > 1.0/64)
{
// Con_Printf ("**** snap: %f\n", Length (l));
VectorCopy (oldorg, ent->v.origin);
SV_Push (ent, move);
}
}
}
@ -653,7 +667,8 @@ SV_Physics_None
Non moving objects can only think
=============
*/
void SV_Physics_None (edict_t *ent)
void
SV_Physics_None ( edict_t *ent )
{
// regular thinking
SV_RunThink (ent);
@ -666,7 +681,8 @@ SV_Physics_Noclip
A moving object that doesn't obey physics
=============
*/
void SV_Physics_Noclip (edict_t *ent)
void
SV_Physics_Noclip ( edict_t *ent )
{
// regular thinking
if (!SV_RunThink (ent))
@ -692,7 +708,8 @@ SV_CheckWaterTransition
=============
*/
void SV_CheckWaterTransition (edict_t *ent)
void
SV_CheckWaterTransition ( edict_t *ent )
{
int cont;
@ -731,7 +748,8 @@ SV_Physics_Toss
Toss, bounce, and fly movement. When onground, do nothing.
=============
*/
void SV_Physics_Toss (edict_t *ent)
void
SV_Physics_Toss ( edict_t *ent )
{
trace_t trace;
vec3_t move;
@ -809,7 +827,8 @@ will fall if the floor is pulled out from under them.
FIXME: is this true?
=============
*/
void SV_Physics_Step (edict_t *ent)
void
SV_Physics_Step ( edict_t *ent )
{
qboolean hitsound;
@ -839,80 +858,82 @@ void SV_Physics_Step (edict_t *ent)
SV_CheckWaterTransition (ent);
}
void SV_PPushMove (edict_t *pusher, float movetime) // player push
void
SV_PPushMove ( edict_t *pusher, float movetime ) // player push
{
int i, e;
edict_t *check;
vec3_t mins, maxs, move;
int oldsolid;
trace_t trace;
int i, e;
edict_t *check;
vec3_t mins, maxs, move;
int oldsolid;
trace_t trace;
SV_CheckVelocity(pusher);
for (i=0 ; i<3 ; i++)
SV_CheckVelocity(pusher);
for (i=0 ; i<3 ; i++)
{
move[i] = pusher->v.velocity[i] * movetime;
move[i] = pusher->v.velocity[i] * movetime;
mins[i] = pusher->v.absmin[i] + move[i];
maxs[i] = pusher->v.absmax[i] + move[i];
}
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Backup origin
trace = SV_Move (pusher->v.origin, pusher->v.mins, pusher->v.maxs, move, MOVE_NOMONSTERS, pusher);
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Backup origin
trace = SV_Move (pusher->v.origin, pusher->v.mins, pusher->v.maxs, move, MOVE_NOMONSTERS, pusher);
if (trace.fraction == 1) {
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Revert
return;
}
if (trace.fraction == 1) {
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Revert
return;
}
VectorAdd (pusher->v.origin, move, pusher->v.origin); // Move
SV_LinkEdict (pusher, false);
pusher->v.ltime += movetime;
VectorAdd (pusher->v.origin, move, pusher->v.origin); // Move
SV_LinkEdict (pusher, false);
pusher->v.ltime += movetime;
oldsolid = pusher->v.solid;
oldsolid = pusher->v.solid;
check = NEXT_EDICT(sv.edicts);
for (e=1 ; e<sv.num_edicts ; e++, check = NEXT_EDICT(check))
{
if (check->free) // What entity?
if (check->free) // What entity?
continue;
// Stage 1: Is it in contact with me?
if (!SV_TestEntityPosition (check)) // Nope
continue;
// Stage 1: Is it in contact with me?
if (!SV_TestEntityPosition (check)) // Nope
continue;
// Stage 2: Is it a player we can push?
if (check->v.movetype == MOVETYPE_WALK) {
Con_Printf("Pusher encountered a player\n"); // Yes!@#!@
pusher->v.solid = SOLID_NOT;
SV_PushEntity (check, move);
pusher->v.solid = oldsolid;
continue;
}
// Stage 2: Is it a player we can push?
if (check->v.movetype == MOVETYPE_WALK) {
Con_Printf("Pusher encountered a player\n"); // Yes!@#!@
pusher->v.solid = SOLID_NOT;
SV_PushEntity (check, move);
pusher->v.solid = oldsolid;
continue;
}
// Stage 3: No.. Is it something that blocks us?
if (check->v.mins[0] == check->v.maxs[0])
continue;
if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
continue;
// Stage 3: No.. Is it something that blocks us?
if (check->v.mins[0] == check->v.maxs[0])
continue;
if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
continue;
// Stage 4: Yes, it must be. Fail the move.
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Revert
if (pusher->v.blocked) { // Blocked func?
pr_global_struct->self = EDICT_TO_PROG(pusher);
pr_global_struct->other = EDICT_TO_PROG(check);
PR_ExecuteProgram (pusher->v.blocked);
}
return;
}
// Stage 4: Yes, it must be. Fail the move.
VectorCopy (pusher->v.origin, pusher->v.oldorigin); // Revert
if (pusher->v.blocked) { // Blocked func?
pr_global_struct->self = EDICT_TO_PROG(pusher);
pr_global_struct->other = EDICT_TO_PROG(check);
PR_ExecuteProgram (pusher->v.blocked);
}
return;
}
}
void SV_Physics_PPusher (edict_t *ent)
void
SV_Physics_PPusher ( edict_t *ent )
{
float thinktime;
float oldltime;
float movetime;
// float l;
float movetime;
// float l;
oldltime = ent->v.ltime;
@ -926,10 +947,10 @@ void SV_Physics_PPusher (edict_t *ent)
else
movetime = sv_frametime;
// if (movetime)
// {
SV_PPushMove (ent, 0.0009); // advances ent->v.ltime if not blocked
// }
// if (movetime)
// {
SV_PPushMove (ent, 0.0009); // advances ent->v.ltime if not blocked
// }
if (thinktime > oldltime && thinktime <= ent->v.ltime)
{
@ -945,7 +966,8 @@ void SV_Physics_PPusher (edict_t *ent)
//============================================================================
void SV_ProgStartFrame (void)
void
SV_ProgStartFrame ( void )
{
// let the progs know that a new frame has started
pr_global_struct->self = EDICT_TO_PROG(sv.edicts);
@ -960,7 +982,8 @@ SV_RunEntity
================
*/
void SV_RunEntity (edict_t *ent)
void
SV_RunEntity ( edict_t *ent )
{
if (ent->v.lastruntime == (float)realtime)
return;
@ -971,8 +994,8 @@ void SV_RunEntity (edict_t *ent)
case MOVETYPE_PUSH:
SV_Physics_Pusher (ent);
break;
case MOVETYPE_PPUSH:
SV_Physics_PPusher (ent);
case MOVETYPE_PPUSH:
SV_Physics_PPusher (ent);
break;
case MOVETYPE_NONE:
SV_Physics_None (ent);
@ -1000,7 +1023,8 @@ SV_RunNewmis
================
*/
void SV_RunNewmis (void)
void
SV_RunNewmis ( void )
{
edict_t *ent;
@ -1019,7 +1043,8 @@ SV_Physics
================
*/
void SV_Physics (void)
void
SV_Physics ( void )
{
int i;
edict_t *ent;
@ -1061,7 +1086,8 @@ void SV_Physics (void)
pr_global_struct->force_retouch--;
}
void SV_SetMoveVars(void)
void
SV_SetMoveVars ( void )
{
movevars.gravity = sv_gravity->value;
movevars.stopspeed = sv_stopspeed->value;