Skip to content

Commit

Permalink
Refactor Process Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Valla-Chan committed Nov 2, 2023
1 parent e85e3aa commit 6dcb3a6
Show file tree
Hide file tree
Showing 21 changed files with 264 additions and 187 deletions.
4 changes: 4 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/particles_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/particles_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
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 @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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");
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 @@ -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);

Expand Down
33 changes: 18 additions & 15 deletions scene/2d/camera_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions scene/2d/camera_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 11 additions & 11 deletions scene/3d/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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());
Expand Down
10 changes: 5 additions & 5 deletions scene/3d/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -236,6 +236,6 @@ class ClippedCamera : public Camera {
~ClippedCamera();
};

VARIANT_ENUM_CAST(ClippedCamera::ProcessMode);
VARIANT_ENUM_CAST(ClippedCamera::ClipProcessCallback);

#endif // CAMERA_H
30 changes: 15 additions & 15 deletions scene/3d/interpolated_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions scene/3d/interpolated_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
};
Expand Down
Loading

0 comments on commit 6dcb3a6

Please sign in to comment.