diff options
author | reduz <reduzio@gmail.com> | 2021-02-18 15:52:29 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-02-18 20:39:55 -0300 |
commit | 083aa9b95e6e32d13bf6a406137b3fd12287c4d0 (patch) | |
tree | 81adeec75eae715cb3a06591d1f1f159ec16396b /scene/animation | |
parent | 247b7e24483931e978f0c203030b5135109655cc (diff) |
Refactor Process Mode
Implements https://github.com/godotengine/godot-proposals/issues/1835#issuecomment-727186192
* PauseMode is now ProcessMode, containing the following states:
```
PROCESS_MODE_INHERIT, // same as parent node
PROCESS_MODE_NORMAL, // process only if not paused
PROCESS_MODE_PAUSE_ONLY, // process only if paused
PROCESS_MODE_ALWAYS, // process always
PROCESS_MODE_DISABLED, // never process
```
* NOTIFICATION_PAUSED and NOTIFICATION_UNPAUSED are received effectively when the node is paused and unpaused (not any longer when pause mode is set in SceneTree).
* Renamed some nodes that used ProcessMode/process_mode to specify a callback type to ProcessCallback to avoid clashes.
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_player.cpp | 22 | ||||
-rw-r--r-- | scene/animation/animation_player.h | 10 | ||||
-rw-r--r-- | scene/animation/animation_tree.cpp | 22 | ||||
-rw-r--r-- | scene/animation/animation_tree.h | 10 | ||||
-rw-r--r-- | scene/animation/root_motion_view.cpp | 4 |
5 files changed, 34 insertions, 34 deletions
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index c6fa55b76e..2c19307c52 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -206,7 +206,7 @@ void AnimationPlayer::_notification(int p_what) { } } break; case NOTIFICATION_INTERNAL_PROCESS: { - if (animation_process_mode == ANIMATION_PROCESS_PHYSICS) { + if (process_callback == ANIMATION_PROCESS_PHYSICS) { break; } @@ -215,7 +215,7 @@ void AnimationPlayer::_notification(int p_what) { } } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (animation_process_mode == ANIMATION_PROCESS_IDLE) { + if (process_callback == ANIMATION_PROCESS_IDLE) { break; } @@ -1403,8 +1403,8 @@ bool AnimationPlayer::is_reset_on_save_enabled() const { return reset_on_save; } -void AnimationPlayer::set_animation_process_mode(AnimationProcessMode p_mode) { - if (animation_process_mode == p_mode) { +void AnimationPlayer::set_process_callback(AnimationProcessCallback p_mode) { + if (process_callback == p_mode) { return; } @@ -1412,14 +1412,14 @@ void AnimationPlayer::set_animation_process_mode(AnimationProcessMode p_mode) { if (pr) { _set_process(false); } - animation_process_mode = p_mode; + process_callback = p_mode; if (pr) { _set_process(true); } } -AnimationPlayer::AnimationProcessMode AnimationPlayer::get_animation_process_mode() const { - return animation_process_mode; +AnimationPlayer::AnimationProcessCallback AnimationPlayer::get_process_callback() const { + return process_callback; } void AnimationPlayer::set_method_call_mode(AnimationMethodCallMode p_mode) { @@ -1435,7 +1435,7 @@ void AnimationPlayer::_set_process(bool p_process, bool p_force) { return; } - switch (animation_process_mode) { + switch (process_callback) { case ANIMATION_PROCESS_PHYSICS: set_physics_process_internal(p_process && active); break; @@ -1637,8 +1637,8 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_caches"), &AnimationPlayer::clear_caches); - ClassDB::bind_method(D_METHOD("set_animation_process_mode", "mode"), &AnimationPlayer::set_animation_process_mode); - ClassDB::bind_method(D_METHOD("get_animation_process_mode"), &AnimationPlayer::get_animation_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &AnimationPlayer::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &AnimationPlayer::get_process_callback); ClassDB::bind_method(D_METHOD("set_method_call_mode", "mode"), &AnimationPlayer::set_method_call_mode); ClassDB::bind_method(D_METHOD("get_method_call_mode"), &AnimationPlayer::get_method_call_mode); @@ -1658,7 +1658,7 @@ void AnimationPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position"); ADD_GROUP("Playback Options", "playback_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_animation_process_mode", "get_animation_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_callback", "get_process_callback"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_active", PROPERTY_HINT_NONE, "", 0), "set_active", "is_active"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale"); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index f2774cb395..2a1821c215 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -64,7 +64,7 @@ class AnimationPlayer : public Node { OBJ_CATEGORY("Animation Nodes"); public: - enum AnimationProcessMode { + enum AnimationProcessCallback { ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_IDLE, ANIMATION_PROCESS_MANUAL, @@ -206,7 +206,7 @@ private: String autoplay; bool reset_on_save = true; - AnimationProcessMode animation_process_mode = ANIMATION_PROCESS_IDLE; + AnimationProcessCallback process_callback = ANIMATION_PROCESS_IDLE; AnimationMethodCallMode method_call_mode = ANIMATION_METHOD_CALL_DEFERRED; bool processing = false; bool active = true; @@ -298,8 +298,8 @@ public: void set_reset_on_save_enabled(bool p_enabled); bool is_reset_on_save_enabled() const; - void set_animation_process_mode(AnimationProcessMode p_mode); - AnimationProcessMode get_animation_process_mode() const; + void set_process_callback(AnimationProcessCallback p_mode); + AnimationProcessCallback get_process_callback() const; void set_method_call_mode(AnimationMethodCallMode p_mode); AnimationMethodCallMode get_method_call_mode() const; @@ -328,7 +328,7 @@ public: ~AnimationPlayer(); }; -VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessMode); +VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback); VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode); #endif diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index c0da35d803..26a13f33c9 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -473,7 +473,7 @@ void AnimationTree::set_active(bool p_active) { active = p_active; started = active; - if (process_mode == ANIMATION_PROCESS_IDLE) { + if (process_callback == ANIMATION_PROCESS_IDLE) { set_process_internal(active); } else { set_physics_process_internal(active); @@ -494,8 +494,8 @@ bool AnimationTree::is_active() const { return active; } -void AnimationTree::set_process_mode(AnimationProcessMode p_mode) { - if (process_mode == p_mode) { +void AnimationTree::set_process_callback(AnimationProcessCallback p_mode) { + if (process_callback == p_mode) { return; } @@ -504,15 +504,15 @@ void AnimationTree::set_process_mode(AnimationProcessMode p_mode) { set_active(false); } - process_mode = p_mode; + process_callback = p_mode; if (was_active) { set_active(true); } } -AnimationTree::AnimationProcessMode AnimationTree::get_process_mode() const { - return process_mode; +AnimationTree::AnimationProcessCallback AnimationTree::get_process_callback() const { + return process_callback; } void AnimationTree::_node_removed(Node *p_node) { @@ -1234,11 +1234,11 @@ void AnimationTree::advance(float p_time) { } void AnimationTree::_notification(int p_what) { - if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) { + if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_callback == ANIMATION_PROCESS_PHYSICS) { _process_graph(get_physics_process_delta_time()); } - if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_mode == ANIMATION_PROCESS_IDLE) { + if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_callback == ANIMATION_PROCESS_IDLE) { _process_graph(get_process_delta_time()); } @@ -1471,8 +1471,8 @@ void AnimationTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_tree_root", "root"), &AnimationTree::set_tree_root); ClassDB::bind_method(D_METHOD("get_tree_root"), &AnimationTree::get_tree_root); - ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &AnimationTree::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &AnimationTree::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &AnimationTree::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &AnimationTree::get_process_callback); ClassDB::bind_method(D_METHOD("set_animation_player", "root"), &AnimationTree::set_animation_player); ClassDB::bind_method(D_METHOD("get_animation_player"), &AnimationTree::get_animation_player); @@ -1491,7 +1491,7 @@ void AnimationTree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode"), "set_tree_root", "get_tree_root"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_mode", "get_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_callback", "get_process_callback"); ADD_GROUP("Root Motion", "root_motion_"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_motion_track"), "set_root_motion_track", "get_root_motion_track"); diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 0f78b1f0e2..1c5aec26ab 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -163,7 +163,7 @@ class AnimationTree : public Node { GDCLASS(AnimationTree, Node); public: - enum AnimationProcessMode { + enum AnimationProcessCallback { ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_IDLE, ANIMATION_PROCESS_MANUAL, @@ -238,7 +238,7 @@ private: Ref<AnimationNode> root; - AnimationProcessMode process_mode = ANIMATION_PROCESS_IDLE; + AnimationProcessCallback process_callback = ANIMATION_PROCESS_IDLE; bool active = false; NodePath animation_player; @@ -294,8 +294,8 @@ public: void set_active(bool p_active); bool is_active() const; - void set_process_mode(AnimationProcessMode p_mode); - AnimationProcessMode get_process_mode() const; + void set_process_callback(AnimationProcessCallback p_mode); + AnimationProcessCallback get_process_callback() const; void set_animation_player(const NodePath &p_player); NodePath get_animation_player() const; @@ -320,6 +320,6 @@ public: ~AnimationTree(); }; -VARIANT_ENUM_CAST(AnimationTree::AnimationProcessMode) +VARIANT_ENUM_CAST(AnimationTree::AnimationProcessCallback) #endif // ANIMATION_GRAPH_PLAYER_H diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp index a4a1b02a4c..9ee1f32581 100644 --- a/scene/animation/root_motion_view.cpp +++ b/scene/animation/root_motion_view.cpp @@ -89,12 +89,12 @@ void RootMotionView::_notification(int p_what) { AnimationTree *tree = Object::cast_to<AnimationTree>(node); if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) { - if (is_processing_internal() && tree->get_process_mode() == AnimationTree::ANIMATION_PROCESS_PHYSICS) { + if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) { set_process_internal(false); set_physics_process_internal(true); } - if (is_physics_processing_internal() && tree->get_process_mode() == AnimationTree::ANIMATION_PROCESS_IDLE) { + if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) { set_process_internal(true); set_physics_process_internal(false); } |