Skip to content

Commit

Permalink
Refactor Process Mode
Browse files Browse the repository at this point in the history
Implements godotengine/godot-proposals#1835 (comment)

* 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.
  • Loading branch information
reduz committed Feb 18, 2021
1 parent 247b7e2 commit 083aa9b
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 141 deletions.
4 changes: 4 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,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 && RS::get_singleton()->is_low_end()) {
continue; //do not show this property in low end gfx
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/gpu_particles_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void GPUParticles2DEditorPlugin::_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();
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/gpu_particles_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void GPUParticles3DEditor::_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 CPUParticles3D"));
Expand Down
9 changes: 9 additions & 0 deletions editor/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,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_theme_color("accent_color", "Editor"));
} else if (!p_node->can_process()) {
item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
} else if (!marked_selectable && !marked_children_selectable) {
Node *node = p_node;
while (node) {
Expand Down Expand Up @@ -585,6 +587,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
Expand Down Expand Up @@ -655,6 +662,7 @@ void SceneTreeEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
get_tree()->connect("tree_changed", callable_mp(this, &SceneTreeEditor::_tree_changed));
get_tree()->connect("tree_process_mode_changed", callable_mp(this, &SceneTreeEditor::_tree_process_mode_changed));
get_tree()->connect("node_removed", callable_mp(this, &SceneTreeEditor::_node_removed));
get_tree()->connect("node_renamed", callable_mp(this, &SceneTreeEditor::_node_renamed));
get_tree()->connect("node_configuration_warning_changed", callable_mp(this, &SceneTreeEditor::_warning_changed));
Expand All @@ -665,6 +673,7 @@ void SceneTreeEditor::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
get_tree()->disconnect("tree_changed", callable_mp(this, &SceneTreeEditor::_tree_changed));
get_tree()->disconnect("tree_process_mode_changed", callable_mp(this, &SceneTreeEditor::_tree_process_mode_changed));
get_tree()->disconnect("node_removed", callable_mp(this, &SceneTreeEditor::_node_removed));
get_tree()->disconnect("node_renamed", callable_mp(this, &SceneTreeEditor::_node_renamed));
tree->disconnect("item_collapsed", callable_mp(this, &SceneTreeEditor::_cell_collapsed));
Expand Down
1 change: 1 addition & 0 deletions editor/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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);

Expand Down
26 changes: 13 additions & 13 deletions scene/2d/camera_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ void Camera2D::_update_scroll() {
};
}

