VehicleController.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Physics/Vehicle/VehicleConstraint.h>
  6. #include <Jolt/ObjectStream/SerializableObject.h>
  7. #include <Jolt/Core/StreamIn.h>
  8. #include <Jolt/Core/StreamOut.h>
  9. JPH_NAMESPACE_BEGIN
  10. class VehicleController;
  11. /// Basic settings object for interface that controls acceleration / decelleration of the vehicle
  12. class VehicleControllerSettings : public SerializableObject, public RefTarget<VehicleControllerSettings>
  13. {
  14. public:
  15. JPH_DECLARE_SERIALIZABLE_ABSTRACT(VehicleControllerSettings)
  16. /// Saves the contents of the controller settings in binary form to inStream.
  17. virtual void SaveBinaryState(StreamOut &inStream) const = 0;
  18. /// Restore the contents of the controller settings in binary form from inStream.
  19. virtual void RestoreBinaryState(StreamIn &inStream) = 0;
  20. /// Create an instance of the vehicle controller class
  21. virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const = 0;
  22. };
  23. /// Runtime data for interface that controls acceleration / decelleration of the vehicle
  24. class VehicleController : public RefTarget<VehicleController>
  25. {
  26. public:
  27. JPH_OVERRIDE_NEW_DELETE
  28. /// Constructor / destructor
  29. explicit VehicleController(VehicleConstraint &inConstraint) : mConstraint(inConstraint) { }
  30. virtual ~VehicleController() = default;
  31. protected:
  32. // The functions below are only for the VehicleConstraint
  33. friend class VehicleConstraint;
  34. // Create a new instance of wheel
  35. virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const = 0;
  36. // If the vehicle is allowed to go to sleep
  37. virtual bool AllowSleep() const = 0;
  38. // Called before the wheel probes have been done
  39. virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  40. // Called after the wheel probes have been done
  41. virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  42. // Solve longitudinal and lateral constraint parts for all of the wheels
  43. virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) = 0;
  44. // Saving state for replay
  45. virtual void SaveState(StateRecorder &inStream) const = 0;
  46. virtual void RestoreState(StateRecorder &inStream) = 0;
  47. #ifdef JPH_DEBUG_RENDERER
  48. // Drawing interface
  49. virtual void Draw(DebugRenderer *inRenderer) const = 0;
  50. #endif // JPH_DEBUG_RENDERER
  51. VehicleConstraint & mConstraint; ///< The vehicle constraint we belong to
  52. };
  53. JPH_NAMESPACE_END