Skip to content

Commit 996923b

Browse files
committed
Vehicle serialization bugfixes
* Fixed incorrect RTTI definition of MotorcycleControllerSettings which led to the members of WheeledVehicleControllerSettings not being serialized. * Implemented missing VehicleConstraint::GetConstraintSettings function. Fixes #1743
1 parent 8399da3 commit 996923b

9 files changed

Lines changed: 67 additions & 3 deletions

‎Docs/ReleaseNotes.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ For breaking API changes see [this document](https://github.com/jrouwe/JoltPhysi
3030
* Added an epsilon to the `CastRay` / `CastShape` early out condition to avoid dividing by a very small number and overflowing to INF. This can cause a float overflow exception.
3131
* Fixed Samples requiring Vulkan extension `VK_EXT_device_address_binding_report` without checking if it is available.
3232
* Fixed Vulkan warning in Samples: VkSemaphore is being signaled by VkQueue but it may still be in use by VkSwapchainKHR.
33+
* Fixed incorrect RTTI definition of MotorcycleControllerSettings which led to the members of WheeledVehicleControllerSettings not being serialized.
34+
* Implemented missing VehicleConstraint::GetConstraintSettings function.
3335

3436
## v5.3.0
3537

‎Jolt/Physics/Vehicle/MotorcycleController.cpp‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ JPH_NAMESPACE_BEGIN
1717

1818
JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(MotorcycleControllerSettings)
1919
{
20-
JPH_ADD_BASE_CLASS(MotorcycleControllerSettings, VehicleControllerSettings)
20+
JPH_ADD_BASE_CLASS(MotorcycleControllerSettings, WheeledVehicleControllerSettings)
2121

2222
JPH_ADD_ATTRIBUTE(MotorcycleControllerSettings, mMaxLeanAngle)
2323
JPH_ADD_ATTRIBUTE(MotorcycleControllerSettings, mLeanSpringConstant)
@@ -290,4 +290,17 @@ void MotorcycleController::Draw(DebugRenderer *inRenderer) const
290290

291291
#endif // JPH_DEBUG_RENDERER
292292

293+
Ref<VehicleControllerSettings> MotorcycleController::GetSettings() const
294+
{
295+
MotorcycleControllerSettings *settings = new MotorcycleControllerSettings;
296+
ToSettings(*settings);
297+
settings->mMaxLeanAngle = mMaxLeanAngle;
298+
settings->mLeanSpringConstant = mLeanSpringConstant;
299+
settings->mLeanSpringDamping = settings->mLeanSpringDamping;
300+
settings->mLeanSpringIntegrationCoefficient = mLeanSpringIntegrationCoefficient;
301+
settings->mLeanSpringIntegrationCoefficientDecay = mLeanSpringIntegrationCoefficientDecay;
302+
settings->mLeanSmoothingFactor = mLeanSmoothingFactor;
303+
return settings;
304+
}
305+
293306
JPH_NAMESPACE_END

‎Jolt/Physics/Vehicle/MotorcycleController.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class JPH_EXPORT MotorcycleController : public WheeledVehicleController
8383
void SetLeanSmoothingFactor(float inFactor) { mLeanSmoothingFactor = inFactor; }
8484
float GetLeanSmoothingFactor() const { return mLeanSmoothingFactor; }
8585

86+
// See: VehicleController
87+
virtual Ref<VehicleControllerSettings> GetSettings() const override;
88+
8689
protected:
8790
// See: VehicleController
8891
virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override;

‎Jolt/Physics/Vehicle/TrackedVehicleController.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,14 @@ void TrackedVehicleController::RestoreState(StateRecorder &inStream)
534534
t.RestoreState(inStream);
535535
}
536536

537+
Ref<VehicleControllerSettings> TrackedVehicleController::GetSettings() const
538+
{
539+
TrackedVehicleControllerSettings *settings = new TrackedVehicleControllerSettings;
540+
settings->mEngine = mEngine;
541+
settings->mTransmission = mTransmission;
542+
for (size_t i = 0; i < std::size(mTracks); ++i)
543+
settings->mTracks[i] = mTracks[i];
544+
return settings;
545+
}
546+
537547
JPH_NAMESPACE_END

‎Jolt/Physics/Vehicle/TrackedVehicleController.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class JPH_EXPORT TrackedVehicleController : public VehicleController
129129
void SetRPMMeter(Vec3Arg inPosition, float inSize) { mRPMMeterPosition = inPosition; mRPMMeterSize = inSize; }
130130
#endif // JPH_DEBUG_RENDERER
131131

132+
// See: VehicleController
133+
virtual Ref<VehicleControllerSettings> GetSettings() const override;
134+
132135
protected:
133136
/// Synchronize angular velocities of left and right tracks according to their ratios
134137
void SyncLeftRightTracks();

‎Jolt/Physics/Vehicle/VehicleConstraint.cpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,17 @@ void VehicleConstraint::RestoreState(StateRecorder &inStream)
687687

688688
Ref<ConstraintSettings> VehicleConstraint::GetConstraintSettings() const
689689
{
690-
JPH_ASSERT(false); // Not implemented yet
691-
return nullptr;
690+
VehicleConstraintSettings *settings = new VehicleConstraintSettings;
691+
ToConstraintSettings(*settings);
692+
settings->mUp = mUp;
693+
settings->mForward = mForward;
694+
settings->mMaxPitchRollAngle = ACos(mCosMaxPitchRollAngle);
695+
settings->mWheels.resize(mWheels.size());
696+
for (Wheels::size_type w = 0; w < mWheels.size(); ++w)
697+
settings->mWheels[w] = const_cast<WheelSettings *>(mWheels[w]->mSettings.GetPtr());
698+
settings->mAntiRollBars = mAntiRollBars;
699+
settings->mController = mController->GetSettings();
700+
return settings;
692701
}
693702

694703
JPH_NAMESPACE_END

‎Jolt/Physics/Vehicle/VehicleController.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class JPH_EXPORT VehicleController : public NonCopyable
5050
VehicleConstraint & GetConstraint() { return mConstraint; }
5151
const VehicleConstraint & GetConstraint() const { return mConstraint; }
5252

53+
/// Recreate the settings for this controller
54+
virtual Ref<VehicleControllerSettings> GetSettings() const = 0;
55+
5356
protected:
5457
// The functions below are only for the VehicleConstraint
5558
friend class VehicleConstraint;

‎Jolt/Physics/Vehicle/WheeledVehicleController.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,4 +848,19 @@ void WheeledVehicleController::RestoreState(StateRecorder &inStream)
848848
mTransmission.RestoreState(inStream);
849849
}
850850

