Fix crash sounds a bit

This commit is contained in:
Miloslav Ciz 2025-01-28 21:28:35 +01:00
parent bf06697917
commit e695921c5c
4 changed files with 36 additions and 11 deletions

View file

@ -66,8 +66,8 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_CAR_DRIFT_THRESHOLD_1 (LCR_GAME_UNIT / 4)
#define LCR_CAR_DRIFT_THRESHOLD_0 (LCR_GAME_UNIT / 200)
#define LCR_CAR_CRASH_SPEED_DIFF 25
#define LCR_CAR_CRASH_SPEED_THRESHOLD 70
#define LCR_CAR_CRASH_SPEED_SMALL 400
#define LCR_CAR_CRASH_SPEED_BIG 800
// multipliers (in 8ths) of friction and acceleration on concrete:
#define LCR_CAR_GRASS_FACTOR 5
@ -108,6 +108,8 @@ struct
TPE_Vec3 carOKPositions[LCR_CAR_JOINTS];
uint8_t carNotOKCount;
uint16_t crashState;
uint8_t playingReplay;
} LCR_racing;
@ -795,6 +797,20 @@ uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2,
{
// check which wheels are touching the ground.
#if LCR_SETTING_CRASH_SOUNDS
TPE_Unit speed = TPE_vec3Len( // detect crashes
TPE_vec3Project(
TPE_vec3(
LCR_racing.carBody.joints[j1].velocity[0],
LCR_racing.carBody.joints[j1].velocity[1],
LCR_racing.carBody.joints[j1].velocity[2]),
TPE_vec3Minus(p,
LCR_racing.carBody.joints[j1].position)));
LCR_racing.crashState |= ((speed >= LCR_CAR_CRASH_SPEED_BIG) << 1) |
(speed >= LCR_CAR_CRASH_SPEED_SMALL);
#endif
if (j1 < 4) // wheel joint?
LCR_racing.wheelCollisions |= 0x01 << j1;
@ -872,6 +888,7 @@ void LCR_racingRestart(uint8_t replay)
LCR_racing.carSpeeds[0] = 0;
LCR_racing.carSpeeds[1] = 0;
LCR_racing.carDrifting = 0;
LCR_racing.crashState = 0;
// make the car body:
TPE_makeCenterRectFull(LCR_racing.carJoints,
@ -1339,14 +1356,14 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.fanForce = 0;
}
#if LCR_SETTING_CRASH_SOUNDS
LCR_racing.crashState <<= 2;
#endif
LCR_LOG2("stepping physics (start)");
TPE_worldStep(&(LCR_racing.physicsWorld));
LCR_LOG2("stepping physics (end)");
int speedDiff =
TPE_abs(LCR_racing.carSpeeds[0]) -
TPE_abs(LCR_racing.carSpeeds[1]);
LCR_racing.carSpeeds[1] = LCR_racing.carSpeeds[0];
LCR_racing.carSpeeds[0] = (TPE_vec3Len(carVel) * LCR_GAME_UNIT)
@ -1355,10 +1372,12 @@ uint32_t LCR_racingStep(unsigned int input)
if (TPE_vec3Dot(carVel,carForw) < 0)
LCR_racing.carSpeeds[0] *= -1;
if (speedDiff < -1 * LCR_CAR_CRASH_SPEED_DIFF &&
TPE_abs(LCR_racing.carSpeeds[0]) <= LCR_CAR_CRASH_SPEED_THRESHOLD)
result |= (speedDiff < -2 * LCR_CAR_CRASH_SPEED_DIFF) ?
LCR_RACING_EVENT_CRASH_BIG : LCR_RACING_EVENT_CRASH_SMALL;
#if LCR_SETTING_CRASH_SOUNDS
if (LCR_racing.crashState == 1)
result |= LCR_RACING_EVENT_CRASH_SMALL;
else if (LCR_racing.crashState == 3)
result |= LCR_RACING_EVENT_CRASH_BIG;
#endif
_LCR_racingUpdateCarPosRot();