Explorar o código

Bugfix: Don't allow the vehicle to sleep when the transmission is switching (#609)

Jorrit Rouwe %!s(int64=2) %!d(string=hai) anos
pai
achega
dcaa98f66a

+ 2 - 1
Jolt/Physics/Vehicle/TrackedVehicleController.cpp

@@ -156,7 +156,8 @@ TrackedVehicleController::TrackedVehicleController(const TrackedVehicleControlle
 bool TrackedVehicleController::AllowSleep() const
 {
 	return mForwardInput == 0.0f								// No user input
-		&& mEngine.GetCurrentRPM() <= 1.01f * mEngine.mMinRPM;	// Engine is idling
+		&& mTransmission.AllowSleep()							// Transmission is not shifting
+		&& mEngine.AllowSleep();								// Engine is idling
 }
 
 void TrackedVehicleController::PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem)

+ 3 - 0
Jolt/Physics/Vehicle/VehicleEngine.h

@@ -79,6 +79,9 @@ public:
 	void					DrawRPM(DebugRenderer *inRenderer, RVec3Arg inPosition, Vec3Arg inForward, Vec3Arg inUp, float inSize, float inShiftDownRPM, float inShiftUpRPM) const;
 #endif // JPH_DEBUG_RENDERER
 
+	/// If the engine is idle we allow the vehicle to sleep
+	bool					AllowSleep() const							{ return mCurrentRPM <= 1.01f * mMinRPM; }
+
 	/// Saving state for replay
 	void					SaveState(StateRecorder &inStream) const;
 	void					RestoreState(StateRecorder &inStream);

+ 3 - 0
Jolt/Physics/Vehicle/VehicleTransmission.h

@@ -69,6 +69,9 @@ public:
 	/// Return the transmission ratio based on the current gear (ratio between engine and differential)
 	float					GetCurrentRatio() const;
 
+	/// Only allow sleeping when the transmission is idle
+	bool					AllowSleep() const							{ return mGearSwitchTimeLeft <= 0.0f && mClutchReleaseTimeLeft <= 0.0f && mGearSwitchLatencyTimeLeft <= 0.0f; }
+
 	/// Saving state for replay
 	void					SaveState(StateRecorder &inStream) const;
 	void					RestoreState(StateRecorder &inStream);

+ 2 - 1
Jolt/Physics/Vehicle/WheeledVehicleController.cpp

@@ -224,7 +224,8 @@ float WheeledVehicleController::GetWheelSpeedAtClutch() const
 bool WheeledVehicleController::AllowSleep() const
 {
 	return mForwardInput == 0.0f								// No user input
-		&& mEngine.GetCurrentRPM() <= 1.01f * mEngine.mMinRPM;	// Engine is idling
+		&& mTransmission.AllowSleep()							// Transmission is not shifting
+		&& mEngine.AllowSleep();								// Engine is idling
 }
 
 void WheeledVehicleController::PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem)