Debian Codegraph @

scene/2d/physics/collision_object_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* collision_object_2d.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 "scene/2d/node_2d.h"
34 #include "scene/main/viewport.h"
35 #include "scene/resources/2d/shape_2d.h"
36 #include "servers/physics_2d/physics_server_2d.h"
37
38 class CollisionObject2D : public Node2D {
39 GDCLASS(CollisionObject2D, Node2D);
40
41 public:
42 static constexpr AncestralClass static_ancestral_class = AncestralClass::COLLISION_OBJECT_2D;
43
44 enum DisableMode {
45 DISABLE_MODE_REMOVE,
46 DISABLE_MODE_MAKE_STATIC,
47 DISABLE_MODE_KEEP_ACTIVE,
48 };
49
50 private:
51 uint32_t collision_layer = 1;
52 uint32_t collision_mask = 1;
53 real_t collision_priority = 1.0;
54
55 bool area = false;
56 RID rid;
57 uint32_t callback_lock = 0;
58 bool pickable = false;
59
60 DisableMode disable_mode = DISABLE_MODE_REMOVE;
61
62 PhysicsServer2D::BodyMode body_mode = PhysicsServer2D::BODY_MODE_STATIC;
63
64 struct ShapeData {
65 ObjectID owner_id;
66 Transform2D xform;
67 struct Shape {
68 Ref<Shape2D> shape;
69 int index = 0;
70 };
71
72 Vector<Shape> shapes;
73
74 bool disabled = false;
75 bool one_way_collision = false;
76 real_t one_way_collision_margin = 0.0;
77 };
78
79 int total_subshapes = 0;
80
81 RBMap<uint32_t, ShapeData> shapes;
82 bool only_update_transform_changes = false; // This is used for sync to physics.
83
84 void _apply_disabled();
85 void _apply_enabled();
86
87 protected:
88 _FORCE_INLINE_ void lock_callback() { callback_lock++; }
89 _FORCE_INLINE_ void unlock_callback() {
90 ERR_FAIL_COND(callback_lock == 0);
91 callback_lock--;
92 }
93
94 CollisionObject2D(RID p_rid, bool p_area);
95
96 void _notification(int p_what);
97 static void _bind_methods();
98
99 void _update_pickable();
100 friend class Viewport;
101 void _input_event_call(Viewport *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape);
102 void _mouse_enter();
103 void _mouse_exit();
104
105 void _mouse_shape_enter(int p_shape);
106 void _mouse_shape_exit(int p_shape);
107
108 void set_only_update_transform_changes(bool p_enable);
109 bool is_only_update_transform_changes_enabled() const;
110
111 void set_body_mode(PhysicsServer2D::BodyMode p_mode);
112
113 virtual void _space_changed(const RID &p_new_space);
114
115 GDVIRTUAL3(_input_event, RequiredParam<Viewport>, RequiredParam<InputEvent>, int)
116 GDVIRTUAL0(_mouse_enter)
117 GDVIRTUAL0(_mouse_exit)
118 GDVIRTUAL1(_mouse_shape_enter, int)
119 GDVIRTUAL1(_mouse_shape_exit, int)
120 public:
121 void set_collision_layer(uint32_t p_layer);
122 uint32_t get_collision_layer() const;
123
124 void set_collision_mask(uint32_t p_mask);
125 uint32_t get_collision_mask() const;
126
127 void set_collision_layer_value(int p_layer_number, bool p_value);
128 bool get_collision_layer_value(int p_layer_number) const;
129
130 void set_collision_mask_value(int p_layer_number, bool p_value);
131 bool get_collision_mask_value(int p_layer_number) const;
132
133 void set_collision_priority(real_t p_priority);
134 real_t get_collision_priority() const;
135
136 void set_disable_mode(DisableMode p_mode);
137 DisableMode get_disable_mode() const;
138
139 uint32_t create_shape_owner(Object *p_owner);
140 void remove_shape_owner(uint32_t owner);
141 void get_shape_owners(List<uint32_t> *r_owners);
142 PackedInt32Array _get_shape_owners();
143
144 void shape_owner_set_transform(uint32_t p_owner, const Transform2D &p_transform);
145 Transform2D shape_owner_get_transform(uint32_t p_owner) const;
146 Object *shape_owner_get_owner(uint32_t p_owner) const;
147
148 void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled);
149 bool is_shape_owner_disabled(uint32_t p_owner) const;
150
151 void shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable);
152 bool is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const;
153
154 void shape_owner_set_one_way_collision_margin(uint32_t p_owner, real_t p_margin);
155 real_t get_shape_owner_one_way_collision_margin(uint32_t p_owner) const;
156
157 void shape_owner_add_shape(uint32_t p_owner, RequiredParam<Shape2D> rp_shape);
158 int shape_owner_get_shape_count(uint32_t p_owner) const;
159 Ref<Shape2D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
160 int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;
161
162 void shape_owner_remove_shape(uint32_t p_owner, int p_shape);
163 void shape_owner_clear_shapes(uint32_t p_owner);
164
165 uint32_t shape_find_owner(int p_shape_index) const;
166
167 void set_pickable(bool p_enabled);
168 bool is_pickable() const;
169
170 PackedStringArray get_configuration_warnings() const override;
171
172 _FORCE_INLINE_ RID get_rid() const { return rid; }
173
174 CollisionObject2D();
175 ~CollisionObject2D();
176 };
177
178 VARIANT_ENUM_CAST(CollisionObject2D::DisableMode);