Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Vehicle/VehicleController.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/ObjectStream/SerializableObject.h>
8 #include <Jolt/Core/StreamIn.h>
9 #include <Jolt/Core/StreamOut.h>
10 #ifdef JPH_DEBUG_RENDERER
11 #include <Jolt/Renderer/DebugRenderer.h>
12 #endif // JPH_DEBUG_RENDERER
13
14 JPH_NAMESPACE_BEGIN
15
16 class PhysicsSystem;
17 class VehicleController;
18 class VehicleConstraint;
19 class WheelSettings;
20 class Wheel;
21 class StateRecorder;
22
23 /// Basic settings object for interface that controls acceleration / deceleration of the vehicle
24 class JPH_EXPORT VehicleControllerSettings : public SerializableObject, public RefTarget<VehicleControllerSettings>
25 {
26 JPH_DECLARE_SERIALIZABLE_ABSTRACT(JPH_EXPORT, VehicleControllerSettings)
27
28 public:
29 /// Saves the contents of the controller settings in binary form to inStream.
30 virtual void SaveBinaryState(StreamOut &inStream) const = 0;
31
32 /// Restore the contents of the controller settings in binary form from inStream.
33 virtual void RestoreBinaryState(StreamIn &inStream) = 0;
34
35 /// Create an instance of the vehicle controller class
36 virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const = 0;
37 };
38
39 /// Runtime data for interface that controls acceleration / deceleration of the vehicle
40 class JPH_EXPORT VehicleController : public NonCopyable
41 {
42 public:
43 JPH_OVERRIDE_NEW_DELETE
44
45 /// Constructor / destructor
46 explicit VehicleController(VehicleConstraint &inConstraint) : mConstraint(inConstraint) { }
47 virtual ~VehicleController() = default;
48
49 /// Access the vehicle constraint that this controller is part of
50 VehicleConstraint & GetConstraint() { return mConstraint; }
51 const VehicleConstraint & GetConstraint() const { return mConstraint; }
52
53 /// Recreate the settings for this controller
54 virtual Ref<VehicleControllerSettings> GetSettings() const = 0;
55
56 protected:
57 // The functions below are only for the VehicleConstraint
58 friend class VehicleConstraint;
59
60 // Create a new instance of wheel
61 virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const = 0;
62
63 // If the vehicle is allowed to go to sleep
64 virtual bool AllowSleep() const = 0;
65
66 // Called before the wheel probes have been done
67 virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
68
69 // Called after the wheel probes have been done
70 virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
71
72 // Solve longitudinal and lateral constraint parts for all of the wheels
73 virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) = 0;
74
75 // Saving state for replay
76 virtual void SaveState(StateRecorder &inStream) const = 0;
77 virtual void RestoreState(StateRecorder &inStream) = 0;
78
79 #ifdef JPH_DEBUG_RENDERER
80 // Drawing interface
81 virtual void Draw(DebugRenderer *inRenderer) const = 0;
82 #endif // JPH_DEBUG_RENDERER
83
84 VehicleConstraint & mConstraint; ///< The vehicle constraint we belong to
85 };
86
87 JPH_NAMESPACE_END