VehicleController.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Physics/Vehicle/VehicleConstraint.h>
  5. #include <ObjectStream/SerializableObject.h>
  6. #include <Core/StreamIn.h>
  7. #include <Core/StreamOut.h>
  8. namespace JPH {
  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. /// Constructor / destructor
  27. explicit VehicleController(VehicleConstraint &inConstraint) : mConstraint(inConstraint) { }
  28. virtual ~VehicleController() = default;
  29. protected:
  30. // The functions below are only for the VehicleConstraint
  31. friend class VehicleConstraint;
  32. // Create a new instance of wheel
  33. virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const = 0;
  34. // Called before the wheel probes have been done
  35. virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  36. // Called after the wheel probes have been done
  37. virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  38. // Solve longitudinal and lateral constraint parts for all of the wheels
  39. virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) = 0;
  40. // Saving state for replay
  41. virtual void SaveState(StateRecorder &inStream) const = 0;
  42. virtual void RestoreState(StateRecorder &inStream) = 0;
  43. #ifdef JPH_DEBUG_RENDERER
  44. // Drawing interface
  45. virtual void Draw(DebugRenderer *inRenderer) const = 0;
  46. #endif // JPH_DEBUG_RENDERER
  47. VehicleConstraint & mConstraint; ///< The vehicle constraint we belong to
  48. };
  49. } // JPH