Editor separate physics fallback

This commit is contained in:
Jayden Sipe 2024-10-21 21:27:58 -04:00
parent b3bcb2dc14
commit be0ad401bb
4 changed files with 54 additions and 30 deletions

View file

@ -1504,8 +1504,10 @@ ProjectSettings::ProjectSettings() {
// Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
GLOBAL_DEF_RST("physics/2d/run_on_separate_thread", false);
GLOBAL_DEF_RST("physics/2d/run_on_separate_thread.editor", false);
GLOBAL_DEF_RST("physics/3d/run_on_separate_thread", false);
GLOBAL_DEF_RST("physics/3d/run_on_separate_thread.editor", false);
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled");
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep");

View file

@ -2224,6 +2224,9 @@
<member name="physics/2d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
If [code]true[/code], the 2D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 2D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process.
</member>
<member name="physics/2d/run_on_separate_thread.editor" type="bool" setter="" getter="" default="false">
Editor override for [member physics/2d/run_on_separate_thread] to specify whether the editor's 2D physics server should run on a separate thread or not.
</member>
<member name="physics/2d/sleep_threshold_angular" type="float" setter="" getter="" default="0.139626">
Threshold angular velocity under which a 2D physics body will be considered inactive. See [constant PhysicsServer2D.SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD].
</member>
@ -2303,6 +2306,9 @@
<member name="physics/3d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
If [code]true[/code], the 3D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 3D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process.
</member>
<member name="physics/3d/run_on_separate_thread.editor" type="bool" setter="" getter="" default="false">
Editor override for [member physics/3d/run_on_separate_thread] to specify whether the editor's 3D physics server should run on a separate thread or not.
</member>
<member name="physics/3d/sleep_threshold_angular" type="float" setter="" getter="" default="0.139626">
Threshold angular velocity under which a 3D physics body will be considered inactive. See [constant PhysicsServer3D.SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD].
</member>

View file

@ -917,6 +917,38 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, Vector<_RayRe
r_results.sort();
}
void Node3DEditorViewport::_reposition_selected_nodes() {
if (collision_reposition) {
List<Node *> &selection = editor_selection->get_selected_node_list();
if (selection.size() == 1) {
Node3D *first_selected_node = Object::cast_to<Node3D>(selection.front()->get());
double snap = EDITOR_GET("interface/inspector/default_float_step");
int snap_step_decimals = Math::range_step_decimals(snap);
set_message(TTR("Translating:") + " (" + String::num(first_selected_node->get_global_position().x, snap_step_decimals) + ", " +
String::num(first_selected_node->get_global_position().y, snap_step_decimals) + ", " + String::num(first_selected_node->get_global_position().z, snap_step_decimals) + ")");
first_selected_node->set_global_position(spatial_editor->snap_point(_get_instance_position(_edit.mouse_pos, first_selected_node)));
}
}
if (!update_preview_node) {
return;
}
if (preview_node->is_inside_tree()) {
preview_node_pos = spatial_editor->snap_point(_get_instance_position(preview_node_viewport_pos, preview_node));
double snap = EDITOR_GET("interface/inspector/default_float_step");
int snap_step_decimals = Math::range_step_decimals(snap);
set_message(TTR("Instantiating:") + " (" + String::num(preview_node_pos.x, snap_step_decimals) + ", " +
String::num(preview_node_pos.y, snap_step_decimals) + ", " + String::num(preview_node_pos.z, snap_step_decimals) + ")");
Transform3D preview_gl_transform = Transform3D(Basis(), preview_node_pos);
preview_node->set_global_transform(preview_gl_transform);
if (!preview_node->is_visible()) {
preview_node->show();
}
}
update_preview_node = false;
}
Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) {
Projection cm;
if (orthogonal) {
@ -2850,6 +2882,8 @@ void Node3DEditorViewport::_project_settings_changed() {
const float texture_mipmap_bias = GLOBAL_GET("rendering/textures/default_filters/texture_mipmap_bias");
viewport->set_texture_mipmap_bias(texture_mipmap_bias);
is_3d_editor_using_separate_physics_thread = GLOBAL_GET("physics/3d/run_on_separate_thread");
}
void Node3DEditorViewport::_notification(int p_what) {
@ -3082,38 +3116,16 @@ void Node3DEditorViewport::_notification(int p_what) {
float locked_half_width = locked_label->get_size().width / 2.0f;
locked_label->set_anchor_and_offset(SIDE_LEFT, 0.5f, -locked_half_width);
}
if (!is_3d_editor_using_separate_physics_thread) {
_reposition_selected_nodes();
}
} break;
case NOTIFICATION_PHYSICS_PROCESS: {
if (collision_reposition) {
List<Node *> &selection = editor_selection->get_selected_node_list();
if (selection.size() == 1) {
Node3D *first_selected_node = Object::cast_to<Node3D>(selection.front()->get());
double snap = EDITOR_GET("interface/inspector/default_float_step");
int snap_step_decimals = Math::range_step_decimals(snap);
set_message(TTR("Translating:") + " (" + String::num(first_selected_node->get_global_position().x, snap_step_decimals) + ", " +
String::num(first_selected_node->get_global_position().y, snap_step_decimals) + ", " + String::num(first_selected_node->get_global_position().z, snap_step_decimals) + ")");
first_selected_node->set_global_position(spatial_editor->snap_point(_get_instance_position(_edit.mouse_pos, first_selected_node)));
if (is_3d_editor_using_separate_physics_thread) {
_reposition_selected_nodes();
}
}
if (!update_preview_node) {
return;
}
if (preview_node->is_inside_tree()) {
preview_node_pos = spatial_editor->snap_point(_get_instance_position(preview_node_viewport_pos, preview_node));
double snap = EDITOR_GET("interface/inspector/default_float_step");
int snap_step_decimals = Math::range_step_decimals(snap);
set_message(TTR("Instantiating:") + " (" + String::num(preview_node_pos.x, snap_step_decimals) + ", " +
String::num(preview_node_pos.y, snap_step_decimals) + ", " + String::num(preview_node_pos.z, snap_step_decimals) + ")");
Transform3D preview_gl_transform = Transform3D(Basis(), preview_node_pos);
preview_node->set_global_transform(preview_gl_transform);
if (!preview_node->is_visible()) {
preview_node->show();
}
}
update_preview_node = false;
} break;
case NOTIFICATION_APPLICATION_FOCUS_OUT:
@ -5707,6 +5719,8 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
freelook_active = false;
freelook_speed = EDITOR_GET("editors/3d/freelook/freelook_base_speed");
is_3d_editor_using_separate_physics_thread = GLOBAL_GET("physics/3d/run_on_separate_thread");
selection_menu = memnew(PopupMenu);
add_child(selection_menu);
selection_menu->set_min_size(Size2(100, 0) * EDSCALE);

View file

@ -246,6 +246,7 @@ private:
bool lock_rotation;
bool transform_gizmo_visible = true;
bool collision_reposition = false;
bool is_3d_editor_using_separate_physics_thread = false;
real_t gizmo_scale;
bool freelook_active;
@ -285,6 +286,7 @@ private:
void _select_clicked(bool p_allow_locked);
ObjectID _select_ray(const Point2 &p_pos) const;
void _find_items_at_pos(const Point2 &p_pos, Vector<_RayResult> &r_results, bool p_include_locked);
void _reposition_selected_nodes();
Transform3D _get_camera_transform() const;
int get_selected_count() const;