851+
void WheeledVehicleController::ToSettings(WheeledVehicleControllerSettings &outSettings) const
852+
{
853+
outSettings.mEngine = mEngine;
854+
outSettings.mTransmission = mTransmission;
855+
outSettings.mDifferentials = mDifferentials;
856+
outSettings.mDifferentialLimitedSlipRatio = mDifferentialLimitedSlipRatio;
857+
}
858+
859+
Ref<VehicleControllerSettings> WheeledVehicleController::GetSettings() const
860+
{
861+
WheeledVehicleControllerSettings *settings = new WheeledVehicleControllerSettings;
862+
ToSettings(*settings);
863+
return settings;
864+
}
865+
851866
JPH_NAMESPACE_END

‎Jolt/Physics/Vehicle/WheeledVehicleController.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ class JPH_EXPORT WheeledVehicleController : public VehicleController
155155
void SetRPMMeter(Vec3Arg inPosition, float inSize) { mRPMMeterPosition = inPosition; mRPMMeterSize = inSize; }
156156
#endif // JPH_DEBUG_RENDERER
157157

158+
// See: VehicleController
159+
virtual Ref<VehicleControllerSettings> GetSettings() const override;
160+
158161
protected:
162+
/// Convert controller back to settings
163+
void ToSettings(WheeledVehicleControllerSettings &outSettings) const;
164+
159165
// See: VehicleController
160166
virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const override { JPH_ASSERT(IsKindOf(&inWheel, JPH_RTTI(WheelSettingsWV))); return new WheelWV(static_cast<const WheelSettingsWV &>(inWheel)); }
161167
virtual bool AllowSleep() const override;

0 commit comments

Comments
 (0)