Skip to content

Commit 673e770

Browse files
committed
Merge pull request godotengine#90575 from TokageItLab/boneattachment-performance
Remove `bone_pose_updated` signal and replace it with the `skeleton_updated` signal
2 parents 50fd380 + 78a5ef4 commit 673e770

File tree

9 files changed

+80
-25
lines changed

9 files changed

+80
-25
lines changed

doc/classes/BoneAttachment3D.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
Returns whether the BoneAttachment3D node is using an external [Skeleton3D] rather than attempting to use its parent node as the [Skeleton3D].
2222
</description>
2323
</method>
24-
<method name="on_bone_pose_update">
24+
<method name="on_skeleton_update">
2525
<return type="void" />
26-
<param index="0" name="bone_index" type="int" />
2726
<description>
28-
A function that is called automatically when the [Skeleton3D] the BoneAttachment3D node is using has a bone that has changed its pose. This function is where the BoneAttachment3D node updates its position so it is correctly bound when it is [i]not[/i] set to override the bone pose.
27+
A function that is called automatically when the [Skeleton3D] is updated. This function is where the [BoneAttachment3D] node updates its position so it is correctly bound when it is [i]not[/i] set to override the bone pose.
2928
</description>
3029
</method>
3130
<method name="set_external_skeleton">

doc/classes/Skeleton3D.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
<param index="1" name="pose" type="Transform3D" />
253253
<description>
254254
Sets the global pose transform, [param pose], for the bone at [param bone_idx].
255-
[b]Note:[/b] If other bone poses have been changed, this method executes an update process and will cause performance to deteriorate. If you know that multiple global poses will be applied, consider using [method set_bone_pose] with precalculation.
255+
[b]Note:[/b] If other bone poses have been changed, this method executes a dirty poses recalculation and will cause performance to deteriorate. If you know that multiple global poses will be applied, consider using [method set_bone_pose] with precalculation.
256256
</description>
257257
</method>
258258
<method name="set_bone_global_pose_override" deprecated="">
@@ -355,27 +355,27 @@
355355
<description>
356356
</description>
357357
</signal>
358-
<signal name="bone_pose_changed">
359-
<param index="0" name="bone_idx" type="int" />
360-
<description>
361-
Emitted when the bone at [param bone_idx] changes its transform/pose. This can be used to update other nodes that rely on bone positions.
362-
</description>
363-
</signal>
364358
<signal name="pose_updated">
365359
<description>
366-
Emitted when the pose is updated, after [constant NOTIFICATION_UPDATE_SKELETON] is received.
360+
Emitted when the pose is updated.
361+
[b]Note:[/b] During the update process, this signal is not fired, so modification by [SkeletonModifier3D] is not detected.
367362
</description>
368363
</signal>
369364
<signal name="show_rest_only_changed">
370365
<description>
371366
Emitted when the value of [member show_rest_only] changes.
372367
</description>
373368
</signal>
369+
<signal name="skeleton_updated">
370+
<description>
371+
Emitted when the final pose has been calculated will be applied to the skin in the update process.
372+
This means that all [SkeletonModifier3D] processing is complete. In order to detect the completion of the processing of each [SkeletonModifier3D], use [signal SkeletonModifier3D.modification_processed].
373+
</description>
374+
</signal>
374375
</signals>
375376
<constants>
376377
<constant name="NOTIFICATION_UPDATE_SKELETON" value="50">
377-
Notification received when this skeleton's pose needs to be updated.
378-
This notification is received [i]before[/i] the related [signal pose_updated] signal.
378+
Notification received when this skeleton's pose needs to be updated. In that case, this is called only once per frame in a deferred process.
379379
</constant>
380380
<constant name="MODIFIER_CALLBACK_MODE_PROCESS_PHYSICS" value="0" enum="ModifierCallbackModeProcess">
381381
Set a flag to process modification during physics frames (see [constant Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS]).

