From 68df5326d7a15bbaa9b07582b83539962d5672eb Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Sat, 3 May 2025 18:02:32 +0200 Subject: [PATCH] Fiddle with physics again --- TODO.txt | 1 + racing.h | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/TODO.txt b/TODO.txt index 191415d..b0bff28 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,6 +2,7 @@ fuck issue trackers :D =========== GENERAL ============== +- LOD blocks in lower res look too small - hitting ramps at higher speed still often bugs, try to fiddle with physics again (reshape iterations, tension, ...) - make replays have better names (time etc.) diff --git a/racing.h b/racing.h index cd9ba74..9556730 100644 --- a/racing.h +++ b/racing.h @@ -61,12 +61,16 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit #define LCR_RACING_EVENT_FAN 0x0020 #define LCR_PHYSICS_UNIT 4096 ///< len. of square for phys. engine - -#define TPE_RESHAPE_TENSION_LIMIT 8 -#define TPE_RESHAPE_ITERATIONS 16 /**< Empirically tested, seems to have a - big impact on bugs that happen when - driving onto a curved ramp under - various angles. */ + +/* The combination of values TPE_RESHAPE_TENSION_LIMIT and + TPE_RESHAPE_ITERATIONS has crucial effect on the bugginess and feel of car + physics, especially when driving onto ramps in high speed etc., the values + were chosen empirically by testing, these are the ones that showed to + subjectively feel the best. */ + +#define TPE_RESHAPE_TENSION_LIMIT 7 +#define TPE_RESHAPE_ITERATIONS 18 + #include "general.h" #include "map.h" #include "tinyphysicsengine.h" @@ -1504,8 +1508,31 @@ uint32_t LCR_racingStep(unsigned int input) TPE_worldStep(&(LCR_racing.physicsWorld)); // normal step - if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) || - !_LCR_racingCarShapeOK()) // bad? + uint8_t useSimplified = (LCR_racing.carBody.flags & + TPE_BODY_FLAG_UNRESOLVED) != 0; + + if (!useSimplified && !_LCR_racingCarShapeOK()) + { + useSimplified = 1; + + // we only do this with wheels on ground, because squeezed roof bugs here + if ((LCR_racing.wheelCollisions & 0x0f) == 0x0f) + for (int i = 0; i < 4 * TPE_RESHAPE_ITERATIONS; ++i) + { + LCR_LOG2("trying harder to resolve physics"); + + TPE_bodyReshape(&LCR_racing.carBody,_LCR_racingEnvironmentFunction); + + if ((i % 4 == 0) && _LCR_racingCarShapeOK()) + { + LCR_LOG2("succeeded in fixing physics"); + useSimplified = 0; + break; + } + } + } + + if (useSimplified) { LCR_LOG2("using simplified physics"); @@ -1555,6 +1582,7 @@ uint32_t LCR_racingStep(unsigned int input) } // Accelerate roof and wheels away from each other: + for (int i = 0; i < LCR_CAR_JOINTS; ++i) { LCR_racing.carBody.joints[i].velocity[0] += (i == 4 ? 1 : -1) * tmpVec.x;