From 54c646420e72cdcf8a39e40d6d6845a5069abaae Mon Sep 17 00:00:00 2001 From: Shpoike Date: Tue, 2 Aug 2022 01:39:04 +0100 Subject: [PATCH] Fix csqc's addentities ignoring scale+colormod, fix culling of scaled entities. --- Quake/gl_rmain.c | 13 +++++++------ Quake/mathlib.c | 8 -------- Quake/mathlib.h | 9 ++++----- Quake/pr_ext.c | 10 ++++++++++ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Quake/gl_rmain.c b/Quake/gl_rmain.c index 4facfa94..bbbfc6cd 100644 --- a/Quake/gl_rmain.c +++ b/Quake/gl_rmain.c @@ -303,21 +303,22 @@ R_CullModelForEntity -- johnfitz -- uses correct bounds based on rotation qboolean R_CullModelForEntity (entity_t *e) { vec3_t mins, maxs; + float scale = e->netstate.scale/16.0; if (e->angles[0] || e->angles[2]) //pitch or roll { - VectorAdd (e->origin, e->model->rmins, mins); - VectorAdd (e->origin, e->model->rmaxs, maxs); + VectorMA (e->origin, scale, e->model->rmins, mins); + VectorMA (e->origin, scale, e->model->rmaxs, maxs); } else if (e->angles[1]) //yaw { - VectorAdd (e->origin, e->model->ymins, mins); - VectorAdd (e->origin, e->model->ymaxs, maxs); + VectorMA (e->origin, scale, e->model->ymins, mins); + VectorMA (e->origin, scale, e->model->ymaxs, maxs); } else //no rotation { - VectorAdd (e->origin, e->model->mins, mins); - VectorAdd (e->origin, e->model->maxs, maxs); + VectorMA (e->origin, scale, e->model->mins, mins); + VectorMA (e->origin, scale, e->model->maxs, maxs); } return R_CullBox (mins, maxs); diff --git a/Quake/mathlib.c b/Quake/mathlib.c index 86854c7b..8d74c934 100644 --- a/Quake/mathlib.c +++ b/Quake/mathlib.c @@ -342,14 +342,6 @@ int VectorCompare (const vec3_t v1, const vec3_t v2) return 1; } -void VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc) -{ - vecc[0] = veca[0] + scale*vecb[0]; - vecc[1] = veca[1] + scale*vecb[1]; - vecc[2] = veca[2] + scale*vecb[2]; -} - - vec_t _DotProduct (const vec3_t v1, const vec3_t v2) { return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]; diff --git a/Quake/mathlib.h b/Quake/mathlib.h index b8e818cf..a5238d75 100644 --- a/Quake/mathlib.h +++ b/Quake/mathlib.h @@ -55,9 +55,10 @@ static inline int IS_NAN (float x) { #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) #define DotProduct2(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]) #define DoublePrecisionDotProduct(x,y) ((double)(x)[0]*(y)[0]+(double)(x)[1]*(y)[1]+(double)(x)[2]*(y)[2]) -#define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];} -#define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];} -#define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];} +#define VectorSubtract(a,b,c) do{(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];}while(0) +#define VectorAdd(a,b,c) do{(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];}while(0) +#define VectorMA(a,s,b,c) do{(c)[0]=(a)[0]+(s)*(b)[0];(c)[1]=(a)[1]+(s)*(b)[1];(c)[2]=(a)[2]+(s)*(b)[2];}while(0) +#define VectorCopy(a,b) do{(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];}while(0) //johnfitz -- courtesy of lordhavoc // QuakeSpasm: To avoid strict aliasing violations, use a float/int union instead of type punning. @@ -76,8 +77,6 @@ static inline int IS_NAN (float x) { void TurnVector (vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz void VectorAngles (const vec3_t forward, float *up, vec3_t angles); //johnfitz, spike(up is optional) -void VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc); - vec_t _DotProduct (const vec3_t v1, const vec3_t v2); void _VectorSubtract (const vec3_t veca, const vec3_t vecb, vec3_t out); void _VectorAdd (const vec3_t veca, const vec3_t vecb, vec3_t out); diff --git a/Quake/pr_ext.c b/Quake/pr_ext.c index c94d6fb9..982f71cf 100644 --- a/Quake/pr_ext.c +++ b/Quake/pr_ext.c @@ -6067,7 +6067,9 @@ static void PR_addentity_internal(edict_t *ed) //adds a csqc entity into the sce eval_t *lerpfrac = GetEdictFieldValue(ed, qcvm->extfields.lerpfrac); eval_t *frame1time = GetEdictFieldValue(ed, qcvm->extfields.frame1time); eval_t *frame2time = GetEdictFieldValue(ed, qcvm->extfields.frame2time); + eval_t *colormod = GetEdictFieldValue(ed, qcvm->extfields.colormod); eval_t *alpha = GetEdictFieldValue(ed, qcvm->extfields.alpha); + eval_t *scale = GetEdictFieldValue(ed, qcvm->extfields.scale); eval_t *renderflags = GetEdictFieldValue(ed, qcvm->extfields.renderflags); int rf = renderflags?renderflags->_float:0; @@ -6075,7 +6077,15 @@ static void PR_addentity_internal(edict_t *ed) //adds a csqc entity into the sce VectorCopy(ed->v.angles, e->angles); e->model = model; e->skinnum = ed->v.skin; + if (colormod && (colormod->vector[0]||colormod->vector[1]||colormod->vector[2])) + { + e->netstate.colormod[0] *= colormod->vector[0]; + e->netstate.colormod[1] *= colormod->vector[1]; + e->netstate.colormod[2] *= colormod->vector[2]; + } e->alpha = alpha?ENTALPHA_ENCODE(alpha->_float):ENTALPHA_DEFAULT; + if (scale && scale->_float) + e->netstate.scale *= scale->_float; //can't exactly use currentpose/previous pose, as we don't know them. e->lerpflags = LERP_EXPLICIT|LERP_RESETANIM|LERP_RESETMOVE;