misc/extension_api_validation/4.2-stable.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,11 @@ Validate extension JSON: API was removed: classes/SkeletonIK3D/methods/set_inter
272272
Validate extension JSON: API was removed: classes/SkeletonIK3D/properties/interpolation
273273

274274
These base class is changed to SkeletonModifier3D which is processed by Skeleton3D with the assumption that it is Skeleton3D's child.
275+
276+
277+
GH-90575
278+
--------
279+
Validate extension JSON: API was removed: classes/BoneAttachment3D/methods/on_bone_pose_update
280+
Validate extension JSON: API was removed: classes/Skeleton3D/signals/bone_pose_changed
281+
282+
They have been replaced by a safer API due to performance concerns. Compatibility method registered.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**************************************************************************/
2+
/* bone_attachment_3d.compat.inc */
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+
#ifndef DISABLE_DEPRECATED
32+
33+
#include "bone_attachment_3d.h"
34+
35+
void BoneAttachment3D::_on_bone_pose_update_bind_compat_90575(int p_bone_index) {
36+
return on_skeleton_update();
37+
}
38+
39+
void BoneAttachment3D::_bind_compatibility_methods() {
40+
ClassDB::bind_compatibility_method(D_METHOD("on_bone_pose_update", "bone_index"), &BoneAttachment3D::_on_bone_pose_update_bind_compat_90575);
41+
}
42+
43+
#endif // DISABLE_DEPRECATED

scene/3d/bone_attachment_3d.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/**************************************************************************/
3030

3131
#include "bone_attachment_3d.h"
32+
#include "bone_attachment_3d.compat.inc"
3233

3334
void BoneAttachment3D::_validate_property(PropertyInfo &p_property) const {
3435
if (p_property.name == "bone_name") {
@@ -148,9 +149,9 @@ void BoneAttachment3D::_check_bind() {
148149
bone_idx = sk->find_bone(bone_name);
149150
}
150151
if (bone_idx != -1) {
151-
sk->connect(SNAME("bone_pose_changed"), callable_mp(this, &BoneAttachment3D::on_bone_pose_update));
152+
sk->connect(SNAME("skeleton_updated"), callable_mp(this, &BoneAttachment3D::on_skeleton_update));
152153
bound = true;
153-
callable_mp(this, &BoneAttachment3D::on_bone_pose_update).call_deferred(bone_idx);
154+
callable_mp(this, &BoneAttachment3D::on_skeleton_update);
154155
}
155156
}
156157
}
@@ -176,7 +177,7 @@ void BoneAttachment3D::_check_unbind() {
176177
Skeleton3D *sk = _get_skeleton3d();
177178

178179
if (sk) {
179-
sk->disconnect(SNAME("bone_pose_changed"), callable_mp(this, &BoneAttachment3D::on_bone_pose_update));
180+
sk->disconnect(SNAME("skeleton_updated"), callable_mp(this, &BoneAttachment3D::on_skeleton_update));
180181
}
181182
bound = false;
182183
}
@@ -308,12 +309,12 @@ void BoneAttachment3D::_notification(int p_what) {
308309
}
309310
}
310311