void Camera2D::_update_process_mode() {
void Camera2D::_update_process_callback() {
if (Engine::get_singleton()->is_editor_hint()) {
set_process_internal(false);
set_physics_process_internal(false);
} else if (process_mode == CAMERA2D_PROCESS_IDLE) {
} else if (process_callback == CAMERA2D_PROCESS_IDLE) {
set_process_internal(true);
set_physics_process_internal(false);
} else {
Expand Down Expand Up @@ -157,7 +157,7 @@ Transform2D Camera2D::get_camera_transform() {
}

if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) {
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;
//camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
Expand Down Expand Up @@ -247,7 +247,7 @@ void Camera2D::_notification(int p_what) {
add_to_group(group_name);
add_to_group(canvas_group_name);

_update_process_mode();
_update_process_callback();
_update_scroll();
first = true;

Expand Down Expand Up @@ -375,17 +375,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(Camera2DProcessCallback 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::Camera2DProcessCallback Camera2D::get_process_callback() const {
return process_callback;
}

void Camera2D::_make_current(Object *p_which) {
Expand Down Expand Up @@ -651,8 +651,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);
Expand Down Expand Up @@ -714,7 +714,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", SIDE_LEFT);
Expand Down
12 changes: 6 additions & 6 deletions scene/2d/camera_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Camera2D : public Node2D {
ANCHOR_MODE_DRAG_CENTER
};

enum Camera2DProcessMode {
enum Camera2DProcessCallback {
CAMERA2D_PROCESS_PHYSICS,
CAMERA2D_PROCESS_IDLE
};
Expand Down Expand Up @@ -79,7 +79,7 @@ class Camera2D : public Node2D {
bool drag_vertical_offset_changed = false;

Point2 camera_screen_center;
void _update_process_mode();
void _update_process_callback();
void _update_scroll();

void _make_current(Object *p_which);
Expand All @@ -91,7 +91,7 @@ class Camera2D : public Node2D {
bool limit_drawing_enabled = false;
bool margin_drawing_enabled = false;

Camera2DProcessMode process_mode = CAMERA2D_PROCESS_IDLE;
Camera2DProcessCallback process_callback = CAMERA2D_PROCESS_IDLE;

Size2 _get_camera_screen_size() const;

Expand Down Expand Up @@ -137,8 +137,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(Camera2DProcessCallback p_mode);
Camera2DProcessCallback get_process_callback() const;

void make_current();
void clear_current();
Expand Down Expand Up @@ -170,6 +170,6 @@ class Camera2D : public Node2D {
};

VARIANT_ENUM_CAST(Camera2D::AnchorMode);
VARIANT_ENUM_CAST(Camera2D::Camera2DProcessMode);
VARIANT_ENUM_CAST(Camera2D::Camera2DProcessCallback);

#endif // CAMERA_2D_H
20 changes: 10 additions & 10 deletions scene/3d/camera_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,17 +673,17 @@ float ClippedCamera3D::get_margin() const {
return margin;
}

void ClippedCamera3D::set_process_mode(ProcessMode p_mode) {
if (process_mode == p_mode) {
void ClippedCamera3D::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);
}

ClippedCamera3D::ProcessMode ClippedCamera3D::get_process_mode() const {
return process_mode;
ClippedCamera3D::ClipProcessCallback ClippedCamera3D::get_process_callback() const {
return process_callback;
}

Transform ClippedCamera3D::get_camera_transform() const {
Expand Down Expand Up @@ -828,8 +828,8 @@ void ClippedCamera3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera3D::set_margin);
ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera3D::get_margin);

ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera3D::set_process_mode);
ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera3D::get_process_mode);
ClassDB::bind_method(D_METHOD("set_process_callback", "process_callback"), &ClippedCamera3D::set_process_callback);
ClassDB::bind_method(D_METHOD("get_process_callback"), &ClippedCamera3D::get_process_callback);

ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera3D::set_collision_mask);
ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera3D::get_collision_mask);
Expand All @@ -854,7 +854,7 @@ void ClippedCamera3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera3D::clear_exceptions);

ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "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");
Expand Down
10 changes: 5 additions & 5 deletions scene/3d/camera_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ class ClippedCamera3D : public Camera3D {
GDCLASS(ClippedCamera3D, Camera3D);

public:
enum ProcessMode {
enum ClipProcessCallback {
CLIP_PROCESS_PHYSICS,
CLIP_PROCESS_IDLE,
};

private:
ProcessMode process_mode = CLIP_PROCESS_PHYSICS;
ClipProcessCallback process_callback = CLIP_PROCESS_PHYSICS;
RID pyramid_shape;
float margin = 0.0;
float clip_offset = 0.0;
Expand All @@ -219,8 +219,8 @@ class ClippedCamera3D : public Camera3D {
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;
Expand All @@ -240,5 +240,5 @@ class ClippedCamera3D : public Camera3D {
~ClippedCamera3D();
};

VARIANT_ENUM_CAST(ClippedCamera3D::ProcessMode);
VARIANT_ENUM_CAST(ClippedCamera3D::ClipProcessCallback);
#endif
22 changes: 11 additions & 11 deletions scene/animation/animation_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -1403,23 +1403,23 @@ 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;
}

bool pr = processing;
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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions scene/animation/animation_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -206,7 +206,7 @@ class AnimationPlayer : public Node {

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;
Expand Down Expand Up @@ -298,8 +298,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;
Expand Down Expand Up @@ -328,7 +328,7 @@ class AnimationPlayer : public Node {
~AnimationPlayer();
};

VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessMode);
VARIANT_ENUM_CAST(AnimationPlayer::AnimationProcessCallback);
VARIANT_ENUM_CAST(AnimationPlayer::AnimationMethodCallMode);

#endif
Loading

0 comments on commit 083aa9b

Please sign in to comment.