VehicleController.h 2.7 KB

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