Skip to content

Commit

Permalink
Fix a typo in R_StudioDrawPlayer hook handler which was causing crash…
Browse files Browse the repository at this point in the history
… in Opposing Force. #224
  • Loading branch information
hzqst committed Jan 10, 2023
1 parent b9a07a3 commit 03c1690
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 75 deletions.
4 changes: 2 additions & 2 deletions Plugins/BulletPhysics/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ int __fastcall GameStudioRenderer_StudioDrawModel(void *pthis, int dummy, int fl

//EngineDrawPlayer

int __fastcall R_StudioDrawPlayer(int flags, struct entity_state_s *pplayer)
int R_StudioDrawPlayer(int flags, struct entity_state_s *pplayer)
{
int playerindex = pplayer->number;

Expand Down Expand Up @@ -1137,7 +1137,7 @@ void HUD_Init(void)

bv_debug = gEngfuncs.pfnRegisterVariable("bv_debug", "0", FCVAR_CLIENTDLL);
bv_simrate = gEngfuncs.pfnRegisterVariable("bv_simrate", "64", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
bv_scale = gEngfuncs.pfnRegisterVariable("bv_scale", "0.5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
bv_scale = gEngfuncs.pfnRegisterVariable("bv_scale", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
bv_enable = gEngfuncs.pfnRegisterVariable("bv_enable", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);
bv_syncview = gEngfuncs.pfnRegisterVariable("bv_syncview", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE);

Expand Down
1 change: 0 additions & 1 deletion Plugins/BulletPhysics/mathlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ void Matrix4x4_Transpose(float out[4][4], float in1[4][4])
out[3][3] = in1[3][3];
}


void Matrix4x4_CreateFromEntity(float out[4][4], const vec3_t angles, const vec3_t origin, float scale)
{
float angle, sr, sp, sy, cr, cp, cy;
Expand Down
80 changes: 11 additions & 69 deletions Plugins/BulletPhysics/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,56 +431,6 @@ CStaticBody *CPhysicsManager::CreateStaticBody(cl_entity_t *ent, vertexarray_t *
return staticbody;
}

void CPhysicsManager::RotateForEntity(cl_entity_t *e, float matrix[4][4])
{
int i;
vec3_t angles;
vec3_t modelpos;

VectorCopy(e->origin, modelpos);
VectorCopy(e->angles, angles);

if (e->curstate.movetype != MOVETYPE_NONE)
{
float f;
float d;

if (e->curstate.animtime + 0.2f > gEngfuncs.GetClientTime() && e->curstate.animtime != e->latched.prevanimtime)
{
f = (gEngfuncs.GetClientTime() - e->curstate.animtime) / (e->curstate.animtime - e->latched.prevanimtime);
}
else
{
f = 0;
}

for (i = 0; i < 3; i++)
{
modelpos[i] -= (e->latched.prevorigin[i] - e->origin[i]) * f;
}

if (f != 0.0f && f < 1.5f)
{
f = 1.0f - f;

for (i = 0; i < 3; i++)
{
d = e->latched.prevangles[i] - e->angles[i];

if (d > 180.0)
d -= 360.0;
else if (d < -180.0)
d += 360.0;

angles[i] += d * f;
}
}
}

memcpy(matrix, r_identity_matrix, sizeof(r_identity_matrix));
Matrix4x4_CreateFromEntity(matrix, angles, modelpos, 1);
}

void CPhysicsManager::CreateBarnacle(cl_entity_t *ent)
{
auto itor = m_staticMap.find(ent->index);
Expand Down Expand Up @@ -2263,11 +2213,11 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con
shape->calculateLocalInertia(mass, localInertia);

btRigidBody::btRigidBodyConstructionInfo cInfo(mass, motionState, shape, localInertia);
cInfo.m_friction = 0.5f;
cInfo.m_friction = 1.0f;
cInfo.m_rollingFriction = 1.0;
cInfo.m_restitution = 0;
cInfo.m_linearSleepingThreshold = 50.0f;
cInfo.m_angularSleepingThreshold = 12.0f;
cInfo.m_linearSleepingThreshold = 10.0f;
cInfo.m_angularSleepingThreshold = 4.5f;
cInfo.m_linearDamping = 0.25f;
cInfo.m_angularDamping = 0.25f;
FloatGoldSrcToBullet(&cInfo.m_linearSleepingThreshold);
Expand All @@ -2282,8 +2232,8 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con

rig->rigbody->setUserPointer(rig);

float ccdThreshould = 50.0f;
float ccdRadius = rigsize;
float ccdThreshould = 1.0f;
float ccdRadius = rigsize * 0.5;

FloatGoldSrcToBullet(&ccdThreshould);

Expand Down Expand Up @@ -2319,13 +2269,14 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con
shape->calculateLocalInertia(mass, localInertia);

btRigidBody::btRigidBodyConstructionInfo cInfo(mass, motionState, shape, localInertia);
cInfo.m_friction = 0.5f;
cInfo.m_friction = 1.0f;
cInfo.m_rollingFriction = 1.0f;
cInfo.m_restitution = 0;
cInfo.m_linearSleepingThreshold = 50.0f;
cInfo.m_angularSleepingThreshold = 12.0f;
cInfo.m_linearSleepingThreshold = 10.0f;
cInfo.m_angularSleepingThreshold = 3 * SIMD_RADS_PER_DEG;
cInfo.m_linearDamping = 0.25f;
cInfo.m_angularDamping = 0.25f;
cInfo.m_additionalDamping = true;

FloatGoldSrcToBullet(&cInfo.m_linearSleepingThreshold);

Expand All @@ -2339,8 +2290,8 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con

rig->rigbody->setUserPointer(rig);

float ccdThreshould = 50.0f;
float ccdRadius = max(rigsize, rigsize2);
float ccdThreshould = 1.0f;
float ccdRadius = max(rigsize, rigsize2) * 0.5;

FloatGoldSrcToBullet(&ccdThreshould);

Expand Down Expand Up @@ -2395,15 +2346,6 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con

rig->rigbody->setUserPointer(rig);

float ccdThreshould = 2.5;
float ccdRadius = 1.25;

FloatGoldSrcToBullet(&ccdThreshould);
FloatGoldSrcToBullet(&ccdRadius);

rig->rigbody->setCcdMotionThreshold(ccdThreshould);
rig->rigbody->setCcdSweptSphereRadius(ccdRadius);

m_dynamicsWorld->addRigidBody(rig->rigbody, rig->group, rig->mask);

return rig;
Expand Down
1 change: 0 additions & 1 deletion Plugins/BulletPhysics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ class CPhysicsManager
void CreateBrushModel(cl_entity_t *ent);
void CreateBarnacle(cl_entity_t *ent);
void CreateGargantua(cl_entity_t *ent);
void RotateForEntity(cl_entity_t *ent, float matrix[4][4]);
void ReleaseRagdollFromBarnacle(CRagdollBody *ragdoll);
void ReleaseRagdollFromGargantua(CRagdollBody *ragdoll);
bool GetRagdollOrigin(CRagdollBody *ragdoll, float *origin);
Expand Down
2 changes: 0 additions & 2 deletions Plugins/BulletPhysics/privatehook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ void Client_FillAddress(void)
g_iUser2 = (decltype(g_iUser2))ctx.Candidates[ctx.iNumCandidates - 1];
}
}


}

void R_NewMap(void)
Expand Down

0 comments on commit 03c1690

Please sign in to comment.