Skip to content

Commit

Permalink
Fix #205
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Oct 21, 2022
1 parent 60ee22e commit 04da87b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
28 changes: 20 additions & 8 deletions Plugins/BulletPhysics/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,10 +1245,12 @@ void V_CalcRefdef(struct ref_params_s *pparams)
if (local && local->player && bv_syncview->value)
{
auto spectating_player = local;
auto aiming_player = local;

if (g_iUser1 && g_iUser2 && (*g_iUser1))
{
spectating_player = gEngfuncs.GetEntityByIndex(*g_iUser2);
spectating_player = gEngfuncs.GetEntityByIndex((*g_iUser2));
aiming_player = gEngfuncs.GetEntityByIndex((*g_iUser1));
}

if (!CL_IsFirstPersonMode(spectating_player))
Expand All @@ -1258,16 +1260,29 @@ void V_CalcRefdef(struct ref_params_s *pparams)
if (ragdoll && ragdoll->m_iActivityType != 0)
{
vec3_t save_simorg;
vec3_t save_origin;
vec3_t save_origin_spec;
vec3_t save_origin_aiming;

VectorCopy(pparams->simorg, save_simorg);
VectorCopy(spectating_player->origin, save_origin);
VectorCopy(spectating_player->origin, save_origin_spec);
VectorCopy(aiming_player->origin, save_origin_aiming);

gPhysicsManager.SyncThirdPersonView(ragdoll, spectating_player, pparams);
gPhysicsManager.GetRagdollOrigin(ragdoll, spectating_player->origin);
VectorCopy(spectating_player->origin, pparams->simorg);

if (spectating_player != aiming_player)
{
auto ragdoll_aiming = gPhysicsManager.FindRagdoll(aiming_player->index);
if (ragdoll_aiming)
{
gPhysicsManager.GetRagdollOrigin(ragdoll_aiming, aiming_player->origin);
}
}

gExportfuncs.V_CalcRefdef(pparams);

VectorCopy(save_origin, spectating_player->origin);
VectorCopy(save_origin_aiming, aiming_player->origin);
VectorCopy(save_origin_spec, spectating_player->origin);
VectorCopy(save_simorg, pparams->simorg);

return;
Expand All @@ -1288,17 +1303,14 @@ void V_CalcRefdef(struct ref_params_s *pparams)
vec3_t save_simorg;
vec3_t save_cl_viewangles;
int save_health = pparams->health;
//vec3_t save_origin;

VectorCopy(pparams->simorg, save_simorg);
VectorCopy(pparams->cl_viewangles, save_cl_viewangles);
//VectorCopy(spectating_player->origin, save_origin);

gPhysicsManager.SyncFirstPersonView(ragdoll, spectating_player, pparams);

gExportfuncs.V_CalcRefdef(pparams);

//VectorCopy(save_origin, spectating_player->origin);
VectorCopy(save_simorg, pparams->simorg);
VectorCopy(save_cl_viewangles, pparams->cl_viewangles);
pparams->health = save_health;
Expand Down
10 changes: 4 additions & 6 deletions Plugins/BulletPhysics/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,8 @@ void CPhysicsManager::ReleaseRagdollFromBarnacle(CRagdollBody *ragdoll)
ragdoll->m_barnacleDragRigBody.clear();
}
}

bool CPhysicsManager::SyncThirdPersonView(CRagdollBody *ragdoll, cl_entity_t *ent, struct ref_params_s *pparams)
#if 0
bool CPhysicsManager::SyncThirdPersonView(CRagdollBody *ragdoll, float *org)
{
if (ragdoll->m_pelvisRigBody)
{
Expand All @@ -1082,15 +1082,14 @@ bool CPhysicsManager::SyncThirdPersonView(CRagdollBody *ragdoll, cl_entity_t *en

Vec3BulletToGoldSrc(origin);

VectorCopy(origin, pparams->simorg);
VectorCopy(origin, ent->origin);
VectorCopy(origin, org);

return true;
}

return false;
}

#endif
bool CPhysicsManager::SyncFirstPersonView(CRagdollBody *ragdoll, cl_entity_t *ent, struct ref_params_s *pparams)
{
if (ragdoll->m_headRigBody)
Expand Down Expand Up @@ -1122,7 +1121,6 @@ bool CPhysicsManager::SyncFirstPersonView(CRagdollBody *ragdoll, cl_entity_t *en

pparams->viewheight[2] = 0;
VectorCopy(origin, pparams->simorg);
//VectorCopy(origin, ent->origin);
VectorCopy(angles, pparams->cl_viewangles);

pparams->health = 0;
Expand Down
2 changes: 1 addition & 1 deletion Plugins/BulletPhysics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class CPhysicsManager
bool UpdateRagdoll(cl_entity_t *ent, CRagdollBody *ragdoll, double frame_time, double client_time);
void UpdateRagdollWaterSimulation(cl_entity_t *ent, CRagdollBody *ragdoll, double frame_time, double client_time);
void UpdateTempEntity(TEMPENTITY **ppTempEntActive, double frame_time, double client_time);
bool SyncThirdPersonView(CRagdollBody *ragdoll, cl_entity_t *ent, struct ref_params_s *pparams);
//bool SyncThirdPersonView(CRagdollBody *ragdoll, float *org);
bool SyncFirstPersonView(CRagdollBody *ragdoll, cl_entity_t *ent, struct ref_params_s *pparams);
private:
ragdoll_itor FreeRagdollInternal(ragdoll_itor &itor);
Expand Down

0 comments on commit 04da87b

Please sign in to comment.