Fix bullet hole sometimes not playing

This commit is contained in:
smallmodel 2025-01-28 20:24:02 +01:00
parent 1fc36fce9b
commit 8341f8cb6a
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -85,7 +85,12 @@ void CG_MakeBulletHoleSound(const vec3_t i_vPos, const vec3_t i_vNorm, int iLarg
iSurfType = SURF_PUDDLE; iSurfType = SURF_PUDDLE;
} }
if (trace.fraction == 1.0f || trace.startsolid || (trace.surfaceFlags & SURF_SKY)) { if (trace.fraction == 1) {
// no reason to make a sound if it nothing was hit
return;
}
if ((trace.surfaceFlags & SURF_SKY) || !CG_CheckMakeMarkOnEntity(trace.entityNum)) {
return; return;
} }
@ -253,7 +258,12 @@ CG_MakeBulletHole(const vec3_t i_vPos, const vec3_t i_vNorm, int iLarge, trace_t
iSurfType = SURF_PUDDLE; iSurfType = SURF_PUDDLE;
} }
if (trace.fraction == 1.0f || trace.startsolid || (trace.surfaceFlags & SURF_SKY)) { if (trace.fraction == 1.0f || trace.startsolid) {
return;
}
if (trace.surfaceFlags & SURF_SKY) {
// ignore sky surfaces
return; return;
} }
@ -460,35 +470,36 @@ static void CG_MakeBulletTracerInternal(
float alpha float alpha
) )
{ {
vec3_t vPos; vec3_t vPos;
int iBullet; int iBullet;
int iContinueCount; int iContinueCount;
int iDist; int iDist;
int iHeadDist; int iHeadDist;
int iTravelDist; int iTravelDist;
float fLen, fDist; float fLen, fDist;
trace_t trace; trace_t trace;
qboolean bStartInWater, bInWater; qboolean bStartInWater, bInWater;
qboolean bBulletDone; qboolean bBulletDone;
qboolean bMadeTracer; qboolean bMadeTracer;
vec3_t vDir; vec3_t vDir;
vec3_t vTrailStart; vec3_t vTrailStart;
vec3_t vTraceStart; vec3_t vTraceStart;
vec3_t vTraceEnd; vec3_t vTraceEnd;
vec3_t vTmp; vec3_t vTmp;
int iNumImpacts; int iNumImpacts;
trace_t tImpacts[128]; trace_t tImpacts[128];
float fImpSndDistRA; float fImpSndDistRA;
static float fImpSndDistLA; float fImpSndDistLA;
float fImpSndDistRB; float fImpSndDistRB;
float fImpSndDistLB; float fImpSndDistLB;
int iImpSndIndexRA; int iImpSndIndexRA;
int iImpSndIndexRB; int iImpSndIndexLA;
int iImpSndIndexLB; int iImpSndIndexRB;
float fVolume; int iImpSndIndexLB;
float fPitch; float fVolume;
float fZingDistA, fZingDistB, fZingDistC; float fPitch;
vec3_t vZingPosA, vZingPosB, vZingPosC; float fZingDistA, fZingDistB, fZingDistC;
vec3_t vZingPosA, vZingPosB, vZingPosC;
fZingDistB = 9999.0; fZingDistB = 9999.0;
fZingDistA = 9999.0; fZingDistA = 9999.0;
@ -659,46 +670,46 @@ static void CG_MakeBulletTracerInternal(
if (iNumImpacts > 2) { if (iNumImpacts > 2) {
fImpSndDistRA = 9999.0f; fImpSndDistRA = 9999.0f;
fImpSndDistRB = 9999.0f; fImpSndDistRB = 9999.0f;
iImpSndIndexRA = 0; fImpSndDistLA = 9999.0f;
iImpSndIndexRB = 0;
fImpSndDistLB = 9999.0f; fImpSndDistLB = 9999.0f;
iImpSndIndexRA = 0;
iImpSndIndexLA = 0;
iImpSndIndexRB = 0;
iImpSndIndexLB = 0; iImpSndIndexLB = 0;
for (iBullet = 0; iBullet < iNumImpacts; iBullet++) { for (iBullet = 0; iBullet < iNumImpacts; iBullet++) {
CG_MakeBulletHole( CG_MakeBulletHole(
tImpacts[iImpSndIndexLB].endpos, tImpacts[iBullet].endpos, tImpacts[iBullet].plane.normal, iLarge, &tImpacts[iBullet], qfalse
tImpacts[iImpSndIndexLB].plane.normal,
iLarge,
&tImpacts[iImpSndIndexLB],
qfalse
); );
VectorSubtract(tImpacts[iImpSndIndexLB].endpos, cg.SoundOrg, vTmp); VectorSubtract(tImpacts[iBullet].endpos, cg.SoundOrg, vTmp);
iHeadDist = VectorLength(vTmp); iHeadDist = VectorLength(vTmp);
if (DotProduct(vTmp, cg.SoundAxis[1]) <= 0.f) { if (DotProduct(vTmp, cg.SoundAxis[1]) <= 0.f) {
if (iHeadDist < 9999.0f || iHeadDist < fImpSndDistLB) { if (iHeadDist < fImpSndDistLA || iHeadDist < fImpSndDistLB) {
if (iHeadDist < 9999.0f) { if (iHeadDist < fImpSndDistLA) {
fImpSndDistRA = iHeadDist; iImpSndIndexLB = iImpSndIndexLA;
fImpSndDistLB = 9999.0; fImpSndDistLB = fImpSndDistLA;
iImpSndIndexRA = iBullet; iImpSndIndexRA = iBullet;
fImpSndDistRA = iHeadDist;
} else if (iHeadDist < fImpSndDistLB) { } else if (iHeadDist < fImpSndDistLB) {
fImpSndDistLB = iHeadDist; iImpSndIndexLB = iBullet;
fImpSndDistLB = iHeadDist;
} }
} }
} else { } else {
if (iHeadDist < fImpSndDistRA || iHeadDist < fImpSndDistRB) { if (iHeadDist < fImpSndDistRA || iHeadDist < fImpSndDistRB) {
if (iHeadDist < fImpSndDistRA) { if (iHeadDist < fImpSndDistRA) {
iImpSndIndexRB = iImpSndIndexRA; iImpSndIndexRB = iImpSndIndexRA;
fImpSndDistRB = fImpSndDistRA;
iImpSndIndexRA = iBullet; iImpSndIndexRA = iBullet;
fImpSndDistRA = iHeadDist;
} else if (iHeadDist < fImpSndDistRB) { } else if (iHeadDist < fImpSndDistRB) {
fImpSndDistRB = iHeadDist;
iImpSndIndexRB = iBullet; iImpSndIndexRB = iBullet;
fImpSndDistRB = iHeadDist;
} }
} }
} }
iImpSndIndexLB++;
} }
if (fImpSndDistRA < 9999.0f) { if (fImpSndDistRA < 9999.0f) {
@ -718,6 +729,24 @@ static void CG_MakeBulletTracerInternal(
); );
} }
} }
if (fImpSndDistLA < 9999.0f) {
CG_MakeBulletHoleSound(
tImpacts[iImpSndIndexLA].endpos,
tImpacts[iImpSndIndexLA].plane.normal,
iLarge,
&tImpacts[iImpSndIndexLA]
);
if (fImpSndDistLB < 9999.0f) {
CG_MakeBulletHoleSound(
tImpacts[iImpSndIndexLB].endpos,
tImpacts[iImpSndIndexLB].plane.normal,
iLarge,
&tImpacts[iImpSndIndexLB]
);
}
}
} else { } else {
for (iBullet = 0; iBullet < iNumImpacts; iBullet++) { for (iBullet = 0; iBullet < iNumImpacts; iBullet++) {
CG_MakeBulletHole( CG_MakeBulletHole(