VehicleController.h 2.5 KB

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