From add1a1b0abc10b8e720d74aeac52ad8276ee9fe0 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 4 Apr 2012 07:04:45 +0000 Subject: [PATCH] added PRVM_64 define which upgrades the QC VM to double precision variables (such that levels can run for more than 24 hours without time precision breakdown, and bit arithmetic can be done on 52 bit flags rather than 23 bit flags) changed csqc setmodel builtin to do setsize as well (like on server) fixed multiple bugs where csqc builtins were passing right as left in a matrix conversion git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11785 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_collision.c | 30 +- cl_main.c | 4 +- cl_particles.c | 44 ++- client.h | 30 +- clvm_cmds.c | 726 ++++++++++++++++++++++++++------------------- common.c | 4 +- common.h | 22 +- csprogs.c | 8 +- gl_rmain.c | 2 +- host.c | 2 +- host_cmd.c | 4 +- mathlib.c | 2 +- mathlib.h | 30 +- matrixlib.h | 20 +- menu.c | 6 +- model_shared.h | 2 +- mvm_cmds.c | 2 +- progsvm.h | 77 ++--- prvm_cmds.c | 117 +++++--- prvm_cmds.h | 2 +- prvm_edict.c | 85 ++++-- prvm_exec.c | 12 +- prvm_execprogram.h | 100 +++---- qtypes.h | 24 ++ quakedef.h | 4 + r_shadow.c | 20 +- r_shadow.h | 4 +- render.h | 4 +- sv_main.c | 8 +- sv_move.c | 11 +- sv_phys.c | 88 ++++-- sv_user.c | 41 ++- svvm_cmds.c | 104 ++++--- vid_sdl.c | 2 +- world.c | 12 +- 35 files changed, 981 insertions(+), 672 deletions(-) diff --git a/cl_collision.c b/cl_collision.c index 1fc448da..bee473b2 100644 --- a/cl_collision.c +++ b/cl_collision.c @@ -11,9 +11,9 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve float maxfrac, maxrealfrac; int n; entity_render_t *ent; - float tracemins[3], tracemaxs[3]; + vec_t tracemins[3], tracemaxs[3]; trace_t trace; - float tempnormal[3], starttransformed[3], endtransformed[3]; + vec_t tempnormal[3], starttransformed[3], endtransformed[3]; #ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND vec3_t end; vec_t len = 0; @@ -194,7 +194,7 @@ void CL_LinkEdict(prvm_edict_t *ent) VectorCopy(mins, PRVM_clientedictvector(ent, absmin)); VectorCopy(maxs, PRVM_clientedictvector(ent, absmax)); - World_LinkEdict(&cl.world, ent, PRVM_clientedictvector(ent, absmin), PRVM_clientedictvector(ent, absmax)); + World_LinkEdict(&cl.world, ent, mins, maxs); } int CL_GenericHitSuperContentsMask(const prvm_edict_t *passedict) @@ -235,6 +235,8 @@ trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int int passedictprog; prvm_edict_t *traceowner, *touch; trace_t trace; + // temporary storage because prvm_vec_t may need conversion + vec3_t touchmins, touchmaxs; // bounding box of entire move area vec3_t clipboxmins, clipboxmaxs; // size when clipping against monsters @@ -418,10 +420,12 @@ skipnetworkplayers: else Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]); Matrix4x4_Invert_Simple(&imatrix, &matrix); + VectorCopy(PRVM_clientedictvector(touch, mins), touchmins); + VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs); if ((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER) - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipstart, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipstart, hitsupercontentsmask); else - Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask); + Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask); if (cliptrace.realfraction > trace.realfraction && hitnetworkentity) *hitnetworkentity = 0; @@ -448,6 +452,8 @@ trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_ int passedictprog; prvm_edict_t *traceowner, *touch; trace_t trace; + // temporary storage because prvm_vec_t may need conversion + vec3_t touchmins, touchmaxs; // bounding box of entire move area vec3_t clipboxmins, clipboxmaxs; // size when clipping against monsters @@ -652,10 +658,12 @@ skipnetworkplayers: else Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]); Matrix4x4_Invert_Simple(&imatrix, &matrix); + VectorCopy(PRVM_clientedictvector(touch, mins), touchmins); + VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs); if (type == MOVE_MISSILE && (int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER) - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); else - Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, hitsurfaces); + Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, hitsurfaces); if (cliptrace.realfraction > trace.realfraction && hitnetworkentity) *hitnetworkentity = 0; @@ -688,6 +696,8 @@ trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co qboolean pointtrace; prvm_edict_t *traceowner, *touch; trace_t trace; + // temporary storage because prvm_vec_t may need conversion + vec3_t touchmins, touchmaxs; // bounding box of entire move area vec3_t clipboxmins, clipboxmaxs; // size of the moving object @@ -927,10 +937,12 @@ skipnetworkplayers: else Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]); Matrix4x4_Invert_Simple(&imatrix, &matrix); + VectorCopy(PRVM_clientedictvector(touch, mins), touchmins); + VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs); if ((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER) - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); else - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask); if (cliptrace.realfraction > trace.realfraction && hitnetworkentity) *hitnetworkentity = 0; diff --git a/cl_main.c b/cl_main.c index 20451c8e..180a90d5 100644 --- a/cl_main.c +++ b/cl_main.c @@ -927,7 +927,7 @@ static void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean int const matrix4x4_t *matrix; matrix4x4_t blendmatrix, tempmatrix, matrix2; int frame; - float origin[3], angles[3], lerp; + vec_t origin[3], angles[3], lerp; entity_t *t; entity_render_t *r; //entity_persistent_t *p = &e->persistent; @@ -1520,7 +1520,7 @@ static void CL_LinkNetworkEntity(entity_t *e) if ((e->state_current.lightpflags & PFLAGS_FULLDYNAMIC) && r_refdef.scene.numlights < MAX_DLIGHTS) { matrix4x4_t dlightmatrix; - float light[4]; + vec4_t light; VectorScale(e->state_current.light, (1.0f / 256.0f), light); light[3] = e->state_current.light[3]; if (light[0] == 0 && light[1] == 0 && light[2] == 0) diff --git a/cl_particles.c b/cl_particles.c index 5faa737d..6222200f 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -884,8 +884,10 @@ void CL_SpawnDecalParticleForSurface(int hitent, const vec3_t org, const vec3_t void CL_SpawnDecalParticleForPoint(const vec3_t org, float maxdist, float size, float alpha, int texnum, int color1, int color2) { int i; - float bestfrac, bestorg[3], bestnormal[3]; - float org2[3]; + vec_t bestfrac; + vec3_t bestorg; + vec3_t bestnormal; + vec3_t org2; int besthitent = 0, hitent; trace_t trace; bestfrac = 10; @@ -1640,7 +1642,8 @@ CL_EntityParticles void CL_EntityParticles (const entity_t *ent) { int i; - float pitch, yaw, dist = 64, beamlength = 16, org[3], v[3]; + vec_t pitch, yaw, dist = 64, beamlength = 16; + vec3_t org, v; static vec3_t avelocities[NUMVERTEXNORMALS]; if (!cl_particles.integer) return; if (cl.time <= cl.oldtime) return; // don't spawn new entity particles while paused @@ -1665,7 +1668,8 @@ void CL_EntityParticles (const entity_t *ent) void CL_ReadPointFile_f (void) { - vec3_t org, leakorg; + double org[3], leakorg[3]; + vec3_t vecorg; int r, c, s; char *pointfile = NULL, *pointfilepos, *t, tchar; char name[MAX_QPATH]; @@ -1700,7 +1704,8 @@ void CL_ReadPointFile_f (void) #if _MSC_VER >= 1400 #define sscanf sscanf_s #endif - r = sscanf (pointfilepos,"%f %f %f", &org[0], &org[1], &org[2]); + r = sscanf (pointfilepos,"%lf %lf %lf", &org[0], &org[1], &org[2]); + VectorCopy(org, vecorg); *t = tchar; pointfilepos = t; if (r != 3) @@ -1712,16 +1717,16 @@ void CL_ReadPointFile_f (void) if (cl.num_particles < cl.max_particles - 3) { s++; - CL_NewParticle(org, pt_alphastatic, particlepalette[(-c)&15], particlepalette[(-c)&15], tex_particle, 2, 0, 255, 0, 0, 0, org[0], org[1], org[2], 0, 0, 0, 0, 0, 0, 0, true, 1<<30, 1, PBLEND_ALPHA, PARTICLE_BILLBOARD, -1, -1, -1, 1, 1, 0, 0, NULL); + CL_NewParticle(vecorg, pt_alphastatic, particlepalette[(-c)&15], particlepalette[(-c)&15], tex_particle, 2, 0, 255, 0, 0, 0, org[0], org[1], org[2], 0, 0, 0, 0, 0, 0, 0, true, 1<<30, 1, PBLEND_ALPHA, PARTICLE_BILLBOARD, -1, -1, -1, 1, 1, 0, 0, NULL); } } Mem_Free(pointfile); - VectorCopy(leakorg, org); - Con_Printf("%i points read (%i particles spawned)\nLeak at %f %f %f\n", c, s, org[0], org[1], org[2]); + VectorCopy(leakorg, vecorg); + Con_Printf("%i points read (%i particles spawned)\nLeak at %f %f %f\n", c, s, leakorg[0], leakorg[1], leakorg[2]); - CL_NewParticle(org, pt_beam, 0xFF0000, 0xFF0000, tex_beam, 64, 0, 255, 0, 0, 0, org[0] - 4096, org[1], org[2], org[0] + 4096, org[1], org[2], 0, 0, 0, 0, false, 1<<30, 1, PBLEND_ADD, PARTICLE_HBEAM, -1, -1, -1, 1, 1, 0, 0, NULL); - CL_NewParticle(org, pt_beam, 0x00FF00, 0x00FF00, tex_beam, 64, 0, 255, 0, 0, 0, org[0], org[1] - 4096, org[2], org[0], org[1] + 4096, org[2], 0, 0, 0, 0, false, 1<<30, 1, PBLEND_ADD, PARTICLE_HBEAM, -1, -1, -1, 1, 1, 0, 0, NULL); - CL_NewParticle(org, pt_beam, 0x0000FF, 0x0000FF, tex_beam, 64, 0, 255, 0, 0, 0, org[0], org[1], org[2] - 4096, org[0], org[1], org[2] + 4096, 0, 0, 0, 0, false, 1<<30, 1, PBLEND_ADD, PARTICLE_HBEAM, -1, -1, -1, 1, 1, 0, 0, NULL); + CL_NewParticle(vecorg, pt_beam, 0xFF0000, 0xFF0000, tex_beam, 64, 0, 255, 0, 0, 0, org[0] - 4096, org[1], org[2], org[0] + 4096, org[1], org[2], 0, 0, 0, 0, false, 1<<30, 1, PBLEND_ADD, PARTICLE_HBEAM, -1, -1, -1, 1, 1, 0, 0, NULL); + CL_NewParticle(vecorg, pt_beam, 0x00FF00, 0x00FF00, tex_beam, 64, 0, 255, 0, 0, 0, org[0], org[1] - 4096, org[2], org[0], org[1] + 4096, org[2], 0, 0, 0, 0, false, 1<<30, 1, PBLEND_ADD, PARTICLE_HBEAM, -1, -1, -1, 1, 1, 0, 0, NULL); + CL_NewParticle(vecorg, pt_beam, 0x0000FF, 0x0000FF, tex_beam, 64, 0, 255, 0, 0, 0, org[0], org[1], org[2] - 4096, org[0], org[1], org[2] + 4096, 0, 0, 0, 0, false, 1<<30, 1, PBLEND_ADD, PARTICLE_HBEAM, -1, -1, -1, 1, 1, 0, 0, NULL); } /* @@ -2425,7 +2430,7 @@ static void R_DrawDecal_TransparentCallback(const entity_render_t *ent, const rt const decal_t *d; float *v3f, *t2f, *c4f; particletexture_t *tex; - float right[3], up[3], size, ca; + vec_t right[3], up[3], size, ca; float alphascale = (1.0f / 65536.0f) * cl_particles_alpha.value; RSurf_ActiveWorldEntity(); @@ -2572,6 +2577,7 @@ killdecal: static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist) { + vec3_t vecorg, vecvel, baseright, baseup; int surfacelistindex; int batchstart, batchcount; const particle_t *p; @@ -2581,7 +2587,7 @@ static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const particletexture_t *tex; float up2[3], v[3], right[3], up[3], fog, ifog, size, len, lenfactor, alpha; // float ambient[3], diffuse[3], diffusenormal[3]; - float palpha, spintime, spinrad, spincos, spinsin, spinm1, spinm2, spinm3, spinm4, baseright[3], baseup[3]; + float palpha, spintime, spinrad, spincos, spinsin, spinm1, spinm2, spinm3, spinm4; vec4_t colormultiplier; float minparticledist_start, minparticledist_end; qboolean dofade; @@ -2649,7 +2655,12 @@ static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const c4f[3] = alpha; // note: lighting is not cheap! if (particletype[p->typeindex].lighting) - R_LightPoint(c4f, p->org, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT); + { + vecorg[0] = p->org[0]; + vecorg[1] = p->org[1]; + vecorg[2] = p->org[2]; + R_LightPoint(c4f, vecorg, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT); + } // mix in the fog color if (r_refdef.fogenabled) { @@ -2710,7 +2721,10 @@ static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const t2f[6] = tex->s2;t2f[7] = tex->t2; break; case PARTICLE_ORIENTED_DOUBLESIDED: - VectorVectors(p->vel, baseright, baseup); + vecvel[0] = p->vel[0]; + vecvel[1] = p->vel[1]; + vecvel[2] = p->vel[2]; + VectorVectors(vecvel, baseright, baseup); if (p->angle + p->spin) { spinrad = (p->angle + p->spin * (spintime - p->delayedspawn)) * (float)(M_PI / 180.0f); diff --git a/client.h b/client.h index 9f86fdab..c229d288 100644 --- a/client.h +++ b/client.h @@ -393,32 +393,22 @@ typedef struct entity_render_s double last_trace_visibility; // user wavefunc parameters (from csqc) - float userwavefunc_param[Q3WAVEFUNC_USER_COUNT]; + vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT]; } entity_render_t; typedef struct entity_persistent_s { - vec3_t trail_origin; - - // particle trail - float trail_time; + vec3_t trail_origin; // previous position for particle trail spawning + vec3_t oldorigin; // lerp + vec3_t oldangles; // lerp + vec3_t neworigin; // lerp + vec3_t newangles; // lerp + vec_t lerpstarttime; // lerp + vec_t lerpdeltatime; // lerp + float muzzleflash; // muzzleflash intensity, fades over time + float trail_time; // residual error accumulation for particle trail spawning (to keep spacing across frames) qboolean trail_allowed; // set to false by teleports, true by update code, prevents bad lerps - - // muzzleflash fading - float muzzleflash; - - // interpolated movement - - // start time of move - float lerpstarttime; - // time difference from start to end of move - float lerpdeltatime; - // the move itself, start and end - float oldorigin[3]; - float oldangles[3]; - float neworigin[3]; - float newangles[3]; } entity_persistent_t; diff --git a/clvm_cmds.c b/clvm_cmds.c index b1ed1035..c765ca25 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -29,15 +29,20 @@ r_refdef_view_t csqc_main_r_refdef_view; // #1 void(vector ang) makevectors static void VM_CL_makevectors (prvm_prog_t *prog) { + vec3_t angles, forward, right, up; VM_SAFEPARMCOUNT(1, VM_CL_makevectors); - AngleVectors (PRVM_G_VECTOR(OFS_PARM0), PRVM_clientglobalvector(v_forward), PRVM_clientglobalvector(v_right), PRVM_clientglobalvector(v_up)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), angles); + AngleVectors(angles, forward, right, up); + VectorCopy(forward, PRVM_clientglobalvector(v_forward)); + VectorCopy(right, PRVM_clientglobalvector(v_right)); + VectorCopy(up, PRVM_clientglobalvector(v_up)); } // #2 void(entity e, vector o) setorigin static void VM_CL_setorigin (prvm_prog_t *prog) { prvm_edict_t *e; - float *org; + prvm_vec_t *org; VM_SAFEPARMCOUNT(2, VM_CL_setorigin); e = PRVM_G_EDICT(OFS_PARM0); @@ -58,7 +63,7 @@ static void VM_CL_setorigin (prvm_prog_t *prog) CL_LinkEdict(e); } -static void SetMinMaxSize (prvm_prog_t *prog, prvm_edict_t *e, float *min, float *max) +static void SetMinMaxSizePRVM (prvm_prog_t *prog, prvm_edict_t *e, prvm_vec_t *min, prvm_vec_t *max) { int i; @@ -74,6 +79,14 @@ static void SetMinMaxSize (prvm_prog_t *prog, prvm_edict_t *e, float *min, float CL_LinkEdict (e); } +static void SetMinMaxSize (prvm_prog_t *prog, prvm_edict_t *e, const vec_t *min, const vec_t *max) +{ + prvm_vec3_t mins, maxs; + VectorCopy(min, mins); + VectorCopy(max, maxs); + SetMinMaxSizePRVM(prog, e, mins, maxs); +} + // #3 void(entity e, string m) setmodel static void VM_CL_setmodel (prvm_prog_t *prog) { @@ -116,7 +129,8 @@ static void VM_CL_setmodel (prvm_prog_t *prog) if( mod ) { // TODO: check if this breaks needed consistency and maybe add a cvar for it too?? [1/10/2008 Black] - //SetMinMaxSize (e, mod->normalmins, mod->normalmaxs); + // LordHavoc: erm you broke it by commenting this out - setmodel must do setsize or else the qc can't find out the model size, and ssqc does this by necessity, consistency. + SetMinMaxSize (prog, e, mod->normalmins, mod->normalmaxs); } else { @@ -129,7 +143,7 @@ static void VM_CL_setmodel (prvm_prog_t *prog) static void VM_CL_setsize (prvm_prog_t *prog) { prvm_edict_t *e; - float *min, *max; + vec3_t mins, maxs; VM_SAFEPARMCOUNT(3, VM_CL_setsize); e = PRVM_G_EDICT(OFS_PARM0); @@ -143,10 +157,10 @@ static void VM_CL_setsize (prvm_prog_t *prog) VM_Warning(prog, "setsize: can not modify free entity\n"); return; } - min = PRVM_G_VECTOR(OFS_PARM1); - max = PRVM_G_VECTOR(OFS_PARM2); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), mins); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), maxs); - SetMinMaxSize( prog, e, min, max ); + SetMinMaxSize( prog, e, mins, maxs ); CL_LinkEdict(e); } @@ -257,7 +271,7 @@ static void CL_VM_SetTraceGlobals(prvm_prog_t *prog, const trace_t *trace, int s // #16 void(vector v1, vector v2, float movetype, entity ignore) traceline static void VM_CL_traceline (prvm_prog_t *prog) { - float *v1, *v2; + vec3_t v1, v2; trace_t trace; int move, svent; prvm_edict_t *ent; @@ -268,12 +282,12 @@ static void VM_CL_traceline (prvm_prog_t *prog) prog->xfunction->builtinsprofile += 30; - v1 = PRVM_G_VECTOR(OFS_PARM0); - v2 = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), v1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), v2); move = (int)PRVM_G_FLOAT(OFS_PARM2); ent = PRVM_G_EDICT(OFS_PARM3); - if (IS_NAN(v1[0]) || IS_NAN(v1[1]) || IS_NAN(v1[2]) || IS_NAN(v2[0]) || IS_NAN(v2[1]) || IS_NAN(v2[2])) + if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) prog->error_cmd("%s: NAN errors detected in traceline('%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = CL_TraceLine(v1, v2, move, ent, CL_GenericHitSuperContentsMask(ent), CL_HitNetworkBrushModels(move), CL_HitNetworkPlayers(move), &svent, true, false); @@ -296,7 +310,7 @@ tracebox (vector1, vector mins, vector maxs, vector2, tryents) // LordHavoc: added this for my own use, VERY useful, similar to traceline static void VM_CL_tracebox (prvm_prog_t *prog) { - float *v1, *v2, *m1, *m2; + vec3_t v1, v2, m1, m2; trace_t trace; int move, svent; prvm_edict_t *ent; @@ -306,14 +320,14 @@ static void VM_CL_tracebox (prvm_prog_t *prog) prog->xfunction->builtinsprofile += 30; - v1 = PRVM_G_VECTOR(OFS_PARM0); - m1 = PRVM_G_VECTOR(OFS_PARM1); - m2 = PRVM_G_VECTOR(OFS_PARM2); - v2 = PRVM_G_VECTOR(OFS_PARM3); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), v1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), m1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), m2); + VectorCopy(PRVM_G_VECTOR(OFS_PARM3), v2); move = (int)PRVM_G_FLOAT(OFS_PARM4); ent = PRVM_G_EDICT(OFS_PARM5); - if (IS_NAN(v1[0]) || IS_NAN(v1[1]) || IS_NAN(v1[2]) || IS_NAN(v2[0]) || IS_NAN(v2[1]) || IS_NAN(v2[2])) + if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) prog->error_cmd("%s: NAN errors detected in tracebox('%f %f %f', '%f %f %f', '%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], m1[0], m1[1], m1[2], m2[0], m2[1], m2[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = CL_TraceBox(v1, m1, m2, v2, move, ent, CL_GenericHitSuperContentsMask(ent), CL_HitNetworkBrushModels(move), CL_HitNetworkPlayers(move), &svent, true); @@ -326,7 +340,7 @@ static trace_t CL_Trace_Toss (prvm_prog_t *prog, prvm_edict_t *tossent, prvm_edi { int i; float gravity; - vec3_t move, end; + vec3_t start, end, mins, maxs, move; vec3_t original_origin; vec3_t original_velocity; vec3_t original_angles; @@ -349,7 +363,10 @@ static trace_t CL_Trace_Toss (prvm_prog_t *prog, prvm_edict_t *tossent, prvm_edi VectorMA (PRVM_clientedictvector(tossent, angles), 0.05, PRVM_clientedictvector(tossent, avelocity), PRVM_clientedictvector(tossent, angles)); VectorScale (PRVM_clientedictvector(tossent, velocity), 0.05, move); VectorAdd (PRVM_clientedictvector(tossent, origin), move, end); - trace = CL_TraceBox(PRVM_clientedictvector(tossent, origin), PRVM_clientedictvector(tossent, mins), PRVM_clientedictvector(tossent, maxs), end, MOVE_NORMAL, tossent, CL_GenericHitSuperContentsMask(tossent), true, true, NULL, true); + VectorCopy(PRVM_clientedictvector(tossent, origin), start); + VectorCopy(PRVM_clientedictvector(tossent, mins), mins); + VectorCopy(PRVM_clientedictvector(tossent, maxs), maxs); + trace = CL_TraceBox(start, mins, maxs, end, MOVE_NORMAL, tossent, CL_GenericHitSuperContentsMask(tossent), true, true, NULL, true); VectorCopy (trace.endpos, PRVM_clientedictvector(tossent, origin)); if (trace.fraction < 1) @@ -513,7 +530,7 @@ static void VM_CL_findradius (prvm_prog_t *prog) static void VM_CL_droptofloor (prvm_prog_t *prog) { prvm_edict_t *ent; - vec3_t end; + vec3_t start, end, mins, maxs; trace_t trace; VM_SAFEPARMCOUNTRANGE(0, 2, VM_CL_droptofloor); // allow 2 parameters because the id1 defs.qc had an incorrect prototype @@ -533,10 +550,13 @@ static void VM_CL_droptofloor (prvm_prog_t *prog) return; } - VectorCopy (PRVM_clientedictvector(ent, origin), end); + VectorCopy(PRVM_clientedictvector(ent, origin), start); + VectorCopy(PRVM_clientedictvector(ent, mins), mins); + VectorCopy(PRVM_clientedictvector(ent, maxs), maxs); + VectorCopy(PRVM_clientedictvector(ent, origin), end); end[2] -= 256; - trace = CL_TraceBox(PRVM_clientedictvector(ent, origin), PRVM_clientedictvector(ent, mins), PRVM_clientedictvector(ent, maxs), end, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, NULL, true); + trace = CL_TraceBox(start, mins, maxs, end, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, NULL, true); if (trace.fraction != 1) { @@ -643,20 +663,22 @@ realcheck: // #41 float(vector v) pointcontents static void VM_CL_pointcontents (prvm_prog_t *prog) { + vec3_t point; VM_SAFEPARMCOUNT(1, VM_CL_pointcontents); - PRVM_G_FLOAT(OFS_RETURN) = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, CL_PointSuperContents(PRVM_G_VECTOR(OFS_PARM0))); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), point); + PRVM_G_FLOAT(OFS_RETURN) = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, CL_PointSuperContents(point)); } // #48 void(vector o, vector d, float color, float count) particle static void VM_CL_particle (prvm_prog_t *prog) { - float *org, *dir; + vec3_t org, dir; int count; unsigned char color; VM_SAFEPARMCOUNT(4, VM_CL_particle); - org = PRVM_G_VECTOR(OFS_PARM0); - dir = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), dir); color = (int)PRVM_G_FLOAT(OFS_PARM2); count = (int)PRVM_G_FLOAT(OFS_PARM3); CL_ParticleEffect(EFFECT_SVC_PARTICLE, count, org, org, dir, dir, NULL, color); @@ -665,11 +687,11 @@ static void VM_CL_particle (prvm_prog_t *prog) // #74 void(vector pos, string samp, float vol, float atten) ambientsound static void VM_CL_ambientsound (prvm_prog_t *prog) { - float *f; + vec3_t f; sfx_t *s; VM_SAFEPARMCOUNT(4, VM_CL_ambientsound); s = S_FindName(PRVM_G_STRING(OFS_PARM0)); - f = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), f); S_StaticSound (s, f, PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM3)*64); } @@ -677,11 +699,11 @@ static void VM_CL_ambientsound (prvm_prog_t *prog) static void VM_CL_getlight (prvm_prog_t *prog) { vec3_t ambientcolor, diffusecolor, diffusenormal; - vec_t *p; + vec3_t p; VM_SAFEPARMCOUNTRANGE(1, 3, VM_CL_getlight); - p = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), p); VectorClear(ambientcolor); VectorClear(diffusecolor); VectorClear(diffusenormal); @@ -783,7 +805,7 @@ static void VM_CL_R_AddEntity (prvm_prog_t *prog) static void VM_CL_R_SetView (prvm_prog_t *prog) { int c; - float *f; + prvm_vec_t *f; float k; VM_SAFEPARMCOUNTRANGE(1, 3, VM_CL_R_SetView); @@ -1079,9 +1101,9 @@ static void VM_CL_R_SetView (prvm_prog_t *prog) static void VM_CL_R_AddDynamicLight (prvm_prog_t *prog) { double t = Sys_DirtyTime(); - vec_t *org; + vec3_t org; float radius = 300; - vec_t *col; + vec3_t col; int style = -1; const char *cubemapname = NULL; int pflags = PFLAGS_CORONA | PFLAGS_FULLDYNAMIC; @@ -1099,9 +1121,9 @@ static void VM_CL_R_AddDynamicLight (prvm_prog_t *prog) if (r_refdef.scene.numlights >= MAX_DLIGHTS) return; - org = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); radius = PRVM_G_FLOAT(OFS_PARM1); - col = PRVM_G_VECTOR(OFS_PARM2); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), col); if (prog->argc >= 4) { style = (int)PRVM_G_FLOAT(OFS_PARM3); @@ -1134,29 +1156,31 @@ static void VM_CL_R_AddDynamicLight (prvm_prog_t *prog) //#310 vector (vector v) cs_unproject (EXT_CSQC) static void VM_CL_unproject (prvm_prog_t *prog) { - float *f; - vec3_t temp; + vec3_t f; + vec3_t temp; + vec3_t result; VM_SAFEPARMCOUNT(1, VM_CL_unproject); - f = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), f); VectorSet(temp, f[2], (-1.0 + 2.0 * (f[0] / vid_conwidth.integer)) * f[2] * -r_refdef.view.frustum_x, (-1.0 + 2.0 * (f[1] / vid_conheight.integer)) * f[2] * -r_refdef.view.frustum_y); if(v_flipped.integer) temp[1] = -temp[1]; - Matrix4x4_Transform(&r_refdef.view.matrix, temp, PRVM_G_VECTOR(OFS_RETURN)); + Matrix4x4_Transform(&r_refdef.view.matrix, temp, result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); } //#311 vector (vector v) cs_project (EXT_CSQC) static void VM_CL_project (prvm_prog_t *prog) { - float *f; - vec3_t v; + vec3_t f; + vec3_t v; matrix4x4_t m; VM_SAFEPARMCOUNT(1, VM_CL_project); - f = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), f); Matrix4x4_Invert_Simple(&m, &r_refdef.view.matrix); Matrix4x4_Transform(&m, f, v); if(v_flipped.integer) @@ -1305,18 +1329,19 @@ static void VM_CL_particleeffectnum (prvm_prog_t *prog) static void VM_CL_trailparticles (prvm_prog_t *prog) { int i; - float *start, *end; + vec3_t start, end, velocity; prvm_edict_t *t; VM_SAFEPARMCOUNTRANGE(4, 5, VM_CL_trailparticles); t = PRVM_G_EDICT(OFS_PARM0); i = (int)PRVM_G_FLOAT(OFS_PARM1); - start = PRVM_G_VECTOR(OFS_PARM2); - end = PRVM_G_VECTOR(OFS_PARM3); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), start); + VectorCopy(PRVM_G_VECTOR(OFS_PARM3), end); + VectorCopy(PRVM_clientedictvector(t, velocity), velocity); if (i < 0) return; - CL_ParticleEffect(i, 1, start, end, PRVM_clientedictvector(t, velocity), PRVM_clientedictvector(t, velocity), NULL, prog->argc >= 5 ? (int)PRVM_G_FLOAT(OFS_PARM4) : 0); + CL_ParticleEffect(i, 1, start, end, velocity, velocity, NULL, prog->argc >= 5 ? (int)PRVM_G_FLOAT(OFS_PARM4) : 0); } //#337 void(float effectnum, vector origin, vector dir, float count[, float color]) pointparticles (EXT_CSQC) @@ -1324,11 +1349,11 @@ static void VM_CL_pointparticles (prvm_prog_t *prog) { int i; float n; - float *f, *v; + vec3_t f, v; VM_SAFEPARMCOUNTRANGE(4, 5, VM_CL_pointparticles); i = (int)PRVM_G_FLOAT(OFS_PARM0); - f = PRVM_G_VECTOR(OFS_PARM1); - v = PRVM_G_VECTOR(OFS_PARM2); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), f); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), v); n = PRVM_G_FLOAT(OFS_PARM3); if (i < 0) return; @@ -1340,7 +1365,7 @@ static void VM_CL_boxparticles (prvm_prog_t *prog) { int effectnum; // prvm_edict_t *own; - float *origin_from, *origin_to, *dir_from, *dir_to; + vec3_t origin_from, origin_to, dir_from, dir_to; float count; int flags; float tintmins[4], tintmaxs[4]; @@ -1348,10 +1373,10 @@ static void VM_CL_boxparticles (prvm_prog_t *prog) effectnum = (int)PRVM_G_FLOAT(OFS_PARM0); // own = PRVM_G_EDICT(OFS_PARM1); // TODO find use for this - origin_from = PRVM_G_VECTOR(OFS_PARM2); - origin_to = PRVM_G_VECTOR(OFS_PARM3); - dir_from = PRVM_G_VECTOR(OFS_PARM4); - dir_to = PRVM_G_VECTOR(OFS_PARM5); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), origin_from); + VectorCopy(PRVM_G_VECTOR(OFS_PARM3), origin_to ); + VectorCopy(PRVM_G_VECTOR(OFS_PARM4), dir_from ); + VectorCopy(PRVM_G_VECTOR(OFS_PARM5), dir_to ); count = PRVM_G_FLOAT(OFS_PARM6); if(prog->argc >= 8) flags = PRVM_G_FLOAT(OFS_PARM7); @@ -1588,8 +1613,13 @@ static void VM_CL_getplayerkey (prvm_prog_t *prog) //#351 void(vector origin, vector forward, vector right, vector up) SetListener (EXT_CSQC) static void VM_CL_setlistener (prvm_prog_t *prog) { + vec3_t origin, forward, left, up; VM_SAFEPARMCOUNT(4, VM_CL_setlistener); - Matrix4x4_FromVectors(&cl.csqc_listenermatrix, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), PRVM_G_VECTOR(OFS_PARM3), PRVM_G_VECTOR(OFS_PARM0)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), origin); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), forward); + VectorNegate(PRVM_G_VECTOR(OFS_PARM2), left); + VectorCopy(PRVM_G_VECTOR(OFS_PARM3), up); + Matrix4x4_FromVectors(&cl.csqc_listenermatrix, forward, left, up, origin); cl.csqc_usecsqclistener = true; //use csqc listener at this frame } @@ -1769,9 +1799,12 @@ static void VM_CL_makestatic (prvm_prog_t *prog) renderflags = (int)PRVM_clientedictfloat(ent, renderflags); if (renderflags & RF_USEAXIS) { - vec3_t left; + vec3_t forward, left, up, origin; + VectorCopy(PRVM_clientglobalvector(v_forward), forward); VectorNegate(PRVM_clientglobalvector(v_right), left); - Matrix4x4_FromVectors(&staticent->render.matrix, PRVM_clientglobalvector(v_forward), left, PRVM_clientglobalvector(v_up), PRVM_clientedictvector(ent, origin)); + VectorCopy(PRVM_clientglobalvector(v_up), up); + VectorCopy(PRVM_clientedictvector(ent, origin), origin); + Matrix4x4_FromVectors(&staticent->render.matrix, forward, left, up, origin); Matrix4x4_Scale(&staticent->render.matrix, staticent->render.scale, 1); } else @@ -1842,7 +1875,7 @@ static void VM_CL_copyentity (prvm_prog_t *prog) VM_Warning(prog, "copyentity: can not modify free entity\n"); return; } - memcpy(out->fields.vp, in->fields.vp, prog->entityfields * 4); + memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t)); CL_LinkEdict(out); } @@ -1851,28 +1884,30 @@ static void VM_CL_copyentity (prvm_prog_t *prog) // #404 void(vector org, string modelname, float startframe, float endframe, float framerate) effect (DP_SV_EFFECT) static void VM_CL_effect (prvm_prog_t *prog) { + vec3_t org; VM_SAFEPARMCOUNT(5, VM_CL_effect); - CL_Effect(PRVM_G_VECTOR(OFS_PARM0), (int)PRVM_G_FLOAT(OFS_PARM1), (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), PRVM_G_FLOAT(OFS_PARM4)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); + CL_Effect(org, (int)PRVM_G_FLOAT(OFS_PARM1), (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), PRVM_G_FLOAT(OFS_PARM4)); } // #405 void(vector org, vector velocity, float howmany) te_blood (DP_TE_BLOOD) static void VM_CL_te_blood (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, vel, pos2; VM_SAFEPARMCOUNT(3, VM_CL_te_blood); if (PRVM_G_FLOAT(OFS_PARM2) < 1) return; - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), vel); CL_FindNonSolidLocation(pos, pos2, 4); - CL_ParticleEffect(EFFECT_TE_BLOOD, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM1), NULL, 0); + CL_ParticleEffect(EFFECT_TE_BLOOD, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, vel, vel, NULL, 0); } // #406 void(vector mincorner, vector maxcorner, float explosionspeed, float howmany) te_bloodshower (DP_TE_BLOODSHOWER) static void VM_CL_te_bloodshower (prvm_prog_t *prog) { vec_t speed; - vec3_t vel1, vel2; + vec3_t mincorner, maxcorner, vel1, vel2; VM_SAFEPARMCOUNT(4, VM_CL_te_bloodshower); if (PRVM_G_FLOAT(OFS_PARM3) < 1) return; @@ -1883,17 +1918,19 @@ static void VM_CL_te_bloodshower (prvm_prog_t *prog) vel2[0] = speed; vel2[1] = speed; vel2[2] = speed; - CL_ParticleEffect(EFFECT_TE_BLOOD, PRVM_G_FLOAT(OFS_PARM3), PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), vel1, vel2, NULL, 0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), mincorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), maxcorner); + CL_ParticleEffect(EFFECT_TE_BLOOD, PRVM_G_FLOAT(OFS_PARM3), mincorner, maxcorner, vel1, vel2, NULL, 0); } // #407 void(vector org, vector color) te_explosionrgb (DP_TE_EXPLOSIONRGB) static void VM_CL_te_explosionrgb (prvm_prog_t *prog) { - float *pos; + vec3_t pos; vec3_t pos2; matrix4x4_t tempmatrix; VM_SAFEPARMCOUNT(2, VM_CL_te_explosionrgb); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 10); CL_ParticleExplosion(pos2); Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]); @@ -1903,46 +1940,57 @@ static void VM_CL_te_explosionrgb (prvm_prog_t *prog) // #408 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color, float gravityflag, float randomveljitter) te_particlecube (DP_TE_PARTICLECUBE) static void VM_CL_te_particlecube (prvm_prog_t *prog) { + vec3_t mincorner, maxcorner, vel; VM_SAFEPARMCOUNT(7, VM_CL_te_particlecube); - CL_ParticleCube(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), PRVM_G_FLOAT(OFS_PARM5), PRVM_G_FLOAT(OFS_PARM6)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), mincorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), maxcorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), vel); + CL_ParticleCube(mincorner, maxcorner, vel, (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), PRVM_G_FLOAT(OFS_PARM5), PRVM_G_FLOAT(OFS_PARM6)); } // #409 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color) te_particlerain (DP_TE_PARTICLERAIN) static void VM_CL_te_particlerain (prvm_prog_t *prog) { + vec3_t mincorner, maxcorner, vel; VM_SAFEPARMCOUNT(5, VM_CL_te_particlerain); - CL_ParticleRain(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), 0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), mincorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), maxcorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), vel); + CL_ParticleRain(mincorner, maxcorner, vel, (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), 0); } // #410 void(vector mincorner, vector maxcorner, vector vel, float howmany, float color) te_particlesnow (DP_TE_PARTICLESNOW) static void VM_CL_te_particlesnow (prvm_prog_t *prog) { + vec3_t mincorner, maxcorner, vel; VM_SAFEPARMCOUNT(5, VM_CL_te_particlesnow); - CL_ParticleRain(PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), 1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), mincorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), maxcorner); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), vel); + CL_ParticleRain(mincorner, maxcorner, vel, (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4), 1); } // #411 void(vector org, vector vel, float howmany) te_spark static void VM_CL_te_spark (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2, vel; VM_SAFEPARMCOUNT(3, VM_CL_te_spark); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), vel); CL_FindNonSolidLocation(pos, pos2, 4); - CL_ParticleEffect(EFFECT_TE_SPARK, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM1), NULL, 0); + CL_ParticleEffect(EFFECT_TE_SPARK, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, vel, vel, NULL, 0); } extern cvar_t cl_sound_ric_gunshot; // #412 void(vector org) te_gunshotquad (DP_QUADEFFECTS1) static void VM_CL_te_gunshotquad (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; int rnd; VM_SAFEPARMCOUNT(1, VM_CL_te_gunshotquad); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_GUNSHOTQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); if(cl_sound_ric_gunshot.integer >= 2) @@ -1961,12 +2009,11 @@ static void VM_CL_te_gunshotquad (prvm_prog_t *prog) // #413 void(vector org) te_spikequad (DP_QUADEFFECTS1) static void VM_CL_te_spikequad (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; int rnd; VM_SAFEPARMCOUNT(1, VM_CL_te_spikequad); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_SPIKEQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); if (rand() % 5) S_StartSound(-1, 0, cl.sfx_tink1, pos2, 1, 1); @@ -1982,12 +2029,11 @@ static void VM_CL_te_spikequad (prvm_prog_t *prog) // #414 void(vector org) te_superspikequad (DP_QUADEFFECTS1) static void VM_CL_te_superspikequad (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; int rnd; VM_SAFEPARMCOUNT(1, VM_CL_te_superspikequad); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_SUPERSPIKEQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); if (rand() % 5) S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1); @@ -2003,11 +2049,10 @@ static void VM_CL_te_superspikequad (prvm_prog_t *prog) // #415 void(vector org) te_explosionquad (DP_QUADEFFECTS1) static void VM_CL_te_explosionquad (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_explosionquad); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 10); CL_ParticleEffect(EFFECT_TE_EXPLOSIONQUAD, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1); @@ -2016,11 +2061,10 @@ static void VM_CL_te_explosionquad (prvm_prog_t *prog) // #416 void(vector org) te_smallflash (DP_TE_SMALLFLASH) static void VM_CL_te_smallflash (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_smallflash); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 10); CL_ParticleEffect(EFFECT_TE_SMALLFLASH, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); } @@ -2028,12 +2072,11 @@ static void VM_CL_te_smallflash (prvm_prog_t *prog) // #417 void(vector org, float radius, float lifetime, vector color) te_customflash (DP_TE_CUSTOMFLASH) static void VM_CL_te_customflash (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; matrix4x4_t tempmatrix; VM_SAFEPARMCOUNT(4, VM_CL_te_customflash); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); Matrix4x4_CreateTranslate(&tempmatrix, pos2[0], pos2[1], pos2[2]); CL_AllocLightFlash(NULL, &tempmatrix, PRVM_G_FLOAT(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM3)[0], PRVM_G_VECTOR(OFS_PARM3)[1], PRVM_G_VECTOR(OFS_PARM3)[2], PRVM_G_FLOAT(OFS_PARM1) / PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM2), 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE); @@ -2042,12 +2085,11 @@ static void VM_CL_te_customflash (prvm_prog_t *prog) // #418 void(vector org) te_gunshot (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_gunshot (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; int rnd; VM_SAFEPARMCOUNT(1, VM_CL_te_gunshot); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_GUNSHOT, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); if(cl_sound_ric_gunshot.integer == 1 || cl_sound_ric_gunshot.integer == 3) @@ -2066,12 +2108,11 @@ static void VM_CL_te_gunshot (prvm_prog_t *prog) // #419 void(vector org) te_spike (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_spike (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; int rnd; VM_SAFEPARMCOUNT(1, VM_CL_te_spike); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_SPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); if (rand() % 5) S_StartSound(-1, 0, cl.sfx_tink1, pos2, 1, 1); @@ -2087,12 +2128,11 @@ static void VM_CL_te_spike (prvm_prog_t *prog) // #420 void(vector org) te_superspike (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_superspike (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; int rnd; VM_SAFEPARMCOUNT(1, VM_CL_te_superspike); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_SUPERSPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); if (rand() % 5) S_StartSound(-1, 0, cl.sfx_tink1, pos2, 1, 1); @@ -2108,11 +2148,10 @@ static void VM_CL_te_superspike (prvm_prog_t *prog) // #421 void(vector org) te_explosion (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_explosion (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_explosion); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 10); CL_ParticleEffect(EFFECT_TE_EXPLOSION, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1); @@ -2121,11 +2160,10 @@ static void VM_CL_te_explosion (prvm_prog_t *prog) // #422 void(vector org) te_tarexplosion (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_tarexplosion (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_tarexplosion); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 10); CL_ParticleEffect(EFFECT_TE_TAREXPLOSION, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); S_StartSound(-1, 0, cl.sfx_r_exp3, pos2, 1, 1); @@ -2134,11 +2172,10 @@ static void VM_CL_te_tarexplosion (prvm_prog_t *prog) // #423 void(vector org) te_wizspike (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_wizspike (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_wizspike); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_WIZSPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); S_StartSound(-1, 0, cl.sfx_wizhit, pos2, 1, 1); @@ -2147,11 +2184,10 @@ static void VM_CL_te_wizspike (prvm_prog_t *prog) // #424 void(vector org) te_knightspike (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_knightspike (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_knightspike); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_KNIGHTSPIKE, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); S_StartSound(-1, 0, cl.sfx_knighthit, pos2, 1, 1); @@ -2160,28 +2196,31 @@ static void VM_CL_te_knightspike (prvm_prog_t *prog) // #425 void(vector org) te_lavasplash (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_lavasplash (prvm_prog_t *prog) { + vec3_t pos; VM_SAFEPARMCOUNT(1, VM_CL_te_lavasplash); - CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM0), vec3_origin, vec3_origin, NULL, 0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); + CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0); } // #426 void(vector org) te_teleport (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_teleport (prvm_prog_t *prog) { + vec3_t pos; VM_SAFEPARMCOUNT(1, VM_CL_te_teleport); - CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, PRVM_G_VECTOR(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM0), vec3_origin, vec3_origin, NULL, 0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); + CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0); } // #427 void(vector org, float colorstart, float colorlength) te_explosion2 (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_explosion2 (prvm_prog_t *prog) { - float *pos; - vec3_t pos2, color; + vec3_t pos, pos2, color; matrix4x4_t tempmatrix; int colorStart, colorLength; unsigned char *tempcolor; VM_SAFEPARMCOUNT(3, VM_CL_te_explosion2); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); colorStart = (int)PRVM_G_FLOAT(OFS_PARM1); colorLength = (int)PRVM_G_FLOAT(OFS_PARM2); CL_FindNonSolidLocation(pos, pos2, 10); @@ -2199,39 +2238,50 @@ static void VM_CL_te_explosion2 (prvm_prog_t *prog) // #428 void(entity own, vector start, vector end) te_lightning1 (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_lightning1 (prvm_prog_t *prog) { + vec3_t start, end; VM_SAFEPARMCOUNT(3, VM_CL_te_lightning1); - CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_bolt, true); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), start); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), end); + CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), start, end, cl.model_bolt, true); } // #429 void(entity own, vector start, vector end) te_lightning2 (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_lightning2 (prvm_prog_t *prog) { + vec3_t start, end; VM_SAFEPARMCOUNT(3, VM_CL_te_lightning2); - CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_bolt2, true); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), start); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), end); + CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), start, end, cl.model_bolt2, true); } // #430 void(entity own, vector start, vector end) te_lightning3 (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_lightning3 (prvm_prog_t *prog) { + vec3_t start, end; VM_SAFEPARMCOUNT(3, VM_CL_te_lightning3); - CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_bolt3, false); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), start); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), end); + CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), start, end, cl.model_bolt3, false); } // #431 void(entity own, vector start, vector end) te_beam (DP_TE_STANDARDEFFECTBUILTINS) static void VM_CL_te_beam (prvm_prog_t *prog) { + vec3_t start, end; VM_SAFEPARMCOUNT(3, VM_CL_te_beam); - CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM2), cl.model_beam, false); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), start); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), end); + CL_NewBeam(PRVM_G_EDICTNUM(OFS_PARM0), start, end, cl.model_beam, false); } // #433 void(vector org) te_plasmaburn (DP_TE_PLASMABURN) static void VM_CL_te_plasmaburn (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2; VM_SAFEPARMCOUNT(1, VM_CL_te_plasmaburn); - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); CL_FindNonSolidLocation(pos, pos2, 4); CL_ParticleEffect(EFFECT_TE_PLASMABURN, 1, pos2, pos2, vec3_origin, vec3_origin, NULL, 0); } @@ -2239,14 +2289,14 @@ static void VM_CL_te_plasmaburn (prvm_prog_t *prog) // #457 void(vector org, vector velocity, float howmany) te_flamejet (DP_TE_FLAMEJET) static void VM_CL_te_flamejet (prvm_prog_t *prog) { - float *pos; - vec3_t pos2; + vec3_t pos, pos2, vel; VM_SAFEPARMCOUNT(3, VM_CL_te_flamejet); if (PRVM_G_FLOAT(OFS_PARM2) < 1) return; - pos = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), vel); CL_FindNonSolidLocation(pos, pos2, 4); - CL_ParticleEffect(EFFECT_TE_FLAMEJET, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, PRVM_G_VECTOR(OFS_PARM1), PRVM_G_VECTOR(OFS_PARM1), NULL, 0); + CL_ParticleEffect(EFFECT_TE_FLAMEJET, PRVM_G_FLOAT(OFS_PARM2), pos2, pos2, vel, vel, NULL, 0); } @@ -2520,7 +2570,7 @@ static void VM_CL_gettaginfo (prvm_prog_t *prog) int parentindex; const char *tagname; int returncode; - vec3_t fo, le, up, trans; + vec3_t forward, left, up, origin; const dp_model_t *model; VM_SAFEPARMCOUNT(2, VM_CL_gettaginfo); @@ -2528,21 +2578,24 @@ static void VM_CL_gettaginfo (prvm_prog_t *prog) e = PRVM_G_EDICT(OFS_PARM0); tagindex = (int)PRVM_G_FLOAT(OFS_PARM1); returncode = CL_GetTagMatrix(prog, &tag_matrix, e, tagindex); - Matrix4x4_ToVectors(&tag_matrix, PRVM_clientglobalvector(v_forward), le, PRVM_clientglobalvector(v_up), PRVM_G_VECTOR(OFS_RETURN)); - VectorScale(le, -1, PRVM_clientglobalvector(v_right)); + Matrix4x4_ToVectors(&tag_matrix, forward, left, up, origin); + VectorCopy(forward, PRVM_clientglobalvector(v_forward)); + VectorScale(left, -1, PRVM_clientglobalvector(v_right)); + VectorCopy(up, PRVM_clientglobalvector(v_up)); + VectorCopy(origin, PRVM_G_VECTOR(OFS_RETURN)); model = CL_GetModelFromEdict(e); VM_GenerateFrameGroupBlend(prog, e->priv.server->framegroupblend, e); VM_FrameBlendFromFrameGroupBlend(e->priv.server->frameblend, e->priv.server->framegroupblend, model, cl.time); VM_UpdateEdictSkeleton(prog, e, model, e->priv.server->frameblend); CL_GetExtendedTagInfo(prog, e, tagindex, &parentindex, &tagname, &tag_localmatrix); - Matrix4x4_ToVectors(&tag_localmatrix, fo, le, up, trans); + Matrix4x4_ToVectors(&tag_localmatrix, forward, left, up, origin); PRVM_clientglobalfloat(gettaginfo_parent) = parentindex; PRVM_clientglobalstring(gettaginfo_name) = tagname ? PRVM_SetTempString(prog, tagname) : 0; - VectorCopy(trans, PRVM_clientglobalvector(gettaginfo_offset)); - VectorCopy(fo, PRVM_clientglobalvector(gettaginfo_forward)); - VectorScale(le, -1, PRVM_clientglobalvector(gettaginfo_right)); + VectorCopy(forward, PRVM_clientglobalvector(gettaginfo_forward)); + VectorScale(left, -1, PRVM_clientglobalvector(gettaginfo_right)); VectorCopy(up, PRVM_clientglobalvector(gettaginfo_up)); + VectorCopy(origin, PRVM_clientglobalvector(gettaginfo_offset)); switch(returncode) { @@ -2613,35 +2666,6 @@ typedef struct vmparticlespawner_s qboolean verified; vmparticletheme_t *themes; int max_themes; - // global addresses - float *particle_type; - float *particle_blendmode; - float *particle_orientation; - float *particle_color1; - float *particle_color2; - float *particle_tex; - float *particle_size; - float *particle_sizeincrease; - float *particle_alpha; - float *particle_alphafade; - float *particle_time; - float *particle_gravity; - float *particle_bounce; - float *particle_airfriction; - float *particle_liquidfriction; - float *particle_originjitter; - float *particle_velocityjitter; - float *particle_qualityreduction; - float *particle_stretch; - float *particle_staincolor1; - float *particle_staincolor2; - float *particle_stainalpha; - float *particle_stainsize; - float *particle_staintex; - float *particle_delayspawn; - float *particle_delaycollision; - float *particle_angle; - float *particle_spin; }vmparticlespawner_t; vmparticlespawner_t vmpartspawner; @@ -2665,38 +2689,6 @@ static void VM_InitParticleSpawner (prvm_prog_t *prog, int maxthemes) vmpartspawner.max_themes = maxthemes; vmpartspawner.initialized = true; vmpartspawner.verified = true; - // get field addresses for fast querying (we can do 1000 calls of spawnparticle in a frame) - vmpartspawner.particle_type = &PRVM_clientglobalfloat(particle_type); - vmpartspawner.particle_blendmode = &PRVM_clientglobalfloat(particle_blendmode); - vmpartspawner.particle_orientation = &PRVM_clientglobalfloat(particle_orientation); - vmpartspawner.particle_color1 = PRVM_clientglobalvector(particle_color1); - vmpartspawner.particle_color2 = PRVM_clientglobalvector(particle_color2); - vmpartspawner.particle_tex = &PRVM_clientglobalfloat(particle_tex); - vmpartspawner.particle_size = &PRVM_clientglobalfloat(particle_size); - vmpartspawner.particle_sizeincrease = &PRVM_clientglobalfloat(particle_sizeincrease); - vmpartspawner.particle_alpha = &PRVM_clientglobalfloat(particle_alpha); - vmpartspawner.particle_alphafade = &PRVM_clientglobalfloat(particle_alphafade); - vmpartspawner.particle_time = &PRVM_clientglobalfloat(particle_time); - vmpartspawner.particle_gravity = &PRVM_clientglobalfloat(particle_gravity); - vmpartspawner.particle_bounce = &PRVM_clientglobalfloat(particle_bounce); - vmpartspawner.particle_airfriction = &PRVM_clientglobalfloat(particle_airfriction); - vmpartspawner.particle_liquidfriction = &PRVM_clientglobalfloat(particle_liquidfriction); - vmpartspawner.particle_originjitter = &PRVM_clientglobalfloat(particle_originjitter); - vmpartspawner.particle_velocityjitter = &PRVM_clientglobalfloat(particle_velocityjitter); - vmpartspawner.particle_qualityreduction = &PRVM_clientglobalfloat(particle_qualityreduction); - vmpartspawner.particle_stretch = &PRVM_clientglobalfloat(particle_stretch); - vmpartspawner.particle_staincolor1 = PRVM_clientglobalvector(particle_staincolor1); - vmpartspawner.particle_staincolor2 = PRVM_clientglobalvector(particle_staincolor2); - vmpartspawner.particle_stainalpha = &PRVM_clientglobalfloat(particle_stainalpha); - vmpartspawner.particle_stainsize = &PRVM_clientglobalfloat(particle_stainsize); - vmpartspawner.particle_staintex = &PRVM_clientglobalfloat(particle_staintex); - vmpartspawner.particle_staintex = &PRVM_clientglobalfloat(particle_staintex); - vmpartspawner.particle_delayspawn = &PRVM_clientglobalfloat(particle_delayspawn); - vmpartspawner.particle_delaycollision = &PRVM_clientglobalfloat(particle_delaycollision); - vmpartspawner.particle_angle = &PRVM_clientglobalfloat(particle_angle); - vmpartspawner.particle_spin = &PRVM_clientglobalfloat(particle_spin); - #undef getglobal - #undef getglobalvector } // reset particle theme to default values @@ -2732,77 +2724,70 @@ static void VM_ResetParticleTheme (vmparticletheme_t *theme) } // particle theme -> QC globals -static void VM_CL_ParticleThemeToGlobals(vmparticletheme_t *theme) -{ - *vmpartspawner.particle_type = theme->typeindex; - *vmpartspawner.particle_blendmode = theme->blendmode; - *vmpartspawner.particle_orientation = theme->orientation; - vmpartspawner.particle_color1[0] = (theme->color1 >> 16) & 0xFF; // VorteX: int only can store 0-255, not 0-256 which means 0 - 0,99609375... - vmpartspawner.particle_color1[1] = (theme->color1 >> 8) & 0xFF; - vmpartspawner.particle_color1[2] = (theme->color1 >> 0) & 0xFF; - vmpartspawner.particle_color2[0] = (theme->color2 >> 16) & 0xFF; - vmpartspawner.particle_color2[1] = (theme->color2 >> 8) & 0xFF; - vmpartspawner.particle_color2[2] = (theme->color2 >> 0) & 0xFF; - *vmpartspawner.particle_tex = (float)theme->tex; - *vmpartspawner.particle_size = theme->size; - *vmpartspawner.particle_sizeincrease = theme->sizeincrease; - *vmpartspawner.particle_alpha = theme->alpha/256; - *vmpartspawner.particle_alphafade = theme->alphafade/256; - *vmpartspawner.particle_time = theme->lifetime; - *vmpartspawner.particle_gravity = theme->gravity; - *vmpartspawner.particle_bounce = theme->bounce; - *vmpartspawner.particle_airfriction = theme->airfriction; - *vmpartspawner.particle_liquidfriction = theme->liquidfriction; - *vmpartspawner.particle_originjitter = theme->originjitter; - *vmpartspawner.particle_velocityjitter = theme->velocityjitter; - *vmpartspawner.particle_qualityreduction = theme->qualityreduction; - *vmpartspawner.particle_stretch = theme->stretch; - vmpartspawner.particle_staincolor1[0] = ((int)theme->staincolor1 >> 16) & 0xFF; - vmpartspawner.particle_staincolor1[1] = ((int)theme->staincolor1 >> 8) & 0xFF; - vmpartspawner.particle_staincolor1[2] = ((int)theme->staincolor1 >> 0) & 0xFF; - vmpartspawner.particle_staincolor2[0] = ((int)theme->staincolor2 >> 16) & 0xFF; - vmpartspawner.particle_staincolor2[1] = ((int)theme->staincolor2 >> 8) & 0xFF; - vmpartspawner.particle_staincolor2[2] = ((int)theme->staincolor2 >> 0) & 0xFF; - *vmpartspawner.particle_staintex = (float)theme->staintex; - *vmpartspawner.particle_stainalpha = (float)theme->stainalpha/256; - *vmpartspawner.particle_stainsize = (float)theme->stainsize; - *vmpartspawner.particle_delayspawn = theme->delayspawn; - *vmpartspawner.particle_delaycollision = theme->delaycollision; - *vmpartspawner.particle_angle = theme->angle; - *vmpartspawner.particle_spin = theme->spin; +static void VM_CL_ParticleThemeToGlobals(vmparticletheme_t *theme, prvm_prog_t *prog) +{ + PRVM_clientglobalfloat(particle_type) = theme->typeindex; + PRVM_clientglobalfloat(particle_blendmode) = theme->blendmode; + PRVM_clientglobalfloat(particle_orientation) = theme->orientation; + // VorteX: int only can store 0-255, not 0-256 which means 0 - 0,99609375... + VectorSet(PRVM_clientglobalvector(particle_color1), (theme->color1 >> 16) & 0xFF, (theme->color1 >> 8) & 0xFF, (theme->color1 >> 0) & 0xFF); + VectorSet(PRVM_clientglobalvector(particle_color2), (theme->color2 >> 16) & 0xFF, (theme->color2 >> 8) & 0xFF, (theme->color2 >> 0) & 0xFF); + PRVM_clientglobalfloat(particle_tex) = (float)theme->tex; + PRVM_clientglobalfloat(particle_size) = theme->size; + PRVM_clientglobalfloat(particle_sizeincrease) = theme->sizeincrease; + PRVM_clientglobalfloat(particle_alpha) = theme->alpha/256; + PRVM_clientglobalfloat(particle_alphafade) = theme->alphafade/256; + PRVM_clientglobalfloat(particle_time) = theme->lifetime; + PRVM_clientglobalfloat(particle_gravity) = theme->gravity; + PRVM_clientglobalfloat(particle_bounce) = theme->bounce; + PRVM_clientglobalfloat(particle_airfriction) = theme->airfriction; + PRVM_clientglobalfloat(particle_liquidfriction) = theme->liquidfriction; + PRVM_clientglobalfloat(particle_originjitter) = theme->originjitter; + PRVM_clientglobalfloat(particle_velocityjitter) = theme->velocityjitter; + PRVM_clientglobalfloat(particle_qualityreduction) = theme->qualityreduction; + PRVM_clientglobalfloat(particle_stretch) = theme->stretch; + VectorSet(PRVM_clientglobalvector(particle_staincolor1), ((int)theme->staincolor1 >> 16) & 0xFF, ((int)theme->staincolor1 >> 8) & 0xFF, ((int)theme->staincolor1 >> 0) & 0xFF); + VectorSet(PRVM_clientglobalvector(particle_staincolor2), ((int)theme->staincolor2 >> 16) & 0xFF, ((int)theme->staincolor2 >> 8) & 0xFF, ((int)theme->staincolor2 >> 0) & 0xFF); + PRVM_clientglobalfloat(particle_staintex) = (float)theme->staintex; + PRVM_clientglobalfloat(particle_stainalpha) = (float)theme->stainalpha/256; + PRVM_clientglobalfloat(particle_stainsize) = (float)theme->stainsize; + PRVM_clientglobalfloat(particle_delayspawn) = theme->delayspawn; + PRVM_clientglobalfloat(particle_delaycollision) = theme->delaycollision; + PRVM_clientglobalfloat(particle_angle) = theme->angle; + PRVM_clientglobalfloat(particle_spin) = theme->spin; } // QC globals -> particle theme -static void VM_CL_ParticleThemeFromGlobals(vmparticletheme_t *theme) -{ - theme->typeindex = (unsigned short)*vmpartspawner.particle_type; - theme->blendmode = (pblend_t)(int)*vmpartspawner.particle_blendmode; - theme->orientation = (porientation_t)(int)*vmpartspawner.particle_orientation; - theme->color1 = ((int)vmpartspawner.particle_color1[0] << 16) + ((int)vmpartspawner.particle_color1[1] << 8) + ((int)vmpartspawner.particle_color1[2]); - theme->color2 = ((int)vmpartspawner.particle_color2[0] << 16) + ((int)vmpartspawner.particle_color2[1] << 8) + ((int)vmpartspawner.particle_color2[2]); - theme->tex = (int)*vmpartspawner.particle_tex; - theme->size = *vmpartspawner.particle_size; - theme->sizeincrease = *vmpartspawner.particle_sizeincrease; - theme->alpha = *vmpartspawner.particle_alpha*256; - theme->alphafade = *vmpartspawner.particle_alphafade*256; - theme->lifetime = *vmpartspawner.particle_time; - theme->gravity = *vmpartspawner.particle_gravity; - theme->bounce = *vmpartspawner.particle_bounce; - theme->airfriction = *vmpartspawner.particle_airfriction; - theme->liquidfriction = *vmpartspawner.particle_liquidfriction; - theme->originjitter = *vmpartspawner.particle_originjitter; - theme->velocityjitter = *vmpartspawner.particle_velocityjitter; - theme->qualityreduction = (*vmpartspawner.particle_qualityreduction) ? true : false; - theme->stretch = *vmpartspawner.particle_stretch; - theme->staincolor1 = ((int)vmpartspawner.particle_staincolor1[0])*65536 + (int)(vmpartspawner.particle_staincolor1[1])*256 + (int)(vmpartspawner.particle_staincolor1[2]); - theme->staincolor2 = (int)(vmpartspawner.particle_staincolor2[0])*65536 + (int)(vmpartspawner.particle_staincolor2[1])*256 + (int)(vmpartspawner.particle_staincolor2[2]); - theme->staintex =(int)*vmpartspawner.particle_staintex; - theme->stainalpha = *vmpartspawner.particle_stainalpha*256; - theme->stainsize = *vmpartspawner.particle_stainsize; - theme->delayspawn = *vmpartspawner.particle_delayspawn; - theme->delaycollision = *vmpartspawner.particle_delaycollision; - theme->angle = *vmpartspawner.particle_angle; - theme->spin = *vmpartspawner.particle_spin; +static void VM_CL_ParticleThemeFromGlobals(vmparticletheme_t *theme, prvm_prog_t *prog) +{ + theme->typeindex = (unsigned short)PRVM_clientglobalfloat(particle_type); + theme->blendmode = (pblend_t)(int)PRVM_clientglobalfloat(particle_blendmode); + theme->orientation = (porientation_t)(int)PRVM_clientglobalfloat(particle_orientation); + theme->color1 = ((int)PRVM_clientglobalvector(particle_color1)[0] << 16) + ((int)PRVM_clientglobalvector(particle_color1)[1] << 8) + ((int)PRVM_clientglobalvector(particle_color1)[2]); + theme->color2 = ((int)PRVM_clientglobalvector(particle_color2)[0] << 16) + ((int)PRVM_clientglobalvector(particle_color2)[1] << 8) + ((int)PRVM_clientglobalvector(particle_color2)[2]); + theme->tex = (int)PRVM_clientglobalfloat(particle_tex); + theme->size = PRVM_clientglobalfloat(particle_size); + theme->sizeincrease = PRVM_clientglobalfloat(particle_sizeincrease); + theme->alpha = PRVM_clientglobalfloat(particle_alpha)*256; + theme->alphafade = PRVM_clientglobalfloat(particle_alphafade)*256; + theme->lifetime = PRVM_clientglobalfloat(particle_time); + theme->gravity = PRVM_clientglobalfloat(particle_gravity); + theme->bounce = PRVM_clientglobalfloat(particle_bounce); + theme->airfriction = PRVM_clientglobalfloat(particle_airfriction); + theme->liquidfriction = PRVM_clientglobalfloat(particle_liquidfriction); + theme->originjitter = PRVM_clientglobalfloat(particle_originjitter); + theme->velocityjitter = PRVM_clientglobalfloat(particle_velocityjitter); + theme->qualityreduction = PRVM_clientglobalfloat(particle_qualityreduction) != 0 ? true : false; + theme->stretch = PRVM_clientglobalfloat(particle_stretch); + theme->staincolor1 = ((int)PRVM_clientglobalvector(particle_staincolor1)[0])*65536 + (int)(PRVM_clientglobalvector(particle_staincolor1)[1])*256 + (int)(PRVM_clientglobalvector(particle_staincolor1)[2]); + theme->staincolor2 = (int)(PRVM_clientglobalvector(particle_staincolor2)[0])*65536 + (int)(PRVM_clientglobalvector(particle_staincolor2)[1])*256 + (int)(PRVM_clientglobalvector(particle_staincolor2)[2]); + theme->staintex =(int)PRVM_clientglobalfloat(particle_staintex); + theme->stainalpha = PRVM_clientglobalfloat(particle_stainalpha)*256; + theme->stainsize = PRVM_clientglobalfloat(particle_stainsize); + theme->delayspawn = PRVM_clientglobalfloat(particle_delayspawn); + theme->delaycollision = PRVM_clientglobalfloat(particle_delaycollision); + theme->angle = PRVM_clientglobalfloat(particle_angle); + theme->spin = PRVM_clientglobalfloat(particle_spin); } // init particle spawner interface @@ -2825,7 +2810,7 @@ static void VM_CL_ResetParticle (prvm_prog_t *prog) VM_Warning(prog, "VM_CL_ResetParticle: particle spawner not initialized\n"); return; } - VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0]); + VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0], prog); } // void(float themenum) particletheme @@ -2843,17 +2828,17 @@ static void VM_CL_ParticleTheme (prvm_prog_t *prog) if (themenum < 0 || themenum >= vmpartspawner.max_themes) { VM_Warning(prog, "VM_CL_ParticleTheme: bad theme number %i\n", themenum); - VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0]); + VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0], prog); return; } if (vmpartspawner.themes[themenum].initialized == false) { VM_Warning(prog, "VM_CL_ParticleTheme: theme #%i not exists\n", themenum); - VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0]); + VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0], prog); return; } // load particle theme into globals - VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[themenum]); + VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[themenum], prog); } // float() saveparticletheme @@ -2884,7 +2869,7 @@ static void VM_CL_ParticleThemeSave (prvm_prog_t *prog) return; } vmpartspawner.themes[themenum].initialized = true; - VM_CL_ParticleThemeFromGlobals(&vmpartspawner.themes[themenum]); + VM_CL_ParticleThemeFromGlobals(&vmpartspawner.themes[themenum], prog); PRVM_G_FLOAT(OFS_RETURN) = themenum; return; } @@ -2896,7 +2881,7 @@ static void VM_CL_ParticleThemeSave (prvm_prog_t *prog) return; } vmpartspawner.themes[themenum].initialized = true; - VM_CL_ParticleThemeFromGlobals(&vmpartspawner.themes[themenum]); + VM_CL_ParticleThemeFromGlobals(&vmpartspawner.themes[themenum], prog); } // void(float themenum) freeparticletheme @@ -2920,7 +2905,7 @@ static void VM_CL_ParticleThemeFree (prvm_prog_t *prog) if (vmpartspawner.themes[themenum].initialized == false) { VM_Warning(prog, "VM_CL_ParticleThemeFree: theme #%i already freed\n", themenum); - VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0]); + VM_CL_ParticleThemeToGlobals(&vmpartspawner.themes[0], prog); return; } // free theme @@ -2932,7 +2917,7 @@ static void VM_CL_ParticleThemeFree (prvm_prog_t *prog) // returns 0 if failed, 1 if succesful static void VM_CL_SpawnParticle (prvm_prog_t *prog) { - float *org, *dir; + vec3_t org, dir; vmparticletheme_t *theme; particle_t *part; int themenum; @@ -2944,21 +2929,54 @@ static void VM_CL_SpawnParticle (prvm_prog_t *prog) PRVM_G_FLOAT(OFS_RETURN) = 0; return; } - org = PRVM_G_VECTOR(OFS_PARM0); - dir = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), dir); if (prog->argc < 3) // global-set particle { - part = CL_NewParticle(org, (unsigned short)*vmpartspawner.particle_type, ((int)(vmpartspawner.particle_color1[0]) << 16) + ((int)(vmpartspawner.particle_color1[1]) << 8) + ((int)(vmpartspawner.particle_color1[2])), ((int)vmpartspawner.particle_color2[0] << 16) + ((int)vmpartspawner.particle_color2[1] << 8) + ((int)vmpartspawner.particle_color2[2]), (int)*vmpartspawner.particle_tex, *vmpartspawner.particle_size, *vmpartspawner.particle_sizeincrease, *vmpartspawner.particle_alpha*256, *vmpartspawner.particle_alphafade*256, *vmpartspawner.particle_gravity, *vmpartspawner.particle_bounce, org[0], org[1], org[2], dir[0], dir[1], dir[2], *vmpartspawner.particle_airfriction, *vmpartspawner.particle_liquidfriction, *vmpartspawner.particle_originjitter, *vmpartspawner.particle_velocityjitter, (*vmpartspawner.particle_qualityreduction) ? true : false, *vmpartspawner.particle_time, *vmpartspawner.particle_stretch, (pblend_t)(int)*vmpartspawner.particle_blendmode, (porientation_t)(int)*vmpartspawner.particle_orientation, (int)(vmpartspawner.particle_staincolor1[0])*65536 + (int)(vmpartspawner.particle_staincolor1[1])*256 + (int)(vmpartspawner.particle_staincolor1[2]), (int)(vmpartspawner.particle_staincolor2[0])*65536 + (int)(vmpartspawner.particle_staincolor2[1])*256 + (int)(vmpartspawner.particle_staincolor2[2]), (int)*vmpartspawner.particle_staintex, *vmpartspawner.particle_stainalpha*256, *vmpartspawner.particle_stainsize, *vmpartspawner.particle_angle, *vmpartspawner.particle_spin, NULL); + part = CL_NewParticle(org, + (unsigned short)PRVM_clientglobalfloat(particle_type), + ((int)PRVM_clientglobalvector(particle_color1)[0] << 16) + ((int)PRVM_clientglobalvector(particle_color1)[1] << 8) + ((int)PRVM_clientglobalvector(particle_color1)[2]), + ((int)PRVM_clientglobalvector(particle_color2)[0] << 16) + ((int)PRVM_clientglobalvector(particle_color2)[1] << 8) + ((int)PRVM_clientglobalvector(particle_color2)[2]), + (int)PRVM_clientglobalfloat(particle_tex), + PRVM_clientglobalfloat(particle_size), + PRVM_clientglobalfloat(particle_sizeincrease), + PRVM_clientglobalfloat(particle_alpha)*256, + PRVM_clientglobalfloat(particle_alphafade)*256, + PRVM_clientglobalfloat(particle_gravity), + PRVM_clientglobalfloat(particle_bounce), + org[0], + org[1], + org[2], + dir[0], + dir[1], + dir[2], + PRVM_clientglobalfloat(particle_airfriction), + PRVM_clientglobalfloat(particle_liquidfriction), + PRVM_clientglobalfloat(particle_originjitter), + PRVM_clientglobalfloat(particle_velocityjitter), + (PRVM_clientglobalfloat(particle_qualityreduction)) ? true : false, + PRVM_clientglobalfloat(particle_time), + PRVM_clientglobalfloat(particle_stretch), + (pblend_t)(int)PRVM_clientglobalfloat(particle_blendmode), + (porientation_t)(int)PRVM_clientglobalfloat(particle_orientation), + (int)(PRVM_clientglobalvector(particle_staincolor1)[0])*65536 + (int)(PRVM_clientglobalvector(particle_staincolor1)[1])*256 + (int)(PRVM_clientglobalvector(particle_staincolor1)[2]), + (int)(PRVM_clientglobalvector(particle_staincolor2)[0])*65536 + (int)(PRVM_clientglobalvector(particle_staincolor2)[1])*256 + (int)(PRVM_clientglobalvector(particle_staincolor2)[2]), + (int)PRVM_clientglobalfloat(particle_staintex), + PRVM_clientglobalfloat(particle_stainalpha)*256, + PRVM_clientglobalfloat(particle_stainsize), + PRVM_clientglobalfloat(particle_angle), + PRVM_clientglobalfloat(particle_spin), + NULL); if (!part) { PRVM_G_FLOAT(OFS_RETURN) = 0; return; } - if (*vmpartspawner.particle_delayspawn) - part->delayedspawn = cl.time + *vmpartspawner.particle_delayspawn; - //if (*vmpartspawner.particle_delaycollision) - // part->delayedcollisions = cl.time + *vmpartspawner.particle_delaycollision; + if (PRVM_clientglobalfloat(particle_delayspawn)) + part->delayedspawn = cl.time + PRVM_clientglobalfloat(particle_delayspawn); + //if (PRVM_clientglobalfloat(particle_delaycollision)) + // part->delayedcollisions = cl.time + PRVM_clientglobalfloat(particle_delaycollision); } else // quick themed particle { @@ -2970,7 +2988,40 @@ static void VM_CL_SpawnParticle (prvm_prog_t *prog) return; } theme = &vmpartspawner.themes[themenum]; - part = CL_NewParticle(org, theme->typeindex, theme->color1, theme->color2, theme->tex, theme->size, theme->sizeincrease, theme->alpha, theme->alphafade, theme->gravity, theme->bounce, org[0], org[1], org[2], dir[0], dir[1], dir[2], theme->airfriction, theme->liquidfriction, theme->originjitter, theme->velocityjitter, theme->qualityreduction, theme->lifetime, theme->stretch, theme->blendmode, theme->orientation, theme->staincolor1, theme->staincolor2, theme->staintex, theme->stainalpha, theme->stainsize, theme->angle, theme->spin, NULL); + part = CL_NewParticle(org, + theme->typeindex, + theme->color1, + theme->color2, + theme->tex, + theme->size, + theme->sizeincrease, + theme->alpha, + theme->alphafade, + theme->gravity, + theme->bounce, + org[0], + org[1], + org[2], + dir[0], + dir[1], + dir[2], + theme->airfriction, + theme->liquidfriction, + theme->originjitter, + theme->velocityjitter, + theme->qualityreduction, + theme->lifetime, + theme->stretch, + theme->blendmode, + theme->orientation, + theme->staincolor1, + theme->staincolor2, + theme->staintex, + theme->stainalpha, + theme->stainsize, + theme->angle, + theme->spin, + NULL); if (!part) { PRVM_G_FLOAT(OFS_RETURN) = 0; @@ -2988,7 +3039,7 @@ static void VM_CL_SpawnParticle (prvm_prog_t *prog) // returns 0 if failed, 1 if success static void VM_CL_SpawnParticleDelayed (prvm_prog_t *prog) { - float *org, *dir; + vec3_t org, dir; vmparticletheme_t *theme; particle_t *part; int themenum; @@ -3000,10 +3051,43 @@ static void VM_CL_SpawnParticleDelayed (prvm_prog_t *prog) PRVM_G_FLOAT(OFS_RETURN) = 0; return; } - org = PRVM_G_VECTOR(OFS_PARM0); - dir = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), dir); if (prog->argc < 5) // global-set particle - part = CL_NewParticle(org, (unsigned short)*vmpartspawner.particle_type, ((int)vmpartspawner.particle_color1[0] << 16) + ((int)vmpartspawner.particle_color1[1] << 8) + ((int)vmpartspawner.particle_color1[2]), ((int)vmpartspawner.particle_color2[0] << 16) + ((int)vmpartspawner.particle_color2[1] << 8) + ((int)vmpartspawner.particle_color2[2]), (int)*vmpartspawner.particle_tex, *vmpartspawner.particle_size, *vmpartspawner.particle_sizeincrease, *vmpartspawner.particle_alpha*256, *vmpartspawner.particle_alphafade*256, *vmpartspawner.particle_gravity, *vmpartspawner.particle_bounce, org[0], org[1], org[2], dir[0], dir[1], dir[2], *vmpartspawner.particle_airfriction, *vmpartspawner.particle_liquidfriction, *vmpartspawner.particle_originjitter, *vmpartspawner.particle_velocityjitter, (*vmpartspawner.particle_qualityreduction) ? true : false, *vmpartspawner.particle_time, *vmpartspawner.particle_stretch, (pblend_t)(int)*vmpartspawner.particle_blendmode, (porientation_t)(int)*vmpartspawner.particle_orientation, ((int)vmpartspawner.particle_staincolor1[0] << 16) + ((int)vmpartspawner.particle_staincolor1[1] << 8) + ((int)vmpartspawner.particle_staincolor1[2]), ((int)vmpartspawner.particle_staincolor2[0] << 16) + ((int)vmpartspawner.particle_staincolor2[1] << 8) + ((int)vmpartspawner.particle_staincolor2[2]), (int)*vmpartspawner.particle_staintex, *vmpartspawner.particle_stainalpha*256, *vmpartspawner.particle_stainsize, *vmpartspawner.particle_angle, *vmpartspawner.particle_spin, NULL); + part = CL_NewParticle(org, + (unsigned short)PRVM_clientglobalfloat(particle_type), + ((int)PRVM_clientglobalvector(particle_color1)[0] << 16) + ((int)PRVM_clientglobalvector(particle_color1)[1] << 8) + ((int)PRVM_clientglobalvector(particle_color1)[2]), + ((int)PRVM_clientglobalvector(particle_color2)[0] << 16) + ((int)PRVM_clientglobalvector(particle_color2)[1] << 8) + ((int)PRVM_clientglobalvector(particle_color2)[2]), + (int)PRVM_clientglobalfloat(particle_tex), + PRVM_clientglobalfloat(particle_size), + PRVM_clientglobalfloat(particle_sizeincrease), + PRVM_clientglobalfloat(particle_alpha)*256, + PRVM_clientglobalfloat(particle_alphafade)*256, + PRVM_clientglobalfloat(particle_gravity), + PRVM_clientglobalfloat(particle_bounce), + org[0], + org[1], + org[2], + dir[0], + dir[1], + dir[2], + PRVM_clientglobalfloat(particle_airfriction), + PRVM_clientglobalfloat(particle_liquidfriction), + PRVM_clientglobalfloat(particle_originjitter), + PRVM_clientglobalfloat(particle_velocityjitter), + (PRVM_clientglobalfloat(particle_qualityreduction)) ? true : false, + PRVM_clientglobalfloat(particle_time), + PRVM_clientglobalfloat(particle_stretch), + (pblend_t)(int)PRVM_clientglobalfloat(particle_blendmode), + (porientation_t)(int)PRVM_clientglobalfloat(particle_orientation), + ((int)PRVM_clientglobalvector(particle_staincolor1)[0] << 16) + ((int)PRVM_clientglobalvector(particle_staincolor1)[1] << 8) + ((int)PRVM_clientglobalvector(particle_staincolor1)[2]), + ((int)PRVM_clientglobalvector(particle_staincolor2)[0] << 16) + ((int)PRVM_clientglobalvector(particle_staincolor2)[1] << 8) + ((int)PRVM_clientglobalvector(particle_staincolor2)[2]), + (int)PRVM_clientglobalfloat(particle_staintex), + PRVM_clientglobalfloat(particle_stainalpha)*256, + PRVM_clientglobalfloat(particle_stainsize), + PRVM_clientglobalfloat(particle_angle), + PRVM_clientglobalfloat(particle_spin), + NULL); else // themed particle { themenum = (int)PRVM_G_FLOAT(OFS_PARM4); @@ -3014,7 +3098,40 @@ static void VM_CL_SpawnParticleDelayed (prvm_prog_t *prog) return; } theme = &vmpartspawner.themes[themenum]; - part = CL_NewParticle(org, theme->typeindex, theme->color1, theme->color2, theme->tex, theme->size, theme->sizeincrease, theme->alpha, theme->alphafade, theme->gravity, theme->bounce, org[0], org[1], org[2], dir[0], dir[1], dir[2], theme->airfriction, theme->liquidfriction, theme->originjitter, theme->velocityjitter, theme->qualityreduction, theme->lifetime, theme->stretch, theme->blendmode, theme->orientation, theme->staincolor1, theme->staincolor2, theme->staintex, theme->stainalpha, theme->stainsize, theme->angle, theme->spin, NULL); + part = CL_NewParticle(org, + theme->typeindex, + theme->color1, + theme->color2, + theme->tex, + theme->size, + theme->sizeincrease, + theme->alpha, + theme->alphafade, + theme->gravity, + theme->bounce, + org[0], + org[1], + org[2], + dir[0], + dir[1], + dir[2], + theme->airfriction, + theme->liquidfriction, + theme->originjitter, + theme->velocityjitter, + theme->qualityreduction, + theme->lifetime, + theme->stretch, + theme->blendmode, + theme->orientation, + theme->staincolor1, + theme->staincolor2, + theme->staintex, + theme->stainalpha, + theme->stainsize, + theme->angle, + theme->spin, + NULL); } if (!part) { @@ -3037,7 +3154,7 @@ static void VM_CL_SpawnParticleDelayed (prvm_prog_t *prog) static void VM_CL_GetEntity (prvm_prog_t *prog) { int entnum, fieldnum; - float org[3], v1[3], v2[3]; + vec3_t forward, left, up, org; VM_SAFEPARMCOUNT(2, VM_CL_GetEntityVec); entnum = PRVM_G_FLOAT(OFS_PARM0); @@ -3053,22 +3170,30 @@ static void VM_CL_GetEntity (prvm_prog_t *prog) PRVM_G_FLOAT(OFS_RETURN) = cl.entities_active[entnum]; break; case 1: // origin - Matrix4x4_OriginFromMatrix(&cl.entities[entnum].render.matrix, PRVM_G_VECTOR(OFS_RETURN)); + Matrix4x4_OriginFromMatrix(&cl.entities[entnum].render.matrix, org); + VectorCopy(org, PRVM_G_VECTOR(OFS_RETURN)); break; case 2: // forward - Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, PRVM_G_VECTOR(OFS_RETURN), v1, v2, org); + Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, forward, left, up, org); + VectorCopy(forward, PRVM_G_VECTOR(OFS_RETURN)); break; case 3: // right - Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, v1, PRVM_G_VECTOR(OFS_RETURN), v2, org); + Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, forward, left, up, org); + VectorNegate(left, PRVM_G_VECTOR(OFS_RETURN)); break; case 4: // up - Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, v1, v2, PRVM_G_VECTOR(OFS_RETURN), org); + Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, forward, left, up, org); + VectorCopy(up, PRVM_G_VECTOR(OFS_RETURN)); break; case 5: // scale PRVM_G_FLOAT(OFS_RETURN) = Matrix4x4_ScaleFromMatrix(&cl.entities[entnum].render.matrix); break; case 6: // origin + v_forward, v_right, v_up - Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, PRVM_clientglobalvector(v_forward), PRVM_clientglobalvector(v_right), PRVM_clientglobalvector(v_up), PRVM_G_VECTOR(OFS_RETURN)); + Matrix4x4_ToVectors(&cl.entities[entnum].render.matrix, forward, left, up, org); + VectorCopy(forward, PRVM_clientglobalvector(v_forward)); + VectorNegate(left, PRVM_clientglobalvector(v_right)); + VectorCopy(up, PRVM_clientglobalvector(v_up)); + VectorCopy(org, PRVM_G_VECTOR(OFS_RETURN)); break; case 7: // alpha PRVM_G_FLOAT(OFS_RETURN) = cl.entities[entnum].render.alpha; @@ -3547,11 +3672,14 @@ static qboolean CL_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qb prvm_prog_t *prog = CLVM_prog; float dz; vec3_t oldorg, neworg, end, traceendpos; + vec3_t mins, maxs, start; trace_t trace; int i, svent; prvm_edict_t *enemy; // try the move + VectorCopy(PRVM_clientedictvector(ent, mins), mins); + VectorCopy(PRVM_clientedictvector(ent, maxs), maxs); VectorCopy (PRVM_clientedictvector(ent, origin), oldorg); VectorAdd (PRVM_clientedictvector(ent, origin), move, neworg); @@ -3571,7 +3699,8 @@ static qboolean CL_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qb if (dz < 30) neworg[2] += 8; } - trace = CL_TraceBox(PRVM_clientedictvector(ent, origin), PRVM_clientedictvector(ent, mins), PRVM_clientedictvector(ent, maxs), neworg, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, &svent, true); + VectorCopy(PRVM_clientedictvector(ent, origin), start); + trace = CL_TraceBox(start, mins, maxs, neworg, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, &svent, true); if (settrace) CL_VM_SetTraceGlobals(prog, &trace, svent); @@ -3599,14 +3728,14 @@ static qboolean CL_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qb VectorCopy (neworg, end); end[2] -= sv_stepheight.value*2; - trace = CL_TraceBox(neworg, PRVM_clientedictvector(ent, mins), PRVM_clientedictvector(ent, maxs), end, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, &svent, true); + trace = CL_TraceBox(neworg, mins, maxs, end, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, &svent, true); if (settrace) CL_VM_SetTraceGlobals(prog, &trace, svent); if (trace.startsolid) { neworg[2] -= sv_stepheight.value; - trace = CL_TraceBox(neworg, PRVM_clientedictvector(ent, mins), PRVM_clientedictvector(ent, maxs), end, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, &svent, true); + trace = CL_TraceBox(neworg, mins, maxs, end, MOVE_NORMAL, ent, CL_GenericHitSuperContentsMask(ent), true, true, &svent, true); if (settrace) CL_VM_SetTraceGlobals(prog, &trace, svent); if (trace.startsolid) @@ -4135,9 +4264,10 @@ static void VM_CL_RotateMoves(prvm_prog_t *prog) */ matrix4x4_t m; vec3_t v = {0, 0, 0}; - vec3_t x, y, z; + vec3_t a, x, y, z; VM_SAFEPARMCOUNT(1, VM_CL_RotateMoves); - AngleVectorsFLU(PRVM_G_VECTOR(OFS_PARM0), x, y, z); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), a); + AngleVectorsFLU(a, x, y, z); Matrix4x4_FromVectors(&m, x, y, z, v); CL_RotateMoves(&m); } diff --git a/common.c b/common.c index 3b986194..7440cc6c 100644 --- a/common.c +++ b/common.c @@ -364,7 +364,7 @@ void MSG_WriteCoord (sizebuf_t *sb, float f, protocolversion_t protocol) MSG_WriteCoord32f (sb, f); } -void MSG_WriteVector (sizebuf_t *sb, float *v, protocolversion_t protocol) +void MSG_WriteVector (sizebuf_t *sb, const vec3_t v, protocolversion_t protocol) { MSG_WriteCoord (sb, v[0], protocol); MSG_WriteCoord (sb, v[1], protocol); @@ -544,7 +544,7 @@ float MSG_ReadCoord (sizebuf_t *sb, protocolversion_t protocol) return MSG_ReadCoord32f(sb); } -void MSG_ReadVector (sizebuf_t *sb, float *v, protocolversion_t protocol) +void MSG_ReadVector (sizebuf_t *sb, vec3_t v, protocolversion_t protocol) { v[0] = MSG_ReadCoord(sb, protocol); v[1] = MSG_ReadCoord(sb, protocol); diff --git a/common.h b/common.h index 8a6dbd2a..48cbbdad 100644 --- a/common.h +++ b/common.h @@ -152,18 +152,18 @@ void MSG_WriteChar (sizebuf_t *sb, int c); void MSG_WriteByte (sizebuf_t *sb, int c); void MSG_WriteShort (sizebuf_t *sb, int c); void MSG_WriteLong (sizebuf_t *sb, int c); -void MSG_WriteFloat (sizebuf_t *sb, float f); +void MSG_WriteFloat (sizebuf_t *sb, vec_t f); void MSG_WriteString (sizebuf_t *sb, const char *s); void MSG_WriteUnterminatedString (sizebuf_t *sb, const char *s); -void MSG_WriteAngle8i (sizebuf_t *sb, float f); -void MSG_WriteAngle16i (sizebuf_t *sb, float f); -void MSG_WriteAngle32f (sizebuf_t *sb, float f); -void MSG_WriteCoord13i (sizebuf_t *sb, float f); -void MSG_WriteCoord16i (sizebuf_t *sb, float f); -void MSG_WriteCoord32f (sizebuf_t *sb, float f); -void MSG_WriteCoord (sizebuf_t *sb, float f, protocolversion_t protocol); -void MSG_WriteVector (sizebuf_t *sb, float *v, protocolversion_t protocol); -void MSG_WriteAngle (sizebuf_t *sb, float f, protocolversion_t protocol); +void MSG_WriteAngle8i (sizebuf_t *sb, vec_t f); +void MSG_WriteAngle16i (sizebuf_t *sb, vec_t f); +void MSG_WriteAngle32f (sizebuf_t *sb, vec_t f); +void MSG_WriteCoord13i (sizebuf_t *sb, vec_t f); +void MSG_WriteCoord16i (sizebuf_t *sb, vec_t f); +void MSG_WriteCoord32f (sizebuf_t *sb, vec_t f); +void MSG_WriteCoord (sizebuf_t *sb, vec_t f, protocolversion_t protocol); +void MSG_WriteVector (sizebuf_t *sb, const vec3_t v, protocolversion_t protocol); +void MSG_WriteAngle (sizebuf_t *sb, vec_t f, protocolversion_t protocol); void MSG_BeginReading (sizebuf_t *sb); int MSG_ReadLittleShort (sizebuf_t *sb); @@ -188,7 +188,7 @@ float MSG_ReadCoord13i (sizebuf_t *sb); float MSG_ReadCoord16i (sizebuf_t *sb); float MSG_ReadCoord32f (sizebuf_t *sb); float MSG_ReadCoord (sizebuf_t *sb, protocolversion_t protocol); -void MSG_ReadVector (sizebuf_t *sb, float *v, protocolversion_t protocol); +void MSG_ReadVector (sizebuf_t *sb, vec3_t v, protocolversion_t protocol); float MSG_ReadAngle (sizebuf_t *sb, protocolversion_t protocol); //@} //============================================================================ diff --git a/csprogs.c b/csprogs.c index ffb5d724..ff6a0a11 100644 --- a/csprogs.c +++ b/csprogs.c @@ -11,7 +11,7 @@ // Client prog handling //[515]: omg !!! optimize it ! a lot of hacks here and there also :P -#define CSQC_RETURNVAL prog->globals.generic[OFS_RETURN] +#define CSQC_RETURNVAL prog->globals.fp[OFS_RETURN] #define CSQC_BEGIN #define CSQC_END @@ -223,6 +223,7 @@ void CSQC_UpdateNetworkTimes(double newtime, double oldtime) //[515]: set globals before calling R_UpdateView, WEIRD CRAP static void CSQC_SetGlobals (void) { + vec3_t pmove_org; prvm_prog_t *prog = CLVM_prog; CSQC_BEGIN PRVM_clientglobalfloat(time) = cl.time; @@ -239,7 +240,8 @@ static void CSQC_SetGlobals (void) // LordHavoc: Spike says not to do this, but without pmove_org the // CSQC is useless as it can't alter the view origin without // completely replacing it - Matrix4x4_OriginFromMatrix(&cl.entities[cl.viewentity].render.matrix, PRVM_clientglobalvector(pmove_org)); + Matrix4x4_OriginFromMatrix(&cl.entities[cl.viewentity].render.matrix, pmove_org); + VectorCopy(pmove_org, PRVM_clientglobalvector(pmove_org)); VectorCopy(cl.movement_velocity, PRVM_clientglobalvector(pmove_vel)); PRVM_clientglobalfloat(pmove_onground) = cl.onground; PRVM_clientglobalfloat(pmove_inwater) = cl.inwater; @@ -899,7 +901,7 @@ static void CLVM_free_edict(prvm_prog_t *prog, prvm_edict_t *ed) R_DecalSystem_Reset(&entrender->decalsystem); memset(entrender, 0, sizeof(*entrender)); World_UnlinkEdict(ed); - memset(ed->fields.vp, 0, prog->entityfields * 4); + memset(ed->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t)); VM_RemoveEdictSkeleton(prog, ed); World_Physics_RemoveFromEntity(&cl.world, ed); World_Physics_RemoveJointFromEntity(&cl.world, ed); diff --git a/gl_rmain.c b/gl_rmain.c index 5c76df44..235434b9 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -7463,7 +7463,7 @@ void R_DrawNoModel(entity_render_t *ent) R_DrawNoModel_TransparentCallback(ent, rsurface.rtlight, 0, NULL); } -void R_CalcBeam_Vertex3f (float *vert, const vec3_t org1, const vec3_t org2, float width) +void R_CalcBeam_Vertex3f (float *vert, const float *org1, const float *org2, float width) { vec3_t right1, right2, diff, normal; diff --git a/host.c b/host.c index 2e503035..9b717993 100644 --- a/host.c +++ b/host.c @@ -899,7 +899,7 @@ void Host_Main(void) SV_SendClientMessages(); if (sv.paused == 1 && realtime > sv.pausedstart && sv.pausedstart > 0) { - prog->globals.generic[OFS_PARM0] = realtime - sv.pausedstart; + prog->globals.fp[OFS_PARM0] = realtime - sv.pausedstart; PRVM_serverglobalfloat(time) = sv.time; prog->ExecuteProgram(prog, PRVM_serverfunction(SV_PausedTic), "QC function SV_PausedTic is missing"); } diff --git a/host_cmd.c b/host_cmd.c index 350cef0d..4d2b93b6 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -945,7 +945,7 @@ static void Host_Loadgame_f (void) while (entnum >= prog->max_edicts) PRVM_MEM_IncreaseEdicts(prog); ent = PRVM_EDICT_NUM(entnum); - memset(ent->fields.vp, 0, prog->entityfields * 4); + memset(ent->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t)); ent->priv.server->free = false; if(developer_entityparsing.integer) @@ -1579,7 +1579,7 @@ static void Host_Color(int changetop, int changebottom) if (host_client->edict && PRVM_serverfunction(SV_ChangeTeam)) { Con_DPrint("Calling SV_ChangeTeam\n"); - prog->globals.generic[OFS_PARM0] = playercolor; + prog->globals.fp[OFS_PARM0] = playercolor; PRVM_serverglobalfloat(time) = sv.time; PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(host_client->edict); prog->ExecuteProgram(prog, PRVM_serverfunction(SV_ChangeTeam), "QC function SV_ChangeTeam is missing"); diff --git a/mathlib.c b/mathlib.c index b4a1b6a0..60cc04b0 100644 --- a/mathlib.c +++ b/mathlib.c @@ -760,7 +760,7 @@ void Matrix4x4_Print(const matrix4x4_t *in) , in->m[3][0], in->m[3][1], in->m[3][2], in->m[3][3]); } -int Math_atov(const char *s, vec3_t out) +int Math_atov(const char *s, prvm_vec3_t out) { int i; VectorClear(out); diff --git a/mathlib.h b/mathlib.h index 06a5ba92..3e7fa4c8 100644 --- a/mathlib.h +++ b/mathlib.h @@ -28,19 +28,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h #endif -typedef float vec_t; -typedef vec_t vec2_t[2]; -typedef vec_t vec3_t[3]; -typedef vec_t vec4_t[4]; -typedef vec_t vec5_t[5]; -typedef vec_t vec6_t[6]; -typedef vec_t vec7_t[7]; -typedef vec_t vec8_t[8]; struct mplane_s; extern vec3_t vec3_origin; -#define nanmask (255<<23) -#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) +#define float_nanmask (0x7F800000) +#define double_nanmask (0x7FF8000000000000) +#define FLOAT_IS_NAN(x) (((*(int *)&x)&float_nanmask)==float_nanmask) +#define DOUBLE_IS_NAN(x) (((*(long long *)&x)&double_nanmask)==double_nanmask) + +#ifdef VEC_64 +#define VEC_IS_NAN(x) DOUBLE_IS_NAN(x) +#else +#define VEC_IS_NAN(x) FLOAT_IS_NAN(x) +#endif + +#ifdef PRVM_64 +#define PRVM_IS_NAN(x) DOUBLE_IS_NAN(x) +#else +#define PRVM_IS_NAN(x) FLOAT_IS_NAN(x) +#endif #define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) @@ -82,7 +88,7 @@ unsigned int CeilPowerOf2(unsigned int value); #define Vector2Compare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])) #define Vector2Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1]) #define Vector2Negate(a,b) ((b)[0]=-((a)[0]),(b)[1]=-((a)[1])) -#define Vector2Set(a,b,c,d,e) ((a)[0]=(b),(a)[1]=(c)) +#define Vector2Set(a,b,c) ((a)[0]=(b),(a)[1]=(c)) #define Vector2Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale)) #define Vector2Normalize2(v,dest) {float ilength = (float) sqrt(DotProduct2((v),(v)));if (ilength) ilength = 1.0f / ilength;dest[0] = (v)[0] * ilength;dest[1] = (v)[1] * ilength;} @@ -287,7 +293,7 @@ float RadiusFromBoundsAndOrigin (const vec3_t mins, const vec3_t maxs, const vec struct matrix4x4_s; /// print a matrix to the console void Matrix4x4_Print(const struct matrix4x4_s *in); -int Math_atov(const char *s, vec3_t out); +int Math_atov(const char *s, prvm_vec3_t out); void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f); diff --git a/matrixlib.h b/matrixlib.h index eb926a10..232f1add 100644 --- a/matrixlib.h +++ b/matrixlib.h @@ -10,7 +10,7 @@ typedef struct matrix4x4_s { - float m[4][4]; + vec_t m[4][4]; } matrix4x4_t; @@ -82,9 +82,9 @@ void Matrix4x4_CreateScale3 (matrix4x4_t *out, double x, double y, double z); void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale); // converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate -void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]); +void Matrix4x4_ToVectors(const matrix4x4_t *in, vec_t vx[3], vec_t vy[3], vec_t vz[3], vec_t t[3]); // creates a matrix4x4 from a set of 3D vectors for axial directions, and translate -void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]); +void Matrix4x4_FromVectors(matrix4x4_t *out, const vec_t vx[3], const vec_t vy[3], const vec_t vz[3], const vec_t t[3]); // converts a matrix4x4 to a double[16] array in the OpenGL orientation void Matrix4x4_ToArrayDoubleGL(const matrix4x4_t *in, double out[16]); @@ -129,21 +129,21 @@ void Matrix4x4_ToBonePose7s(const matrix4x4_t *m, float origininvscale, short *p void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend); // transforms a 3D vector through a matrix4x4 -void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3]); +void Matrix4x4_Transform (const matrix4x4_t *in, const vec_t v[3], vec_t out[3]); // transforms a 4D vector through a matrix4x4 // (warning: if you don't know why you would need this, you don't need it) // (warning: the 4th component of the vector should be 1.0) -void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4]); +void Matrix4x4_Transform4 (const matrix4x4_t *in, const vec_t v[4], vec_t out[4]); // reverse transforms a 3D vector through a matrix4x4, at least for *simple* // cases (rotation and translation *ONLY*), this attempts to undo the results // of Transform -//void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3]); +//void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const vec_t v[3], vec_t out[3]); // transforms a direction vector through the rotation part of a matrix -void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[3]); +void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const vec_t v[3], vec_t out[3]); // transforms a positive distance plane (A*x+B*y+C*z-D=0) through a rotation or translation matrix -void Matrix4x4_TransformPositivePlane (const matrix4x4_t *in, float x, float y, float z, float d, float *o); +void Matrix4x4_TransformPositivePlane (const matrix4x4_t *in, vec_t x, vec_t y, vec_t z, vec_t d, vec_t *o); // transforms a standard plane (A*x+B*y+C*z+D=0) through a rotation or translation matrix -void Matrix4x4_TransformStandardPlane (const matrix4x4_t *in, float x, float y, float z, float d, float *o); +void Matrix4x4_TransformStandardPlane (const matrix4x4_t *in, vec_t x, vec_t y, vec_t z, vec_t d, vec_t *o); // ease of use functions // immediately applies a Translate to the matrix @@ -156,7 +156,7 @@ void Matrix4x4_ConcatScale (matrix4x4_t *out, double x); void Matrix4x4_ConcatScale3 (matrix4x4_t *out, double x, double y, double z); // extracts origin vector (translate) from matrix -void Matrix4x4_OriginFromMatrix (const matrix4x4_t *in, float *out); +void Matrix4x4_OriginFromMatrix (const matrix4x4_t *in, vec_t *out); // extracts scaling factor from matrix (only works for uniform scaling) double Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in); diff --git a/menu.c b/menu.c index 149e8421..2d5fd4be 100644 --- a/menu.c +++ b/menu.c @@ -5272,8 +5272,8 @@ static void MP_KeyEvent (int key, int ascii, qboolean downevent) prvm_prog_t *prog = MVM_prog; // pass key - prog->globals.generic[OFS_PARM0] = (float) key; - prog->globals.generic[OFS_PARM1] = (float) ascii; + prog->globals.fp[OFS_PARM0] = (float) key; + prog->globals.fp[OFS_PARM1] = (float) ascii; if (downevent) prog->ExecuteProgram(prog, PRVM_menufunction(m_keydown),"m_keydown(float key, float ascii) required"); else if (PRVM_menufunction(m_keyup)) @@ -5312,7 +5312,7 @@ static void MP_ToggleMenu(int mode) { prvm_prog_t *prog = MVM_prog; - prog->globals.generic[OFS_PARM0] = (float) mode; + prog->globals.fp[OFS_PARM0] = (float) mode; prog->ExecuteProgram(prog, PRVM_menufunction(m_toggle),"m_toggle(float mode) required"); } diff --git a/model_shared.h b/model_shared.h index 07e840d3..f4e2e3c5 100644 --- a/model_shared.h +++ b/model_shared.h @@ -801,7 +801,7 @@ typedef struct model_brush_s int (*FindBoxClusters)(struct model_s *model, const vec3_t mins, const vec3_t maxs, int maxclusters, int *clusterlist); void (*LightPoint)(struct model_s *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal); void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius); - mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p); + mleaf_t *(*PointInLeaf)(struct model_s *model, const vec3_t p); // these are actually only found on brushq1, but NULL is handled gracefully void (*AmbientSoundLevelsForPoint)(struct model_s *model, const vec3_t p, unsigned char *out, int outsize); void (*RoundUpToHullSize)(struct model_s *cmodel, const vec3_t inmins, const vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs); diff --git a/mvm_cmds.c b/mvm_cmds.c index 63a798b5..603f4fca 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -740,7 +740,7 @@ static void VM_M_copyentity (prvm_prog_t *prog) VM_SAFEPARMCOUNT(2,VM_M_copyentity); in = PRVM_G_EDICT(OFS_PARM0); out = PRVM_G_EDICT(OFS_PARM1); - memcpy(out->fields.vp, in->fields.vp, prog->entityfields * 4); + memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t)); } //#66 vector() getmousepos (EXT_CSQC) diff --git a/progsvm.h b/progsvm.h index 343b99bb..83666557 100644 --- a/progsvm.h +++ b/progsvm.h @@ -49,13 +49,13 @@ typedef struct prvm_stack_s typedef union prvm_eval_s { - string_t string; - float _float; - float vector[3]; - func_t function; - int ivector[3]; - int _int; - int edict; + prvm_int_t string; + prvm_vec_t _float; + prvm_vec_t vector[3]; + prvm_int_t function; + prvm_int_t ivector[3]; + prvm_int_t _int; + prvm_int_t edict; } prvm_eval_t; typedef struct prvm_required_field_s @@ -84,7 +84,8 @@ typedef struct prvm_edict_s union { prvm_edict_private_t *required; - vec_t *vp; + prvm_vec_t *fp; + prvm_int_t *ip; // FIXME: this server pointer really means world, not server // (it is used by both server qc and client qc, but not menu qc) edict_engineprivate_t *server; @@ -108,7 +109,8 @@ typedef struct prvm_edict_s // QuakeC fields (stored in dynamically resized array) union { - vec_t *vp; + prvm_vec_t *fp; + prvm_int_t *ip; // entvars_t *server; // cl_entvars_t *client; } fields; @@ -226,31 +228,31 @@ extern prvm_eval_t prvm_badvalue; #define PRVM_menufunction(funcname) (prog->funcoffsets.funcname) #if 1 -#define PRVM_EDICTFIELDVALUE(ed, fieldoffset) (fieldoffset < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)((int *)ed->fields.vp + fieldoffset)) +#define PRVM_EDICTFIELDVALUE(ed, fieldoffset) (fieldoffset < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)(ed->fields.fp + fieldoffset)) #define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->_float) #define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->vector) #define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->string) #define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->edict) #define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (PRVM_EDICTFIELDVALUE(ed, fieldoffset)->function) -#define PRVM_GLOBALFIELDVALUE(fieldoffset) (fieldoffset < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)((int *)prog->globals.generic + fieldoffset)) +#define PRVM_GLOBALFIELDVALUE(fieldoffset) (fieldoffset < 0 ? Con_Printf("Invalid fieldoffset at %s:%i\n", __FILE__, __LINE__), &prvm_badvalue : (prvm_eval_t *)(prog->globals.fp + fieldoffset)) #define PRVM_GLOBALFIELDFLOAT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->_float) #define PRVM_GLOBALFIELDVECTOR(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->vector) #define PRVM_GLOBALFIELDSTRING(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->string) #define PRVM_GLOBALFIELDEDICT(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->edict) #define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (PRVM_GLOBALFIELDVALUE(fieldoffset)->function) #else -#define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset)) -#define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->_float) -#define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->vector) -#define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->string) -#define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->edict) -#define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (((prvm_eval_t *)((int *)ed->fields.vp + fieldoffset))->function) -#define PRVM_GLOBALFIELDVALUE(fieldoffset) ((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset)) -#define PRVM_GLOBALFIELDFLOAT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->_float) -#define PRVM_GLOBALFIELDVECTOR(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->vector) -#define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->string) -#define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->edict) -#define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)((int *)prog->globals.generic + fieldoffset))->function) +#define PRVM_EDICTFIELDVALUE(ed, fieldoffset) ((prvm_eval_t *)(ed->fields.fp + fieldoffset)) +#define PRVM_EDICTFIELDFLOAT(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->_float) +#define PRVM_EDICTFIELDVECTOR(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->vector) +#define PRVM_EDICTFIELDSTRING(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->string) +#define PRVM_EDICTFIELDEDICT(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->edict) +#define PRVM_EDICTFIELDFUNCTION(ed, fieldoffset) (((prvm_eval_t *)(ed->fields.fp + fieldoffset))->function) +#define PRVM_GLOBALFIELDVALUE(fieldoffset) ((prvm_eval_t *)(prog->globals.fp + fieldoffset)) +#define PRVM_GLOBALFIELDFLOAT(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->_float) +#define PRVM_GLOBALFIELDVECTOR(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->vector) +#define PRVM_GLOBALFIELDSTRING(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->string) +#define PRVM_GLOBALFIELDEDICT(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->edict) +#define PRVM_GLOBALFIELDFUNCTION(fieldoffset) (((prvm_eval_t *)(prog->globals.fp + fieldoffset))->function) #endif //============================================================================ @@ -562,7 +564,8 @@ typedef struct prvm_prog_s double *statement_profile; // only incremented if prvm_statementprofiling is on union { - vec_t *generic; + prvm_vec_t *fp; + prvm_int_t *ip; // globalvars_t *server; // cl_globalvars_t *client; } globals; @@ -596,7 +599,7 @@ typedef struct prvm_prog_s prvm_stack_t stack[PRVM_MAX_STACK_DEPTH+1]; int depth; - int localstack[PRVM_LOCALSTACK_SIZE]; + prvm_int_t localstack[PRVM_LOCALSTACK_SIZE]; int localstack_used; unsigned short filecrc; @@ -628,8 +631,8 @@ typedef struct prvm_prog_s int reserved_edicts; // [INIT] prvm_edict_t *edicts; - vec_t *edictsfields; - void *edictprivate; + prvm_vec_t *edictsfields; + void *edictprivate; // size of the engine private struct int edictprivate_size; // [INIT] @@ -809,19 +812,19 @@ unsigned int PRVM_EDICT_NUM_ERROR(prvm_prog_t *prog, unsigned int n, const char //============================================================================ -#define PRVM_G_FLOAT(o) (prog->globals.generic[o]) -#define PRVM_G_INT(o) (*(int *)&prog->globals.generic[o]) -#define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(*(int *)&prog->globals.generic[o])) +#define PRVM_G_FLOAT(o) (prog->globals.fp[o]) +#define PRVM_G_INT(o) (prog->globals.ip[o]) +#define PRVM_G_EDICT(o) (PRVM_PROG_TO_EDICT(prog->globals.ip[o])) #define PRVM_G_EDICTNUM(o) PRVM_NUM_FOR_EDICT(PRVM_G_EDICT(o)) -#define PRVM_G_VECTOR(o) (&prog->globals.generic[o]) -#define PRVM_G_STRING(o) (PRVM_GetString(prog, *(string_t *)&prog->globals.generic[o])) -//#define PRVM_G_FUNCTION(prog, o) (*(func_t *)&prog->globals.generic[o]) +#define PRVM_G_VECTOR(o) (&prog->globals.fp[o]) +#define PRVM_G_STRING(o) (PRVM_GetString(prog, prog->globals.ip[o])) +//#define PRVM_G_FUNCTION(prog, o) (prog->globals.ip[o]) // FIXME: make these go away? -#define PRVM_E_FLOAT(e,o) (((float*)e->fields.vp)[o]) -#define PRVM_E_INT(e,o) (((int*)e->fields.vp)[o]) -//#define PRVM_E_VECTOR(e,o) (&((float*)e->fields.vp)[o]) -#define PRVM_E_STRING(e,o) (PRVM_GetString(prog, *(string_t *)&((float*)e->fields.vp)[o])) +#define PRVM_E_FLOAT(e,o) (e->fields.fp[o]) +#define PRVM_E_INT(e,o) (e->fields.fp[o]) +//#define PRVM_E_VECTOR(e,o) (&(e->fields.fp[o])) +#define PRVM_E_STRING(e,o) (PRVM_GetString(prog, e->fields.ip[o])) extern int prvm_type_size[8]; // for consistency : I think a goal of this sub-project is to // make the new vm mostly independent from the old one, thus if it's necessary, I copy everything diff --git a/prvm_cmds.c b/prvm_cmds.c index 8fe611d7..f6258311 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -455,7 +455,7 @@ vector normalize(vector) */ void VM_normalize(prvm_prog_t *prog) { - float *value1; + prvm_vec_t *value1; vec3_t newvalue; double f; @@ -497,8 +497,8 @@ float vectoyaw(vector) */ void VM_vectoyaw(prvm_prog_t *prog) { - float *value1; - float yaw; + prvm_vec_t *value1; + prvm_vec_t yaw; VM_SAFEPARMCOUNT(1,VM_vectoyaw); @@ -526,9 +526,18 @@ vector vectoangles(vector[, vector]) */ void VM_vectoangles(prvm_prog_t *prog) { + vec3_t result, forward, up; VM_SAFEPARMCOUNTRANGE(1, 2,VM_vectoangles); - AnglesFromVectors(PRVM_G_VECTOR(OFS_RETURN), PRVM_G_VECTOR(OFS_PARM0), prog->argc >= 2 ? PRVM_G_VECTOR(OFS_PARM1) : NULL, true); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), forward); + if (prog->argc >= 2) + { + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), up); + AnglesFromVectors(result, forward, up, true); + } + else + AnglesFromVectors(result, forward, NULL, true); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); } /* @@ -2069,7 +2078,7 @@ void VM_getentityfieldstring(prvm_prog_t *prog) // put the data into a string ddef_t *d; int type, j; - int *v; + prvm_eval_t *val; prvm_edict_t * ent; int i = (int)PRVM_G_FLOAT(OFS_PARM0); char valuebuf[MAX_INPUTLINE]; @@ -2091,12 +2100,12 @@ void VM_getentityfieldstring(prvm_prog_t *prog) VM_Warning(prog, "VM_entityfielddata: %s: entity %i is free !\n", prog->name, PRVM_NUM_FOR_EDICT(ent)); return; } - v = (int *)((char *)ent->fields.vp + d->ofs*4); + val = (prvm_eval_t *)(ent->fields.fp + d->ofs); // if it's 0 or blank, return an empty string type = d->type & ~DEF_SAVEGLOBAL; for (j=0 ; jivector[j]) break; if (j == prvm_type_size[type]) { @@ -2104,7 +2113,7 @@ void VM_getentityfieldstring(prvm_prog_t *prog) return; } - PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, PRVM_UglyValueString(prog, (etype_t)d->type, (prvm_eval_t *)v, valuebuf, sizeof(valuebuf))); + PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, PRVM_UglyValueString(prog, (etype_t)d->type, val, valuebuf, sizeof(valuebuf))); } // KrimZon - DP_QC_ENTITYDATA @@ -3325,7 +3334,7 @@ float drawcharacter(vector position, float character, vector scale, vector rgb, */ void VM_drawcharacter(prvm_prog_t *prog) { - float *pos,*scale,*rgb; + prvm_vec_t *pos,*scale,*rgb; char character; int flag; float sx, sy; @@ -3375,7 +3384,7 @@ float drawstring(vector position, string text, vector scale, vector rgb, float a */ void VM_drawstring(prvm_prog_t *prog) { - float *pos,*scale,*rgb; + prvm_vec_t *pos,*scale,*rgb; const char *string; int flag = 0; float sx, sy; @@ -3422,7 +3431,7 @@ float drawcolorcodedstring(vector position, string text, vector scale, vector rg */ void VM_drawcolorcodedstring(prvm_prog_t *prog) { - float *pos, *scale; + prvm_vec_t *pos, *scale; const char *string; int flag; vec3_t rgb; @@ -3485,7 +3494,7 @@ float stringwidth(string text, float allowColorCodes, float size) void VM_stringwidth(prvm_prog_t *prog) { const char *string; - float *szv; + vec2_t szv; float mult; // sz is intended font size so we can later add freetype support, mult is font size multiplier in pixels per character cell int colors; float sx, sy; @@ -3495,14 +3504,13 @@ void VM_stringwidth(prvm_prog_t *prog) getdrawfontscale(prog, &sx, &sy); if(prog->argc == 3) { - szv = PRVM_G_VECTOR(OFS_PARM2); + Vector2Copy(PRVM_G_VECTOR(OFS_PARM2), szv); mult = 1; } else { // we want the width for 8x8 font size, divided by 8 - static float defsize[] = {8, 8}; - szv = defsize; + Vector2Set(szv, 8, 8); mult = 0.125; // to make sure snapping is turned off, ALWAYS use a nontrivial scale in this case if(sx >= 0.9 && sx <= 1.1) @@ -3711,7 +3719,7 @@ float drawpic(vector position, string pic, vector size, vector rgb, float alpha, void VM_drawpic(prvm_prog_t *prog) { const char *picname; - float *size, *pos, *rgb; + prvm_vec_t *size, *pos, *rgb; int flag = 0; VM_SAFEPARMCOUNTRANGE(5,6,VM_drawpic); @@ -3756,7 +3764,7 @@ float drawrotpic(vector position, string pic, vector size, vector org, float ang void VM_drawrotpic(prvm_prog_t *prog) { const char *picname; - float *size, *pos, *org, *rgb; + prvm_vec_t *size, *pos, *org, *rgb; int flag; VM_SAFEPARMCOUNT(8,VM_drawrotpic); @@ -3802,7 +3810,7 @@ float drawsubpic(vector position, vector size, string pic, vector srcPos, vector void VM_drawsubpic(prvm_prog_t *prog) { const char *picname; - float *size, *pos, *rgb, *srcPos, *srcSize, alpha; + prvm_vec_t *size, *pos, *rgb, *srcPos, *srcSize, alpha; int flag; VM_SAFEPARMCOUNT(8,VM_drawsubpic); @@ -3855,7 +3863,7 @@ float drawfill(vector position, vector size, vector rgb, float alpha, float flag */ void VM_drawfill(prvm_prog_t *prog) { - float *size, *pos, *rgb; + prvm_vec_t *size, *pos, *rgb; int flag; VM_SAFEPARMCOUNT(5,VM_drawfill); @@ -4298,8 +4306,13 @@ void makevectors(vector angle) */ void VM_makevectors (prvm_prog_t *prog) { + vec3_t angles, forward, right, up; VM_SAFEPARMCOUNT(1, VM_makevectors); - AngleVectors(PRVM_G_VECTOR(OFS_PARM0), PRVM_gameglobalvector(v_forward), PRVM_gameglobalvector(v_right), PRVM_gameglobalvector(v_up)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), angles); + AngleVectors(angles, forward, right, up); + VectorCopy(forward, PRVM_gameglobalvector(v_forward)); + VectorCopy(right, PRVM_gameglobalvector(v_right)); + VectorCopy(up, PRVM_gameglobalvector(v_up)); } /* @@ -4312,9 +4325,13 @@ vectorvectors(vector) */ void VM_vectorvectors (prvm_prog_t *prog) { + vec3_t forward, right, up; VM_SAFEPARMCOUNT(1, VM_vectorvectors); - VectorNormalize2(PRVM_G_VECTOR(OFS_PARM0), PRVM_gameglobalvector(v_forward)); - VectorVectors(PRVM_gameglobalvector(v_forward), PRVM_gameglobalvector(v_right), PRVM_gameglobalvector(v_up)); + VectorNormalize2(PRVM_G_VECTOR(OFS_PARM0), forward); + VectorVectors(forward, right, up); + VectorCopy(forward, PRVM_gameglobalvector(v_forward)); + VectorCopy(right, PRVM_gameglobalvector(v_right)); + VectorCopy(up, PRVM_gameglobalvector(v_up)); } /* @@ -4326,7 +4343,7 @@ void drawline(float width, vector pos1, vector pos2, vector rgb, float alpha, fl */ void VM_drawline (prvm_prog_t *prog) { - float *c1, *c2, *rgb; + prvm_vec_t *c1, *c2, *rgb; float alpha, width; unsigned char flags; @@ -6421,8 +6438,8 @@ void VM_sprintf(prvm_prog_t *prog) char formatbuf[16]; char *f; int isfloat; - static int dummyivec[3] = {0, 0, 0}; - static float dummyvec[3] = {0, 0, 0}; + static prvm_int_t dummyivec[3] = {0, 0, 0}; + static prvm_vec_t dummyvec[3] = {0, 0, 0}; char vabuf[1024]; #define PRINTF_ALTERNATE 1 @@ -6438,7 +6455,7 @@ void VM_sprintf(prvm_prog_t *prog) #define GETARG_FLOAT(a) (((a)>=1 && (a)argc) ? (PRVM_G_FLOAT(OFS_PARM0 + 3 * (a))) : 0) #define GETARG_VECTOR(a) (((a)>=1 && (a)argc) ? (PRVM_G_VECTOR(OFS_PARM0 + 3 * (a))) : dummyvec) #define GETARG_INT(a) (((a)>=1 && (a)argc) ? (PRVM_G_INT(OFS_PARM0 + 3 * (a))) : 0) -#define GETARG_INTVECTOR(a) (((a)>=1 && (a)argc) ? ((int*) PRVM_G_VECTOR(OFS_PARM0 + 3 * (a))) : dummyivec) +#define GETARG_INTVECTOR(a) (((a)>=1 && (a)argc) ? ((prvm_int_t*) PRVM_G_VECTOR(OFS_PARM0 + 3 * (a))) : dummyivec) #define GETARG_STRING(a) (((a)>=1 && (a)argc) ? (PRVM_G_STRING(OFS_PARM0 + 3 * (a))) : "") for(;;) @@ -6921,6 +6938,7 @@ void VM_getsurfacepoint(prvm_prog_t *prog) dp_model_t *model; msurface_t *surface; int pointnum; + vec3_t result; VM_SAFEPARMCOUNT(3, VM_getsurfacepoint); VectorClear(PRVM_G_VECTOR(OFS_RETURN)); ed = PRVM_G_EDICT(OFS_PARM0); @@ -6931,7 +6949,8 @@ void VM_getsurfacepoint(prvm_prog_t *prog) if (pointnum < 0 || pointnum >= surface->num_vertices) return; animatemodel(prog, model, ed); - applytransform_forward(prog, &(animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, PRVM_G_VECTOR(OFS_RETURN)); + applytransform_forward(prog, &(animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); } //PF_getsurfacepointattribute, // #486 vector(entity e, float s, float n, float a) getsurfacepointattribute = #486; // float SPA_POSITION = 0; @@ -6948,6 +6967,7 @@ void VM_getsurfacepointattribute(prvm_prog_t *prog) msurface_t *surface; int pointnum; int attributetype; + vec3_t result; VM_SAFEPARMCOUNT(4, VM_getsurfacepoint); VectorClear(PRVM_G_VECTOR(OFS_RETURN)); @@ -6964,36 +6984,40 @@ void VM_getsurfacepointattribute(prvm_prog_t *prog) switch( attributetype ) { // float SPA_POSITION = 0; case 0: - applytransform_forward(prog, &(animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, PRVM_G_VECTOR(OFS_RETURN)); + applytransform_forward(prog, &(animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); break; // float SPA_S_AXIS = 1; case 1: - applytransform_forward_direction(prog, &(animatemodel_cache.data_svector3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, PRVM_G_VECTOR(OFS_RETURN)); + applytransform_forward_direction(prog, &(animatemodel_cache.data_svector3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); break; // float SPA_T_AXIS = 2; case 2: - applytransform_forward_direction(prog, &(animatemodel_cache.data_tvector3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, PRVM_G_VECTOR(OFS_RETURN)); + applytransform_forward_direction(prog, &(animatemodel_cache.data_tvector3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); break; // float SPA_R_AXIS = 3; // same as SPA_NORMAL case 3: - applytransform_forward_direction(prog, &(animatemodel_cache.data_normal3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, PRVM_G_VECTOR(OFS_RETURN)); + applytransform_forward_direction(prog, &(animatemodel_cache.data_normal3f + 3 * surface->num_firstvertex)[pointnum * 3], ed, result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); break; // float SPA_TEXCOORDS0 = 4; case 4: { - float *ret = PRVM_G_VECTOR(OFS_RETURN); float *texcoord = &(model->surfmesh.data_texcoordtexture2f + 2 * surface->num_firstvertex)[pointnum * 2]; - ret[0] = texcoord[0]; - ret[1] = texcoord[1]; - ret[2] = 0.0f; + result[0] = texcoord[0]; + result[1] = texcoord[1]; + result[2] = 0.0f; + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); break; } // float SPA_LIGHTMAP0_TEXCOORDS = 5; case 5: { - float *ret = PRVM_G_VECTOR(OFS_RETURN); float *texcoord = &(model->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[pointnum * 2]; - ret[0] = texcoord[0]; - ret[1] = texcoord[1]; - ret[2] = 0.0f; + result[0] = texcoord[0]; + result[1] = texcoord[1]; + result[2] = 0.0f; + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); break; } // float SPA_LIGHTMAP0_COLOR = 6; @@ -7012,6 +7036,7 @@ void VM_getsurfacenormal(prvm_prog_t *prog) dp_model_t *model; msurface_t *surface; vec3_t normal; + vec3_t result; VM_SAFEPARMCOUNT(2, VM_getsurfacenormal); VectorClear(PRVM_G_VECTOR(OFS_RETURN)); if (!(model = getmodel(prog, PRVM_G_EDICT(OFS_PARM0))) || !(surface = getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1)))) @@ -7020,8 +7045,9 @@ void VM_getsurfacenormal(prvm_prog_t *prog) // well for curved surfaces or arbitrary meshes animatemodel(prog, model, PRVM_G_EDICT(OFS_PARM0)); TriangleNormal((animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex), (animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex) + 3, (animatemodel_cache.data_vertex3f + 3 * surface->num_firstvertex) + 6, normal); - applytransform_forward_normal(prog, normal, PRVM_G_EDICT(OFS_PARM0), PRVM_G_VECTOR(OFS_RETURN)); - VectorNormalize(PRVM_G_VECTOR(OFS_RETURN)); + applytransform_forward_normal(prog, normal, PRVM_G_EDICT(OFS_PARM0), result); + VectorNormalize(result); + VectorCopy(result, PRVM_G_VECTOR(OFS_RETURN)); } //PF_getsurfacetexture, // #437 string(entity e, float s) getsurfacetexture = #437; void VM_getsurfacetexture(prvm_prog_t *prog) @@ -7043,11 +7069,11 @@ void VM_getsurfacenearpoint(prvm_prog_t *prog) prvm_edict_t *ed; dp_model_t *model; msurface_t *surface; - vec_t *point; + vec3_t point; VM_SAFEPARMCOUNT(2, VM_getsurfacenearpoint); PRVM_G_FLOAT(OFS_RETURN) = -1; ed = PRVM_G_EDICT(OFS_PARM0); - point = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), point); if (!ed || ed->priv.server->free) return; @@ -7090,14 +7116,15 @@ void VM_getsurfaceclippedpoint(prvm_prog_t *prog) prvm_edict_t *ed; dp_model_t *model; msurface_t *surface; - vec3_t p, out; + vec3_t p, out, inp; VM_SAFEPARMCOUNT(3, VM_te_getsurfaceclippedpoint); VectorClear(PRVM_G_VECTOR(OFS_RETURN)); ed = PRVM_G_EDICT(OFS_PARM0); if (!(model = getmodel(prog, ed)) || !(surface = getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1)))) return; animatemodel(prog, model, ed); - applytransform_inverted(prog, PRVM_G_VECTOR(OFS_PARM2), ed, p); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), inp); + applytransform_inverted(prog, inp, ed, p); clippointtosurface(prog, ed, model, surface, p, out); VectorAdd(out, PRVM_serveredictvector(ed, origin), PRVM_G_VECTOR(OFS_RETURN)); } diff --git a/prvm_cmds.h b/prvm_cmds.h index 39ec4961..e21a393f 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -210,7 +210,7 @@ float getserverlistindexforkey(string key) #define VM_SAFEPARMCOUNT(p,f) #endif -#define VM_RETURN_EDICT(e) (((int *)prog->globals.generic)[OFS_RETURN] = PRVM_EDICT_TO_PROG(e)) +#define VM_RETURN_EDICT(e) (prog->globals.ip[OFS_RETURN] = PRVM_EDICT_TO_PROG(e)) #define VM_STRINGTEMP_LENGTH MAX_INPUTLINE diff --git a/prvm_edict.c b/prvm_edict.c index 6dc2a6e8..ddda4e99 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -73,13 +73,13 @@ static void PRVM_MEM_Alloc(prvm_prog_t *prog) // alloc edict fields prog->entityfieldsarea = prog->entityfields * prog->max_edicts; - prog->edictsfields = (vec_t *)Mem_Alloc(prog->progs_mempool, prog->entityfieldsarea * sizeof(vec_t)); + prog->edictsfields = (prvm_vec_t *)Mem_Alloc(prog->progs_mempool, prog->entityfieldsarea * sizeof(prvm_vec_t)); // set edict pointers for(i = 0; i < prog->max_edicts; i++) { prog->edicts[i].priv.required = (prvm_edict_private_t *)((unsigned char *)prog->edictprivate + i * prog->edictprivate_size); - prog->edicts[i].fields.vp = prog->edictsfields + i * prog->entityfields; + prog->edicts[i].fields.fp = prog->edictsfields + i * prog->entityfields; } } @@ -101,14 +101,14 @@ void PRVM_MEM_IncreaseEdicts(prvm_prog_t *prog) prog->max_edicts = min(prog->max_edicts + 256, prog->limit_edicts); prog->entityfieldsarea = prog->entityfields * prog->max_edicts; - prog->edictsfields = (vec_t*)Mem_Realloc(prog->progs_mempool, (void *)prog->edictsfields, prog->entityfieldsarea * sizeof(vec_t)); + prog->edictsfields = (prvm_vec_t*)Mem_Realloc(prog->progs_mempool, (void *)prog->edictsfields, prog->entityfieldsarea * sizeof(prvm_vec_t)); prog->edictprivate = (void *)Mem_Realloc(prog->progs_mempool, (void *)prog->edictprivate, prog->max_edicts * prog->edictprivate_size); //set e and v pointers for(i = 0; i < prog->max_edicts; i++) { prog->edicts[i].priv.required = (prvm_edict_private_t *)((unsigned char *)prog->edictprivate + i * prog->edictprivate_size); - prog->edicts[i].fields.vp = prog->edictsfields + i * prog->entityfields; + prog->edicts[i].fields.fp = prog->edictsfields + i * prog->entityfields; } prog->end_increase_edicts(prog); @@ -190,7 +190,7 @@ Sets everything to NULL */ void PRVM_ED_ClearEdict(prvm_prog_t *prog, prvm_edict_t *e) { - memset(e->fields.vp, 0, prog->entityfields * 4); + memset(e->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t)); e->priv.required->free = false; // AK: Let the init_edict function determine if something needs to be initialized @@ -552,16 +552,16 @@ char *PRVM_GlobalString (prvm_prog_t *prog, int ofs, char *line, size_t lineleng char *s; //size_t i; ddef_t *def; - void *val; + prvm_eval_t *val; char valuebuf[MAX_INPUTLINE]; - val = (void *)&prog->globals.generic[ofs]; + val = (prvm_eval_t *)&prog->globals.fp[ofs]; def = PRVM_ED_GlobalAtOfs(prog, ofs); if (!def) dpsnprintf (line, linelength, "GLOBAL%i", ofs); else { - s = PRVM_ValueString (prog, (etype_t)def->type, (prvm_eval_t *)val, valuebuf, sizeof(valuebuf)); + s = PRVM_ValueString (prog, (etype_t)def->type, val, valuebuf, sizeof(valuebuf)); dpsnprintf (line, linelength, "%s (=%s)", PRVM_GetString(prog, def->s_name), s); } @@ -606,7 +606,7 @@ void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fie { size_t l; ddef_t *d; - int *v; + prvm_eval_t *val; int i, j; const char *name; int type; @@ -634,13 +634,13 @@ void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fie // Didn't match; skip continue; - v = (int *)(ed->fields.vp + d->ofs); + val = (prvm_eval_t *)(ed->fields.fp + d->ofs); // if the value is still all 0, skip the field type = d->type & ~DEF_SAVEGLOBAL; for (j=0 ; jivector[j]) break; if (j == prvm_type_size[type]) continue; @@ -657,7 +657,7 @@ void PRVM_ED_Print(prvm_prog_t *prog, prvm_edict_t *ed, const char *wildcard_fie strlcat(tempstring, " ", sizeof(tempstring)); strlcat(tempstring, " ", sizeof(tempstring)); - name = PRVM_ValueString(prog, (etype_t)d->type, (prvm_eval_t *)v, valuebuf, sizeof(valuebuf)); + name = PRVM_ValueString(prog, (etype_t)d->type, val, valuebuf, sizeof(valuebuf)); if (strlen(name) > sizeof(tempstring2)-4) { memcpy (tempstring2, name, sizeof(tempstring2)-4); @@ -688,7 +688,7 @@ extern cvar_t developer_entityparsing; void PRVM_ED_Write (prvm_prog_t *prog, qfile_t *f, prvm_edict_t *ed) { ddef_t *d; - int *v; + prvm_eval_t *val; int i, j; const char *name; int type; @@ -715,19 +715,19 @@ void PRVM_ED_Write (prvm_prog_t *prog, qfile_t *f, prvm_edict_t *ed) if(strlen(name) > 1 && name[strlen(name)-2] == '_') continue; // skip _x, _y, _z vars, and ALSO other _? vars as some mods expect them to be never saved (TODO: a gameplayfix for using the "more precise" condition above?) - v = (int *)(ed->fields.vp + d->ofs); + val = (prvm_eval_t *)(ed->fields.fp + d->ofs); // if the value is still all 0, skip the field type = d->type & ~DEF_SAVEGLOBAL; for (j=0 ; jivector[j]) break; if (j == prvm_type_size[type]) continue; FS_Printf(f,"\"%s\" ",name); prog->statestring = va(vabuf, sizeof(vabuf), "PRVM_ED_Write, ent=%d, name=%s", i, name); - FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString(prog, (etype_t)d->type, (prvm_eval_t *)v, valuebuf, sizeof(valuebuf))); + FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString(prog, (etype_t)d->type, val, valuebuf, sizeof(valuebuf))); prog->statestring = NULL; } @@ -875,7 +875,7 @@ void PRVM_ED_WriteGlobals (prvm_prog_t *prog, qfile_t *f) prog->statestring = va(vabuf, sizeof(vabuf), "PRVM_ED_WriteGlobals, name=%s", name); FS_Printf(f,"\"%s\" ", name); - FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString(prog, (etype_t)type, (prvm_eval_t *)&prog->globals.generic[def->ofs], valuebuf, sizeof(valuebuf))); + FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString(prog, (etype_t)type, (prvm_eval_t *)&prog->globals.fp[def->ofs], valuebuf, sizeof(valuebuf))); prog->statestring = NULL; } FS_Print(f,"}\n"); @@ -946,9 +946,9 @@ qboolean PRVM_ED_ParseEpair(prvm_prog_t *prog, prvm_edict_t *ent, ddef_t *key, c mfunction_t *func; if (ent) - val = (prvm_eval_t *)(ent->fields.vp + key->ofs); + val = (prvm_eval_t *)(ent->fields.fp + key->ofs); else - val = (prvm_eval_t *)(prog->globals.generic + key->ofs); + val = (prvm_eval_t *)(prog->globals.fp + key->ofs); switch (key->type & ~DEF_SAVEGLOBAL) { case ev_string: @@ -1002,7 +1002,7 @@ qboolean PRVM_ED_ParseEpair(prvm_prog_t *prog, prvm_edict_t *ent, ddef_t *key, c PRVM_MEM_IncreaseEdicts(prog); // if IncreaseEdicts was called the base pointer needs to be updated if (ent) - val = (prvm_eval_t *)(ent->fields.vp + key->ofs); + val = (prvm_eval_t *)(ent->fields.fp + key->ofs); val->edict = PRVM_EDICT_TO_PROG(PRVM_EDICT_NUM((int)i)); break; @@ -1129,7 +1129,7 @@ static void PRVM_ED_EdictGet_f(void) goto fail; } - v = (prvm_eval_t *)(ed->fields.vp + key->ofs); + v = (prvm_eval_t *)(ed->fields.fp + key->ofs); s = PRVM_UglyValueString(prog, (etype_t)key->type, v, valuebuf, sizeof(valuebuf)); if(Cmd_Argc() == 5) { @@ -1172,7 +1172,7 @@ static void PRVM_ED_GlobalGet_f(void) goto fail; } - v = (prvm_eval_t *) &prog->globals.generic[key->ofs]; + v = (prvm_eval_t *) &prog->globals.fp[key->ofs]; s = PRVM_UglyValueString(prog, (etype_t)key->type, v, valuebuf, sizeof(valuebuf)); if(Cmd_Argc() == 4) { @@ -1370,7 +1370,7 @@ void PRVM_ED_LoadFromFile (prvm_prog_t *prog, const char *data) // clear it if (ent != prog->edicts) // hack - memset (ent->fields.vp, 0, prog->entityfields * 4); + memset (ent->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t)); data = PRVM_ED_ParseEdict (prog, data, ent); parsed++; @@ -1882,7 +1882,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, int numrequiredfun dstatement_t *instatements; ddef_t *infielddefs; ddef_t *inglobaldefs; - float *inglobals; + int *inglobals; dfunction_t *infunctions; char *instrings; fs_offset_t filesize; @@ -1891,6 +1891,13 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, int numrequiredfun int a; int b; int c; + union + { + unsigned int i; + float f; + } + u; + unsigned int d; char vabuf[1024]; if (prog->loaded) @@ -1930,7 +1937,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, int numrequiredfun prog->progs_numfunctions = LittleLong(dprograms->numfunctions); instrings = (char *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_strings)); prog->progs_numstrings = LittleLong(dprograms->numstrings); - inglobals = (float *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_globals)); + inglobals = (int *)((unsigned char *)dprograms + LittleLong(dprograms->ofs_globals)); prog->progs_numglobals = LittleLong(dprograms->numglobals); prog->progs_entityfields = LittleLong(dprograms->entityfields); @@ -1957,7 +1964,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, int numrequiredfun // we need to expand the globaldefs and fielddefs to include engine defs prog->globaldefs = (ddef_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numglobaldefs + numrequiredglobals) * sizeof(ddef_t)); - prog->globals.generic = (float *)Mem_Alloc(prog->progs_mempool, (prog->progs_numglobals + requiredglobalspace) * sizeof(float)); + prog->globals.fp = (prvm_vec_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numglobals + requiredglobalspace) * sizeof(prvm_vec_t)); prog->fielddefs = (ddef_t *)Mem_Alloc(prog->progs_mempool, (prog->progs_numfielddefs + numrequiredfields) * sizeof(ddef_t)); // we need to convert the statements to our memory format prog->statements = (mstatement_t *)Mem_Alloc(prog->progs_mempool, prog->progs_numstatements * sizeof(mstatement_t)); @@ -2032,8 +2039,26 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, int numrequiredfun #define remapfield(index) (index) // copy globals + // FIXME: LordHavoc: this uses a crude way to identify integer constants, rather than checking for matching globaldefs and checking their type for (i = 0;i < prog->progs_numglobals;i++) - ((int *)prog->globals.generic)[remapglobal(i)] = LittleLong(((int *)inglobals)[i]); + { + u.i = LittleLong(inglobals[i]); + // most globals are 0, we only need to deal with the ones that are not + if (u.i) + { + d = u.i & 0xFF800000; + if ((d == 0xFF800000) || (d == 0)) + { + // Looks like an integer (expand to int64) + prog->globals.ip[remapglobal(i)] = u.i; + } + else + { + // Looks like a float (expand to double) + prog->globals.fp[remapglobal(i)] = u.f; + } + } + } // LordHavoc: TODO: support 32bit progs statement formats // copy, remap globals in statements, bounds check @@ -2385,7 +2410,7 @@ static void PRVM_Fields_f (void) const char *name; prvm_edict_t *ed; ddef_t *d; - int *v; + prvm_eval_t *val; // TODO /* @@ -2417,11 +2442,11 @@ static void PRVM_Fields_f (void) name = PRVM_GetString(prog, d->s_name); if (name[strlen(name)-2] == '_') continue; // skip _x, _y, _z vars - v = (int *)(ed->fields.vp + d->ofs); + val = (prvm_eval_t *)(ed->fields.fp + d->ofs); // if the value is still all 0, skip the field for (j = 0;j < prvm_type_size[d->type & ~DEF_SAVEGLOBAL];j++) { - if (v[j]) + if (val->ivector[j]) { counts[i]++; break; diff --git a/prvm_exec.c b/prvm_exec.c index 49142b72..df57f66f 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -564,7 +564,7 @@ static int PRVM_EnterFunction (prvm_prog_t *prog, mfunction_t *f) prog->error_cmd("PRVM_ExecuteProgram: locals stack overflow in %s", prog->name); for (i=0 ; i < c ; i++) - prog->localstack[prog->localstack_used+i] = ((int *)prog->globals.generic)[f->parm_start + i]; + prog->localstack[prog->localstack_used+i] = prog->globals.ip[f->parm_start + i]; prog->localstack_used += c; // copy parameters @@ -573,7 +573,7 @@ static int PRVM_EnterFunction (prvm_prog_t *prog, mfunction_t *f) { for (j=0 ; jparm_size[i] ; j++) { - ((int *)prog->globals.generic)[o] = ((int *)prog->globals.generic)[OFS_PARM0+i*3+j]; + prog->globals.ip[o] = prog->globals.ip[OFS_PARM0+i*3+j]; o++; } } @@ -605,7 +605,7 @@ static int PRVM_LeaveFunction (prvm_prog_t *prog) prog->error_cmd("PRVM_ExecuteProgram: locals stack underflow in %s", prog->name); for (i=0 ; i < c ; i++) - ((int *)prog->globals.generic)[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i]; + prog->globals.ip[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i]; // up stack prog->depth--; @@ -644,9 +644,9 @@ void PRVM_Init_Exec(prvm_prog_t *prog) // nothing here yet } -#define OPA ((prvm_eval_t *)&prog->globals.generic[st->operand[0]]) -#define OPB ((prvm_eval_t *)&prog->globals.generic[st->operand[1]]) -#define OPC ((prvm_eval_t *)&prog->globals.generic[st->operand[2]]) +#define OPA ((prvm_eval_t *)&prog->globals.fp[st->operand[0]]) +#define OPB ((prvm_eval_t *)&prog->globals.fp[st->operand[1]]) +#define OPC ((prvm_eval_t *)&prog->globals.fp[st->operand[2]]) extern cvar_t prvm_traceqc; extern cvar_t prvm_statementprofiling; extern qboolean prvm_runawaycheck; diff --git a/prvm_execprogram.h b/prvm_execprogram.h index 3ae82b33..82f09d12 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -74,10 +74,10 @@ } break; case OP_BITAND: - OPC->_float = (int)OPA->_float & (int)OPB->_float; + OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float; break; case OP_BITOR: - OPC->_float = (int)OPA->_float | (int)OPB->_float; + OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float; break; case OP_GE: OPC->_float = OPA->_float >= OPB->_float; @@ -165,13 +165,13 @@ if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea) { PreError(); - prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, OPB->_int); + prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } if (OPB->_int < prog->entityfields && !prog->allowworldwrites) { prog->xstatement = st - prog->statements; - VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), OPB->_int, prog->name); + VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name); } ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int); ptr->_int = OPA->_int; @@ -180,13 +180,13 @@ if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea) { PreError(); - prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, OPB->_int); + prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } if (OPB->_int < prog->entityfields && !prog->allowworldwrites) { prog->xstatement = st - prog->statements; - VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), OPB->_int, prog->name); + VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name); } ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int); ptr->ivector[0] = OPA->ivector[0]; @@ -204,7 +204,7 @@ if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields)) { PreError(); - prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, OPB->_int); + prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int); goto cleanup; } #if 0 @@ -216,7 +216,7 @@ } #endif ed = PRVM_PROG_TO_EDICT(OPA->edict); - OPC->_int = ed->fields.vp - prog->edictsfields + OPB->_int; + OPC->_int = ed->fields.fp - prog->edictsfields + OPB->_int; break; case OP_LOAD_F: @@ -233,11 +233,11 @@ if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields)) { PreError(); - prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, OPB->_int); + prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } ed = PRVM_PROG_TO_EDICT(OPA->edict); - OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int; + OPC->_int = ((prvm_eval_t *)(ed->fields.fp + OPB->_int))->_int; break; case OP_LOAD_V: @@ -250,13 +250,13 @@ if (OPB->_int < 0 || OPB->_int + 2 >= prog->entityfields) { PreError(); - prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, OPB->_int); + prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } ed = PRVM_PROG_TO_EDICT(OPA->edict); - OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0]; - OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1]; - OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2]; + OPC->ivector[0] = ((prvm_eval_t *)(ed->fields.fp + OPB->_int))->ivector[0]; + OPC->ivector[1] = ((prvm_eval_t *)(ed->fields.fp + OPB->_int))->ivector[1]; + OPC->ivector[2] = ((prvm_eval_t *)(ed->fields.fp + OPB->_int))->ivector[2]; break; //================== @@ -333,7 +333,7 @@ if (!OPA->function) prog->error_cmd("NULL function in %s", prog->name); - if(!OPA->function || OPA->function >= (unsigned int)prog->numfunctions) + if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions) { PreError(); prog->error_cmd("%s CALL outside the program", prog->name); @@ -376,9 +376,9 @@ prog->xfunction->profile += (st - startst); prog->xstatement = st - prog->statements; - prog->globals.generic[OFS_RETURN] = prog->globals.generic[st->operand[0]]; - prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[st->operand[0]+1]; - prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[st->operand[0]+2]; + prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ]; + prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1]; + prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2]; st = prog->statements + PRVM_LeaveFunction(prog); startst = st; @@ -410,33 +410,33 @@ OPC->_int = OPA->_int + OPB->_int; break; case OP_ADD_IF: - OPC->_int = OPA->_int + (int) OPB->_float; + OPC->_int = OPA->_int + (prvm_int_t) OPB->_float; break; case OP_ADD_FI: - OPC->_float = OPA->_float + (float) OPB->_int; + OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int; break; case OP_SUB_I: OPC->_int = OPA->_int - OPB->_int; break; case OP_SUB_IF: - OPC->_int = OPA->_int - (int) OPB->_float; + OPC->_int = OPA->_int - (prvm_int_t) OPB->_float; break; case OP_SUB_FI: - OPC->_float = OPA->_float - (float) OPB->_int; + OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int; break; case OP_MUL_I: OPC->_int = OPA->_int * OPB->_int; break; case OP_MUL_IF: - OPC->_int = OPA->_int * (int) OPB->_float; + OPC->_int = OPA->_int * (prvm_int_t) OPB->_float; break; case OP_MUL_FI: - OPC->_float = OPA->_float * (float) OPB->_int; + OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int; break; case OP_MUL_VI: - OPC->vector[0] = (float) OPB->_int * OPA->vector[0]; - OPC->vector[1] = (float) OPB->_int * OPA->vector[1]; - OPC->vector[2] = (float) OPB->_int * OPA->vector[2]; + OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0]; + OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1]; + OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2]; break; case OP_DIV_VF: { @@ -450,10 +450,10 @@ OPC->_int = OPA->_int / OPB->_int; break; case OP_DIV_IF: - OPC->_int = OPA->_int / (int) OPB->_float; + OPC->_int = OPA->_int / (prvm_int_t) OPB->_float; break; case OP_DIV_FI: - OPC->_float = OPA->_float / (float) OPB->_int; + OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int; break; case OP_CONV_IF: OPC->_float = OPA->_int; @@ -468,16 +468,16 @@ OPC->_int = OPA->_int | OPB->_int; break; case OP_BITAND_IF: - OPC->_int = OPA->_int & (int)OPB->_float; + OPC->_int = OPA->_int & (prvm_int_t)OPB->_float; break; case OP_BITOR_IF: - OPC->_int = OPA->_int | (int)OPB->_float; + OPC->_int = OPA->_int | (prvm_int_t)OPB->_float; break; case OP_BITAND_FI: - OPC->_float = (int)OPA->_float & OPB->_int; + OPC->_float = (prvm_int_t)OPA->_float & OPB->_int; break; case OP_BITOR_FI: - OPC->_float = (int)OPA->_float | OPB->_int; + OPC->_float = (prvm_int_t)OPA->_float | OPB->_int; break; case OP_GE_I: OPC->_float = OPA->_int >= OPB->_int; @@ -498,40 +498,40 @@ OPC->_float = OPA->_int || OPB->_int; break; case OP_GE_IF: - OPC->_float = (float)OPA->_int >= OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float; break; case OP_LE_IF: - OPC->_float = (float)OPA->_int <= OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float; break; case OP_GT_IF: - OPC->_float = (float)OPA->_int > OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float; break; case OP_LT_IF: - OPC->_float = (float)OPA->_int < OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float; break; case OP_AND_IF: - OPC->_float = (float)OPA->_int && OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float; break; case OP_OR_IF: - OPC->_float = (float)OPA->_int || OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float; break; case OP_GE_FI: - OPC->_float = OPA->_float >= (float)OPB->_int; + OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int; break; case OP_LE_FI: - OPC->_float = OPA->_float <= (float)OPB->_int; + OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int; break; case OP_GT_FI: - OPC->_float = OPA->_float > (float)OPB->_int; + OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int; break; case OP_LT_FI: - OPC->_float = OPA->_float < (float)OPB->_int; + OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int; break; case OP_AND_FI: - OPC->_float = OPA->_float && (float)OPB->_int; + OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int; break; case OP_OR_FI: - OPC->_float = OPA->_float || (float)OPB->_int; + OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int; break; case OP_NOT_I: OPC->_float = !OPA->_int; @@ -540,19 +540,19 @@ OPC->_float = OPA->_int == OPB->_int; break; case OP_EQ_IF: - OPC->_float = (float)OPA->_int == OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float; break; case OP_EQ_FI: - OPC->_float = OPA->_float == (float)OPB->_int; + OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int; break; case OP_NE_I: OPC->_float = OPA->_int != OPB->_int; break; case OP_NE_IF: - OPC->_float = (float)OPA->_int != OPB->_float; + OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float; break; case OP_NE_FI: - OPC->_float = OPA->_float != (float)OPB->_int; + OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int; break; case OP_STORE_I: OPB->_int = OPA->_int; @@ -619,7 +619,7 @@ break; case OP_GADDRESS: - i = OPA->_int + (int) OPB->_float; + i = OPA->_int + (prvm_int_t) OPB->_float; #if PRBOUNDSCHECK if (i < 0 || i >= pr_globaldefs) { diff --git a/qtypes.h b/qtypes.h index 250beaee..38b3b9fa 100644 --- a/qtypes.h +++ b/qtypes.h @@ -35,4 +35,28 @@ typedef bool qboolean; #define RESTRICT #endif +// LordHavoc: upgrade the prvm to double precision for better time values +//#define PRVM_64 +#ifdef PRVM_64 +typedef double prvm_vec_t; +typedef long long prvm_int_t; +#else +typedef float prvm_vec_t; +typedef int prvm_int_t; +#endif +typedef prvm_vec_t prvm_vec3_t[3]; + +#ifdef VEC_64 +typedef double vec_t; +#else +typedef float vec_t; +#endif +typedef vec_t vec2_t[2]; +typedef vec_t vec3_t[3]; +typedef vec_t vec4_t[4]; +typedef vec_t vec5_t[5]; +typedef vec_t vec6_t[6]; +typedef vec_t vec7_t[7]; +typedef vec_t vec8_t[8]; + #endif diff --git a/quakedef.h b/quakedef.h index 66fdfb30..a3ba79f3 100644 --- a/quakedef.h +++ b/quakedef.h @@ -551,7 +551,11 @@ void Sys_Shared_Init(void); #define ISWHITESPACEORCONTROL(ch) ((signed char) (ch) <= (signed char) ' ') +#ifdef PRVM_64 +#define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFFFFFFFFFF) // also match "negative zero" doubles of value 0x8000000000000000 +#else #define FLOAT_IS_TRUE_FOR_INT(x) ((x) & 0x7FFFFFFF) // also match "negative zero" floats of value 0x80000000 +#endif #endif diff --git a/r_shadow.c b/r_shadow.c index 1073aa3f..71701fb5 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -4678,6 +4678,7 @@ void R_Shadow_PrepareModelShadows(void) { int i; float scale, size, radius, dot1, dot2; + prvm_vec3_t prvmshadowdir, prvmshadowfocus; vec3_t shadowdir, shadowforward, shadowright, shadoworigin, shadowfocus, shadowmins, shadowmaxs; entity_render_t *ent; @@ -4706,7 +4707,8 @@ void R_Shadow_PrepareModelShadows(void) scale = r_shadow_shadowmapping_precision.value * r_shadows_shadowmapscale.value; radius = 0.5f * size / scale; - Math_atov(r_shadows_throwdirection.string, shadowdir); + Math_atov(r_shadows_throwdirection.string, prvmshadowdir); + VectorCopy(prvmshadowdir, shadowdir); VectorNormalize(shadowdir); dot1 = DotProduct(r_refdef.view.forward, shadowdir); dot2 = DotProduct(r_refdef.view.up, shadowdir); @@ -4716,7 +4718,8 @@ void R_Shadow_PrepareModelShadows(void) VectorMA(r_refdef.view.up, -dot2, shadowdir, shadowforward); VectorNormalize(shadowforward); CrossProduct(shadowdir, shadowforward, shadowright); - Math_atov(r_shadows_focus.string, shadowfocus); + Math_atov(r_shadows_focus.string, prvmshadowfocus); + VectorCopy(prvmshadowfocus, shadowfocus); VectorM(shadowfocus[0], r_refdef.view.right, shadoworigin); VectorMA(shadoworigin, shadowfocus[1], r_refdef.view.up, shadoworigin); VectorMA(shadoworigin, -shadowfocus[2], r_refdef.view.forward, shadoworigin); @@ -4752,6 +4755,7 @@ void R_DrawModelShadowMaps(int fbo, rtexture_t *depthtexture, rtexture_t *colort vec3_t relativelightdirection, relativeforward, relativeright; vec3_t relativeshadowmins, relativeshadowmaxs; vec3_t shadowdir, shadowforward, shadowright, shadoworigin, shadowfocus; + prvm_vec3_t prvmshadowdir, prvmshadowfocus; float m[12]; matrix4x4_t shadowmatrix, cameramatrix, mvpmatrix, invmvpmatrix, scalematrix, texmatrix; r_viewport_t viewport; @@ -4803,9 +4807,11 @@ void R_DrawModelShadowMaps(int fbo, rtexture_t *depthtexture, rtexture_t *colort r_shadow_shadowmap_parameters[2] = 1.0; r_shadow_shadowmap_parameters[3] = bound(0.0f, 1.0f - r_shadows_darken.value, 1.0f); - Math_atov(r_shadows_throwdirection.string, shadowdir); + Math_atov(r_shadows_throwdirection.string, prvmshadowdir); + VectorCopy(prvmshadowdir, shadowdir); VectorNormalize(shadowdir); - Math_atov(r_shadows_focus.string, shadowfocus); + Math_atov(r_shadows_focus.string, prvmshadowfocus); + VectorCopy(prvmshadowfocus, shadowfocus); VectorM(shadowfocus[0], r_refdef.view.right, shadoworigin); VectorMA(shadoworigin, shadowfocus[1], r_refdef.view.up, shadoworigin); VectorMA(shadoworigin, -shadowfocus[2], r_refdef.view.forward, shadoworigin); @@ -4954,6 +4960,7 @@ void R_DrawModelShadows(int fbo, rtexture_t *depthtexture, rtexture_t *colortext vec3_t relativelightdirection; vec3_t relativeshadowmins, relativeshadowmaxs; vec3_t tmp, shadowdir; + prvm_vec3_t prvmshadowdir; if (!r_refdef.scene.numentities || !vid.stencil || (r_shadow_shadowmode != R_SHADOW_SHADOWMODE_STENCIL && r_shadows.integer != 1)) return; @@ -4976,7 +4983,8 @@ void R_DrawModelShadows(int fbo, rtexture_t *depthtexture, rtexture_t *colortext // get shadow dir if (r_shadows.integer == 2) { - Math_atov(r_shadows_throwdirection.string, shadowdir); + Math_atov(r_shadows_throwdirection.string, prvmshadowdir); + VectorCopy(prvmshadowdir, shadowdir); VectorNormalize(shadowdir); } @@ -6692,7 +6700,7 @@ LIGHT SAMPLING ============================================================================= */ -void R_LightPoint(vec3_t color, const vec3_t p, const int flags) +void R_LightPoint(float *color, const vec3_t p, const int flags) { int i, numlights, flag; float f, relativepoint[3], dist, dist2, lightradius2; diff --git a/r_shadow.h b/r_shadow.h index d4d4b078..907173dc 100644 --- a/r_shadow.h +++ b/r_shadow.h @@ -101,8 +101,8 @@ void R_Shadow_PrepareModelShadows(void); #define LP_LIGHTMAP 1 #define LP_RTWORLD 2 #define LP_DYNLIGHT 4 -void R_LightPoint(vec3_t color, const vec3_t p, const int flags); -void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, const int flags); +void R_LightPoint(float *color, const vec3_t p, const int flags); +void R_CompleteLightPoint(float *ambientcolor, float *diffusecolor, float *diffusenormal, const vec3_t p, const int flags); void R_DrawModelShadowMaps(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture); void R_DrawModelShadows(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture); diff --git a/render.h b/render.h index 7e60e504..998739fb 100644 --- a/render.h +++ b/render.h @@ -223,8 +223,8 @@ void R_TimeReport(const char *name); // r_stain void R_Stain(const vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2); -void R_CalcBeam_Vertex3f(float *vert, const vec3_t org1, const vec3_t org2, float width); -void R_CalcSprite_Vertex3f(float *vertex3f, const vec3_t origin, const vec3_t left, const vec3_t up, float scalex1, float scalex2, float scaley1, float scaley2); +void R_CalcBeam_Vertex3f(float *vert, const float *org1, const float *org2, float width); +void R_CalcSprite_Vertex3f(float *vertex3f, const float *origin, const float *left, const float *up, float scalex1, float scalex2, float scaley1, float scaley2); extern mempool_t *r_main_mempool; diff --git a/sv_main.c b/sv_main.c index b2e70f3b..d94bb032 100644 --- a/sv_main.c +++ b/sv_main.c @@ -1160,7 +1160,7 @@ static qboolean SV_PrepareEntityForSending (prvm_edict_t *ent, entity_state_t *c unsigned int customizeentityforclient; unsigned int sendentity; float f; - float *v; + prvm_vec_t *v; vec3_t cullmins, cullmaxs; dp_model_t *model; @@ -1993,7 +1993,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t { // angle fixing was requested by global thinking code... // so store the current angles for later use - memcpy(host_client->fixangle_angles, PRVM_serveredictvector(ent, angles), sizeof(host_client->fixangle_angles)); + VectorCopy(PRVM_serveredictvector(ent, angles), host_client->fixangle_angles); host_client->fixangle_angles_set = TRUE; // and clear fixangle for the next frame @@ -3409,7 +3409,7 @@ void SV_SpawnServer (const char *server) // // AK possible hack since num_edicts is still 0 ent = PRVM_EDICT_NUM(0); - memset (ent->fields.vp, 0, prog->entityfields * 4); + memset (ent->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t)); ent->priv.server->free = false; PRVM_serveredictstring(ent, model) = PRVM_SetEngineString(prog, sv.worldname); PRVM_serveredictfloat(ent, modelindex) = 1; // world model @@ -3985,7 +3985,7 @@ static int SV_ThreadFunc(void *voiddata) if (sv.paused == 1 && sv_realtime > sv.pausedstart && sv.pausedstart > 0) { PRVM_serverglobalfloat(time) = sv.time; - prog->globals.generic[OFS_PARM0] = sv_realtime - sv.pausedstart; + prog->globals.fp[OFS_PARM0] = sv_realtime - sv.pausedstart; prog->ExecuteProgram(prog, PRVM_serverfunction(SV_PausedTic), "QC function SV_PausedTic is missing"); } diff --git a/sv_move.c b/sv_move.c index eb577c77..13b96c7b 100644 --- a/sv_move.c +++ b/sv_move.c @@ -110,7 +110,7 @@ qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean { prvm_prog_t *prog = SVVM_prog; float dz; - vec3_t oldorg, neworg, end, traceendpos; + vec3_t oldorg, neworg, end, traceendpos, entorigin, entmins, entmaxs; trace_t trace; int i; prvm_edict_t *enemy; @@ -118,6 +118,8 @@ qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean // try the move VectorCopy (PRVM_serveredictvector(ent, origin), oldorg); VectorAdd (PRVM_serveredictvector(ent, origin), move, neworg); + VectorCopy(PRVM_serveredictvector(ent, mins), entmins); + VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs); // flying monsters don't step up if ( (int)PRVM_serveredictfloat(ent, flags) & (FL_SWIM | FL_FLY) ) @@ -140,7 +142,8 @@ qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean neworg[2] += 8; } } - trace = SV_TraceBox(PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), neworg, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); + VectorCopy(PRVM_serveredictvector(ent, origin), entorigin); + trace = SV_TraceBox(entorigin, entmins, entmaxs, neworg, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); if (trace.fraction == 1) { @@ -169,12 +172,12 @@ qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean VectorCopy (neworg, end); end[2] -= sv_stepheight.value*2; - trace = SV_TraceBox(neworg, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); + trace = SV_TraceBox(neworg, entmins, entmaxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); if (trace.startsolid) { neworg[2] -= sv_stepheight.value; - trace = SV_TraceBox(neworg, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); + trace = SV_TraceBox(neworg, entmins, entmaxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); if (trace.startsolid) return false; } diff --git a/sv_phys.c b/sv_phys.c index 66951105..f05cad8c 100644 --- a/sv_phys.c +++ b/sv_phys.c @@ -109,6 +109,8 @@ trace_t SV_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int float pitchsign = 1; prvm_edict_t *traceowner, *touch; trace_t trace; + // temporary storage because prvm_vec_t may differ from vec_t + vec3_t touchmins, touchmaxs; // bounding box of entire move area vec3_t clipboxmins, clipboxmaxs; // size when clipping against monsters @@ -226,10 +228,12 @@ trace_t SV_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int VM_GenerateFrameGroupBlend(prog, touch->priv.server->framegroupblend, touch); VM_FrameBlendFromFrameGroupBlend(touch->priv.server->frameblend, touch->priv.server->framegroupblend, model, sv.time); VM_UpdateEdictSkeleton(prog, touch, model, touch->priv.server->frameblend); + VectorCopy(PRVM_serveredictvector(touch, mins), touchmins); + VectorCopy(PRVM_serveredictvector(touch, maxs), touchmaxs); if (type == MOVE_MISSILE && (int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER) - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipstart, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipstart, hitsupercontentsmask); else - Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask); + Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask); Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_serveredictfloat(touch, solid) == SOLID_BSP); } @@ -255,6 +259,8 @@ trace_t SV_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_ float pitchsign = 1; prvm_edict_t *traceowner, *touch; trace_t trace; + // temporary storage because prvm_vec_t may differ from vec_t + vec3_t touchmins, touchmaxs; // bounding box of entire move area vec3_t clipboxmins, clipboxmaxs; // size when clipping against monsters @@ -393,10 +399,12 @@ trace_t SV_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_ VM_GenerateFrameGroupBlend(prog, touch->priv.server->framegroupblend, touch); VM_FrameBlendFromFrameGroupBlend(touch->priv.server->frameblend, touch->priv.server->framegroupblend, model, sv.time); VM_UpdateEdictSkeleton(prog, touch, model, touch->priv.server->frameblend); + VectorCopy(PRVM_serveredictvector(touch, mins), touchmins); + VectorCopy(PRVM_serveredictvector(touch, maxs), touchmaxs); if (type == MOVE_MISSILE && (int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER) - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); else - Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, false); + Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, false); Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_serveredictfloat(touch, solid) == SOLID_BSP); } @@ -436,6 +444,8 @@ trace_t SV_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co qboolean pointtrace; prvm_edict_t *traceowner, *touch; trace_t trace; + // temporary storage because prvm_vec_t may differ from vec_t + vec3_t touchmins, touchmaxs; // bounding box of entire move area vec3_t clipboxmins, clipboxmaxs; // size of the moving object @@ -607,10 +617,12 @@ trace_t SV_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, co VM_GenerateFrameGroupBlend(prog, touch->priv.server->framegroupblend, touch); VM_FrameBlendFromFrameGroupBlend(touch->priv.server->frameblend, touch->priv.server->framegroupblend, model, sv.time); VM_UpdateEdictSkeleton(prog, touch, model, touch->priv.server->frameblend); + VectorCopy(PRVM_serveredictvector(touch, mins), touchmins); + VectorCopy(PRVM_serveredictvector(touch, maxs), touchmaxs); if (type == MOVE_MISSILE && (int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER) - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask); else - Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs), bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask); + Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask); Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_serveredictfloat(touch, solid) == SOLID_BSP); } @@ -837,7 +849,7 @@ void SV_LinkEdict (prvm_edict_t *ent) { prvm_prog_t *prog = SVVM_prog; dp_model_t *model; - vec3_t mins, maxs; + vec3_t mins, maxs, entmins, entmaxs, entangles; int modelindex; if (ent == prog->edicts) @@ -864,7 +876,10 @@ void SV_LinkEdict (prvm_edict_t *ent) { // TODO maybe should do this for rotating SOLID_BSP too? Would behave better with rotating doors // TODO special handling for spheres? - RotateBBox(PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), PRVM_serveredictvector(ent, angles), mins, maxs); + VectorCopy(PRVM_serveredictvector(ent, mins), entmins); + VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs); + VectorCopy(PRVM_serveredictvector(ent, angles), entangles); + RotateBBox(entmins, entmaxs, entangles, mins, maxs); VectorAdd(PRVM_serveredictvector(ent, origin), mins, mins); VectorAdd(PRVM_serveredictvector(ent, origin), maxs, maxs); } @@ -954,11 +969,14 @@ static int SV_TestEntityPosition (prvm_edict_t *ent, vec3_t offset) { prvm_prog_t *prog = SVVM_prog; int contents; - vec3_t org; + vec3_t org, entorigin, entmins, entmaxs; trace_t trace; contents = SV_GenericHitSuperContentsMask(ent); VectorAdd(PRVM_serveredictvector(ent, origin), offset, org); - trace = SV_TraceBox(org, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), PRVM_serveredictvector(ent, origin), ((PRVM_serveredictfloat(ent, movetype) == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), ent, contents); + VectorCopy(PRVM_serveredictvector(ent, origin), entorigin); + VectorCopy(PRVM_serveredictvector(ent, mins), entmins); + VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs); + trace = SV_TraceBox(org, entmins, entmaxs, entorigin, ((PRVM_serveredictfloat(ent, movetype) == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), ent, contents); if (trace.startsupercontents & contents) return true; else @@ -971,8 +989,8 @@ static int SV_TestEntityPosition (prvm_edict_t *ent, vec3_t offset) // FIXME: this breaks entities larger than the hull size int i; vec3_t v, m1, m2, s; - VectorAdd(org, PRVM_serveredictvector(ent, mins), m1); - VectorAdd(org, PRVM_serveredictvector(ent, maxs), m2); + VectorAdd(org, entmins, m1); + VectorAdd(org, entmaxs, m2); VectorSubtract(m2, m1, s); #define EPSILON (1.0f / 32.0f) if (s[0] >= EPSILON*2) {m1[0] += EPSILON;m2[0] -= EPSILON;} @@ -997,7 +1015,7 @@ static int SV_TestEntityPosition (prvm_edict_t *ent, vec3_t offset) #else // verify if the endpos is REALLY outside solid VectorCopy(trace.endpos, org); - trace = SV_TraceBox(org, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), org, MOVE_NOMONSTERS, ent, contents); + trace = SV_TraceBox(org, entmins, entmaxs, org, MOVE_NOMONSTERS, ent, contents); if(trace.startsolid) Con_Printf("SV_TestEntityPosition: trace.endpos detected to be in solid. NOT using it.\n"); else @@ -1065,12 +1083,12 @@ void SV_CheckVelocity (prvm_edict_t *ent) // for (i=0 ; i<3 ; i++) { - if (IS_NAN(PRVM_serveredictvector(ent, velocity)[i])) + if (PRVM_IS_NAN(PRVM_serveredictvector(ent, velocity)[i])) { Con_Printf("Got a NaN velocity on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent), PRVM_GetString(prog, PRVM_serveredictstring(ent, classname))); PRVM_serveredictvector(ent, velocity)[i] = 0; } - if (IS_NAN(PRVM_serveredictvector(ent, origin)[i])) + if (PRVM_IS_NAN(PRVM_serveredictvector(ent, origin)[i])) { Con_Printf("Got a NaN origin on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent), PRVM_GetString(prog, PRVM_serveredictstring(ent, classname))); PRVM_serveredictvector(ent, origin)[i] = 0; @@ -1190,7 +1208,7 @@ returns the blocked flags (1 = floor, 2 = step / wall) ================== */ #define STOP_EPSILON 0.1 -static void ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) +static void ClipVelocity (prvm_vec3_t in, vec3_t normal, prvm_vec3_t out, prvm_vec_t overbounce) { int i; float backoff; @@ -1226,7 +1244,8 @@ static int SV_FlyMove (prvm_edict_t *ent, float time, qboolean applygravity, flo int blocked, bumpcount; int i, j, numplanes; float d, time_left, gravity; - vec3_t dir, push, planes[MAX_CLIP_PLANES], primal_velocity, original_velocity, new_velocity; + vec3_t dir, push, planes[MAX_CLIP_PLANES]; + prvm_vec3_t primal_velocity, original_velocity, new_velocity; #if 0 vec3_t end; #endif @@ -1686,7 +1705,7 @@ static void SV_PushMove (prvm_edict_t *pusher, float movetime) int checkcontents; qboolean rotated; float savesolid, movetime2, pushltime; - vec3_t mins, maxs, move, move1, moveangle, pushorig, pushang, a, forward, left, up, org; + vec3_t mins, maxs, move, move1, moveangle, pushorig, pushang, a, forward, left, up, org, pushermins, pushermaxs, checkorigin, checkmins, checkmaxs; int num_moved; int numcheckentities; static prvm_edict_t *checkentities[MAX_EDICTS]; @@ -1850,7 +1869,12 @@ static void SV_PushMove (prvm_edict_t *pusher, float movetime) // final position, move it if (!((int)PRVM_serveredictfloat(check, flags) & FL_ONGROUND) || PRVM_PROG_TO_EDICT(PRVM_serveredictedict(check, groundentity)) != pusher) { - Collision_ClipToGenericEntity(&trace, pushermodel, pusher->priv.server->frameblend, &pusher->priv.server->skeleton, PRVM_serveredictvector(pusher, mins), PRVM_serveredictvector(pusher, maxs), SUPERCONTENTS_BODY, &pusherfinalmatrix, &pusherfinalimatrix, PRVM_serveredictvector(check, origin), PRVM_serveredictvector(check, mins), PRVM_serveredictvector(check, maxs), PRVM_serveredictvector(check, origin), checkcontents); + VectorCopy(PRVM_serveredictvector(pusher, mins), pushermins); + VectorCopy(PRVM_serveredictvector(pusher, maxs), pushermaxs); + VectorCopy(PRVM_serveredictvector(check, origin), checkorigin); + VectorCopy(PRVM_serveredictvector(check, mins), checkmins); + VectorCopy(PRVM_serveredictvector(check, maxs), checkmaxs); + Collision_ClipToGenericEntity(&trace, pushermodel, pusher->priv.server->frameblend, &pusher->priv.server->skeleton, pushermins, pushermaxs, SUPERCONTENTS_BODY, &pusherfinalmatrix, &pusherfinalimatrix, checkorigin, checkmins, checkmaxs, checkorigin, checkcontents); //trace = SV_TraceBox(PRVM_serveredictvector(check, origin), PRVM_serveredictvector(check, mins), PRVM_serveredictvector(check, maxs), PRVM_serveredictvector(check, origin), MOVE_NOMONSTERS, check, checkcontents); if (!trace.startsolid) { @@ -1912,7 +1936,12 @@ static void SV_PushMove (prvm_edict_t *pusher, float movetime) PRVM_serveredictfloat(check, flags) = (int)PRVM_serveredictfloat(check, flags) & ~FL_ONGROUND; // if it is still inside the pusher, block - Collision_ClipToGenericEntity(&trace, pushermodel, pusher->priv.server->frameblend, &pusher->priv.server->skeleton, PRVM_serveredictvector(pusher, mins), PRVM_serveredictvector(pusher, maxs), SUPERCONTENTS_BODY, &pusherfinalmatrix, &pusherfinalimatrix, PRVM_serveredictvector(check, origin), PRVM_serveredictvector(check, mins), PRVM_serveredictvector(check, maxs), PRVM_serveredictvector(check, origin), checkcontents); + VectorCopy(PRVM_serveredictvector(pusher, mins), pushermins); + VectorCopy(PRVM_serveredictvector(pusher, maxs), pushermaxs); + VectorCopy(PRVM_serveredictvector(check, origin), checkorigin); + VectorCopy(PRVM_serveredictvector(check, mins), checkmins); + VectorCopy(PRVM_serveredictvector(check, maxs), checkmaxs); + Collision_ClipToGenericEntity(&trace, pushermodel, pusher->priv.server->frameblend, &pusher->priv.server->skeleton, pushermins, pushermaxs, SUPERCONTENTS_BODY, &pusherfinalmatrix, &pusherfinalimatrix, checkorigin, checkmins, checkmaxs, checkorigin, checkcontents); if (trace.startsolid) { vec3_t move2; @@ -2208,9 +2237,10 @@ static void SV_WallFriction (prvm_edict_t *ent, float *stepnormal) { prvm_prog_t *prog = SVVM_prog; float d, i; - vec3_t forward, into, side; + vec3_t forward, into, side, v_angle; - AngleVectors (PRVM_serveredictvector(ent, v_angle), forward, NULL, NULL); + VectorCopy(PRVM_serveredictvector(ent, v_angle), v_angle); + AngleVectors (v_angle, forward, NULL, NULL); if ((d = DotProduct (stepnormal, forward) + 0.5) < 0) { // cut the tangential velocity @@ -2301,7 +2331,7 @@ static void SV_WalkMove (prvm_edict_t *ent) int originalmove_groundentity; int hitsupercontentsmask; int type; - vec3_t upmove, downmove, start_origin, start_velocity, stepnormal, originalmove_origin, originalmove_velocity; + vec3_t upmove, downmove, start_origin, start_velocity, stepnormal, originalmove_origin, originalmove_velocity, entmins, entmaxs; trace_t downtrace, trace; qboolean applygravity; @@ -2343,7 +2373,9 @@ static void SV_WalkMove (prvm_edict_t *ent) type = MOVE_NOMONSTERS; // only clip against bmodels else type = MOVE_NORMAL; - trace = SV_TraceBox(upmove, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), downmove, type, ent, SV_GenericHitSuperContentsMask(ent)); + VectorCopy(PRVM_serveredictvector(ent, mins), entmins); + VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs); + trace = SV_TraceBox(upmove, entmins, entmaxs, downmove, type, ent, SV_GenericHitSuperContentsMask(ent)); if(trace.fraction < 1 && trace.plane.normal[2] > 0.7) clip |= 1; // but we HAVE found a floor } @@ -2552,10 +2584,12 @@ SV_CheckWaterTransition */ static void SV_CheckWaterTransition (prvm_edict_t *ent) { + vec3_t entorigin; prvm_prog_t *prog = SVVM_prog; // LordHavoc: bugfixes in this function are keyed to the sv_gameplayfix_bugfixedcheckwatertransition cvar - if this cvar is 0 then all the original bugs should be reenabled for compatibility int cont; - cont = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, SV_PointSuperContents(PRVM_serveredictvector(ent, origin))); + VectorCopy(PRVM_serveredictvector(ent, origin), entorigin); + cont = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, SV_PointSuperContents(entorigin)); if (!PRVM_serveredictfloat(ent, watertype)) { // just spawned here @@ -2935,7 +2969,7 @@ void SV_Physics_ClientMove(void) { // angle fixing was requested by physics code... // so store the current angles for later use - memcpy(host_client->fixangle_angles, PRVM_serveredictvector(ent, angles), sizeof(host_client->fixangle_angles)); + VectorCopy(PRVM_serveredictvector(ent, angles), host_client->fixangle_angles); host_client->fixangle_angles_set = TRUE; // and clear fixangle for the next frame @@ -2994,7 +3028,7 @@ static void SV_Physics_ClientEntity_PostThink(prvm_edict_t *ent) { // angle fixing was requested by physics code... // so store the current angles for later use - memcpy(host_client->fixangle_angles, PRVM_serveredictvector(ent, angles), sizeof(host_client->fixangle_angles)); + VectorCopy(PRVM_serveredictvector(ent, angles), host_client->fixangle_angles); host_client->fixangle_angles_set = TRUE; // and clear fixangle for the next frame diff --git a/sv_user.c b/sv_user.c index ce0b8e07..83a0e86a 100644 --- a/sv_user.c +++ b/sv_user.c @@ -194,26 +194,32 @@ static void SV_AirAccelerate (vec3_t wishveloc) static void DropPunchAngle (void) { prvm_prog_t *prog = SVVM_prog; - float len; - vec3_t v; + vec_t len; + vec3_t punchangle, punchvector; - len = VectorNormalizeLength (PRVM_serveredictvector(host_client->edict, punchangle)); + VectorCopy(PRVM_serveredictvector(host_client->edict, punchangle), punchangle); + VectorCopy(PRVM_serveredictvector(host_client->edict, punchvector), punchvector); - len -= 10*sv.frametime; - if (len < 0) - len = 0; - VectorScale (PRVM_serveredictvector(host_client->edict, punchangle), len, PRVM_serveredictvector(host_client->edict, punchangle)); + len = VectorNormalizeLength(punchangle); + if (len > 0) + { + len -= 10*sv.frametime; + if (len < 0) + len = 0; + VectorScale(punchangle, len, punchangle); + } - VectorCopy(PRVM_serveredictvector(host_client->edict, punchvector), v); - len = VectorNormalizeLength(v); + len = VectorNormalizeLength(punchvector); if (len > 0) { len -= 20*sv.frametime; if (len < 0) len = 0; - VectorScale(v, len, v); + VectorScale(punchvector, len, punchvector); } - VectorCopy(v, PRVM_serveredictvector(host_client->edict, punchvector)); + + VectorCopy(punchangle, PRVM_serveredictvector(host_client->edict, punchangle)); + VectorCopy(punchvector, PRVM_serveredictvector(host_client->edict, punchvector)); } /* @@ -226,11 +232,12 @@ static void SV_WaterMove (void) { prvm_prog_t *prog = SVVM_prog; int i; - vec3_t wishvel; - float speed, newspeed, wishspeed, addspeed, accelspeed, temp; + vec3_t wishvel, v_angle; + vec_t speed, newspeed, wishspeed, addspeed, accelspeed, temp; // user intentions - AngleVectors (PRVM_serveredictvector(host_client->edict, v_angle), forward, right, up); + VectorCopy(PRVM_serveredictvector(host_client->edict, v_angle), v_angle); + AngleVectors(v_angle, forward, right, up); for (i=0 ; i<3 ; i++) wishvel[i] = forward[i]*cmd.forwardmove + right[i]*cmd.sidemove; @@ -360,7 +367,7 @@ the angle fields specify an exact angular motion in degrees void SV_ClientThink (void) { prvm_prog_t *prog = SVVM_prog; - vec3_t v_angle; + vec3_t v_angle, angles, velocity; //Con_Printf("clientthink for %ims\n", (int) (sv.frametime * 1000)); @@ -394,7 +401,9 @@ void SV_ClientThink (void) // angles // show 1/3 the pitch angle and all the roll angle VectorAdd (PRVM_serveredictvector(host_client->edict, v_angle), PRVM_serveredictvector(host_client->edict, punchangle), v_angle); - PRVM_serveredictvector(host_client->edict, angles)[ROLL] = V_CalcRoll (PRVM_serveredictvector(host_client->edict, angles), PRVM_serveredictvector(host_client->edict, velocity))*4; + VectorCopy(PRVM_serveredictvector(host_client->edict, angles), angles); + VectorCopy(PRVM_serveredictvector(host_client->edict, velocity), velocity); + PRVM_serveredictvector(host_client->edict, angles)[ROLL] = V_CalcRoll (angles, velocity)*4; if (!PRVM_serveredictfloat(host_client->edict, fixangle)) { PRVM_serveredictvector(host_client->edict, angles)[PITCH] = -v_angle[PITCH]/3; diff --git a/svvm_cmds.c b/svvm_cmds.c index 2fd3464c..a68a5258 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -239,7 +239,6 @@ setorigin (entity, origin) static void VM_SV_setorigin(prvm_prog_t *prog) { prvm_edict_t *e; - float *org; VM_SAFEPARMCOUNT(2, VM_setorigin); @@ -254,8 +253,7 @@ static void VM_SV_setorigin(prvm_prog_t *prog) VM_Warning(prog, "setorigin: can not modify free entity\n"); return; } - org = PRVM_G_VECTOR(OFS_PARM1); - VectorCopy (org, PRVM_serveredictvector(e, origin)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), PRVM_serveredictvector(e, origin)); if(e->priv.required->mark == PRVM_EDICT_MARK_WAIT_FOR_SETORIGIN) e->priv.required->mark = PRVM_EDICT_MARK_SETORIGIN_CAUGHT; SV_LinkEdict(e); @@ -291,7 +289,7 @@ setsize (entity, minvector, maxvector) static void VM_SV_setsize(prvm_prog_t *prog) { prvm_edict_t *e; - float *min, *max; + vec3_t mins, maxs; VM_SAFEPARMCOUNT(3, VM_setsize); @@ -306,9 +304,9 @@ static void VM_SV_setsize(prvm_prog_t *prog) VM_Warning(prog, "setsize: can not modify free entity\n"); return; } - min = PRVM_G_VECTOR(OFS_PARM1); - max = PRVM_G_VECTOR(OFS_PARM2); - SetMinMaxSize(prog, e, min, max, false); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), mins); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), maxs); + SetMinMaxSize(prog, e, mins, maxs, false); } @@ -441,14 +439,14 @@ particle(origin, color, count) */ static void VM_SV_particle(prvm_prog_t *prog) { - float *org, *dir; + vec3_t org, dir; float color; float count; VM_SAFEPARMCOUNT(4, VM_SV_particle); - org = PRVM_G_VECTOR(OFS_PARM0); - dir = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), dir); color = PRVM_G_FLOAT(OFS_PARM2); count = PRVM_G_FLOAT(OFS_PARM3); SV_StartParticle (org, dir, (int)color, (int)count); @@ -464,13 +462,13 @@ VM_SV_ambientsound static void VM_SV_ambientsound(prvm_prog_t *prog) { const char *samp; - float *pos; + vec3_t pos; float vol, attenuation; int soundnum, large; VM_SAFEPARMCOUNT(4, VM_SV_ambientsound); - pos = PRVM_G_VECTOR (OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), pos); samp = PRVM_G_STRING(OFS_PARM1); vol = PRVM_G_FLOAT(OFS_PARM2); attenuation = PRVM_G_FLOAT(OFS_PARM3); @@ -635,7 +633,7 @@ traceline (vector1, vector2, movetype, ignore) */ static void VM_SV_traceline(prvm_prog_t *prog) { - float *v1, *v2; + vec3_t v1, v2; trace_t trace; int move; prvm_edict_t *ent; @@ -644,12 +642,12 @@ static void VM_SV_traceline(prvm_prog_t *prog) prog->xfunction->builtinsprofile += 30; - v1 = PRVM_G_VECTOR(OFS_PARM0); - v2 = PRVM_G_VECTOR(OFS_PARM1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), v1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), v2); move = (int)PRVM_G_FLOAT(OFS_PARM2); ent = PRVM_G_EDICT(OFS_PARM3); - if (IS_NAN(v1[0]) || IS_NAN(v1[1]) || IS_NAN(v1[2]) || IS_NAN(v2[0]) || IS_NAN(v2[1]) || IS_NAN(v2[2])) + if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) prog->error_cmd("%s: NAN errors detected in traceline('%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = SV_TraceLine(v1, v2, move, ent, SV_GenericHitSuperContentsMask(ent)); @@ -672,7 +670,7 @@ tracebox (vector1, vector mins, vector maxs, vector2, tryents) // LordHavoc: added this for my own use, VERY useful, similar to traceline static void VM_SV_tracebox(prvm_prog_t *prog) { - float *v1, *v2, *m1, *m2; + vec3_t v1, v2, m1, m2; trace_t trace; int move; prvm_edict_t *ent; @@ -681,14 +679,14 @@ static void VM_SV_tracebox(prvm_prog_t *prog) prog->xfunction->builtinsprofile += 30; - v1 = PRVM_G_VECTOR(OFS_PARM0); - m1 = PRVM_G_VECTOR(OFS_PARM1); - m2 = PRVM_G_VECTOR(OFS_PARM2); - v2 = PRVM_G_VECTOR(OFS_PARM3); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), v1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM1), m1); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), m2); + VectorCopy(PRVM_G_VECTOR(OFS_PARM3), v2); move = (int)PRVM_G_FLOAT(OFS_PARM4); ent = PRVM_G_EDICT(OFS_PARM5); - if (IS_NAN(v1[0]) || IS_NAN(v1[1]) || IS_NAN(v1[2]) || IS_NAN(v2[0]) || IS_NAN(v2[1]) || IS_NAN(v2[2])) + if (VEC_IS_NAN(v1[0]) || VEC_IS_NAN(v1[1]) || VEC_IS_NAN(v1[2]) || VEC_IS_NAN(v2[0]) || VEC_IS_NAN(v2[1]) || VEC_IS_NAN(v2[2])) prog->error_cmd("%s: NAN errors detected in tracebox('%f %f %f', '%f %f %f', '%f %f %f', '%f %f %f', %i, entity %i)\n", prog->name, v1[0], v1[1], v1[2], m1[0], m1[1], m1[2], m2[0], m2[1], m2[2], v2[0], v2[1], v2[2], move, PRVM_EDICT_TO_PROG(ent)); trace = SV_TraceBox(v1, m1, m2, v2, move, ent, SV_GenericHitSuperContentsMask(ent)); @@ -700,7 +698,7 @@ static trace_t SV_Trace_Toss(prvm_prog_t *prog, prvm_edict_t *tossent, prvm_edic { int i; float gravity; - vec3_t move, end; + vec3_t move, end, tossentorigin, tossentmins, tossentmaxs; vec3_t original_origin; vec3_t original_velocity; vec3_t original_angles; @@ -724,7 +722,10 @@ static trace_t SV_Trace_Toss(prvm_prog_t *prog, prvm_edict_t *tossent, prvm_edic VectorMA (PRVM_serveredictvector(tossent, angles), 0.05, PRVM_serveredictvector(tossent, avelocity), PRVM_serveredictvector(tossent, angles)); VectorScale (PRVM_serveredictvector(tossent, velocity), 0.05, move); VectorAdd (PRVM_serveredictvector(tossent, origin), move, end); - trace = SV_TraceBox(PRVM_serveredictvector(tossent, origin), PRVM_serveredictvector(tossent, mins), PRVM_serveredictvector(tossent, maxs), end, MOVE_NORMAL, tossent, SV_GenericHitSuperContentsMask(tossent)); + VectorCopy(PRVM_serveredictvector(tossent, origin), tossentorigin); + VectorCopy(PRVM_serveredictvector(tossent, mins), tossentmins); + VectorCopy(PRVM_serveredictvector(tossent, maxs), tossentmaxs); + trace = SV_TraceBox(tossentorigin, tossentmins, tossentmaxs, end, MOVE_NORMAL, tossent, SV_GenericHitSuperContentsMask(tossent)); VectorCopy (trace.endpos, PRVM_serveredictvector(tossent, origin)); PRVM_serveredictvector(tossent, velocity)[2] -= gravity; @@ -874,7 +875,7 @@ float checkpvs(vector viewpos, entity viewee) = #240; */ static void VM_SV_checkpvs(prvm_prog_t *prog) { - vec3_t viewpos; + vec3_t viewpos, absmin, absmax; prvm_edict_t *viewee; #if 1 unsigned char *pvs; @@ -908,7 +909,9 @@ static void VM_SV_checkpvs(prvm_prog_t *prog) PRVM_G_FLOAT(OFS_RETURN) = 2; return; } - PRVM_G_FLOAT(OFS_RETURN) = sv.worldmodel->brush.BoxTouchingPVS(sv.worldmodel, pvs, PRVM_serveredictvector(viewee, absmin), PRVM_serveredictvector(viewee, absmax)); + VectorCopy(PRVM_serveredictvector(viewee, absmin), absmin); + VectorCopy(PRVM_serveredictvector(viewee, absmax), absmax); + PRVM_G_FLOAT(OFS_RETURN) = sv.worldmodel->brush.BoxTouchingPVS(sv.worldmodel, pvs, absmin, absmax); #else // using fat PVS like FTEQW does (slow) if(!sv.worldmodel || !sv.worldmodel->brush.FatPVS || !sv.worldmodel->brush.BoxTouchingPVS) @@ -924,7 +927,9 @@ static void VM_SV_checkpvs(prvm_prog_t *prog) PRVM_G_FLOAT(OFS_RETURN) = 2; return; } - PRVM_G_FLOAT(OFS_RETURN) = sv.worldmodel->brush.BoxTouchingPVS(sv.worldmodel, fatpvs, PRVM_serveredictvector(viewee, absmin), PRVM_serveredictvector(viewee, absmax)); + VectorCopy(PRVM_serveredictvector(viewee, absmin), absmin); + VectorCopy(PRVM_serveredictvector(viewee, absmax), absmax); + PRVM_G_FLOAT(OFS_RETURN) = sv.worldmodel->brush.BoxTouchingPVS(sv.worldmodel, fatpvs, absmin, absmax); #endif } @@ -1119,7 +1124,7 @@ void() droptofloor static void VM_SV_droptofloor(prvm_prog_t *prog) { prvm_edict_t *ent; - vec3_t end; + vec3_t end, entorigin, entmins, entmaxs; trace_t trace; VM_SAFEPARMCOUNTRANGE(0, 2, VM_SV_droptofloor); // allow 2 parameters because the id1 defs.qc had an incorrect prototype @@ -1146,7 +1151,10 @@ static void VM_SV_droptofloor(prvm_prog_t *prog) if (sv_gameplayfix_unstickentities.integer) SV_UnstickEntity(ent); - trace = SV_TraceBox(PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); + VectorCopy(PRVM_serveredictvector(ent, origin), entorigin); + VectorCopy(PRVM_serveredictvector(ent, mins), entmins); + VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs); + trace = SV_TraceBox(entorigin, entmins, entmaxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent)); if (trace.startsolid && sv_gameplayfix_droptofloorstartsolid.integer) { vec3_t offset, org; @@ -1253,8 +1261,10 @@ VM_SV_pointcontents */ static void VM_SV_pointcontents(prvm_prog_t *prog) { + vec3_t point; VM_SAFEPARMCOUNT(1, VM_SV_pointcontents); - PRVM_G_FLOAT(OFS_RETURN) = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, SV_PointSuperContents(PRVM_G_VECTOR(OFS_PARM0))); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), point); + PRVM_G_FLOAT(OFS_RETURN) = Mod_Q1BSP_NativeContentsFromSuperContents(NULL, SV_PointSuperContents(point)); } /* @@ -1601,9 +1611,9 @@ getlight(vector) static void VM_SV_getlight(prvm_prog_t *prog) { vec3_t ambientcolor, diffusecolor, diffusenormal; - vec_t *p; + vec3_t p; VM_SAFEPARMCOUNT(1, VM_SV_getlight); - p = PRVM_G_VECTOR(OFS_PARM0); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), p); VectorClear(ambientcolor); VectorClear(diffusecolor); VectorClear(diffusenormal); @@ -1753,7 +1763,7 @@ static void VM_SV_copyentity(prvm_prog_t *prog) VM_Warning(prog, "copyentity: can not modify free entity\n"); return; } - memcpy(out->fields.vp, in->fields.vp, prog->entityfields * 4); + memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t)); SV_LinkEdict(out); } @@ -1810,6 +1820,7 @@ static void VM_SV_effect(prvm_prog_t *prog) { int i; const char *s; + vec3_t org; VM_SAFEPARMCOUNT(5, VM_SV_effect); s = PRVM_G_STRING(OFS_PARM1); if (!s[0]) @@ -1837,7 +1848,8 @@ static void VM_SV_effect(prvm_prog_t *prog) return; } - SV_StartEffect(PRVM_G_VECTOR(OFS_PARM0), i, (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4)); + VectorCopy(PRVM_G_VECTOR(OFS_PARM0), org); + SV_StartEffect(org, i, (int)PRVM_G_FLOAT(OFS_PARM2), (int)PRVM_G_FLOAT(OFS_PARM3), (int)PRVM_G_FLOAT(OFS_PARM4)); } static void VM_SV_te_blood(prvm_prog_t *prog) @@ -2581,7 +2593,7 @@ static void VM_SV_gettaginfo(prvm_prog_t *prog) int parentindex; const char *tagname; int returncode; - vec3_t fo, le, up, trans; + vec3_t forward, left, up, origin; const dp_model_t *model; VM_SAFEPARMCOUNT(2, VM_SV_gettaginfo); @@ -2590,21 +2602,24 @@ static void VM_SV_gettaginfo(prvm_prog_t *prog) tagindex = (int)PRVM_G_FLOAT(OFS_PARM1); returncode = SV_GetTagMatrix(prog, &tag_matrix, e, tagindex); - Matrix4x4_ToVectors(&tag_matrix, PRVM_serverglobalvector(v_forward), le, PRVM_serverglobalvector(v_up), PRVM_G_VECTOR(OFS_RETURN)); - VectorScale(le, -1, PRVM_serverglobalvector(v_right)); + Matrix4x4_ToVectors(&tag_matrix, forward, left, up, origin); + VectorCopy(forward, PRVM_serverglobalvector(v_forward)); + VectorNegate(left, PRVM_serverglobalvector(v_right)); + VectorCopy(up, PRVM_serverglobalvector(v_up)); + VectorCopy(origin, PRVM_G_VECTOR(OFS_RETURN)); model = SV_GetModelFromEdict(e); VM_GenerateFrameGroupBlend(prog, e->priv.server->framegroupblend, e); VM_FrameBlendFromFrameGroupBlend(e->priv.server->frameblend, e->priv.server->framegroupblend, model, sv.time); VM_UpdateEdictSkeleton(prog, e, model, e->priv.server->frameblend); SV_GetExtendedTagInfo(prog, e, tagindex, &parentindex, &tagname, &tag_localmatrix); - Matrix4x4_ToVectors(&tag_localmatrix, fo, le, up, trans); + Matrix4x4_ToVectors(&tag_localmatrix, forward, left, up, origin); PRVM_serverglobalfloat(gettaginfo_parent) = parentindex; PRVM_serverglobalstring(gettaginfo_name) = tagname ? PRVM_SetTempString(prog, tagname) : 0; - VectorCopy(trans, PRVM_serverglobalvector(gettaginfo_offset)); - VectorCopy(fo, PRVM_serverglobalvector(gettaginfo_forward)); - VectorScale(le, -1, PRVM_serverglobalvector(gettaginfo_right)); + VectorCopy(forward, PRVM_serverglobalvector(gettaginfo_forward)); + VectorNegate(left, PRVM_serverglobalvector(gettaginfo_right)); VectorCopy(up, PRVM_serverglobalvector(gettaginfo_up)); + VectorCopy(origin, PRVM_serverglobalvector(gettaginfo_offset)); switch(returncode) { @@ -2788,6 +2803,7 @@ static void VM_SV_particleeffectnum(prvm_prog_t *prog) // #336 void(entity ent, float effectnum, vector start, vector end) trailparticles (EXT_CSQC) static void VM_SV_trailparticles(prvm_prog_t *prog) { + vec3_t start, end; VM_SAFEPARMCOUNT(4, VM_SV_trailparticles); if ((int)PRVM_G_FLOAT(OFS_PARM0) < 0) @@ -2796,8 +2812,10 @@ static void VM_SV_trailparticles(prvm_prog_t *prog) MSG_WriteByte(&sv.datagram, svc_trailparticles); MSG_WriteShort(&sv.datagram, PRVM_G_EDICTNUM(OFS_PARM0)); MSG_WriteShort(&sv.datagram, (int)PRVM_G_FLOAT(OFS_PARM1)); - MSG_WriteVector(&sv.datagram, PRVM_G_VECTOR(OFS_PARM2), sv.protocol); - MSG_WriteVector(&sv.datagram, PRVM_G_VECTOR(OFS_PARM3), sv.protocol); + VectorCopy(PRVM_G_VECTOR(OFS_PARM2), start); + VectorCopy(PRVM_G_VECTOR(OFS_PARM3), end); + MSG_WriteVector(&sv.datagram, start, sv.protocol); + MSG_WriteVector(&sv.datagram, end, sv.protocol); SV_FlushBroadcastMessages(); } diff --git a/vid_sdl.c b/vid_sdl.c index 88c8e605..9484f6c2 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -574,7 +574,7 @@ void IN_Move( void ) scr_numtouchscreenareas = 0; if (vid_touchscreen.integer) { - vec3_t move, aim, click; + float move[3], aim[3], click[3]; static qboolean buttons[16]; static keydest_t oldkeydest; keydest_t keydest = (key_consoleactive & KEY_CONSOLEACTIVE_USER) ? key_console : key_dest; diff --git a/world.c b/world.c index 0becd8a8..ffa54d19 100644 --- a/world.c +++ b/world.c @@ -2107,7 +2107,6 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed) const int *ie; dBodyID body = (dBodyID)ed->priv.server->ode_body; dMass mass; - dReal test; const dReal *ovelocity, *ospinvelocity; void *dataID; dp_model_t *model; @@ -2142,6 +2141,7 @@ static void World_Physics_Frame_BodyFromEntity(world_t *world, prvm_edict_t *ed) vec_t radius; vec3_t scale; vec_t spinlimit; + vec_t test; qboolean gravity; qboolean geom_modified = false; edict_odefunc_t *func, *nextf; @@ -2726,17 +2726,17 @@ treatasbox: if (physics_ode_trick_fixnan.integer) { test = VectorLength2(origin) + VectorLength2(forward) + VectorLength2(left) + VectorLength2(up) + VectorLength2(velocity) + VectorLength2(spinvelocity); - if (IS_NAN(test)) + if (VEC_IS_NAN(test)) { modified = true; //Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .axis_forward = '%f %f %f' .axis_left = '%f %f %f' .axis_up = %f %f %f' .spinvelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], forward[0], forward[1], forward[2], left[0], left[1], left[2], up[0], up[1], up[2], spinvelocity[0], spinvelocity[1], spinvelocity[2]); if (physics_ode_trick_fixnan.integer >= 2) Con_Printf("Fixing NAN values on entity %i : .classname = \"%s\" .origin = '%f %f %f' .velocity = '%f %f %f' .angles = '%f %f %f' .avelocity = '%f %f %f'\n", PRVM_NUM_FOR_EDICT(ed), PRVM_GetString(prog, PRVM_gameedictstring(ed, classname)), origin[0], origin[1], origin[2], velocity[0], velocity[1], velocity[2], angles[0], angles[1], angles[2], avelocity[0], avelocity[1], avelocity[2]); test = VectorLength2(origin); - if (IS_NAN(test)) + if (VEC_IS_NAN(test)) VectorClear(origin); test = VectorLength2(forward) * VectorLength2(left) * VectorLength2(up); - if (IS_NAN(test)) + if (VEC_IS_NAN(test)) { VectorSet(angles, 0, 0, 0); VectorSet(forward, 1, 0, 0); @@ -2744,10 +2744,10 @@ treatasbox: VectorSet(up, 0, 0, 1); } test = VectorLength2(velocity); - if (IS_NAN(test)) + if (VEC_IS_NAN(test)) VectorClear(velocity); test = VectorLength2(spinvelocity); - if (IS_NAN(test)) + if (VEC_IS_NAN(test)) { VectorClear(avelocity); VectorClear(spinvelocity); -- 2.39.2