VehicleController.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 / deceleration of the vehicle
  19. class JPH_EXPORT VehicleControllerSettings : public SerializableObject, public RefTarget<VehicleControllerSettings>
  20. {
  21. JPH_DECLARE_SERIALIZABLE_ABSTRACT(JPH_EXPORT, VehicleControllerSettings)
  22. public:
  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 / deceleration of the vehicle
  31. class JPH_EXPORT 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. /// Access the vehicle constraint that this controller is part of
  39. VehicleConstraint & GetConstraint() { return mConstraint; }
  40. const VehicleConstraint & GetConstraint() const { return mConstraint; }
  41. /// Recreate the settings for this controller
  42. virtual Ref<VehicleControllerSettings> GetSettings() const = 0;
  43. protected:
  44. // The functions below are only for the VehicleConstraint
  45. friend class VehicleConstraint;
  46. // Create a new instance of wheel
  47. virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const = 0;
  48. // If the vehicle is allowed to go to sleep
  49. virtual bool AllowSleep() const = 0;
  50. // Called before the wheel probes have been done
  51. virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  52. // Called after the wheel probes have been done
  53. virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  54. // Solve longitudinal and lateral constraint parts for all of the wheels
  55. virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) = 0;
  56. // Saving state for replay
  57. virtual void SaveState(StateRecorder &inStream) const = 0;
  58. virtual void RestoreState(StateRecorder &inStream) = 0;
  59. #ifdef JPH_DEBUG_RENDERER
  60. // Drawing interface
  61. virtual void Draw(DebugRenderer *inRenderer) const = 0;
  62. #endif // JPH_DEBUG_RENDERER
  63. VehicleConstraint & mConstraint; ///< The vehicle constraint we belong to
  64. };
  65. JPH_NAMESPACE_END