From 6dcb3a6ecd0ffdd2371adcc319cc193c57efebc9 Mon Sep 17 00:00:00 2001 From: Allison Ghost Date: Thu, 2 Nov 2023 01:09:53 -0700 Subject: [PATCH] Refactor Process Mode Implement PR: https://github.com/godotengine/godot/pull/46191 --- editor/editor_inspector.cpp | 4 + editor/plugins/particles_2d_editor_plugin.cpp | 2 +- editor/plugins/particles_editor_plugin.cpp | 2 +- editor/scene_tree_editor.cpp | 9 + editor/scene_tree_editor.h | 1 + scene/2d/camera_2d.cpp | 33 ++-- scene/2d/camera_2d.h | 8 +- scene/3d/camera.cpp | 22 +-- scene/3d/camera.h | 10 +- scene/3d/interpolated_camera.cpp | 30 +-- scene/3d/interpolated_camera.h | 8 +- scene/animation/animation_player.cpp | 24 +-- scene/animation/animation_player.h | 10 +- scene/animation/animation_tree.cpp | 24 +-- scene/animation/animation_tree.h | 10 +- scene/animation/animation_tree_player.cpp | 24 +-- scene/animation/animation_tree_player.h | 10 +- scene/animation/root_motion_view.cpp | 4 +- scene/main/node.cpp | 184 +++++++++++------- scene/main/node.h | 26 ++- scene/main/scene_tree.cpp | 6 +- 21 files changed, 264 insertions(+), 187 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 477c1f51..43ac8907 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1536,6 +1536,10 @@ void EditorInspector::update_tree() { continue; } + if (p.name == "script") { + category_vbox = nullptr; // script should go into its own category + } + if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && VS::get_singleton()->is_low_end()) { continue; //do not show this property in low end gfx } diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index dfd72fc1..2613f172 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -103,7 +103,7 @@ void Particles2DEditorPlugin::_menu_callback(int p_idx) { cpu_particles->set_name(particles->get_name()); cpu_particles->set_transform(particles->get_transform()); cpu_particles->set_visible(particles->is_visible()); - cpu_particles->set_pause_mode(particles->get_pause_mode()); + cpu_particles->set_process_mode(particles->get_process_mode()); cpu_particles->set_z_index(particles->get_z_index()); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index e6203b4b..635a996e 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -290,7 +290,7 @@ void ParticlesEditor::_menu_option(int p_option) { cpu_particles->set_name(node->get_name()); cpu_particles->set_transform(node->get_transform()); cpu_particles->set_visible(node->is_visible()); - cpu_particles->set_pause_mode(node->get_pause_mode()); + cpu_particles->set_process_mode(node->get_process_mode()); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Convert to CPUParticles")); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 1a051949..af17748f 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -253,6 +253,8 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll item->set_text(0, node_name); item->set_selectable(0, marked_selectable); item->set_custom_color(0, get_color("accent_color", "Editor")); + } else if (!p_node->can_process()) { + item->set_custom_color(0, get_color("disabled_font_color", "Editor")); } else if (!marked_selectable && !marked_children_selectable) { Node *node = p_node; while (node) { @@ -634,6 +636,11 @@ void SceneTreeEditor::_test_update_tree() { tree_dirty = true; } +void SceneTreeEditor::_tree_process_mode_changed() { + MessageQueue::get_singleton()->push_call(this, "_update_tree"); + tree_dirty = true; +} + void SceneTreeEditor::_tree_changed() { if (EditorNode::get_singleton()->is_exiting()) { return; //speed up exit @@ -704,6 +711,7 @@ void SceneTreeEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { get_tree()->connect("tree_changed", this, "_tree_changed"); + get_tree()->connect("tree_process_mode_changed", this, "_tree_process_mode_changed"); get_tree()->connect("node_removed", this, "_node_removed"); get_tree()->connect("node_renamed", this, "_node_renamed"); get_tree()->connect("node_configuration_warning_changed", this, "_warning_changed"); @@ -714,6 +722,7 @@ void SceneTreeEditor::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { get_tree()->disconnect("tree_changed", this, "_tree_changed"); + get_tree()->disconnect("tree_process_mode_changed", this, "_tree_process_mode_changed"); get_tree()->disconnect("node_removed", this, "_node_removed"); get_tree()->disconnect("node_renamed", this, "_node_renamed"); tree->disconnect("item_collapsed", this, "_cell_collapsed"); diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h index 6db4c60c..0ca2e884 100644 --- a/editor/scene_tree_editor.h +++ b/editor/scene_tree_editor.h @@ -76,6 +76,7 @@ class SceneTreeEditor : public Control { void _test_update_tree(); void _update_tree(bool p_scroll_to_selected = false); void _tree_changed(); + void _tree_process_mode_changed(); void _node_removed(Node *p_node); void _node_renamed(Node *p_node); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 2d3e13e3..1447b4a7 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -63,9 +63,12 @@ void Camera2D::_update_scroll() { }; } -void Camera2D::_update_process_mode() { +void Camera2D::_update_process_callback() { // smoothing can be enabled in the editor but will never be active - if (process_mode == CAMERA2D_PROCESS_IDLE) { + if (Engine::get_singleton()->is_editor_hint()) { + set_process_internal(false); + set_physics_process_internal(false); + } else if (process_callback == CAMERA2D_PROCESS_IDLE) { set_process_internal(smoothing_active); set_physics_process_internal(false); } else { @@ -176,7 +179,7 @@ Transform2D Camera2D::get_camera_transform() { } if (smoothing_active) { - float c = smoothing * (process_mode == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); + float c = smoothing * (process_callback == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos; ret_camera_pos = smoothed_camera_pos; } else { @@ -249,7 +252,7 @@ void Camera2D::_notification(int p_what) { canvas = get_canvas(); _setup_viewport(); - _update_process_mode(); + _update_process_callback(); // if a camera enters the tree that is set to current, // it should take over as the current camera, and mark @@ -383,17 +386,17 @@ bool Camera2D::is_rotating() const { return rotating; } -void Camera2D::set_process_mode(Camera2DProcessMode p_mode) { - if (process_mode == p_mode) { +void Camera2D::set_process_callback(Camera2DProcessMode p_mode) { + if (process_callback == p_mode) { return; } - process_mode = p_mode; - _update_process_mode(); + process_callback = p_mode; + _update_process_callback(); } -Camera2D::Camera2DProcessMode Camera2D::get_process_mode() const { - return process_mode; +Camera2D::Camera2DProcessMode Camera2D::get_process_callback() const { + return process_callback; } void Camera2D::_make_current(Object *p_which) { @@ -570,7 +573,7 @@ void Camera2D::set_enable_follow_smoothing(bool p_enabled) { smoothing_active = smoothing_enabled && !Engine::get_singleton()->is_editor_hint(); // keep the processing up to date after each change - _update_process_mode(); + _update_process_callback(); } bool Camera2D::is_follow_smoothing_enabled() const { @@ -654,8 +657,8 @@ void Camera2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll); - ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Camera2D::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &Camera2D::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &Camera2D::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &Camera2D::get_process_callback); ClassDB::bind_method(D_METHOD("_set_current", "current"), &Camera2D::_set_current); ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current); @@ -715,7 +718,7 @@ void Camera2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "_set_current", "is_current"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom"), "set_zoom", "get_zoom"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", 0), "set_custom_viewport", "get_custom_viewport"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback"); ADD_GROUP("Limit", "limit_"); ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left"), "set_limit", "get_limit", MARGIN_LEFT); @@ -775,7 +778,7 @@ Camera2D::Camera2D() { viewport = nullptr; custom_viewport = nullptr; custom_viewport_id = 0; - process_mode = CAMERA2D_PROCESS_IDLE; + process_callback = CAMERA2D_PROCESS_IDLE; smoothing = 5.0; zoom = Vector2(1, 1); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index d7c9f5ef..f85245d3 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -81,7 +81,7 @@ class Camera2D : public Node2D { bool v_offset_changed; Point2 camera_screen_center; - void _update_process_mode(); + void _update_process_callback(); void _update_scroll(); void _setup_viewport(); @@ -92,7 +92,7 @@ class Camera2D : public Node2D { bool limit_drawing_enabled; bool margin_drawing_enabled; - Camera2DProcessMode process_mode; + Camera2DProcessMode process_callback; protected: virtual Transform2D get_camera_transform(); @@ -136,8 +136,8 @@ class Camera2D : public Node2D { void set_follow_smoothing(float p_speed); float get_follow_smoothing() const; - void set_process_mode(Camera2DProcessMode p_mode); - Camera2DProcessMode get_process_mode() const; + void set_process_callback(Camera2DProcessMode p_mode); + Camera2DProcessMode get_process_callback() const; void make_current(); void clear_current(); diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 9e1cca17..e1ed28b6 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -688,16 +688,16 @@ void ClippedCamera::set_margin(float p_margin) { float ClippedCamera::get_margin() const { return margin; } -void ClippedCamera::set_process_mode(ProcessMode p_mode) { - if (process_mode == p_mode) { +void ClippedCamera::set_process_callback(ClipProcessCallback p_mode) { + if (process_callback == p_mode) { return; } - process_mode = p_mode; - set_process_internal(process_mode == CLIP_PROCESS_IDLE); - set_physics_process_internal(process_mode == CLIP_PROCESS_PHYSICS); + process_callback = p_mode; + set_process_internal(process_callback == CLIP_PROCESS_IDLE); + set_physics_process_internal(process_callback == CLIP_PROCESS_PHYSICS); } -ClippedCamera::ProcessMode ClippedCamera::get_process_mode() const { - return process_mode; +ClippedCamera::ClipProcessCallback ClippedCamera::get_process_callback() const { + return process_callback; } Transform ClippedCamera::get_camera_transform() const { @@ -844,8 +844,8 @@ void ClippedCamera::_bind_methods() { ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera::set_margin); ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera::get_margin); - ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "process_callback"), &ClippedCamera::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &ClippedCamera::get_process_callback); ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera::set_collision_mask); ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera::get_collision_mask); @@ -870,7 +870,7 @@ void ClippedCamera::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera::clear_exceptions); ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_margin", "get_margin"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); ADD_GROUP("Clip To", "clip_to"); @@ -883,7 +883,7 @@ void ClippedCamera::_bind_methods() { ClippedCamera::ClippedCamera() { margin = 0; clip_offset = 0; - process_mode = CLIP_PROCESS_PHYSICS; + process_callback = CLIP_PROCESS_PHYSICS; set_physics_process_internal(true); collision_mask = 1; set_notify_local_transform(Engine::get_singleton()->is_editor_hint()); diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 0412b536..57576f3c 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -182,13 +182,13 @@ class ClippedCamera : public Camera { GDCLASS(ClippedCamera, Camera); public: - enum ProcessMode { + enum ClipProcessCallback { CLIP_PROCESS_PHYSICS, CLIP_PROCESS_IDLE, }; private: - ProcessMode process_mode; + ClipProcessCallback process_callback; RID pyramid_shape; float margin; float clip_offset; @@ -215,8 +215,8 @@ class ClippedCamera : public Camera { void set_margin(float p_margin); float get_margin() const; - void set_process_mode(ProcessMode p_mode); - ProcessMode get_process_mode() const; + void set_process_callback(ClipProcessCallback p_mode); + ClipProcessCallback get_process_callback() const; void set_collision_mask(uint32_t p_mask); uint32_t get_collision_mask() const; @@ -236,6 +236,6 @@ class ClippedCamera : public Camera { ~ClippedCamera(); }; -VARIANT_ENUM_CAST(ClippedCamera::ProcessMode); +VARIANT_ENUM_CAST(ClippedCamera::ClipProcessCallback); #endif // CAMERA_H diff --git a/scene/3d/interpolated_camera.cpp b/scene/3d/interpolated_camera.cpp index 8c26e350..ffef722b 100644 --- a/scene/3d/interpolated_camera.cpp +++ b/scene/3d/interpolated_camera.cpp @@ -35,7 +35,7 @@ void InterpolatedCamera::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - _update_process_mode(); + _update_process_callback(); } break; case NOTIFICATION_INTERNAL_PROCESS: case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { @@ -48,7 +48,7 @@ void InterpolatedCamera::_notification(int p_what) { break; } - float delta = speed * (process_mode == INTERPOLATED_CAMERA_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); + float delta = speed * (process_callback == INTERPOLATED_CAMERA_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); Transform target_xform = node->get_global_transform(); Transform local_transform = get_global_transform(); local_transform = local_transform.interpolate_with(target_xform, delta); @@ -74,16 +74,16 @@ void InterpolatedCamera::_notification(int p_what) { } } -void InterpolatedCamera::set_process_mode(InterpolatedCameraProcessMode p_mode) { - if (process_mode == p_mode) { +void InterpolatedCamera::set_process_callback(InterpolatedCameraProcessMode p_mode) { + if (process_callback == p_mode) { return; } - process_mode = p_mode; - _update_process_mode(); + process_callback = p_mode; + _update_process_callback(); } -InterpolatedCamera::InterpolatedCameraProcessMode InterpolatedCamera::get_process_mode() const { - return process_mode; +InterpolatedCamera::InterpolatedCameraProcessMode InterpolatedCamera::get_process_callback() const { + return process_callback; } void InterpolatedCamera::_set_target(const Object *p_target) { @@ -109,14 +109,14 @@ void InterpolatedCamera::set_interpolation_enabled(bool p_enable) { return; } enabled = p_enable; - _update_process_mode(); + _update_process_callback(); } -void InterpolatedCamera::_update_process_mode() { +void InterpolatedCamera::_update_process_callback() { if (Engine::get_singleton()->is_editor_hint() || !enabled) { set_process_internal(false); set_physics_process_internal(false); - } else if (process_mode == INTERPOLATED_CAMERA_PROCESS_IDLE) { + } else if (process_callback == INTERPOLATED_CAMERA_PROCESS_IDLE) { set_process_internal(true); set_physics_process_internal(false); } else { @@ -148,13 +148,13 @@ void InterpolatedCamera::_bind_methods() { ClassDB::bind_method(D_METHOD("set_interpolation_enabled", "target_path"), &InterpolatedCamera::set_interpolation_enabled); ClassDB::bind_method(D_METHOD("is_interpolation_enabled"), &InterpolatedCamera::is_interpolation_enabled); - ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &InterpolatedCamera::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &InterpolatedCamera::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &InterpolatedCamera::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &InterpolatedCamera::get_process_callback); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target"), "set_target_path", "get_target_path"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed"), "set_speed", "get_speed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_interpolation_enabled", "is_interpolation_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback"); BIND_ENUM_CONSTANT(INTERPOLATED_CAMERA_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(INTERPOLATED_CAMERA_PROCESS_IDLE); @@ -163,5 +163,5 @@ void InterpolatedCamera::_bind_methods() { InterpolatedCamera::InterpolatedCamera() { enabled = false; speed = 1; - process_mode = INTERPOLATED_CAMERA_PROCESS_IDLE; + process_callback = INTERPOLATED_CAMERA_PROCESS_IDLE; } diff --git a/scene/3d/interpolated_camera.h b/scene/3d/interpolated_camera.h index 95731414..2ca0c045 100644 --- a/scene/3d/interpolated_camera.h +++ b/scene/3d/interpolated_camera.h @@ -46,9 +46,9 @@ class InterpolatedCamera : public Camera { bool enabled; real_t speed; NodePath target; - InterpolatedCameraProcessMode process_mode; + InterpolatedCameraProcessMode process_callback; - void _update_process_mode(); + void _update_process_callback(); protected: void _notification(int p_what); @@ -66,8 +66,8 @@ class InterpolatedCamera : public Camera { void set_interpolation_enabled(bool p_enable); bool is_interpolation_enabled() const; - void set_process_mode(InterpolatedCameraProcessMode p_mode); - InterpolatedCameraProcessMode get_process_mode() const; + void set_process_callback(InterpolatedCameraProcessMode p_mode); + InterpolatedCameraProcessMode get_process_callback() const; InterpolatedCamera(); }; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index f96eb653..c379d1f0 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; } @@ -1420,8 +1420,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; } @@ -1429,14 +1429,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) { @@ -1452,7 +1452,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; @@ -1656,8 +1656,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); @@ -1677,7 +1677,7 @@ void AnimationPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "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::REAL, "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::REAL, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale"); @@ -1705,7 +1705,7 @@ AnimationPlayer::AnimationPlayer() { end_reached = false; end_notify = false; reset_on_save = true; - animation_process_mode = ANIMATION_PROCESS_IDLE; + process_callback = ANIMATION_PROCESS_IDLE; method_call_mode = ANIMATION_METHOD_CALL_DEFERRED; processing = false; default_blend_time = 0; diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 0009e2fa..c5c5dbc3 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, @@ -243,7 +243,7 @@ class AnimationPlayer : public Node { String autoplay; bool reset_on_save; - AnimationProcessMode animation_process_mode; + AnimationProcessCallback process_callback; AnimationMethodCallMode method_call_mode; bool processing; bool active; @@ -334,8 +334,8 @@ class AnimationPlayer : public Node { 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; @@ -364,7 +364,7 @@ class AnimationPlayer : public Node { ~AnimationPlayer(); }; -VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessMode); +VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback); VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode); #endif // ANIMATION_PLAYER_H diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 095cd9ff..8861b21c 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -478,7 +478,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); @@ -499,8 +499,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; } @@ -509,15 +509,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) { @@ -1244,11 +1244,11 @@ void AnimationTree::advance(float p_time) { void AnimationTree::_notification(int p_what) { if (active && OS::get_singleton()->is_update_pending()) { - if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) { + if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_callback == ANIMATION_PROCESS_PHYSICS) { _process_graph(get_physics_process_delta_time()); } - if (p_what == NOTIFICATION_INTERNAL_PROCESS && process_mode == ANIMATION_PROCESS_IDLE) { + if (p_what == NOTIFICATION_INTERNAL_PROCESS && process_callback == ANIMATION_PROCESS_IDLE) { _process_graph(get_process_delta_time()); } } @@ -1492,8 +1492,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); @@ -1516,7 +1516,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"); @@ -1526,7 +1526,7 @@ void AnimationTree::_bind_methods() { } AnimationTree::AnimationTree() { - process_mode = ANIMATION_PROCESS_IDLE; + process_callback = ANIMATION_PROCESS_IDLE; active = false; cache_valid = false; setup_pass = 1; diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index a60cc064..f5ead15c 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -158,7 +158,7 @@ class AnimationTree : public Node { GDCLASS(AnimationTree, Node); public: - enum AnimationProcessMode { + enum AnimationProcessCallback { ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_IDLE, ANIMATION_PROCESS_MANUAL, @@ -246,7 +246,7 @@ class AnimationTree : public Node { Ref root; - AnimationProcessMode process_mode; + AnimationProcessCallback process_callback; bool active; NodePath animation_player; @@ -301,8 +301,8 @@ class AnimationTree : public Node { 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; @@ -327,6 +327,6 @@ class AnimationTree : public Node { ~AnimationTree(); }; -VARIANT_ENUM_CAST(AnimationTree::AnimationProcessMode) +VARIANT_ENUM_CAST(AnimationTree::AnimationProcessCallback) #endif // ANIMATION_TREE_H diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index b45472ee..e99d825b 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -34,8 +34,8 @@ #include "core/os/os.h" #include "scene/scene_string_names.h" -void AnimationTreePlayer::set_animation_process_mode(AnimationProcessMode p_mode) { - if (animation_process_mode == p_mode) { +void AnimationTreePlayer::set_process_callback(AnimationProcessCallback p_mode) { + if (process_callback == p_mode) { return; } @@ -43,14 +43,14 @@ void AnimationTreePlayer::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); } } -AnimationTreePlayer::AnimationProcessMode AnimationTreePlayer::get_animation_process_mode() const { - return animation_process_mode; +AnimationTreePlayer::AnimationProcessCallback AnimationTreePlayer::get_process_callback() const { + return process_callback; } void AnimationTreePlayer::_set_process(bool p_process, bool p_force) { @@ -58,7 +58,7 @@ void AnimationTreePlayer::_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; @@ -430,7 +430,7 @@ void AnimationTreePlayer::_notification(int p_what) { } } break; case NOTIFICATION_INTERNAL_PROCESS: { - if (animation_process_mode == ANIMATION_PROCESS_PHYSICS) { + if (process_callback == ANIMATION_PROCESS_PHYSICS) { break; } @@ -439,7 +439,7 @@ void AnimationTreePlayer::_notification(int p_what) { } } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (animation_process_mode == ANIMATION_PROCESS_IDLE) { + if (process_callback == ANIMATION_PROCESS_IDLE) { break; } @@ -1729,8 +1729,8 @@ void AnimationTreePlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_node_list"), &AnimationTreePlayer::_get_node_list); - ClassDB::bind_method(D_METHOD("set_animation_process_mode", "mode"), &AnimationTreePlayer::set_animation_process_mode); - ClassDB::bind_method(D_METHOD("get_animation_process_mode"), &AnimationTreePlayer::get_animation_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &AnimationTreePlayer::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &AnimationTreePlayer::get_process_callback); ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTreePlayer::advance); @@ -1739,7 +1739,7 @@ void AnimationTreePlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("recompute_caches"), &AnimationTreePlayer::recompute_caches); ADD_GROUP("Playback", "playback_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_animation_process_mode", "get_animation_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "master_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_master_player", "get_master_player"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "base_path"), "set_base_path", "get_base_path"); @@ -1766,7 +1766,7 @@ AnimationTreePlayer::AnimationTreePlayer() { out_name = "out"; out->pos = Point2(40, 40); node_map.insert(out_name, out); - animation_process_mode = ANIMATION_PROCESS_IDLE; + process_callback = ANIMATION_PROCESS_IDLE; processing = false; active = false; dirty_caches = true; diff --git a/scene/animation/animation_tree_player.h b/scene/animation/animation_tree_player.h index b4abf55c..05525163 100644 --- a/scene/animation/animation_tree_player.h +++ b/scene/animation/animation_tree_player.h @@ -41,7 +41,7 @@ class AnimationTreePlayer : public Node { OBJ_CATEGORY("Animation Nodes"); public: - enum AnimationProcessMode { + enum AnimationProcessCallback { ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_IDLE, }; @@ -300,7 +300,7 @@ class AnimationTreePlayer : public Node { ConnectError last_error; AnimationNode *active_list; - AnimationProcessMode animation_process_mode; + AnimationProcessCallback process_callback; bool processing; bool active; bool dirty_caches; @@ -455,8 +455,8 @@ class AnimationTreePlayer : public Node { ConnectError get_last_error() 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_process(bool p_process, bool p_force = false); @@ -467,6 +467,6 @@ class AnimationTreePlayer : public Node { }; VARIANT_ENUM_CAST(AnimationTreePlayer::NodeType); -VARIANT_ENUM_CAST(AnimationTreePlayer::AnimationProcessMode); +VARIANT_ENUM_CAST(AnimationTreePlayer::AnimationProcessCallback); #endif // ANIMATION_TREE_PLAYER_H diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp index 24b944f6..f5077fc9 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(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); } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0b992fbd..6eb1c533 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -29,6 +29,7 @@ /**************************************************************************/ #include "node.h" +#include "editor/editor_node.h" #include "core/core_string_names.h" #include "core/io/resource_loader.h" @@ -44,7 +45,7 @@ #include "editor/editor_settings.h" #endif -VARIANT_ENUM_CAST(Node::PauseMode); +VARIANT_ENUM_CAST(Node::ProcessMode); VARIANT_ENUM_CAST(Node::PhysicsInterpolationMode); int Node::orphan_node_count = 0; @@ -70,22 +71,14 @@ void Node::_notification(int p_notification) { ERR_FAIL_COND(!get_viewport()); ERR_FAIL_COND(!get_tree()); - if (data.pause_mode == PAUSE_MODE_INHERIT) { + if (data.process_mode == PROCESS_MODE_INHERIT) { if (data.parent) { - data.pause_owner = data.parent->data.pause_owner; + data.process_owner = data.parent->data.process_owner; } else { - data.pause_owner = nullptr; + data.process_owner = nullptr; } } else { - data.pause_owner = this; - } - - if (data.physics_interpolation_mode == PHYSICS_INTERPOLATION_MODE_INHERIT) { - bool interpolate = true; // Root node default is for interpolation to be on - if (data.parent) { - interpolate = data.parent->is_physics_interpolated(); - } - _propagate_physics_interpolated(interpolate); + data.process_owner = this; } if (data.input) { @@ -119,7 +112,7 @@ void Node::_notification(int p_notification) { remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); } - data.pause_owner = nullptr; + data.process_owner = nullptr; if (data.path_cache) { memdelete(data.path_cache); data.path_cache = nullptr; @@ -503,44 +496,85 @@ bool Node::is_physics_processing_internal() const { return data.physics_process_internal; } -void Node::set_pause_mode(PauseMode p_mode) { - if (data.pause_mode == p_mode) { - return; - } +void Node::set_process_mode(ProcessMode p_mode) { + //if (data.process_mode == p_mode) { + // return; + //} - bool prev_inherits = data.pause_mode == PAUSE_MODE_INHERIT; - data.pause_mode = p_mode; if (!is_inside_tree()) { - return; //pointless - } - if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits) { - return; ///nothing changed + data.process_mode = p_mode; + return; } - Node *owner = nullptr; + bool prev_can_process = can_process(); + + data.process_mode = p_mode; - if (data.pause_mode == PAUSE_MODE_INHERIT) { + if (data.process_mode == PROCESS_MODE_INHERIT) { if (data.parent) { - owner = data.parent->data.pause_owner; + data.process_owner = data.parent->data.owner; + } else { + data.process_owner = nullptr; } } else { - owner = this; + data.process_owner = this; + } + + bool next_can_process = can_process(); + + int pause_notification = 0; + + if (prev_can_process && !next_can_process) { + pause_notification = NOTIFICATION_PAUSED; + } else if (!prev_can_process && next_can_process) { + pause_notification = NOTIFICATION_UNPAUSED; } - _propagate_pause_owner(owner); + _propagate_process_owner(data.process_owner, pause_notification); + +#ifdef TOOLS_ENABLED + // This is required for the editor to update the visibility of disabled nodes + // Its very expensive during runtime to change, so editor-only + if (Engine::get_singleton()->is_editor_hint()) { + // VALLA EDITS: TODO: This is currently broken. commented till i know how to fix. + //get_tree()->emit_signal("tree_process_mode_changed"); + // test this as a temp bandaid. + get_tree()->emit_signal("tree_changed"); + } +#endif } -Node::PauseMode Node::get_pause_mode() const { - return data.pause_mode; +void Node::_propagate_pause_notification(bool p_enable) { + bool prev_can_process = _can_process(!p_enable); + bool next_can_process = _can_process(p_enable); + + if (prev_can_process && !next_can_process) { + notification(NOTIFICATION_PAUSED); + } else if (!prev_can_process && next_can_process) { + notification(NOTIFICATION_UNPAUSED); + } + + for (int i = 0; i < data.children.size(); i++) { + data.children[i]->_propagate_pause_notification(p_enable); + } } -void Node::_propagate_pause_owner(Node *p_owner) { - if (this != p_owner && data.pause_mode != PAUSE_MODE_INHERIT) { - return; +Node::ProcessMode Node::get_process_mode() const { + return data.process_mode; +} + +void Node::_propagate_process_owner(Node *p_owner, int p_notification) { + data.process_owner = p_owner; + + if (p_notification != 0) { + notification(p_notification); } - data.pause_owner = p_owner; + for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_pause_owner(p_owner); + Node *c = data.children[i]; + if (c->data.process_mode == PROCESS_MODE_INHERIT) { + c->_propagate_process_owner(p_owner, p_notification); + } } } @@ -815,30 +849,33 @@ bool Node::can_process_notification(int p_what) const { bool Node::can_process() const { ERR_FAIL_COND_V(!is_inside_tree(), false); + return _can_process(get_tree()->is_paused()); +} - if (get_tree()->is_paused()) { - if (data.pause_mode == PAUSE_MODE_STOP) { - return false; - } - if (data.pause_mode == PAUSE_MODE_PROCESS) { - return true; - } - if (data.pause_mode == PAUSE_MODE_INHERIT) { - if (!data.pause_owner) { - return false; //clearly no pause owner by default - } - - if (data.pause_owner->data.pause_mode == PAUSE_MODE_PROCESS) { - return true; - } +bool Node::_can_process(bool p_paused) const { + ProcessMode process_mode; - if (data.pause_owner->data.pause_mode == PAUSE_MODE_STOP) { - return false; - } + if (data.process_mode == PROCESS_MODE_INHERIT) { + if (!data.process_owner) { + process_mode = PROCESS_MODE_PAUSABLE; + } else { + process_mode = data.process_owner->data.process_mode; } + } else { + process_mode = data.process_mode; } - return true; + if (process_mode == PROCESS_MODE_DISABLED) { + return false; + } else if (process_mode == PROCESS_MODE_ALWAYS) { + return true; + } + + if (p_paused) { + return process_mode == PROCESS_MODE_WHEN_PAUSED; + } else { + return process_mode == PROCESS_MODE_PAUSABLE; + } } void Node::set_physics_interpolation_mode(PhysicsInterpolationMode p_mode) { @@ -2037,6 +2074,7 @@ String Node::get_editor_description() const { } else { return ""; } + return data.editor_description; } void Node::set_editable_instance(Node *p_node, bool p_editable) { @@ -3036,8 +3074,8 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("is_processing_unhandled_input"), &Node::is_processing_unhandled_input); ClassDB::bind_method(D_METHOD("set_process_unhandled_key_input", "enable"), &Node::set_process_unhandled_key_input); ClassDB::bind_method(D_METHOD("is_processing_unhandled_key_input"), &Node::is_processing_unhandled_key_input); - ClassDB::bind_method(D_METHOD("set_pause_mode", "mode"), &Node::set_pause_mode); - ClassDB::bind_method(D_METHOD("get_pause_mode"), &Node::get_pause_mode); + ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Node::set_process_mode); + ClassDB::bind_method(D_METHOD("get_process_mode"), &Node::get_process_mode); ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process); ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes); ClassDB::bind_method(D_METHOD("get_position_in_parent"), &Node::get_position_in_parent); @@ -3083,9 +3121,12 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("rpc_config", "method", "mode"), &Node::rpc_config); ClassDB::bind_method(D_METHOD("rset_config", "property", "mode"), &Node::rset_config); - ClassDB::bind_method(D_METHOD("_set_editor_description", "editor_description"), &Node::set_editor_description); - ClassDB::bind_method(D_METHOD("_get_editor_description"), &Node::get_editor_description); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_editor_description", "_get_editor_description"); + //ClassDB::bind_method(D_METHOD("_set_editor_description", "editor_description"), &Node::set_editor_description); + //ClassDB::bind_method(D_METHOD("_get_editor_description"), &Node::get_editor_description); + //ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_editor_description", "_get_editor_description"); + + ClassDB::bind_method(D_METHOD("set_editor_description", "editor_description"), &Node::set_editor_description); + ClassDB::bind_method(D_METHOD("get_editor_description"), &Node::get_editor_description); ClassDB::bind_method(D_METHOD("_set_import_path", "import_path"), &Node::set_import_path); ClassDB::bind_method(D_METHOD("_get_import_path"), &Node::get_import_path); @@ -3156,9 +3197,11 @@ void Node::_bind_methods() { BIND_CONSTANT(NOTIFICATION_APP_RESUMED); BIND_CONSTANT(NOTIFICATION_APP_PAUSED); - BIND_ENUM_CONSTANT(PAUSE_MODE_INHERIT); - BIND_ENUM_CONSTANT(PAUSE_MODE_STOP); - BIND_ENUM_CONSTANT(PAUSE_MODE_PROCESS); + BIND_ENUM_CONSTANT(PROCESS_MODE_INHERIT); + BIND_ENUM_CONSTANT(PROCESS_MODE_PAUSABLE); + BIND_ENUM_CONSTANT(PROCESS_MODE_WHEN_PAUSED); + BIND_ENUM_CONSTANT(PROCESS_MODE_ALWAYS); + BIND_ENUM_CONSTANT(PROCESS_MODE_DISABLED); BIND_ENUM_CONSTANT(PHYSICS_INTERPOLATION_MODE_INHERIT); BIND_ENUM_CONSTANT(PHYSICS_INTERPOLATION_MODE_OFF); @@ -3177,9 +3220,7 @@ void Node::_bind_methods() { ADD_SIGNAL(MethodInfo("child_entered_tree", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Node"))); ADD_SIGNAL(MethodInfo("child_exiting_tree", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Node"))); - ADD_PROPERTY(PropertyInfo(Variant::INT, "pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), "set_pause_mode", "get_pause_mode"); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_interpolation_mode", PROPERTY_HINT_ENUM, "Inherit,Off,On"), "set_physics_interpolation_mode", "get_physics_interpolation_mode"); + //ADD_PROPERTY(PropertyInfo(Variant::INT, "pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), "set_process_mode", "get_process_mode"); #ifdef ENABLE_DEPRECATED //no longer exists, but remains for compatibility (keep previous scenes folded @@ -3192,8 +3233,15 @@ void Node::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_owner", "get_owner"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "", "get_multiplayer"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "set_custom_multiplayer", "get_custom_multiplayer"); + + ADD_GROUP("Process", "process_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_interpolation_mode", PROPERTY_HINT_ENUM, "Inherit,Off,On"), "set_physics_interpolation_mode", "get_physics_interpolation_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Inherit,Pausable,WhenPaused,Always,Disabled"), "set_process_mode", "get_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_priority"), "set_process_priority", "get_process_priority"); + ADD_GROUP("Editor Description", "editor_"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "set_editor_description", "get_editor_description"); + BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta"))); BIND_VMETHOD(MethodInfo("_physics_process", PropertyInfo(Variant::REAL, "delta"))); BIND_VMETHOD(MethodInfo("_enter_tree")); @@ -3242,9 +3290,9 @@ Node::Node() { data.input = false; data.unhandled_input = false; data.unhandled_key_input = false; - data.pause_mode = PAUSE_MODE_INHERIT; + data.process_mode = PROCESS_MODE_INHERIT; data.physics_interpolation_mode = PHYSICS_INTERPOLATION_MODE_INHERIT; - data.pause_owner = nullptr; + data.process_owner = nullptr; data.network_master = 1; //server by default data.path_cache = nullptr; data.parent_owned = false; diff --git a/scene/main/node.h b/scene/main/node.h index d9b69412..3f7b7529 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -52,11 +52,12 @@ class Node : public Object { // be specified as UNSIGNED to work around // some compilers trying to store it as signed, // and requiring 1 more bit than necessary. - enum PauseMode : unsigned int { - - PAUSE_MODE_INHERIT, - PAUSE_MODE_STOP, - PAUSE_MODE_PROCESS + enum ProcessMode { + PROCESS_MODE_INHERIT, // same as parent node + PROCESS_MODE_PAUSABLE, // process only if not paused + PROCESS_MODE_WHEN_PAUSED, // process only if paused + PROCESS_MODE_ALWAYS, // process always + PROCESS_MODE_DISABLED, // never process }; enum PhysicsInterpolationMode : unsigned int { @@ -119,6 +120,7 @@ class Node : public Object { #ifdef TOOLS_ENABLED NodePath import_path; //path used when imported, used by scene editors to keep tracking #endif + String editor_description; Viewport *viewport; @@ -126,6 +128,9 @@ class Node : public Object { List::Element *OW; // owned element List owned; + ProcessMode process_mode;// = PROCESS_MODE_INHERIT; + Node *process_owner = nullptr; + Node *pause_owner; int network_master; @@ -135,7 +140,7 @@ class Node : public Object { int process_priority; // Keep bitpacked values together to get better packing - PauseMode pause_mode : 2; + //ProcessMode pause_mode : 2; PhysicsInterpolationMode physics_interpolation_mode : 2; // variables used to properly sort the node when processing, ignored otherwise @@ -206,7 +211,7 @@ class Node : public Object { void _propagate_physics_interpolated(bool p_interpolated); void _propagate_physics_interpolation_reset_requested(); void _print_stray_nodes(); - void _propagate_pause_owner(Node *p_owner); + void _propagate_process_owner(Node *p_owner, int p_notification); Array _get_node_and_resource(const NodePath &p_path); void _duplicate_signals(const Node *p_original, Node *p_copy) const; @@ -224,6 +229,9 @@ class Node : public Object { friend class SceneTree; void _set_tree(SceneTree *p_tree); + void _propagate_pause_notification(bool p_enable); + _FORCE_INLINE_ bool _can_process(bool p_paused) const; + void _release_unique_name_in_owner(); void _acquire_unique_name_in_owner(); @@ -440,8 +448,8 @@ class Node : public Object { void replace_by(Node *p_node, bool p_keep_data = false); - void set_pause_mode(PauseMode p_mode); - PauseMode get_pause_mode() const; + void set_process_mode(ProcessMode p_mode); + ProcessMode get_process_mode() const; bool can_process() const; bool can_process_notification(int p_what) const; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index ec64272d..a95d2adf 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1020,7 +1020,10 @@ void SceneTree::set_pause(bool p_enabled) { PhysicsServer::get_singleton()->set_active(!p_enabled); Physics2DServer::get_singleton()->set_active(!p_enabled); if (get_root()) { - get_root()->propagate_notification(p_enabled ? Node::NOTIFICATION_PAUSED : Node::NOTIFICATION_UNPAUSED); + + // VALLA EDITS: 2nd line here is the correct one but it's crashing :/ + //get_root()->propagate_notification(p_enabled ? Node::NOTIFICATION_PAUSED : Node::NOTIFICATION_UNPAUSED); + get_root()->_propagate_pause_notification(p_enabled); } } @@ -2077,6 +2080,7 @@ void SceneTree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_interpolation"), "set_physics_interpolation_enabled", "is_physics_interpolation_enabled"); ADD_SIGNAL(MethodInfo("tree_changed")); + ADD_SIGNAL(MethodInfo("tree_process_mode_changed")); //editor only signal, but due to API hash it cant be removed in run-time ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("node_renamed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));