311-
void BoneAttachment3D::on_bone_pose_update(int p_bone_index) {
312+
void BoneAttachment3D::on_skeleton_update() {
312313
if (updating) {
313314
return;
314315
}
315316
updating = true;
316-
if (bone_idx == p_bone_index) {
317+
if (bone_idx >= 0) {
317318
Skeleton3D *sk = _get_skeleton3d();
318319
if (sk) {
319320
if (!override_pose) {
@@ -371,7 +372,7 @@ void BoneAttachment3D::_bind_methods() {
371372
ClassDB::bind_method(D_METHOD("set_bone_idx", "bone_idx"), &BoneAttachment3D::set_bone_idx);
372373
ClassDB::bind_method(D_METHOD("get_bone_idx"), &BoneAttachment3D::get_bone_idx);
373374

374-
ClassDB::bind_method(D_METHOD("on_bone_pose_update", "bone_index"), &BoneAttachment3D::on_bone_pose_update);
375+
ClassDB::bind_method(D_METHOD("on_skeleton_update"), &BoneAttachment3D::on_skeleton_update);
375376

376377
ClassDB::bind_method(D_METHOD("set_override_pose", "override_pose"), &BoneAttachment3D::set_override_pose);
377378
ClassDB::bind_method(D_METHOD("get_override_pose"), &BoneAttachment3D::get_override_pose);

scene/3d/bone_attachment_3d.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class BoneAttachment3D : public Node3D {
6767
void _notification(int p_what);
6868

6969
static void _bind_methods();
70+
#ifndef DISABLE_DEPRECATED
71+
virtual void _on_bone_pose_update_bind_compat_90575(int p_bone_index);
72+
static void _bind_compatibility_methods();
73+
#endif
7074

7175
public:
7276
#ifdef TOOLS_ENABLED
@@ -89,7 +93,7 @@ class BoneAttachment3D : public Node3D {
8993
void set_external_skeleton(NodePath p_skeleton);
9094
NodePath get_external_skeleton() const;
9195

92-
virtual void on_bone_pose_update(int p_bone_index);
96+
virtual void on_skeleton_update();
9397

9498
#ifdef TOOLS_ENABLED
9599
virtual void notify_rebind_required();

scene/3d/skeleton_3d.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ void Skeleton3D::_notification(int p_what) {
327327
_process_modifiers();
328328
}
329329

330+
emit_signal(SceneStringNames::get_singleton()->skeleton_updated);
331+
330332
// Update skins.
331333
RenderingServer *rs = RenderingServer::get_singleton();
332334
for (SkinReference *E : skin_bindings) {
@@ -921,8 +923,6 @@ void Skeleton3D::force_update_bone_children_transforms(int p_bone_idx) {
921923
for (int i = 0; i < child_bone_size; i++) {
922924
bones_to_process.push_back(b.child_bones[i]);
923925
}
924-
925-
emit_signal(SceneStringNames::get_singleton()->bone_pose_changed, current_bone_idx);
926926
}
927927
}
928928

@@ -1059,7 +1059,7 @@ void Skeleton3D::_bind_methods() {
10591059
ADD_PROPERTY(PropertyInfo(Variant::INT, "modifier_callback_mode_process", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_modifier_callback_mode_process", "get_modifier_callback_mode_process");
10601060

10611061
ADD_SIGNAL(MethodInfo("pose_updated"));
1062-
ADD_SIGNAL(MethodInfo("bone_pose_changed", PropertyInfo(Variant::INT, "bone_idx")));
1062+
ADD_SIGNAL(MethodInfo("skeleton_updated"));
10631063
ADD_SIGNAL(MethodInfo("bone_enabled_changed", PropertyInfo(Variant::INT, "bone_idx")));
10641064
ADD_SIGNAL(MethodInfo("bone_list_changed"));
10651065
ADD_SIGNAL(MethodInfo("show_rest_only_changed"));

scene/scene_string_names.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SceneStringNames::SceneStringNames() {
6363
RESET = StaticCString::create("RESET");
6464

6565
pose_updated = StaticCString::create("pose_updated");
66-
bone_pose_changed = StaticCString::create("bone_pose_changed");
66+
skeleton_updated = StaticCString::create("skeleton_updated");
6767
bone_enabled_changed = StaticCString::create("bone_enabled_changed");
6868
show_rest_only_changed = StaticCString::create("show_rest_only_changed");
6969

scene/scene_string_names.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class SceneStringNames {
9999
StringName RESET;
100100

101101
StringName pose_updated;
102-
StringName bone_pose_changed;
102+
StringName skeleton_updated;
103103
StringName bone_enabled_changed;
104104
StringName show_rest_only_changed;
105105

0 commit comments

Comments
 (0)