diff --git a/assets.h b/assets.h index de7729d..13378b0 100644 --- a/assets.h +++ b/assets.h @@ -26,7 +26,7 @@ static const uint8_t map1[] = LCR_MAP_BLOCK(LCR_BLOCK_START,1,1,1,0,0), -LCR_MAP_BLOCK(LCR_BLOCK_FULL,0,0,0,LCR_BLOCK_MATERIAL_GRASS,0), +LCR_MAP_BLOCK(LCR_BLOCK_FULL,0,0,0,LCR_BLOCK_MATERIAL_CONCRETE,0), LCR_MAP_BLOCK(LCR_BLOCK_CUBOID_FILL,15,1,20,0,0), LCR_MAP_BLOCK(LCR_BLOCK_FULL,0,0,20,LCR_BLOCK_MATERIAL_CONCRETE,0), @@ -69,6 +69,8 @@ LCR_MAP_BLOCK(LCR_BLOCK_CUBOID_FILL,2,5,1,0,0), LCR_MAP_BLOCK(LCR_BLOCK_FULL,3,6,6,LCR_BLOCK_MATERIAL_CONCRETE,0), LCR_MAP_BLOCK(LCR_BLOCK_CUBOID_FILL,2,1,3,0,0), +LCR_MAP_BLOCK(LCR_BLOCK_CORNER,1,1,4,LCR_BLOCK_MATERIAL_CONCRETE,0), + LCR_MAP_BLOCK(LCR_BLOCK_FULL,15,0,0,LCR_BLOCK_MATERIAL_CONCRETE,0), LCR_MAP_BLOCK(LCR_BLOCK_CUBOID_FILL,10,1,15,0,0), diff --git a/racing.h b/racing.h index da1a916..2d653f9 100644 --- a/racing.h +++ b/racing.h @@ -799,53 +799,73 @@ void LCR_racingStep(unsigned int input) } } + // now make a special test for a "pinch" front collision + TPE_Vec3 frontWheelMiddle = TPE_vec3Plus( + LCR_racing.carBody.joints[0].position, + LCR_racing.carBody.joints[1].position); + frontWheelMiddle.x /= 2; + frontWheelMiddle.y /= 2; + frontWheelMiddle.z /= 2; + frontWheelMiddle = TPE_vec3Minus(frontWheelMiddle, + _LCR_racingEnvironmentFunction(frontWheelMiddle,LCR_PHYSICS_UNIT / 4)); + uint8_t frontCollision = frontWheelMiddle.x == 0 && frontWheelMiddle.y == 0 && + frontWheelMiddle.z == 0; -if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) || - !_LCR_racingCarShapeOK()) -{ - // car not OK - - if (LCR_racing.carNotOKCount > 8) // TODO: constant + if (frontCollision) { - LCR_LOG1("car not OK for some time, fixing"); - - for (int i = 0; i < LCR_CAR_JOINTS; ++i) - { - if (LCR_racing.carNotOKCount < 30) // TODO: const - { - // for a while try to smoothly iterate towards previous OK position - LCR_racing.carBody.joints[i].position = - TPE_vec3Plus(LCR_racing.carBody.joints[i].position, - LCR_racing.carOKPositions[i]); - - LCR_racing.carBody.joints[i].position.x /= 2; - LCR_racing.carBody.joints[i].position.y /= 2; - LCR_racing.carBody.joints[i].position.z /= 2; - } - else // hard set the pos (iteration may be infinite due to sim.) - LCR_racing.carBody.joints[i].position = LCR_racing.carOKPositions[i]; - - for (int j = 0; j < 3; ++j) // lower speed a bit - LCR_racing.carBody.joints[i].velocity[j] = - (7 * ((int) LCR_racing.carBody.joints[i].velocity[j])) / 8; - } + // stop the car immediately + LCR_LOG1("car front pierced"); + LCR_racing.carNotOKCount += (LCR_racing.carNotOKCount < 15 ? 32 : 0); // TODO: consts } - LCR_racing.carNotOKCount += LCR_racing.carNotOKCount < 32 ? 1 : 0; -} -else -{ - // car OK -// LCR_racing.carNotOKCount -= LCR_racing.carNotOKCount ? 1 : 0; - LCR_racing.carNotOKCount = 0; + if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) || frontCollision || + !_LCR_racingCarShapeOK()) + { + // car not OK - for (int i = 0; i < LCR_CAR_JOINTS; ++i) - LCR_racing.carOKPositions[i] = LCR_racing.carBody.joints[i].position; -} + if (LCR_racing.carNotOKCount > 5) // TODO: constant + { + LCR_LOG1("car not OK (short), fixing"); + + for (int i = 0; i < LCR_CAR_JOINTS; ++i) + { + if (LCR_racing.carNotOKCount < 50) // TODO: const + { + // for a while try to smoothly iterate towards previous OK position + LCR_racing.carBody.joints[i].position = + TPE_vec3Plus(LCR_racing.carBody.joints[i].position, + LCR_racing.carOKPositions[i]); + + LCR_racing.carBody.joints[i].position.x /= 2; + LCR_racing.carBody.joints[i].position.y /= 2; + LCR_racing.carBody.joints[i].position.z /= 2; + + for (int j = 0; j < 3; ++j) // lower speed a bit + LCR_racing.carBody.joints[i].velocity[j] = + (7 * ((int) LCR_racing.carBody.joints[i].velocity[j])) / 8; + } + else // hard set the pos (iteration may be infinite due to sim.) + { + LCR_LOG1("car not OK (long), teleporting"); + LCR_racing.carBody.joints[i].position = LCR_racing.carOKPositions[i]; + } + } + } + + LCR_racing.carNotOKCount += LCR_racing.carNotOKCount < 255 ? 1 : 0; + } + else + { + // car OK + LCR_racing.carNotOKCount = 0; + + for (int i = 0; i < LCR_CAR_JOINTS; ++i) + LCR_racing.carOKPositions[i] = LCR_racing.carBody.joints[i].position; + } LCR_racing.tick++;