From 854157a4e733ffe5d97749212d1e2e3d56672fb2 Mon Sep 17 00:00:00 2001 From: Spoike Date: Fri, 17 Feb 2012 01:12:37 +0000 Subject: [PATCH] Added .vector gravitydir; Added csqc getentity builtin (untested, broken for players). git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3998 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/client.h | 4 ++ engine/common/pmove.c | 9 +++-- engine/gl/gl_alias.c | 57 +++++++++++++++------------ engine/qclib/execloop.h | 2 +- engine/server/pr_cmds.c | 17 ++++++-- engine/server/progdefs.h | 1 + engine/server/sv_phys.c | 83 ++++++++++++++++++++++++---------------- engine/server/sv_user.c | 7 +++- 8 files changed, 112 insertions(+), 68 deletions(-) diff --git a/engine/client/client.h b/engine/client/client.h index 025eb73a3..6d0363029 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -478,6 +478,10 @@ typedef struct { vec3_t oldorigin; /*origin that we're lerping away from*/ vec3_t newangle; vec3_t oldangle; + + //for further info + int sequence; + entity_state_t *entstate; } lerpents_t; // // the client_state_t structure is wiped completely at every diff --git a/engine/common/pmove.c b/engine/common/pmove.c index a654615f0..0d57ab071 100644 --- a/engine/common/pmove.c +++ b/engine/common/pmove.c @@ -712,9 +712,12 @@ void PM_CategorizePosition (void) int cont; trace_t trace; - pmove.gravitydir[0] = 0; - pmove.gravitydir[1] = 0; - pmove.gravitydir[2] = -1; + if (pmove.gravitydir[0] == 0 && pmove.gravitydir[1] == 0 && pmove.gravitydir[2] == 0) + { + pmove.gravitydir[0] = 0; + pmove.gravitydir[1] = 0; + pmove.gravitydir[2] = -1; + } if (pmove.pm_type == PM_WALLWALK) { vec3_t tmin,tmax; diff --git a/engine/gl/gl_alias.c b/engine/gl/gl_alias.c index f5d7a1ddb..c7824231b 100644 --- a/engine/gl/gl_alias.c +++ b/engine/gl/gl_alias.c @@ -1651,7 +1651,7 @@ static void R_DB_Sprite(batch_t *batch) entity_t *e = batch->ent; vec3_t point; mspriteframe_t *frame, genframe; - vec3_t forward, right, up; + vec3_t spraxis[3]; msprite_t *psprite; vec3_t sprorigin; unsigned int sprtype; @@ -1708,34 +1708,41 @@ static void R_DB_Sprite(batch_t *batch) { case SPR_ORIENTED: // bullet marks on walls - AngleVectors (e->angles, forward, right, up); + if (e->flags & Q2RF_WEAPONMODEL && r_refdef.currentplayernum >= 0) + { + vec3_t ea[3]; + AngleVectors (e->angles, ea[0], ea[1], ea[2]); + Matrix3_Multiply(ea, cl.viewent[r_refdef.currentplayernum].axis, spraxis); + } + else + AngleVectors (e->angles, spraxis[0], spraxis[1], spraxis[2]); break; case SPR_FACING_UPRIGHT: - up[0] = 0;up[1] = 0;up[2]=1; - right[0] = sprorigin[1] - r_origin[1]; - right[1] = -(sprorigin[0] - r_origin[0]); - right[2] = 0; - VectorNormalize (right); + spraxis[2][0] = 0;spraxis[2][1] = 0;spraxis[2][2]=1; + spraxis[1][0] = sprorigin[1] - r_origin[1]; + spraxis[1][1] = -(sprorigin[0] - r_origin[0]); + spraxis[1][2] = 0; + VectorNormalize (spraxis[1]); break; case SPR_VP_PARALLEL_UPRIGHT: - up[0] = 0;up[1] = 0;up[2]=1; - VectorCopy (vright, right); + spraxis[2][0] = 0;spraxis[2][1] = 0;spraxis[2][2]=1; + VectorCopy (vright, spraxis[1]); break; default: case SPR_VP_PARALLEL: //normal sprite - VectorCopy(vup, up); - VectorCopy(vright, right); + VectorCopy(vup, spraxis[2]); + VectorCopy(vright, spraxis[1]); break; } - up[0]*=e->scale; - up[1]*=e->scale; - up[2]*=e->scale; - right[0]*=e->scale; - right[1]*=e->scale; - right[2]*=e->scale; + spraxis[2][0]*=e->scale; + spraxis[2][1]*=e->scale; + spraxis[2][2]*=e->scale; + spraxis[1][0]*=e->scale; + spraxis[1][1]*=e->scale; + spraxis[1][2]*=e->scale; if (e->shaderRGBAf[0] > 1) e->shaderRGBAf[0] = 1; @@ -1749,17 +1756,17 @@ static void R_DB_Sprite(batch_t *batch) Vector4Copy(e->shaderRGBAf, colours[2]); Vector4Copy(e->shaderRGBAf, colours[3]); - VectorMA (sprorigin, frame->down, up, point); - VectorMA (point, frame->left, right, vertcoords[0]); + VectorMA (sprorigin, frame->down, spraxis[2], point); + VectorMA (point, frame->left, spraxis[1], vertcoords[0]); - VectorMA (sprorigin, frame->up, up, point); - VectorMA (point, frame->left, right, vertcoords[1]); + VectorMA (sprorigin, frame->up, spraxis[2], point); + VectorMA (point, frame->left, spraxis[1], vertcoords[1]); - VectorMA (sprorigin, frame->up, up, point); - VectorMA (point, frame->right, right, vertcoords[2]); + VectorMA (sprorigin, frame->up, spraxis[2], point); + VectorMA (point, frame->right, spraxis[1], vertcoords[2]); - VectorMA (sprorigin, frame->down, up, point); - VectorMA (point, frame->right, right, vertcoords[3]); + VectorMA (sprorigin, frame->down, spraxis[2], point); + VectorMA (point, frame->right, spraxis[1], vertcoords[3]); batch->ent = &r_worldentity; batch->mesh = &meshptr; diff --git a/engine/qclib/execloop.h b/engine/qclib/execloop.h index a49d76539..f6aa4eb5d 100644 --- a/engine/qclib/execloop.h +++ b/engine/qclib/execloop.h @@ -495,7 +495,7 @@ reeval: fdef_t *f; d16 = ED_GlobalAtOfs16(progfuncs, st->a); f = ED_FieldAtOfs(progfuncs, OPB->_int + progfuncs->fieldadjust); - PR_RunError (progfuncs, "assignment to read-only entity in %s (%s.%s)", PR_StringToNative(progfuncs, pr_xfunction->s_name), d16?PR_StringToNative(progfuncs, d16->s_name):NULL, f?f->name:NULL); + printf ("assignment to read-only entity in %s (%s.%s)\n", PR_StringToNative(progfuncs, pr_xfunction->s_name), d16?PR_StringToNative(progfuncs, d16->s_name):NULL, f?f->name:NULL); } #endif } diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 66bf861a5..a30bd0e5b 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -3855,14 +3855,21 @@ static void QCBUILTIN PF_droptofloor (progfuncs_t *prinst, struct globalvars_s * vec3_t end; vec3_t start; trace_t trace; + const float *gravitydir; + extern const vec3_t standardgravity; ent = PROG_TO_EDICT(prinst, pr_global_struct->self); + if (ent->xv->gravitydir[2] || ent->xv->gravitydir[1] || ent->xv->gravitydir[0]) + gravitydir = ent->xv->gravitydir; + else + gravitydir = standardgravity; + VectorCopy (ent->v->origin, end); if (pr_droptofloorunits.value > 0) - end[2] -= pr_droptofloorunits.value; + VectorMA(end, pr_droptofloorunits.value, gravitydir, end); else - end[2] -= 256; + VectorMA(end, 256, gravitydir, end); VectorCopy (ent->v->origin, start); trace = World_Move (&sv.world, start, ent->v->mins, ent->v->maxs, end, MOVE_NORMAL, (wedict_t*)ent); @@ -9207,12 +9214,14 @@ BuiltinList_t BuiltinList[] = { //nq qw h2 ebfs //DP_SV_WRITEPICTURE {"WritePicture", PF_WritePicture, 0, 0, 0, 501, "void(float to, string s, float sz)"},// + {"ReadPicture", PF_Fixme, 0, 0, 0, 501, "string()"},// - //no 502 documented +// {"boxparticles", PF_Fixme, 0, 0, 0, 502, "void(float effectindex, entity own, vector org_from, vector org_to, vector dir_from, vector dir_to, float countmultiplier, float flags)"}, //DP_QC_WHICHPACK {"whichpack", PF_whichpack, 0, 0, 0, 503, "string(string filename)"},// - //no 504 +//DP_CSQC_QUERYRENDERENTITY + {"getentity", PF_Fixme, 0, 0, 0, 504 "__variant(float entnum, fload fieldnum)"}, //DP_QC_URI_ESCAPE {"uri_escape", PF_uri_escape, 0, 0, 0, 510, "string(string in)"},// diff --git a/engine/server/progdefs.h b/engine/server/progdefs.h index a2e63b3d3..88780167d 100644 --- a/engine/server/progdefs.h +++ b/engine/server/progdefs.h @@ -200,6 +200,7 @@ and the extension fields are added on the end and can have extra vm-specific stu comfieldfloat(skeletonindex) /*FTE_CSQC_SKELETONOBJECTS*/\ comfieldvector(colormod)\ comfieldvector(glowmod)\ + comfieldvector(gravitydir)\ comfieldfloat(pmove_flags)/*EXT_CSQC_1*/\ comfieldfloat(friction)/*DP_...PHYSICS*/\ comfieldfloat(erp)/*DP_...PHYSICS*/\ diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index 2d2ef9fde..f20e9aa57 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -91,6 +91,7 @@ void WPhys_Init(void) #define MOVE_EPSILON 0.01 static void WPhys_Physics_Toss (world_t *w, wedict_t *ent); +const vec3_t standardgravity = {0, 0, -1}; // warning: ‘SV_CheckAllEnts’ defined but not used /* @@ -271,7 +272,7 @@ If steptrace is not NULL, the trace of any vertical wall hit will be stored ============ */ #define MAX_CLIP_PLANES 5 -static int WPhys_FlyMove (world_t *w, wedict_t *ent, float time, trace_t *steptrace) +static int WPhys_FlyMove (world_t *w, wedict_t *ent, const vec3_t gravitydir, float time, trace_t *steptrace) { int bumpcount, numbumps; vec3_t dir; @@ -325,7 +326,7 @@ static int WPhys_FlyMove (world_t *w, wedict_t *ent, float time, trace_t *steptr if (!trace.ent) Host_Error ("SV_FlyMove: !trace.ent"); - if (trace.plane.normal[2] > 0.7) + if (-DotProduct(gravitydir, trace.plane.normal) > 0.7) { blocked |= 1; // floor if (((wedict_t *)trace.ent)->v->solid == SOLID_BSP) @@ -334,7 +335,7 @@ static int WPhys_FlyMove (world_t *w, wedict_t *ent, float time, trace_t *steptr ent->v->groundentity = EDICT_TO_PROG(w->progs, trace.ent); } } - if (!trace.plane.normal[2]) + if (!DotProduct(gravitydir, trace.plane.normal)) { blocked |= 2; // step if (steptrace) @@ -439,11 +440,12 @@ SV_AddGravity ============ */ -static void WPhys_AddGravity (world_t *w, wedict_t *ent, float scale) +static void WPhys_AddGravity (world_t *w, wedict_t *ent, const float *gravitydir, float scale) { if (!scale) scale = w->defaultgravityscale; - ent->v->velocity[2] -= scale * movevars.gravity * host_frametime; + + VectorMA(ent->v->velocity, scale * movevars.gravity * host_frametime, gravitydir, ent->v->velocity); } /* @@ -1062,6 +1064,7 @@ static void WPhys_Physics_Toss (world_t *w, wedict_t *ent) vec3_t temporg; int fl; + const float *gravitydir; WPhys_CheckVelocity (w, ent); @@ -1069,10 +1072,15 @@ static void WPhys_Physics_Toss (world_t *w, wedict_t *ent) if (!WPhys_RunThink (w, ent)) return; + if (ent->xv->gravitydir[2] || ent->xv->gravitydir[1] || ent->xv->gravitydir[0]) + gravitydir = ent->xv->gravitydir; + else + gravitydir = standardgravity; + // if onground, return without moving if ( ((int)ent->v->flags & FL_ONGROUND) ) { - if (ent->v->velocity[2] >= (1.0f/32.0f)) + if (-DotProduct(gravitydir, ent->v->velocity) >= (1.0f/32.0f)) ent->v->flags = (int)ent->v->flags & ~FL_ONGROUND; else { @@ -1093,7 +1101,7 @@ static void WPhys_Physics_Toss (world_t *w, wedict_t *ent) && ent->v->movetype != MOVETYPE_FLYMISSILE && ent->v->movetype != MOVETYPE_BOUNCEMISSILE && ent->v->movetype != MOVETYPE_H2SWIM) - WPhys_AddGravity (w, ent, 1.0); + WPhys_AddGravity (w, ent, gravitydir, 1.0); // move angles VectorMA (ent->v->angles, host_frametime, ent->v->avelocity, ent->v->angles); @@ -1117,10 +1125,8 @@ static void WPhys_Physics_Toss (world_t *w, wedict_t *ent) { trace.fraction = 0; -#pragma warningmsg("These three lines might help boost framerates a lot in rmq, not sure if they violate expected behaviour in other mods though - check that they're safe.") - trace.plane.normal[0] = 0; - trace.plane.normal[1] = 0; - trace.plane.normal[2] = 1; +#pragma warningmsg("The following line might help boost framerates a lot in rmq, not sure if they violate expected behaviour in other mods though - check that they're safe.") + VectorNegate(gravitydir, trace.plane.normal); } if (trace.fraction == 1) return; @@ -1146,9 +1152,9 @@ static void WPhys_Physics_Toss (world_t *w, wedict_t *ent) // stop if on ground - if ((trace.plane.normal[2] > 0.7) && (ent->v->movetype != MOVETYPE_BOUNCEMISSILE)) + if ((-DotProduct(gravitydir, trace.plane.normal) > 0.7) && (ent->v->movetype != MOVETYPE_BOUNCEMISSILE)) { - if (ent->v->velocity[2] < 60 || ent->v->movetype != MOVETYPE_BOUNCE ) + if (-DotProduct(gravitydir, ent->v->velocity) < 60 || ent->v->movetype != MOVETYPE_BOUNCE ) { ent->v->flags = (int)ent->v->flags | FL_ONGROUND; ent->v->groundentity = EDICT_TO_PROG(w->progs, trace.ent); @@ -1186,8 +1192,14 @@ static void WPhys_Physics_Step (world_t *w, wedict_t *ent) qboolean hitsound; qboolean freefall; int fl = ent->v->flags; + const float *gravitydir; - if (ent->v->velocity[2] >= (1.0 / 32.0) && (fl & FL_ONGROUND)) + if (ent->xv->gravitydir[2] || ent->xv->gravitydir[1] || ent->xv->gravitydir[0]) + gravitydir = ent->xv->gravitydir; + else + gravitydir = standardgravity; + + if (-DotProduct(gravitydir, ent->v->velocity) >= (1.0 / 32.0) && (fl & FL_ONGROUND)) { fl &= ~FL_ONGROUND; ent->v->flags = fl; @@ -1202,11 +1214,11 @@ static void WPhys_Physics_Step (world_t *w, wedict_t *ent) freefall = ent->v->waterlevel <= 0; if (freefall) { - hitsound = ent->v->velocity[2] < movevars.gravity*-0.1; + hitsound = -DotProduct(gravitydir, ent->v->velocity) < movevars.gravity*-0.1; - WPhys_AddGravity (w, ent, 1.0); + WPhys_AddGravity (w, ent, gravitydir, 1.0); WPhys_CheckVelocity (w, ent); - WPhys_FlyMove (w, ent, host_frametime, NULL); + WPhys_FlyMove (w, ent, gravitydir, host_frametime, NULL); World_LinkEdict (w, ent, true); if ( (int)ent->v->flags & FL_ONGROUND ) // just hit ground @@ -1608,17 +1620,15 @@ static void SV_WalkMove (edict_t *ent) // 1/32 epsilon to keep floating point happy #define DIST_EPSILON (0.03125) -static int WPhys_SetOnGround (world_t *w, wedict_t *ent) +static int WPhys_SetOnGround (world_t *w, wedict_t *ent, const float *gravitydir) { vec3_t end; trace_t trace; if ((int)ent->v->flags & FL_ONGROUND) return 1; - end[0] = ent->v->origin[0]; - end[1] = ent->v->origin[1]; - end[2] = ent->v->origin[2] - 1; + VectorMA(ent->v->origin, 1, gravitydir, end); trace = World_Move(w, ent->v->origin, ent->v->mins, ent->v->maxs, end, MOVE_NORMAL, (wedict_t*)ent); - if (trace.fraction <= DIST_EPSILON && trace.plane.normal[2] >= 0.7) + if (trace.fraction <= DIST_EPSILON && -DotProduct(gravitydir, trace.plane.normal) >= 0.7) { ent->v->flags = (int)ent->v->flags | FL_ONGROUND; ent->v->groundentity = EDICT_TO_PROG(w->progs, trace.ent); @@ -1626,7 +1636,7 @@ static int WPhys_SetOnGround (world_t *w, wedict_t *ent) } return 0; } -static void WPhys_WalkMove (world_t *w, wedict_t *ent) +static void WPhys_WalkMove (world_t *w, wedict_t *ent, const float *gravitydir) { int clip, oldonground, originalmove_clip, originalmove_flags, originalmove_groundentity; vec3_t upmove, downmove, start_origin, start_velocity, originalmove_origin, originalmove_velocity; @@ -1641,9 +1651,9 @@ static void WPhys_WalkMove (world_t *w, wedict_t *ent) VectorCopy (ent->v->origin, start_origin); VectorCopy (ent->v->velocity, start_velocity); - clip = WPhys_FlyMove (w, ent, host_frametime, NULL); + clip = WPhys_FlyMove (w, ent, gravitydir, host_frametime, NULL); - WPhys_SetOnGround (w, ent); + WPhys_SetOnGround (w, ent, gravitydir); WPhys_CheckVelocity(w, ent); VectorCopy(ent->v->origin, originalmove_origin); @@ -1683,14 +1693,13 @@ static void WPhys_WalkMove (world_t *w, wedict_t *ent) VectorCopy (start_velocity, ent->v->velocity); // move up - VectorClear (upmove); - upmove[2] = movevars.stepheight; + VectorScale(gravitydir, -movevars.stepheight, upmove); // FIXME: don't link? WPhys_PushEntity(w, ent, upmove, MOVE_NORMAL); // move forward ent->v->velocity[2] = 0; - clip = WPhys_FlyMove (w, ent, host_frametime, &steptrace); + clip = WPhys_FlyMove (w, ent, gravitydir, host_frametime, &steptrace); ent->v->velocity[2] += start_velocity[2]; WPhys_CheckVelocity(w, ent); @@ -1726,12 +1735,11 @@ static void WPhys_WalkMove (world_t *w, wedict_t *ent) return; // move down - VectorClear (downmove); - downmove[2] = -movevars.stepheight + start_velocity[2]*host_frametime; + VectorScale(gravitydir, -(-movevars.stepheight + start_velocity[2]*host_frametime), downmove); // FIXME: don't link? downtrace = WPhys_PushEntity (w, ent, downmove, MOVE_NORMAL); - if (downtrace.fraction < 1 && downtrace.plane.normal[2] > 0.7) + if (downtrace.fraction < 1 && -DotProduct(gravitydir, downtrace.plane.normal) > 0.7) { // LordHavoc: disabled this check so you can walk on monsters/players //if (ent->v->solid == SOLID_BSP) @@ -1754,7 +1762,7 @@ static void WPhys_WalkMove (world_t *w, wedict_t *ent) ent->v->groundentity = originalmove_groundentity; } - WPhys_SetOnGround (w, ent); + WPhys_SetOnGround (w, ent, gravitydir); WPhys_CheckVelocity(w, ent); } #endif @@ -1801,6 +1809,7 @@ void WPhys_RunEntity (world_t *w, wedict_t *ent) { wedict_t *movechain; vec3_t initial_origin = {0},initial_angle = {0}; // warning: ‘initial_?[?]’ may be used uninitialized in this function + const float *gravitydir; #ifndef CLIENTONLY edict_t *svent = (edict_t*)ent; @@ -1894,11 +1903,17 @@ void WPhys_RunEntity (world_t *w, wedict_t *ent) case MOVETYPE_WALK: if (!WPhys_RunThink (w, ent)) return; + + if (ent->xv->gravitydir[2] || ent->xv->gravitydir[1] || ent->xv->gravitydir[0]) + gravitydir = ent->xv->gravitydir; + else + gravitydir = standardgravity; + if (!WPhys_CheckWater (w, ent) && ! ((int)ent->v->flags & FL_WATERJUMP) ) - WPhys_AddGravity (w, ent, ent->xv->gravity); + WPhys_AddGravity (w, ent, gravitydir, ent->xv->gravity); WPhys_CheckStuck (w, ent); - WPhys_WalkMove (w, ent); + WPhys_WalkMove (w, ent, gravitydir); #ifndef CLIENTONLY if (!(ent->entnum > 0 && ent->entnum <= sv.allocated_client_slots) && w == &sv.world) diff --git a/engine/server/sv_user.c b/engine/server/sv_user.c index 9aee32323..47171534c 100644 --- a/engine/server/sv_user.c +++ b/engine/server/sv_user.c @@ -5440,6 +5440,9 @@ int SV_PMTypeForClient (client_t *cl) } #endif + if (!cl->isindependant) + return PM_NONE; + if (sv_brokenmovetypes.value) //this is to mimic standard qw servers, which don't support movetypes other than MOVETYPE_FLY. { //it prevents bugs from being visible in unsuspecting mods. if (cl->spectator) @@ -5751,6 +5754,8 @@ void SV_RunCmd (usercmd_t *ucmd, qboolean recurse) player_maxs[1] = sv_player->v->maxs[1]; player_maxs[2] = sv_player->v->maxs[2]; + VectorCopy(sv_player->xv->gravitydir, pmove.gravitydir); + for (i=0 ; i<3 ; i++) pmove.origin[i] = sv_player->v->origin[i];// + (sv_player->v->mins[i] - player_mins[i]); @@ -5847,7 +5852,7 @@ if (sv_player->v->health > 0 && before && !after ) VectorCopy (pmove.origin, sv_player->v->origin); VectorCopy (pmove.angles, sv_player->v->v_angle); - if (pmove.pm_type == PM_WALLWALK) + if (pmove.gravitydir[0] || pmove.gravitydir[1] || pmove.gravitydir[2] != -1) { if (!sv_player->v->fixangle) {