Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize update flag by SkeletonModifier #93502

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions scene/3d/skeleton_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ void Skeleton3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_process_changed();
_make_dirty();
_make_modifiers_dirty();
force_update_all_dirty_bones();
#ifndef DISABLE_DEPRECATED
Expand All @@ -333,6 +334,13 @@ void Skeleton3D::_notification(int p_what) {
_process_modifiers();
}

// Abort if pose is not changed.
if (!(update_flags & UPDATE_FLAG_POSE)) {
updating = false;
update_flags = UPDATE_FLAG_NONE;
return;
}

emit_signal(SceneStringName(skeleton_updated));

// Update skins.
Expand Down Expand Up @@ -400,13 +408,13 @@ void Skeleton3D::_notification(int p_what) {
}

updating = false;
is_update_needed = false;
update_flags = UPDATE_FLAG_NONE;
} break;
case NOTIFICATION_INTERNAL_PROCESS:
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
_find_modifiers();
if (!modifiers.is_empty()) {
_update_deferred();
_update_deferred(UPDATE_FLAG_MODIFIER);
}
} break;
}
Expand Down Expand Up @@ -436,7 +444,7 @@ void Skeleton3D::_process_changed() {

void Skeleton3D::_make_modifiers_dirty() {
modifiers_dirty = true;
_update_deferred();
_update_deferred(UPDATE_FLAG_MODIFIER);
}

Transform3D Skeleton3D::get_bone_global_pose(int p_bone) const {
Expand Down Expand Up @@ -745,10 +753,12 @@ void Skeleton3D::_make_dirty() {
_update_deferred();
}

void Skeleton3D::_update_deferred() {
if (!is_update_needed && !updating && is_inside_tree()) {
is_update_needed = true;
notify_deferred_thread_group(NOTIFICATION_UPDATE_SKELETON); // It must never be called more than once in a single frame.
void Skeleton3D::_update_deferred(UpdateFlag p_update_flag) {
if (is_inside_tree()) {
if (update_flags == UPDATE_FLAG_NONE && !updating) {
notify_deferred_thread_group(NOTIFICATION_UPDATE_SKELETON); // It must never be called more than once in a single frame.
}
update_flags |= p_update_flag;
}
}

Expand Down
10 changes: 8 additions & 2 deletions scene/3d/skeleton_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ class Skeleton3D : public Node3D {
private:
friend class SkinReference;

void _update_deferred();
bool is_update_needed = false; // Is updating reserved?
enum UpdateFlag {
UPDATE_FLAG_NONE = 1,
UPDATE_FLAG_MODIFIER = 2,
UPDATE_FLAG_POSE = 4,
};

void _update_deferred(UpdateFlag p_update_flag = UPDATE_FLAG_POSE);
uint8_t update_flags = UPDATE_FLAG_NONE;
bool updating = false; // Is updating now?

struct Bone {
Expand Down
Loading