Debian Codegraph @

modules/jolt_physics/spaces/jolt_space_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* jolt_space_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "servers/physics_3d/physics_server_3d.h"
34
35 #include "Jolt/Jolt.h"
36
37 #include "Jolt/Core/JobSystem.h"
38 #include "Jolt/Core/TempAllocator.h"
39 #include "Jolt/Physics/Body/BodyInterface.h"
40 #include "Jolt/Physics/Collision/BroadPhase/BroadPhaseQuery.h"
41 #include "Jolt/Physics/Collision/NarrowPhaseQuery.h"
42 #include "Jolt/Physics/Constraints/Constraint.h"
43 #include "Jolt/Physics/PhysicsSystem.h"
44
45 class JoltArea3D;
46 class JoltBody3D;
47 class JoltBodyActivationListener3D;
48 class JoltContactListener3D;
49 class JoltJoint3D;
50 class JoltLayers;
51 class JoltObject3D;
52 class JoltPhysicsDirectSpaceState3D;
53 class JoltShapedObject3D;
54 class JoltSoftBody3D;
55
56 class JoltSpace3D {
57 Mutex pending_objects_mutex;
58 Mutex body_call_queries_mutex;
59
60 SelfList<JoltBody3D>::List body_call_queries_list;
61 SelfList<JoltArea3D>::List area_call_queries_list;
62 SelfList<JoltShapedObject3D>::List shapes_changed_list;
63 SelfList<JoltShapedObject3D>::List needs_optimization_list;
64
65 LocalVector<JPH::BodyID> pending_objects_sleeping;
66 LocalVector<JPH::BodyID> pending_objects_awake;
67
68 RID rid;
69
70 JPH::JobSystem *job_system = nullptr;
71 JPH::TempAllocator *temp_allocator = nullptr;
72 JoltLayers *layers = nullptr;
73 JoltContactListener3D *contact_listener = nullptr;
74 JoltBodyActivationListener3D *body_activation_listener = nullptr;
75 JPH::PhysicsSystem *physics_system = nullptr;
76 JoltPhysicsDirectSpaceState3D *direct_state = nullptr;
77 JoltArea3D *default_area = nullptr;
78
79 float last_step = 0.0f;
80
81 bool active = false;
82 bool stepping = false;
83
84 void _pre_step(float p_step);
85 void _post_step(float p_step);
86
87 public:
88 explicit JoltSpace3D(JPH::JobSystem *p_job_system);
89 ~JoltSpace3D();
90
91 void step(float p_step);
92
93 void call_queries();
94
95 RID get_rid() const { return rid; }
96 void set_rid(const RID &p_rid) { rid = p_rid; }
97
98 bool is_active() const { return active; }
99 void set_active(bool p_active) { active = p_active; }
100
101 bool is_stepping() const { return stepping; }
102
103 double get_param(PhysicsServer3D::SpaceParameter p_param) const;
104 void set_param(PhysicsServer3D::SpaceParameter p_param, double p_value);
105
106 JPH::PhysicsSystem &get_physics_system() const { return *physics_system; }
107
108 JPH::TempAllocator &get_temp_allocator() const { return *temp_allocator; }
109
110 JPH::BodyInterface &get_body_iface();
111 const JPH::BodyInterface &get_body_iface() const;
112 const JPH::BodyLockInterface &get_lock_iface() const;
113
114 const JPH::BroadPhaseQuery &get_broad_phase_query() const;
115 const JPH::NarrowPhaseQuery &get_narrow_phase_query() const;
116
117 JPH::ObjectLayer map_to_object_layer(JPH::BroadPhaseLayer p_broad_phase_layer, uint32_t p_collision_layer, uint32_t p_collision_mask);
118 void map_from_object_layer(JPH::ObjectLayer p_object_layer, JPH::BroadPhaseLayer &r_broad_phase_layer, uint32_t &r_collision_layer, uint32_t &r_collision_mask) const;
119
120 JPH::Body *try_get_jolt_body(const JPH::BodyID &p_body_id) const;
121 JoltObject3D *try_get_object(const JPH::BodyID &p_body_id) const;
122 JoltShapedObject3D *try_get_shaped(const JPH::BodyID &p_body_id) const;
123 JoltBody3D *try_get_body(const JPH::BodyID &p_body_id) const;
124 JoltArea3D *try_get_area(const JPH::BodyID &p_body_id) const;
125 JoltSoftBody3D *try_get_soft_body(const JPH::BodyID &p_body_id) const;
126
127 JoltPhysicsDirectSpaceState3D *get_direct_state();
128
129 JoltArea3D *get_default_area() const { return default_area; }
130 void set_default_area(JoltArea3D *p_area);
131
132 float get_last_step() const { return last_step; }
133
134 JPH::Body *add_object(const JoltObject3D &p_object, const JPH::BodyCreationSettings &p_settings, bool p_sleeping = false);
135 JPH::Body *add_object(const JoltObject3D &p_object, const JPH::SoftBodyCreationSettings &p_settings, bool p_sleeping = false);
136 void remove_object(const JPH::BodyID &p_jolt_id);
137 void flush_pending_objects();
138
139 void set_is_object_sleeping(const JPH::BodyID &p_jolt_id, bool p_enable);
140
141 void enqueue_call_queries(SelfList<JoltBody3D> *p_body);
142 void enqueue_call_queries(SelfList<JoltArea3D> *p_area);
143 void dequeue_call_queries(SelfList<JoltBody3D> *p_body);
144 void dequeue_call_queries(SelfList<JoltArea3D> *p_area);
145
146 void enqueue_shapes_changed(SelfList<JoltShapedObject3D> *p_object);
147 void dequeue_shapes_changed(SelfList<JoltShapedObject3D> *p_object);
148
149 void enqueue_needs_optimization(SelfList<JoltShapedObject3D> *p_object);
150 void dequeue_needs_optimization(SelfList<JoltShapedObject3D> *p_object);
151
152 void add_joint(JPH::Constraint *p_jolt_ref);
153 void add_joint(JoltJoint3D *p_joint);
154 void remove_joint(JPH::Constraint *p_jolt_ref);
155 void remove_joint(JoltJoint3D *p_joint);
156
157 #ifdef DEBUG_ENABLED
158 void dump_debug_snapshot(const String &p_dir);
159 const PackedVector3Array &get_debug_contacts() const;
160 int get_debug_contact_count() const;
161 int get_max_debug_contacts() const;
162 void set_max_debug_contacts(int p_count);
163 #endif
164 };