From 01653bfd42374b575c412535ef52f0109a4f837c Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Sun, 22 Oct 2023 23:38:07 -0700 Subject: [PATCH] Bobbing + Player animations working again --- src/shared/player.qc | 136 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 3 deletions(-) diff --git a/src/shared/player.qc b/src/shared/player.qc index 8684ced..75850fa 100644 --- a/src/shared/player.qc +++ b/src/shared/player.qc @@ -79,17 +79,147 @@ class player:NSClientPlayer PREDICTED_INT(ammo_medkit) PREDICTED_INT(mode_silencer) + virtual void UpdatePlayerAnimation(float); + #ifdef CLIENT - virtual void(float,float) ReceiveEntity; - virtual void(void) PredictPreFrame; - virtual void(void) PredictPostFrame; + virtual void UpdatePlayerAttachments(bool); + virtual void ReceiveEntity(float,float); + virtual void PredictPreFrame(void); + virtual void PredictPostFrame(void); + virtual void UpdateAliveCam(void); #else virtual void(void) EvaluateEntity; virtual float(entity, float) SendEntity; #endif }; + +void Animation_PlayerUpdate(player); +void Animation_TimerUpdate(player, float); + +void +player::UpdatePlayerAnimation(float timelength) +{ + /* calculate our skeletal progression */ + Animation_PlayerUpdate(this); + /* advance animation timers */ + Animation_TimerUpdate(this, timelength); +} + #ifdef CLIENT +void Camera_RunPosBob(vector angles, __inout vector camera_pos); +void Camera_StrafeRoll(__inout vector camera_angle); +void Shake_Update(NSClientPlayer); + +void +player::UpdateAliveCam(void) +{ + vector cam_pos = GetEyePos(); + Camera_RunPosBob(view_angles, cam_pos); + + g_view.SetCameraOrigin(cam_pos); + Camera_StrafeRoll(view_angles); + g_view.SetCameraAngle(view_angles); + + if (vehicle) { + NSVehicle veh = (NSVehicle)vehicle; + + if (veh.UpdateView) + veh.UpdateView(); + } else if (health) { + if (autocvar_pm_thirdPerson == TRUE) { + makevectors(view_angles); + vector vStart = [pSeat->m_vecPredictedOrigin[0], pSeat->m_vecPredictedOrigin[1], pSeat->m_vecPredictedOrigin[2] + 16] + (v_right * 4); + vector vEnd = vStart + (v_forward * -48) + [0,0,16] + (v_right * 4); + traceline(vStart, vEnd, FALSE, this); + g_view.SetCameraOrigin(trace_endpos + (v_forward * 5)); + } + } + + Shake_Update(this); + g_view.AddPunchAngle(punchangle); +} +.string oldmodel; +string Weapons_GetPlayermodel(player, int); + +void +player::UpdatePlayerAttachments(bool visible) +{ + /* draw the flashlight */ + if (gflags & GF_FLASHLIGHT) { + vector src; + vector ang; + + if (entnum != player_localentnum) { + src = origin + view_ofs; + ang = v_angle; + } else { + src = pSeat->m_vecPredictedOrigin + view_ofs; + ang = view_angles; + } + + makevectors(ang); + traceline(src, src + (v_forward * 8096), MOVE_NORMAL, this); + + if (serverkeyfloat("*bspversion") == BSPVER_HL) { + dynamiclight_add(trace_endpos + (trace_plane_normal * 4), 128, [1,1,1]); + } else { + float p = dynamiclight_add(src, 512, [1,1,1], 0, "textures/flashlight"); + dynamiclight_set(p, LFIELD_ANGLES, ang); + dynamiclight_set(p, LFIELD_FLAGS, 3); + } + } + + /* FIXME: this needs to be incorporated and simplified, now that we can handle it all in-class */ + if (!visible) + return; + + /* what's the current weapon model supposed to be anyway? */ + p_model.oldmodel = Weapons_GetPlayermodel(this, activeweapon); + + /* we changed weapons, update skeletonindex */ + if (p_model.model != p_model.oldmodel) { + /* free memory */ + if (p_model.skeletonindex) + skel_delete(p_model.skeletonindex); + + /* set the new model and mark us updated */ + setmodel(p_model, p_model.oldmodel); + p_model.model = p_model.oldmodel; + + /* set the new skeletonindex */ + p_model.skeletonindex = skel_create(p_model.modelindex); + + /* hack this thing in here FIXME: this should be done when popping in/out of a pvs */ + if (autocvar(cl_himodels, 1, "Use high-quality thisayer models over lower-definition ones")) + setcustomskin(this, "", "geomset 0 2\n"); + else + setcustomskin(this, "", "geomset 0 1\n"); + } + + /* follow thisayer at all times */ + setorigin(p_model, origin); + p_model.angles = angles; + skel_build(p_model.skeletonindex, p_model, p_model.modelindex,0, 0, -1); + + /* we have to loop through all valid bones of the weapon model and match them + * to the thisayer one */ + for (float i = 0; i < g_pbones.length; i++) { + vector bpos; + float pbone = gettagindex(this, g_pbones[i]); + float wbone = gettagindex(p_model, g_pbones[i]); + + /* if the bone doesn't ignore in either skeletal mesh, ignore */ + if (wbone <= 0 || pbone <= 0) + continue; + + bpos = gettaginfo(this, pbone); + + /* the most expensive bit */ + skel_set_bone_world(p_model, wbone, bpos, v_forward, v_right, v_up); + } +} + void Weapons_AmmoUpdate(entity); void HUD_AmmoNotify_Check(player pl); void HUD_ItemNotify_Check(player pl);