diff --git a/TODO.txt b/TODO.txt index 15977dd..42fbe14 100644 --- a/TODO.txt +++ b/TODO.txt @@ -68,6 +68,8 @@ =========== BUGS ================= +- After adding the non-rotating physics feature, the car now gets funny when + turned on the roof, once even shot to the ceiling of the map. - very rarely the near plane overflow bug still happens, maybe shift near plane a bit further still? - sometimes during long loading the screen goes black, seems to have appeared @@ -80,6 +82,8 @@ =========== HANDLED ============== - MAP4: one triangle in top section is missing! +- Antibug: maybe always simulate the step with non-rotating body AND normal one + as well -- if the car ends up bugged, use the non-rotating result? - Fix weird reversing. - CP gets often missed, would be cool to increase its radius, but also hard. We would have to be checking 8 cells instead of one, but even then issues diff --git a/data b/data index 6df21a9..d5f1633 100644 --- a/data +++ b/data @@ -53,13 +53,48 @@ details :.B1w1J :f112 :=h0h2 :fl12 :f11o :=B0i2 :f11m :=m0n2 :fb12 :*n1EI :!n1F :+p1r :+y1l :+y3I :+k1l -#RLC1;00LC1;8bd6e314 0000533:0011:02b9:0091:00a9:0041:0089:0031:0059:0021:00d3:0061:0109:0111:00c5:0051:00e9:0181:0043:0081:00d9:0041:0099:0041:0089:0031:0079:0041:0049:0041:0179:0031:00d3:0021:00d5:0031:01a3:0041:0103:00a1:0013:0021:0033:00f1:0083:0041:0179:0021:03f9:0021:0123:0011 -#BLC1; -#RLC4;00LC4;bcf27d79 0000777:0011:0119:0131:0039:00c1:0079:0041:0059:0031:00f9:0031:00a9:0041:00b3:0031:0183:0021:0083:0031:0043:0021:0023:0041:0079:0091:0053:0031:0053:0051:0079:0051:0083:0051:0013:0041:0033:0051:0103:0071:00b9:0021:0093:0031:0069:0011:0089:0051:0059:0011:00b9:0021:0063:0081:00b9:0051:0243:0021:00d3:0041:0073:0031:0013:0011:0033:0051:0073:0061:0043:0031:0079:0031:00f3:0031:0089:0021:0399:0021:0073:0051:0073:0021:00f3:00c1:00f9:0061:0043:00c1:00a3:0041:0089:0051:0093:0051:0049:0041:0069:0031:0029:0021:0133:0041:0049:0031:0083:0021:0069:0041:0043:0031 +#Mdevtest;4321 0 + +:*313 +:\a13L :m111 +:=000 :fE15 :f41& :f3c1 :f771 +:=g001 :f815 :=o002 :f815 :=w003 :f815 +:>00o :f414 +:=00Z :ft13 +:>107 :f11u +:-40V :f414 +:^404I :fc11 +:;406L :f513 +:|409 :f511 :|40aI :f511 +:|40b- :f511 :|40cI- :f511 +:~61g :f212 :m212 +:^710- :f611 :^711I- :f611 +:-d10- :f212 +:(f10I- +:^b04J :f115 :^c04L :f115 +:.01l2| +:~21D +:^31u +:I40s :f313 +:;e0& +:-g0& +:)311I :f411 +:]011I :f311 +:|021I :f311 +:ub0fL :m111 +:u01& +:^t0ZL :f113 +:^80XL :f112 +:v50k| :m111 +:^90lL :f112 :<90nL :f112 :_90pL :f112 +:(40xL :f112 +:^01RL :v01S| :v01QI +:oe03 +:|21MI :f211 +:^E003L :f115 +:]e0i :}f0i :|e1i :f211 :|e3i- :f211 :]e4i- :f211 :;e0jL :f251 +:]h0gI :}g0gI :|g1gI :f211 :|g3gI- :f211 :]g4gI- :f211 :;g0fJ :f251 +:-e5g :f413 :|g0hL +:+018 :f213 :!v05 :f311 +#RLC4;00LC4;bcf27d79 0000738:0011:00f9:00a1:0049:00a1:0069:0031:0063:0051:0059:0031:01a9:0041:0073:0041:00f9:0021:0215:0031:0049:0091:0023:0081:0053:0061:0089:0041:0073:0021:0079:00d1:0079:0051:0059:0021:0889:0091:0059:0031:0029:00b1:0169:0011:0143:0061:00a9:0061:0059:0051:00b3:0041:01d9:0021:0079:0061:00b9:00a1:0039:0031:0039:0021:0013:0081:0019:00d1:00f9:0081:0049:0031:0043:0051:0103:0061:00b3:0031:0193:0021:0089:0011 #BLC4; -#RLC4;00LC4;bcf27d79 0000737:0011:0149:00d1:0089:0011:00a9:0031:0059:0031:0079:0021:00d9:0021:01f9:0021:0313:0041:01e3:0021:0059:0041:0039:0071:0039:0011:0059:00d1:0159:0011:0399:0021:0093:0041:00a9:0021:0129:0011:0089:0051:0039:0031:0069:0081:0099:0041:0059:0041:0073:0031:0079:0031:00b9:0031:0039:0031:0063:0051:0043:0021:0033:0051:0099:0021:0099:0031:00b9:0031:0049:0031:0059:0071:0149:0041:0039:0041:0039:0041:0033:0051:0049:00c1:0073:0041:0233:0041:00a3:0041:00c3:0031:02a9 -#RLC4;00LC4;bcf27d79 0000746:0011:00f9:0191:0039:0061:0069:00b1:0033:0081:0079:0041:0139:0031:01e3:0041:00f3:0051:0079:0061:00b3:0051:0099:0051:00b9:0021:0013:00c1:0033:00d1:0079:0041:0053:0051:0079:0061:0199:0031:0083:0041:0053:0051:0013:0041:0049:0061:0099:0031:0223:0061:0063:00a1:0083:0091:0063:0011:0089:0031:00d9:0021:00e9:0021:00b3:0021:01a5:0021:00a9:0031:0183:0141:0219:0031:0153:0081:0049:00a1:00a3:0051:0113:0031:00a3:0031:0245 -#RLCtiny5;00LCtiny5;5c14d8b6 0000988:01b8:0040:0161:0010:0038:00f0:2551:0179:00e1:0033:0041:0069:0091:0053:0061:0069:0041:0069:0028:0010:0012:00c3:0201:0049:0060:0088:0061:0079:0041:0073:0071:0059:0041:0033:00b1:0069:0051:0013:0111:0043:0041:0103:0031:0085:0041:0173:0041:0089:00a1 -#BLCtiny5; -#RLC4;00LC4;bcf27d79 0000838:0011:00c9:00d1:0109:0031:0039:0041:00a9:0041:0299:0011:0159:0011:00e9:0021:01f9:0031:00c9:0031:0083:0041:0089:00d1:0069:00d1:0123:0021:00c3:0021:02b3:0031:0089:0031:0249:0091:0069:0061:0029:0081:0159:0021:0109:0041:0039:0041:00b3:00b1:00b9:0061:00c3:0021:0049:0031:0029:0061:0143:0031:0089:0081:0063:0031:0049:00a1:0023:00a1:00d0:0124:0080:0061:0013:00e1:0039:0101:0083:0051:0129:0091:0029:0041:0033:0091:01d9:0041:0043:00b1:00f9:0041:00a9:0021:00d9:0021 -#RLC1;00LC1;8bd6e314 0000478:0011:00e3:0051:0029:0061:0119:0061:0069:0071:0049:0041:0039:0051:0139:0031:0119:0085:0014:0018:00d9:0111:0043:0021:0073:0031:0049:0031:0089:0041:00a9:0081:00e9:0021:0083:0021:0079:0021:0053:0021:00f5:0041:0179:0021:00d3:0141:0043:00d1:0193:0011:0479:0011:00d3:0031:0089:0011 diff --git a/racing.h b/racing.h index adb71ad..769ba4c 100644 --- a/racing.h +++ b/racing.h @@ -125,10 +125,6 @@ struct LCR_GameUnit carSpeeds[2]; /**< Signed speed in game units per tick (negative if backwards) and its previous value. */ - // for fixing physics bugs: - TPE_Vec3 carOKPositions[LCR_CAR_JOINTS]; - uint8_t carNotOKCount; - uint16_t crashState; uint8_t playingReplay; @@ -993,11 +989,6 @@ void LCR_racingRestart(uint8_t replay) TPE_F / 2 : (TPE_F / 4),0)); } - for (int i = 0; i < LCR_CAR_JOINTS; ++i) - LCR_racing.carOKPositions[i] = TPE_vec3(0,0,0); - - LCR_racing.carNotOKCount = 0; - LCR_racing.carPositions[0] = TPE_vec3(0,0,0); LCR_racing.carPositions[1] = LCR_racing.carPositions[0]; LCR_racing.carRotations[0] = TPE_vec3(0,0,0); @@ -1386,7 +1377,7 @@ uint32_t LCR_racingStep(unsigned int input) to unstick itself. */ TPE_bodySpin(&LCR_racing.carBody,_LCR_TPE_vec3DividePlain(carUp, - (steering == (((input & LCR_RACING_INPUT_LEFT) != 0)) == + ((steering == (((input & LCR_RACING_INPUT_LEFT) != 0))) == ((input & (LCR_RACING_INPUT_FORW)) != 0)) ? 100 : -100)); } } @@ -1412,7 +1403,49 @@ uint32_t LCR_racingStep(unsigned int input) #endif LCR_LOG2("stepping physics (start)"); - TPE_worldStep(&(LCR_racing.physicsWorld)); + + { + /* To prevent many physics glitches we simulate the physics steps twice: + once with normal physics and once with non-rotating (completely stiff) + body. If the normal step works out wrong (car shape ends up wrong etc.), + we fall back to the simple non-rotating step. */ + + TPE_Joint joints[LCR_CAR_JOINTS]; + + LCR_racing.carBody.flags |= TPE_BODY_FLAG_NONROTATING; + + for (int i = 0; i < LCR_CAR_JOINTS; ++i) + joints[i] = LCR_racing.carBody.joints[i]; + + TPE_worldStep(&(LCR_racing.physicsWorld)); // non-rotating step + + for (int i = 0; i < LCR_CAR_JOINTS; ++i) // remember the position and reset + { + TPE_Joint tmpJoint = LCR_racing.carBody.joints[i]; + LCR_racing.carBody.joints[i] = joints[i]; + joints[i] = tmpJoint; + } + + LCR_racing.carBody.flags &= ~TPE_BODY_FLAG_NONROTATING; + + TPE_worldStep(&(LCR_racing.physicsWorld)); // normal step + + if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) || + !_LCR_racingCarShapeOK()) // bad? + { + LCR_LOG1("car bad, simplifying physics"); + + for (int i = 0; i < LCR_CAR_JOINTS; ++i) // use the first step positions + LCR_racing.carBody.joints[i] = joints[i]; + + // If still not OK (slim chance), just stop the body (prevent uberbugs): + + if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) || + !_LCR_racingCarShapeOK()) + TPE_bodyStop(&LCR_racing.carBody); + } + } + LCR_LOG2("stepping physics (end)"); LCR_racing.carSpeeds[1] = LCR_racing.carSpeeds[0]; @@ -1493,51 +1526,6 @@ uint32_t LCR_racingStep(unsigned int input) } } - if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) || frontCollision || - !_LCR_racingCarShapeOK()) - { - // car not OK - - if (LCR_racing.carNotOKCount > 4) // TODO: constant - { - LCR_LOG2("car not OK (short), fixing"); - - for (int i = 0; i < LCR_CAR_JOINTS; ++i) - { - if (LCR_racing.carNotOKCount < 20) // 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; - } - int carBlock[3]; LCR_racingGetCarBlockCoords(carBlock);