Debian Codegraph @

scene/2d/skeleton_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* skeleton_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/resources/2d/skeleton/skeleton_modification_2d.h"
35
36 class Skeleton2D;
37
38 class Bone2D : public Node2D {
39 GDCLASS(Bone2D, Node2D);
40
41 friend class Skeleton2D;
42 #ifdef TOOLS_ENABLED
43 friend class AnimatedValuesBackup;
44 #endif
45
46 Bone2D *parent_bone = nullptr;
47 Skeleton2D *skeleton = nullptr;
48 Transform2D rest;
49
50 bool autocalculate_length_and_angle = true;
51 real_t length = 16;
52 real_t bone_angle = 0;
53
54 int skeleton_index = -1;
55
56 void calculate_length_and_rotation();
57
58 #ifdef TOOLS_ENABLED
59 RID editor_gizmo_rid;
60 bool _editor_get_bone_shape(Vector<Vector2> *p_shape, Vector<Vector2> *p_outline_shape, Bone2D *p_other_bone);
61 bool _editor_show_bone_gizmo = true;
62 #endif // TOOLS ENABLED
63
64 protected:
65 void _notification(int p_what);
66 static void _bind_methods();
67 bool _set(const StringName &p_path, const Variant &p_value);
68 bool _get(const StringName &p_path, Variant &r_ret) const;
69 void _get_property_list(List<PropertyInfo> *p_list) const;
70
71 public:
72 Transform2D cache_transform;
73 bool copy_transform_to_cache = true;
74
75 void set_rest(const Transform2D &p_rest);
76 Transform2D get_rest() const;
77 void apply_rest();
78 Transform2D get_skeleton_rest() const;
79
80 PackedStringArray get_configuration_warnings() const override;
81
82 void set_autocalculate_length_and_angle(bool p_autocalculate);
83 bool get_autocalculate_length_and_angle() const;
84 void set_length(real_t p_length);
85 real_t get_length() const;
86 void set_bone_angle(real_t p_angle);
87 real_t get_bone_angle() const;
88
89 int get_index_in_skeleton() const;
90
91 #ifdef TOOLS_ENABLED
92 void _editor_set_show_bone_gizmo(bool p_show_gizmo);
93 bool _editor_get_show_bone_gizmo() const;
94 #endif // TOOLS_ENABLED
95
96 Bone2D();
97 ~Bone2D();
98 };
99
100 class SkeletonModificationStack2D;
101
102 class Skeleton2D : public Node2D {
103 GDCLASS(Skeleton2D, Node2D);
104
105 friend class Bone2D;
106 #ifdef TOOLS_ENABLED
107 friend class AnimatedValuesBackup;
108 #endif
109
110 struct Bone {
111 bool operator<(const Bone &p_bone) const {
112 return p_bone.bone->is_greater_than(bone);
113 }
114 Bone2D *bone = nullptr;
115 int parent_index = 0;
116 Transform2D accum_transform;
117 Transform2D rest_inverse;
118
119 //Transform2D local_pose_cache;
120 Transform2D local_pose_override;
121 real_t local_pose_override_amount = 0;
122 bool local_pose_override_persistent = false;
123 };
124
125 LocalVector<Bone> bones;
126
127 bool bone_setup_dirty = true;
128 void _make_bone_setup_dirty();
129 void _update_bone_setup();
130
131 bool transform_dirty = true;
132 void _make_transform_dirty();
133 void _update_transform();
134
135 RID skeleton;
136
137 Ref<SkeletonModificationStack2D> modification_stack;
138
139 ///////////////////////////////////////////////////////
140 // INTERPOLATION
141 struct InterpolationData {
142 Transform2D xform_curr;
143 Transform2D xform_prev;
144 uint32_t last_update_physics_tick = UINT32_MAX; // Ensure tick 0 is detected as a change.
145 } _interpolation_data;
146
147 void _update_process_mode();
148 void _ensure_update_interpolation_data();
149
150 protected:
151 virtual void _physics_interpolated_changed() override;
152 ///////////////////////////////////////////////////////
153
154 void _notification(int p_what);
155 static void _bind_methods();
156 bool _set(const StringName &p_path, const Variant &p_value);
157 bool _get(const StringName &p_path, Variant &r_ret) const;
158 void _get_property_list(List<PropertyInfo> *p_list) const;
159
160 public:
161 int get_bone_count() const;
162 Bone2D *get_bone(int p_idx);
163
164 RID get_skeleton() const;
165
166 void set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, real_t p_amount, bool p_persistent = true);
167 Transform2D get_bone_local_pose_override(int p_bone_idx);
168
169 Ref<SkeletonModificationStack2D> get_modification_stack() const;
170 void set_modification_stack(Ref<SkeletonModificationStack2D> p_stack);
171 void execute_modifications(real_t p_delta, int p_execution_mode);
172
173 Skeleton2D();
174 ~Skeleton2D();
175 };