From dfaa59bfa86481e7ecc3e85da814ddeab0a24b9c Mon Sep 17 00:00:00 2001 From: WofWca Date: Mon, 10 Nov 2025 13:54:51 +0400 Subject: [PATCH 1/2] improvement: allow multiple bounce marks (gibs) It's more "physically accurate" to decide whether to leave a mark based on velocity. This allows gibs to leave multiple marks, should they keep high velocity after the first impact. --- code/cgame/cg_cvar.h | 2 ++ code/cgame/cg_localents.c | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/code/cgame/cg_cvar.h b/code/cgame/cg_cvar.h index 46811af9..0d82e292 100644 --- a/code/cgame/cg_cvar.h +++ b/code/cgame/cg_cvar.h @@ -39,6 +39,8 @@ CG_CVAR( cg_crosshairY, "cg_crosshairY", "0", CVAR_ARCHIVE ) CG_CVAR( cg_brassTime, "cg_brassTime", "2500", CVAR_ARCHIVE ) CG_CVAR( cg_simpleItems, "cg_simpleItems", "0", CVAR_ARCHIVE ) CG_CVAR( cg_addMarks, "cg_marks", "1", CVAR_ARCHIVE ) +// Note that ~290 corresponds to a free fall with no bounce from player height. +CG_CVAR( cg_bounceMarksMinImpactSpeed, "cg_bounceMarksMinImpactSpeed", "350", CVAR_ARCHIVE ) CG_CVAR( cg_lagometer, "cg_lagometer", "1", CVAR_ARCHIVE ) CG_CVAR( cg_railTrailTime, "cg_railTrailTime", "400", CVAR_ARCHIVE ) CG_CVAR( cg_railTrailRadius, "cg_railTrailRadius", "0", CVAR_ARCHIVE ) diff --git a/code/cgame/cg_localents.c b/code/cgame/cg_localents.c index 45535ab7..77e4e79c 100644 --- a/code/cgame/cg_localents.c +++ b/code/cgame/cg_localents.c @@ -149,9 +149,11 @@ void CG_FragmentBounceMark( localEntity_t *le, trace_t *trace ) { } - // don't allow a fragment to make multiple marks, or they - // pile up while settling - le->leMarkType = LEMT_NONE; + // This is no longer needed, because we now decide whether to leave a mark + // purely based on impact velocity. + // // don't allow a fragment to make multiple marks, or they + // // pile up while settling + // le->leMarkType = LEMT_NONE; } /* @@ -188,9 +190,11 @@ void CG_FragmentBounceSound( localEntity_t *le, trace_t *trace ) { /* ================ CG_ReflectVelocity + +Modifies velocity of `le` and writes the difference to `velocityDifference` ================ */ -void CG_ReflectVelocity( localEntity_t *le, trace_t *trace ) { +void CG_ReflectVelocity( localEntity_t *le, trace_t *trace, vec3_t velocityDifference ) { vec3_t velocity; float dot; int hitTime; @@ -203,6 +207,10 @@ void CG_ReflectVelocity( localEntity_t *le, trace_t *trace ) { VectorScale( le->pos.trDelta, le->bounceFactor, le->pos.trDelta ); + if (velocityDifference) { + VectorSubtract( le->pos.trDelta, velocity, velocityDifference ); + } + VectorCopy( trace->endpos, le->pos.trBase ); le->pos.trTime = cg.time; @@ -223,7 +231,7 @@ CG_AddFragment ================ */ static void CG_AddFragment( localEntity_t *le ) { - vec3_t newOrigin; + vec3_t newOrigin, impactVelocityDiff; trace_t trace; if ( le->pos.trType == TR_STATIONARY ) { @@ -283,15 +291,17 @@ static void CG_AddFragment( localEntity_t *le ) { return; } - // leave a mark - CG_FragmentBounceMark( le, &trace ); + // reflect the velocity on the trace plane + CG_ReflectVelocity( le, &trace, impactVelocityDiff ); + + if ( VectorLengthSquared( impactVelocityDiff ) >= Square( cg_bounceMarksMinImpactSpeed.value ) ) { + // leave a mark + CG_FragmentBounceMark( le, &trace ); + } // do a bouncy sound CG_FragmentBounceSound( le, &trace ); - // reflect the velocity on the trace plane - CG_ReflectVelocity( le, &trace ); - trap_R_AddRefEntityToScene( &le->refEntity ); } From 9ff2dc43048baf3c03e9b7c70d3e2017ff40c8cc Mon Sep 17 00:00:00 2001 From: WofWca Date: Mon, 10 Nov 2025 17:55:51 +0400 Subject: [PATCH 2/2] improvement: better gib sound, blood trail Allow playing the gib sound more than once, and keep leaving the blood trail even if the gib already hit something. --- code/cgame/cg_cvar.h | 1 + code/cgame/cg_localents.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/code/cgame/cg_cvar.h b/code/cgame/cg_cvar.h index 0d82e292..f4cf9b0a 100644 --- a/code/cgame/cg_cvar.h +++ b/code/cgame/cg_cvar.h @@ -41,6 +41,7 @@ CG_CVAR( cg_simpleItems, "cg_simpleItems", "0", CVAR_ARCHIVE ) CG_CVAR( cg_addMarks, "cg_marks", "1", CVAR_ARCHIVE ) // Note that ~290 corresponds to a free fall with no bounce from player height. CG_CVAR( cg_bounceMarksMinImpactSpeed, "cg_bounceMarksMinImpactSpeed", "350", CVAR_ARCHIVE ) +CG_CVAR( cg_bounceSoundMinImpactSpeed, "cg_bounceSoundMinImpactSpeed", "450", CVAR_ARCHIVE ) CG_CVAR( cg_lagometer, "cg_lagometer", "1", CVAR_ARCHIVE ) CG_CVAR( cg_railTrailTime, "cg_railTrailTime", "400", CVAR_ARCHIVE ) CG_CVAR( cg_railTrailRadius, "cg_railTrailRadius", "0", CVAR_ARCHIVE ) diff --git a/code/cgame/cg_localents.c b/code/cgame/cg_localents.c index 77e4e79c..c31bf165 100644 --- a/code/cgame/cg_localents.c +++ b/code/cgame/cg_localents.c @@ -181,9 +181,11 @@ void CG_FragmentBounceSound( localEntity_t *le, trace_t *trace ) { } - // don't allow a fragment to make multiple bounce sounds, - // or it gets too noisy as they settle - le->leBounceSoundType = LEBS_NONE; + // This is no longer needed, because we now decide whether to play a sound + // purely based on impact velocity. + // // don't allow a fragment to make multiple bounce sounds, + // // or it gets too noisy as they settle + // le->leBounceSoundType = LEBS_NONE; } @@ -299,8 +301,10 @@ static void CG_AddFragment( localEntity_t *le ) { CG_FragmentBounceMark( le, &trace ); } - // do a bouncy sound - CG_FragmentBounceSound( le, &trace ); + if ( VectorLengthSquared( impactVelocityDiff ) >= Square( cg_bounceSoundMinImpactSpeed.value ) ) { + // do a bouncy sound + CG_FragmentBounceSound( le, &trace ); + } trap_R_AddRefEntityToScene( &le->refEntity ); }