From 2d764178070472d7b74de7f07871204c33b37f1f Mon Sep 17 00:00:00 2001 From: Shpoike Date: Mon, 24 Jul 2023 08:08:14 +0100 Subject: [PATCH] Rework how the viewmodel is added to the scene. No more phantom viewmodels with csqc, please. --- Quake/cl_main.c | 16 +++++++++++ Quake/gl_rmain.c | 32 ++------------------- Quake/gl_sky.c | 2 +- Quake/pr_ext.c | 9 ++++-- Quake/r_alias.c | 13 +++++---- Quake/view.c | 75 ++++++------------------------------------------ 6 files changed, 41 insertions(+), 106 deletions(-) diff --git a/Quake/cl_main.c b/Quake/cl_main.c index 0c003f13..f4b627eb 100644 --- a/Quake/cl_main.c +++ b/Quake/cl_main.c @@ -848,6 +848,22 @@ void CL_RelinkEntities (void) cl_numvisedicts++; } } + + + // viewmodel. last, for transparency reasons. + ent = &cl.viewent; + if (r_drawviewmodel.value + && !chase_active.value + && cl.stats[STAT_HEALTH] > 0 + && !(cl.items & IT_INVISIBILITY) + && ent->model) + { + if (cl_numvisedicts < cl_maxvisedicts) + { + cl_visedicts[cl_numvisedicts] = ent; + cl_numvisedicts++; + } + } } #ifdef PSET_SCRIPT diff --git a/Quake/gl_rmain.c b/Quake/gl_rmain.c index c3891568..bd5ae112 100644 --- a/Quake/gl_rmain.c +++ b/Quake/gl_rmain.c @@ -688,6 +688,8 @@ void R_DrawEntitiesOnList (qboolean alphapass) //johnfitz -- added parameter //spike -- this would be more efficient elsewhere, but its more correct here. if (currententity->eflags & EFLAGS_EXTERIORMODEL) continue; + if (!currententity->model || currententity->model->needload) + continue; switch (currententity->model->type) { @@ -707,34 +709,6 @@ void R_DrawEntitiesOnList (qboolean alphapass) //johnfitz -- added parameter } } -/* -============= -R_DrawViewModel -- johnfitz -- gutted -============= -*/ -void R_DrawViewModel (void) -{ - if (!r_drawviewmodel.value || !r_drawentities.value || chase_active.value || skyroom_drawing/*silly depthrange*/) - return; - - if (cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0) - return; - - currententity = &cl.viewent; - if (!currententity->model) - return; - - //johnfitz -- this fixes a crash - if (currententity->model->type != mod_alias) - return; - //johnfitz - - // hack the depth range to prevent view model from poking into walls - glDepthRange (0, 0.3); - R_DrawAliasModel (currententity); - glDepthRange (0, 1); -} - /* ================ R_EmitWirePoint -- johnfitz -- draws a wireframe cross shape for point entities @@ -1007,8 +981,6 @@ void R_RenderScene (void) Fog_DisableGFog (); //johnfitz - R_DrawViewModel (); //johnfitz -- moved here from R_RenderView - R_ShowTris (); //johnfitz R_ShowBoundingBoxes (); //johnfitz diff --git a/Quake/gl_sky.c b/Quake/gl_sky.c index 77c55aeb..12737163 100644 --- a/Quake/gl_sky.c +++ b/Quake/gl_sky.c @@ -734,7 +734,7 @@ void Sky_ProcessEntities (void) { e = cl_visedicts[i]; - if (e->model->type != mod_brush) + if (!e->model || e->model->needload || e->model->type != mod_brush) continue; if (R_CullModelForEntity(e)) diff --git a/Quake/pr_ext.c b/Quake/pr_ext.c index 00260e15..40b1a506 100644 --- a/Quake/pr_ext.c +++ b/Quake/pr_ext.c @@ -6714,10 +6714,13 @@ static void PF_cs_addentities(void) if (mask & MASK_VIEWMODEL) { - //default viewmodel. + //default viewmodel. add it into the scene. + if (cl.viewent.model) + { //make sure its relevant + cl_visedicts[cl_numvisedicts] = &cl.viewent; + cl_numvisedicts++; + } } - - } static void PF_cs_addlight(void) { diff --git a/Quake/r_alias.c b/Quake/r_alias.c index b5749659..a7c31dcd 100644 --- a/Quake/r_alias.c +++ b/Quake/r_alias.c @@ -1038,7 +1038,7 @@ void R_SetupAliasLighting (entity_t *e) } // minimum light value on gun (24) - if (e == &cl.viewent) + if (e->eflags & EFLAGS_VIEWMODEL) { add = 72.0f - (lightcolor[0] + lightcolor[1] + lightcolor[2]); if (add > 0.0f) @@ -1125,6 +1125,9 @@ void R_DrawAliasModel (entity_t *e) if (e->eflags & EFLAGS_VIEWMODEL) { + if (skyroom_drawing) + return; //no viewmodels inside skyrooms! + //transform it relative to the view, by rebuilding the modelview matrix without the view position. glPushMatrix (); glLoadIdentity(); @@ -1132,6 +1135,10 @@ void R_DrawAliasModel (entity_t *e) glRotatef (90, 0, 0, 1); // put Z going up glDepthRange (0, 0.3); + + //FIXME: this needs to go. combine with depthrange and explicit viewmodel-only fov into a different projection matrix.. + if (scr_fov.value > 90.f && cl_gun_fovscale.value) + fovscale = tan(scr_fov.value * (0.5f * M_PI / 180.f)); } else { @@ -1147,10 +1154,6 @@ void R_DrawAliasModel (entity_t *e) glPushMatrix (); } - //FIXME: this needs to go. combine with depthrange and explicit viewmodel-only fov into a different projection matrix.. - if (e == &cl.viewent && scr_fov.value > 90.f && cl_gun_fovscale.value) - fovscale = tan(scr_fov.value * (0.5f * M_PI / 180.f)); - R_RotateForEntity (lerpdata.origin, lerpdata.angles, e->netstate.scale); glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1] * fovscale, paliashdr->scale_origin[2] * fovscale); glScalef (paliashdr->scale[0], paliashdr->scale[1] * fovscale, paliashdr->scale[2] * fovscale); diff --git a/Quake/view.c b/Quake/view.c index e806e570..9ce231ce 100644 --- a/Quake/view.c +++ b/Quake/view.c @@ -606,14 +606,6 @@ void V_PolyBlend (void) ============================================================================== */ -float angledelta (float a) -{ - a = anglemod(a); - if (a > 180) - a -= 360; - return a; -} - /* ================== CalcGunAngle @@ -621,55 +613,9 @@ CalcGunAngle */ void CalcGunAngle (void) { - float yaw, pitch, move; - static float oldyaw = 0; - static float oldpitch = 0; - - yaw = r_refdef.viewangles[YAW]; - pitch = -r_refdef.viewangles[PITCH]; - - yaw = angledelta(yaw - r_refdef.viewangles[YAW]) * 0.4; - if (yaw > 10) - yaw = 10; - if (yaw < -10) - yaw = -10; - pitch = angledelta(-pitch - r_refdef.viewangles[PITCH]) * 0.4; - if (pitch > 10) - pitch = 10; - if (pitch < -10) - pitch = -10; - move = host_frametime*20; - if (yaw > oldyaw) - { - if (oldyaw + move < yaw) - yaw = oldyaw + move; - } - else - { - if (oldyaw - move > yaw) - yaw = oldyaw - move; - } - - if (pitch > oldpitch) - { - if (oldpitch + move < pitch) - pitch = oldpitch + move; - } - else - { - if (oldpitch - move > pitch) - pitch = oldpitch - move; - } - - oldyaw = yaw; - oldpitch = pitch; - - cl.viewent.angles[YAW] = r_refdef.viewangles[YAW] + yaw; - cl.viewent.angles[PITCH] = - (r_refdef.viewangles[PITCH] + pitch); - - cl.viewent.angles[ROLL] -= v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value; - cl.viewent.angles[PITCH] -= v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value; - cl.viewent.angles[YAW] -= v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value; + cl.viewent.angles[ROLL] = -v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value - r_refdef.viewangles[ROLL]; + cl.viewent.angles[PITCH] = -v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value; + cl.viewent.angles[YAW] = -v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value; } /* @@ -829,17 +775,13 @@ void V_CalcRefdef (void) V_BoundOffsets (); -// set up gun position - VectorCopy (cl.viewangles, view->angles); - +// set up gun stuff CalcGunAngle (); - VectorCopy (ent->origin, view->origin); - view->origin[2] += cl.stats[STAT_VIEWHEIGHT]; - - for (i=0 ; i<3 ; i++) - view->origin[i] += forward[i]*bob*0.4; - view->origin[2] += bob; + view->eflags = EFLAGS_VIEWMODEL; + VectorScale(forward, 1.0/32, view->origin); //bias it very slightly sideways (so it shifts slightly when turning to mimic the 1/32 bias that used to affect it before we changed how viewmodels work) + view->origin[0] = bob*0.4; //and bob it forwards + view->alpha = ENTALPHA_ENCODE(r_drawviewmodel.value); //johnfitz -- removed all gun position fudging code (was used to keep gun from getting covered by sbar) //MarkV -- restored this with r_viewmodel_quake cvar @@ -900,7 +842,6 @@ void V_CalcRefdef (void) if (ent->origin[2] - oldz > 12) oldz = ent->origin[2] - 12; r_refdef.vieworg[2] += oldz - ent->origin[2]; - view->origin[2] += oldz - ent->origin[2]; } else oldz = ent->origin[2];