diff options
-rw-r--r-- | core/templates/list.h | 4 | ||||
-rw-r--r-- | doc/classes/PhysicsServer2D.xml | 4 | ||||
-rw-r--r-- | editor/editor_properties_array_dict.cpp | 351 | ||||
-rw-r--r-- | editor/editor_properties_array_dict.h | 34 | ||||
-rw-r--r-- | editor/icons/TripleBar.svg | 1 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 99 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 3 | ||||
-rw-r--r-- | servers/physics_2d/physics_server_2d_sw.cpp | 4 | ||||
-rw-r--r-- | servers/physics_2d/physics_server_2d_sw.h | 2 | ||||
-rw-r--r-- | servers/physics_2d/physics_server_2d_wrap_mt.h | 4 | ||||
-rw-r--r-- | servers/physics_2d/space_2d_sw.cpp | 11 | ||||
-rw-r--r-- | servers/physics_2d/space_2d_sw.h | 2 | ||||
-rw-r--r-- | servers/physics_server_2d.cpp | 10 | ||||
-rw-r--r-- | servers/physics_server_2d.h | 4 |
14 files changed, 340 insertions, 193 deletions
diff --git a/core/templates/list.h b/core/templates/list.h index 6047b89670..c2e17a2f6f 100644 --- a/core/templates/list.h +++ b/core/templates/list.h @@ -176,8 +176,8 @@ public: return *this; } - _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } - _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; } _FORCE_INLINE_ ConstIterator(const Element *p_E) { E = p_E; } _FORCE_INLINE_ ConstIterator() {} diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index 67b27b174f..b492ddaa25 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -820,6 +820,10 @@ </argument> <argument index="5" name="result" type="PhysicsTestMotionResult2D" default="null"> </argument> + <argument index="6" name="exclude_raycast_shapes" type="bool" default="true"> + </argument> + <argument index="7" name="exclude" type="Array" default="[]"> + </argument> <description> Returns [code]true[/code] if a collision would result from moving in the given direction from a given point in space. Margin increases the size of the shapes involved in the collision detection. [PhysicsTestMotionResult2D] can be passed to return additional information in. </description> diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 3216728be1..8b67b67571 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -30,16 +30,18 @@ #include "editor_properties_array_dict.h" +#include "core/input/input.h" #include "core/io/marshalls.h" +#include "editor/editor_node.h" #include "editor/editor_scale.h" #include "editor_properties.h" bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_value) { - String pn = p_name; + String name = p_name; - if (pn.begins_with("indices")) { - int idx = pn.get_slicec('/', 1).to_int(); - array.set(idx, p_value); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); + array.set(index, p_value); return true; } @@ -47,12 +49,12 @@ bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_ } bool EditorPropertyArrayObject::_get(const StringName &p_name, Variant &r_ret) const { - String pn = p_name; + String name = p_name; - if (pn.begins_with("indices")) { - int idx = pn.get_slicec('/', 1).to_int(); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); bool valid; - r_ret = array.get(idx, &valid); + r_ret = array.get(index, &valid); if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) { r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id(); } @@ -77,21 +79,21 @@ EditorPropertyArrayObject::EditorPropertyArrayObject() { /////////////////// bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Variant &p_value) { - String pn = p_name; + String name = p_name; - if (pn == "new_item_key") { + if (name == "new_item_key") { new_item_key = p_value; return true; } - if (pn == "new_item_value") { + if (name == "new_item_value") { new_item_value = p_value; return true; } - if (pn.begins_with("indices")) { - int idx = pn.get_slicec('/', 1).to_int(); - Variant key = dict.get_key_at_index(idx); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); + Variant key = dict.get_key_at_index(index); dict[key] = p_value; return true; } @@ -100,21 +102,21 @@ bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Varian } bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_ret) const { - String pn = p_name; + String name = p_name; - if (pn == "new_item_key") { + if (name == "new_item_key") { r_ret = new_item_key; return true; } - if (pn == "new_item_value") { + if (name == "new_item_value") { r_ret = new_item_value; return true; } - if (pn.begins_with("indices")) { - int idx = pn.get_slicec('/', 1).to_int(); - Variant key = dict.get_key_at_index(idx); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); + Variant key = dict.get_key_at_index(index); r_ret = dict[key]; if (r_ret.get_type() == Variant::OBJECT && Object::cast_to<EncodedObjectAsID>(r_ret)) { r_ret = Object::cast_to<EncodedObjectAsID>(r_ret)->get_object_id(); @@ -157,13 +159,13 @@ EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() { void EditorPropertyArray::_property_changed(const String &p_property, Variant p_value, const String &p_name, bool p_changing) { if (p_property.begins_with("indices")) { - int idx = p_property.get_slice("/", 1).to_int(); + int index = p_property.get_slice("/", 1).to_int(); Variant array = object->get_array(); - array.set(idx, p_value); + array.set(index, p_value); emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("duplicate"); // Duplicate, so undo/redo works better. } object->set_array(array); } @@ -171,7 +173,7 @@ void EditorPropertyArray::_property_changed(const String &p_property, Variant p_ void EditorPropertyArray::_change_type(Object *p_button, int p_index) { Button *button = Object::cast_to<Button>(p_button); - changing_type_idx = p_index; + changing_type_index = p_index; Rect2 rect = button->get_screen_rect(); change_type->set_as_minsize(); change_type->set_position(rect.position + rect.size - Vector2(change_type->get_contents_minimum_size().x, 0)); @@ -180,7 +182,7 @@ void EditorPropertyArray::_change_type(Object *p_button, int p_index) { void EditorPropertyArray::_change_type_menu(int p_index) { if (p_index == Variant::VARIANT_MAX) { - _remove_pressed(changing_type_idx); + _remove_pressed(changing_type_index); return; } @@ -188,12 +190,12 @@ void EditorPropertyArray::_change_type_menu(int p_index) { Callable::CallError ce; Variant::construct(Variant::Type(p_index), value, nullptr, 0, ce); Variant array = object->get_array(); - array.set(changing_type_idx, value); + array.set(changing_type_index, value); emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("duplicate"); // Duplicate, so undo/redo works better. } object->set_array(array); @@ -213,7 +215,7 @@ void EditorPropertyArray::update_property() { arrtype = "Array"; } break; - // arrays + // Arrays. case Variant::PACKED_BYTE_ARRAY: { arrtype = "PackedByteArray"; } break; @@ -256,7 +258,12 @@ void EditorPropertyArray::update_property() { return; } - edit->set_text(arrtype + " (size " + itos(array.call("size")) + ")"); + int size = array.call("size"); + int pages = MAX(0, size - 1) / page_length + 1; + page_index = MIN(page_index, pages - 1); + int offset = page_index * page_length; + + edit->set_text(arrtype + " (size " + itos(size) + ")"); bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property()); if (edit->is_pressed() != unfolded) { @@ -270,50 +277,50 @@ void EditorPropertyArray::update_property() { vbox = memnew(VBoxContainer); add_child(vbox); set_bottom_editor(vbox); - HBoxContainer *hbc = memnew(HBoxContainer); - vbox->add_child(hbc); + + HBoxContainer *hbox = memnew(HBoxContainer); + vbox->add_child(hbox); + Label *label = memnew(Label(TTR("Size: "))); label->set_h_size_flags(SIZE_EXPAND_FILL); - hbc->add_child(label); - length = memnew(EditorSpinSlider); - length->set_step(1); - length->set_max(1000000); - length->set_h_size_flags(SIZE_EXPAND_FILL); - hbc->add_child(length); - length->connect("value_changed", callable_mp(this, &EditorPropertyArray::_length_changed)); - - page_hb = memnew(HBoxContainer); - vbox->add_child(page_hb); - label = memnew(Label(TTR("Page: "))); - label->set_h_size_flags(SIZE_EXPAND_FILL); - page_hb->add_child(label); - page = memnew(EditorSpinSlider); - page->set_step(1); - page_hb->add_child(page); - page->set_h_size_flags(SIZE_EXPAND_FILL); - page->connect("value_changed", callable_mp(this, &EditorPropertyArray::_page_changed)); - } else { - //bye bye children of the box - while (vbox->get_child_count() > 2) { - vbox->get_child(2)->queue_delete(); // button still needed after pressed is called - vbox->remove_child(vbox->get_child(2)); - } - } + hbox->add_child(label); - int len = array.call("size"); + size_slider = memnew(EditorSpinSlider); + size_slider->set_step(1); + size_slider->set_max(1000000); + size_slider->set_h_size_flags(SIZE_EXPAND_FILL); + size_slider->connect("value_changed", callable_mp(this, &EditorPropertyArray::_length_changed)); + hbox->add_child(size_slider); - length->set_value(len); + page_hbox = memnew(HBoxContainer); + vbox->add_child(page_hbox); - int pages = MAX(0, len - 1) / page_len + 1; + label = memnew(Label(TTR("Page: "))); + label->set_h_size_flags(SIZE_EXPAND_FILL); + page_hbox->add_child(label); - page->set_max(pages); - page_idx = MIN(page_idx, pages - 1); - page->set_value(page_idx); - page_hb->set_visible(pages > 1); + page_slider = memnew(EditorSpinSlider); + page_slider->set_step(1); + page_slider->set_h_size_flags(SIZE_EXPAND_FILL); + page_slider->connect("value_changed", callable_mp(this, &EditorPropertyArray::_page_changed)); + page_hbox->add_child(page_slider); + } else { + // Bye bye children of the box. + for (int i = vbox->get_child_count() - 1; i >= 2; i--) { + Node *child = vbox->get_child(i); + if (child == reorder_selected_element_hbox) { + continue; // Don't remove the property that the user is moving. + } - int offset = page_idx * page_len; + child->queue_delete(); // Button still needed after pressed is called. + vbox->remove_child(child); + } + } - int amount = MIN(len - offset, page_len); + size_slider->set_value(size); + page_slider->set_max(pages); + page_slider->set_value(page_index); + page_hbox->set_visible(pages > 1); if (array.get_type() == Variant::ARRAY) { array = array.call("duplicate"); @@ -321,7 +328,31 @@ void EditorPropertyArray::update_property() { object->set_array(array); + int amount = MIN(size - offset, page_length); for (int i = 0; i < amount; i++) { + bool reorder_is_from_current_page = reorder_from_index / page_length == page_index; + if (reorder_is_from_current_page && i == reorder_from_index % page_length) { + // Don't duplicate the property that the user is moving. + continue; + } + if (!reorder_is_from_current_page && i == reorder_to_index % page_length) { + // Don't create the property the moving property will take the place of, + // e.g. (if page_length == 20) don't create element 20 if dragging an item from + // the first page to the second page because element 20 would become element 19. + continue; + } + + HBoxContainer *hbox = memnew(HBoxContainer); + vbox->add_child(hbox); + + Button *reorder_button = memnew(Button); + reorder_button->set_icon(get_theme_icon("TripleBar", "EditorIcons")); + reorder_button->set_default_cursor_shape(Control::CURSOR_MOVE); + reorder_button->connect("gui_input", callable_mp(this, &EditorPropertyArray::_reorder_button_gui_input)); + reorder_button->connect("button_down", callable_mp(this, &EditorPropertyArray::_reorder_button_down), varray(i + offset)); + reorder_button->connect("button_up", callable_mp(this, &EditorPropertyArray::_reorder_button_up)); + hbox->add_child(reorder_button); + String prop_name = "indices/" + itos(i + offset); EditorProperty *prop = nullptr; @@ -346,29 +377,29 @@ void EditorPropertyArray::update_property() { prop->connect("property_changed", callable_mp(this, &EditorPropertyArray::_property_changed)); prop->connect("object_id_selected", callable_mp(this, &EditorPropertyArray::_object_id_selected)); prop->set_h_size_flags(SIZE_EXPAND_FILL); - - HBoxContainer *hb = memnew(HBoxContainer); - - vbox->add_child(hb); - hb->add_child(prop); + hbox->add_child(prop); bool is_untyped_array = array.get_type() == Variant::ARRAY && subtype == Variant::NIL; if (is_untyped_array) { Button *edit = memnew(Button); edit->set_icon(get_theme_icon("Edit", "EditorIcons")); - hb->add_child(edit); + hbox->add_child(edit); edit->connect("pressed", callable_mp(this, &EditorPropertyArray::_change_type), varray(edit, i + offset)); } else { Button *remove = memnew(Button); remove->set_icon(get_theme_icon("Remove", "EditorIcons")); remove->connect("pressed", callable_mp(this, &EditorPropertyArray::_remove_pressed), varray(i + offset)); - hb->add_child(remove); + hbox->add_child(remove); } prop->update_property(); } + if (reorder_to_index % page_length > 0) { + vbox->move_child(vbox->get_child(2), reorder_to_index % page_length + 2); + } + updating = false; } else { @@ -384,12 +415,7 @@ void EditorPropertyArray::_remove_pressed(int p_index) { Variant array = object->get_array(); array.call("remove", p_index); - if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); - } - emit_changed(get_edited_property(), array, "", false); - object->set_array(array); update_property(); } @@ -414,14 +440,14 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { for (int j = 0; j < allowed_type.get_slice_count(","); j++) { String at = allowed_type.get_slice(",", j).strip_edges(); - // Fail if one of the files is not of allowed type + // Fail if one of the files is not of allowed type. if (!ClassDB::is_parent_class(ftype, at)) { return false; } } } - // If no files fail, drop is valid + // If no files fail, drop is valid. return true; } @@ -442,13 +468,13 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d Variant array = object->get_array(); - // Handle the case where array is not initialised yet + // Handle the case where array is not initialised yet. if (!array.is_array()) { Callable::CallError ce; Variant::construct(array_type, array, nullptr, 0, ce); } - // Loop the file array and add to existing array + // Loop the file array and add to existing array. for (int i = 0; i < files.size(); i++) { String file = files[i]; @@ -504,7 +530,7 @@ void EditorPropertyArray::_page_changed(double p_page) { if (updating) { return; } - page_idx = p_page; + page_index = p_page; update_property(); } @@ -530,10 +556,10 @@ void EditorPropertyArray::_length_changed(double p_page) { } } } - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("duplicate"); // Duplicate, so undo/redo works better. } else { int size = array.call("size"); - // Pool*Array don't initialize their elements, have to do it manually + // Pool*Array don't initialize their elements, have to do it manually. for (int i = previous_size; i < size; i++) { Callable::CallError ce; Variant r; @@ -551,7 +577,7 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint array_type = p_array_type; // The format of p_hint_string is: - // subType/subTypeHint:nextSubtype ... etc + // subType/subTypeHint:nextSubtype ... etc. if (array_type == Variant::ARRAY && !p_hint_string.is_empty()) { int hint_subtype_separator = p_hint_string.find(":"); if (hint_subtype_separator >= 0) { @@ -568,6 +594,73 @@ void EditorPropertyArray::setup(Variant::Type p_array_type, const String &p_hint } } +void EditorPropertyArray::_reorder_button_gui_input(const Ref<InputEvent> &p_event) { + if (reorder_from_index < 0) { + return; + } + + Ref<InputEventMouseMotion> mm = p_event; + if (mm.is_valid()) { + Variant array = object->get_array(); + int size = array.call("size"); + + if ((reorder_to_index == 0 && mm->get_relative().y < 0.0f) || (reorder_to_index == size - 1 && mm->get_relative().y > 0.0f)) { + return; + } + + reorder_mouse_y_delta += mm->get_relative().y; + float required_y_distance = 20.0f * EDSCALE; + if (ABS(reorder_mouse_y_delta) > required_y_distance) { + int direction = reorder_mouse_y_delta > 0.0f ? 1 : -1; + reorder_mouse_y_delta -= required_y_distance * direction; + + reorder_to_index += direction; + if ((direction < 0 && reorder_to_index % page_length == page_length - 1) || (direction > 0 && reorder_to_index % page_length == 0)) { + // Automatically move to the next/previous page. + page_slider->set_value(page_index + direction); + } + vbox->move_child(reorder_selected_element_hbox, reorder_to_index % page_length + 2); + // Ensure the moving element is visible. + EditorNode::get_singleton()->get_inspector()->ensure_control_visible(reorder_selected_element_hbox); + } + } +} + +void EditorPropertyArray::_reorder_button_down(int p_index) { + reorder_from_index = p_index; + reorder_to_index = p_index; + reorder_selected_element_hbox = Object::cast_to<HBoxContainer>(vbox->get_child(p_index % page_length + 2)); + reorder_selected_button = Object::cast_to<Button>(reorder_selected_element_hbox->get_child(0)); + // Ideally it'd to be able to show the mouse but I had issues with + // Control's `mouse_exit()`/`mouse_entered()` signals not getting called. + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); +} + +void EditorPropertyArray::_reorder_button_up() { + if (reorder_from_index != reorder_to_index) { + // Move the element. + Variant array = object->get_array(); + + Variant value_to_move = array.get(reorder_from_index); + array.call("remove", reorder_from_index); + array.call("insert", reorder_to_index, value_to_move); + + emit_changed(get_edited_property(), array, "", false); + object->set_array(array); + update_property(); + } + + reorder_from_index = -1; + reorder_to_index = -1; + reorder_mouse_y_delta = 0.0f; + + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + reorder_selected_button->warp_mouse(reorder_selected_button->get_size() / 2.0f); + + reorder_selected_element_hbox = nullptr; + reorder_selected_button = nullptr; +} + void EditorPropertyArray::_bind_methods() { ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &EditorPropertyArray::can_drop_data_fw); ClassDB::bind_method(D_METHOD("_drop_data_fw"), &EditorPropertyArray::drop_data_fw); @@ -575,7 +668,7 @@ void EditorPropertyArray::_bind_methods() { EditorPropertyArray::EditorPropertyArray() { object.instantiate(); - page_len = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); + page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); edit = memnew(Button); edit->set_h_size_flags(SIZE_EXPAND_FILL); edit->set_clip_text(true); @@ -586,8 +679,8 @@ EditorPropertyArray::EditorPropertyArray() { add_child(edit); add_focusable(edit); vbox = nullptr; - page = nullptr; - length = nullptr; + page_slider = nullptr; + size_slider = nullptr; updating = false; change_type = memnew(PopupMenu); add_child(change_type); @@ -599,7 +692,7 @@ EditorPropertyArray::EditorPropertyArray() { } change_type->add_separator(); change_type->add_item(TTR("Remove Item"), Variant::VARIANT_MAX); - changing_type_idx = -1; + changing_type_index = -1; subtype = Variant::NIL; subtype_hint = PROPERTY_HINT_NONE; @@ -616,14 +709,14 @@ void EditorPropertyDictionary::_property_changed(const String &p_property, Varia } else if (p_property == "new_item_value") { object->set_new_item_value(p_value); } else if (p_property.begins_with("indices")) { - int idx = p_property.get_slice("/", 1).to_int(); + int index = p_property.get_slice("/", 1).to_int(); Dictionary dict = object->get_dict(); - Variant key = dict.get_key_at_index(idx); + Variant key = dict.get_key_at_index(index); dict[key] = p_value; emit_changed(get_edited_property(), dict, "", true); - dict = dict.duplicate(); //dupe, so undo/redo works better + dict = dict.duplicate(); // Duplicate, so undo/redo works better\. object->set_dict(dict); } } @@ -635,7 +728,7 @@ void EditorPropertyDictionary::_change_type(Object *p_button, int p_index) { change_type->set_as_minsize(); change_type->set_position(rect.position + rect.size - Vector2(change_type->get_contents_minimum_size().x, 0)); change_type->popup(); - changing_type_idx = p_index; + changing_type_index = p_index; } void EditorPropertyDictionary::_add_key_value() { @@ -652,17 +745,17 @@ void EditorPropertyDictionary::_add_key_value() { emit_changed(get_edited_property(), dict, "", false); - dict = dict.duplicate(); //dupe, so undo/redo works better + dict = dict.duplicate(); // Duplicate, so undo/redo works better. object->set_dict(dict); update_property(); } void EditorPropertyDictionary::_change_type_menu(int p_index) { - if (changing_type_idx < 0) { + if (changing_type_index < 0) { Variant value; Callable::CallError ce; Variant::construct(Variant::Type(p_index), value, nullptr, 0, ce); - if (changing_type_idx == -1) { + if (changing_type_index == -1) { object->set_new_item_key(value); } else { object->set_new_item_value(value); @@ -677,16 +770,16 @@ void EditorPropertyDictionary::_change_type_menu(int p_index) { Variant value; Callable::CallError ce; Variant::construct(Variant::Type(p_index), value, nullptr, 0, ce); - Variant key = dict.get_key_at_index(changing_type_idx); + Variant key = dict.get_key_at_index(changing_type_index); dict[key] = value; } else { - Variant key = dict.get_key_at_index(changing_type_idx); + Variant key = dict.get_key_at_index(changing_type_index); dict.erase(key); } emit_changed(get_edited_property(), dict, "", false); - dict = dict.duplicate(); //dupe, so undo/redo works better + dict = dict.duplicate(); // Duplicate, so undo/redo works better\. object->set_dict(dict); update_property(); } @@ -695,7 +788,7 @@ void EditorPropertyDictionary::update_property() { Variant updated_val = get_edited_object()->get(get_edited_property()); if (updated_val.get_type() == Variant::NIL) { - edit->set_text("Dictionary (Nil)"); //This provides symmetry with the array property. + edit->set_text("Dictionary (Nil)"); // This provides symmetry with the array property. edit->set_pressed(false); if (vbox) { set_bottom_editor(nullptr); @@ -722,16 +815,16 @@ void EditorPropertyDictionary::update_property() { add_child(vbox); set_bottom_editor(vbox); - page_hb = memnew(HBoxContainer); - vbox->add_child(page_hb); + page_hbox = memnew(HBoxContainer); + vbox->add_child(page_hbox); Label *label = memnew(Label(TTR("Page: "))); label->set_h_size_flags(SIZE_EXPAND_FILL); - page_hb->add_child(label); - page = memnew(EditorSpinSlider); - page->set_step(1); - page_hb->add_child(page); - page->set_h_size_flags(SIZE_EXPAND_FILL); - page->connect("value_changed", callable_mp(this, &EditorPropertyDictionary::_page_changed)); + page_hbox->add_child(label); + page_slider = memnew(EditorSpinSlider); + page_slider->set_step(1); + page_hbox->add_child(page_slider); + page_slider->set_h_size_flags(SIZE_EXPAND_FILL); + page_slider->connect("value_changed", callable_mp(this, &EditorPropertyDictionary::_page_changed)); } else { // Queue children for deletion, deleting immediately might cause errors. for (int i = 1; i < vbox->get_child_count(); i++) { @@ -739,18 +832,18 @@ void EditorPropertyDictionary::update_property() { } } - int len = dict.size(); + int size = dict.size(); - int pages = MAX(0, len - 1) / page_len + 1; + int pages = MAX(0, size - 1) / page_length + 1; - page->set_max(pages); - page_idx = MIN(page_idx, pages - 1); - page->set_value(page_idx); - page_hb->set_visible(pages > 1); + page_slider->set_max(pages); + page_index = MIN(page_index, pages - 1); + page_slider->set_value(page_index); + page_hbox->set_visible(pages > 1); - int offset = page_idx * page_len; + int offset = page_index * page_length; - int amount = MIN(len - offset, page_len); + int amount = MIN(size - offset, page_length); dict = dict.duplicate(); @@ -782,7 +875,7 @@ void EditorPropertyDictionary::update_property() { } break; - // atomic types + // Atomic types. case Variant::BOOL: { prop = memnew(EditorPropertyCheck); @@ -803,7 +896,7 @@ void EditorPropertyDictionary::update_property() { } break; - // math types + // Math types. case Variant::VECTOR2: { EditorPropertyVector2 *editor = memnew(EditorPropertyVector2); editor->setup(-100000, 100000, 0.001, true); @@ -877,7 +970,7 @@ void EditorPropertyDictionary::update_property() { } break; - // misc types + // Miscellaneous types. case Variant::COLOR: { prop = memnew(EditorPropertyColor); @@ -919,7 +1012,7 @@ void EditorPropertyDictionary::update_property() { prop = editor; } break; - // arrays + // Arrays. case Variant::PACKED_BYTE_ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); editor->setup(Variant::PACKED_BYTE_ARRAY); @@ -1003,17 +1096,17 @@ void EditorPropertyDictionary::update_property() { prop->connect("property_changed", callable_mp(this, &EditorPropertyDictionary::_property_changed)); prop->connect("object_id_selected", callable_mp(this, &EditorPropertyDictionary::_object_id_selected)); - HBoxContainer *hb = memnew(HBoxContainer); + HBoxContainer *hbox = memnew(HBoxContainer); if (add_vbox) { - add_vbox->add_child(hb); + add_vbox->add_child(hbox); } else { - vbox->add_child(hb); + vbox->add_child(hbox); } - hb->add_child(prop); + hbox->add_child(prop); prop->set_h_size_flags(SIZE_EXPAND_FILL); Button *edit = memnew(Button); edit->set_icon(get_theme_icon("Edit", "EditorIcons")); - hb->add_child(edit); + hbox->add_child(edit); edit->connect("pressed", callable_mp(this, &EditorPropertyDictionary::_change_type), varray(edit, change_index)); prop->update_property(); @@ -1060,7 +1153,7 @@ void EditorPropertyDictionary::_page_changed(double p_page) { if (updating) { return; } - page_idx = p_page; + page_index = p_page; update_property(); } @@ -1069,7 +1162,7 @@ void EditorPropertyDictionary::_bind_methods() { EditorPropertyDictionary::EditorPropertyDictionary() { object.instantiate(); - page_len = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); + page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page")); edit = memnew(Button); edit->set_h_size_flags(SIZE_EXPAND_FILL); edit->set_clip_text(true); @@ -1078,7 +1171,7 @@ EditorPropertyDictionary::EditorPropertyDictionary() { add_child(edit); add_focusable(edit); vbox = nullptr; - page = nullptr; + page_slider = nullptr; updating = false; change_type = memnew(PopupMenu); add_child(change_type); @@ -1090,5 +1183,5 @@ EditorPropertyDictionary::EditorPropertyDictionary() { } change_type->add_separator(); change_type->add_item(TTR("Remove Item"), Variant::VARIANT_MAX); - changing_type_idx = -1; + changing_type_index = -1; } diff --git a/editor/editor_properties_array_dict.h b/editor/editor_properties_array_dict.h index aa2d8744b1..7547d57346 100644 --- a/editor/editor_properties_array_dict.h +++ b/editor/editor_properties_array_dict.h @@ -84,19 +84,25 @@ class EditorPropertyArray : public EditorProperty { bool dropping; Ref<EditorPropertyArrayObject> object; - int page_len = 20; - int page_idx = 0; - int changing_type_idx; + int page_length = 20; + int page_index = 0; + int changing_type_index; Button *edit; VBoxContainer *vbox; - EditorSpinSlider *length; - EditorSpinSlider *page; - HBoxContainer *page_hb; + EditorSpinSlider *size_slider; + EditorSpinSlider *page_slider; + HBoxContainer *page_hbox; Variant::Type array_type; Variant::Type subtype; PropertyHint subtype_hint; String subtype_hint_string; + int reorder_from_index = -1; + int reorder_to_index = -1; + float reorder_mouse_y_delta = 0.0f; + HBoxContainer *reorder_selected_element_hbox = nullptr; + Button *reorder_selected_button = nullptr; + void _page_changed(double p_page); void _length_changed(double p_page); void _edit_pressed(); @@ -112,6 +118,10 @@ class EditorPropertyArray : public EditorProperty { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + void _reorder_button_gui_input(const Ref<InputEvent> &p_event); + void _reorder_button_down(int p_index); + void _reorder_button_up(); + protected: static void _bind_methods(); void _notification(int p_what); @@ -129,14 +139,14 @@ class EditorPropertyDictionary : public EditorProperty { bool updating; Ref<EditorPropertyDictionaryObject> object; - int page_len = 20; - int page_idx = 0; - int changing_type_idx; + int page_length = 20; + int page_index = 0; + int changing_type_index; Button *edit; VBoxContainer *vbox; - EditorSpinSlider *length; - EditorSpinSlider *page; - HBoxContainer *page_hb; + EditorSpinSlider *size_slider; + EditorSpinSlider *page_slider; + HBoxContainer *page_hbox; void _page_changed(double p_page); void _edit_pressed(); diff --git a/editor/icons/TripleBar.svg b/editor/icons/TripleBar.svg new file mode 100644 index 0000000000..2b521e6c15 --- /dev/null +++ b/editor/icons/TripleBar.svg @@ -0,0 +1 @@ +<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="m1.9375 4h12.062zm0 4h12.062zm0 4h12.062z" fill="none" stroke="#e0e0e0" stroke-opacity=".99608" stroke-width=".92823"/></svg> diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 80aa99bf5e..b68f0312fc 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -76,12 +76,12 @@ Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_motion, bool p_i return Ref<KinematicCollision2D>(); } -bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding) { +bool PhysicsBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding, const Set<RID> &p_exclude) { if (is_only_update_transform_changes_enabled()) { ERR_PRINT("Move functions do not work together with 'sync to physics' option. Please read the documentation."); } Transform2D gt = get_global_transform(); - bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes); + bool colliding = PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes, p_exclude); // Restore direction of motion to be along original motion, // in order to avoid sliding due to recovery, @@ -960,11 +960,14 @@ void RigidBody2D::_reload_physics_characteristics() { void CharacterBody2D::move_and_slide() { Vector2 body_velocity_normal = linear_velocity.normalized(); - bool was_on_floor = on_floor; + // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky + float delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time(); + Vector2 current_floor_velocity = floor_velocity; - if (on_floor && on_floor_body.is_valid()) { + + if ((on_floor || on_wall) && on_floor_body.is_valid()) { //this approach makes sure there is less delay between the actual body velocity and the one we saved PhysicsDirectBodyState2D *bs = PhysicsServer2D::get_singleton()->body_get_direct_state(on_floor_body); if (bs) { @@ -972,20 +975,30 @@ void CharacterBody2D::move_and_slide() { } } - // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky - Vector2 motion = (current_floor_velocity + linear_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time()); - + motion_results.clear(); on_floor = false; - on_floor_body = RID(); on_ceiling = false; on_wall = false; - motion_results.clear(); floor_normal = Vector2(); floor_velocity = Vector2(); + if (current_floor_velocity != Vector2()) { + PhysicsServer2D::MotionResult floor_result; + Set<RID> exclude; + exclude.insert(on_floor_body); + if (move_and_collide(current_floor_velocity * delta, infinite_inertia, floor_result, true, false, false, false, exclude)) { + motion_results.push_back(floor_result); + _set_collision_direction(floor_result); + } + } + + on_floor_body = RID(); + Vector2 motion = linear_velocity * delta; + // No sliding on first attempt to keep floor motion stable when possible, // when stop on slope is enabled. bool sliding_enabled = !stop_on_slope; + for (int iteration = 0; iteration < max_slides; ++iteration) { PhysicsServer2D::MotionResult result; bool found_collision = false; @@ -1009,35 +1022,19 @@ void CharacterBody2D::move_and_slide() { found_collision = true; motion_results.push_back(result); - - if (up_direction == Vector2()) { - //all is a wall - on_wall = true; - } else { - if (Math::acos(result.collision_normal.dot(up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //floor - - on_floor = true; - floor_normal = result.collision_normal; - on_floor_body = result.collider; - floor_velocity = result.collider_velocity; - - if (stop_on_slope) { - if ((body_velocity_normal + up_direction).length() < 0.01) { - Transform2D gt = get_global_transform(); - if (result.motion.length() > margin) { - gt.elements[2] -= result.motion.slide(up_direction); - } else { - gt.elements[2] -= result.motion; - } - set_global_transform(gt); - linear_velocity = Vector2(); - return; - } + _set_collision_direction(result); + + if (on_floor && stop_on_slope) { + if ((body_velocity_normal + up_direction).length() < 0.01) { + Transform2D gt = get_global_transform(); + if (result.motion.length() > margin) { + gt.elements[2] -= result.motion.slide(up_direction); + } else { + gt.elements[2] -= result.motion; } - } else if (Math::acos(result.collision_normal.dot(-up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling - on_ceiling = true; - } else { - on_wall = true; + set_global_transform(gt); + linear_velocity = Vector2(); + return; } } @@ -1057,6 +1054,11 @@ void CharacterBody2D::move_and_slide() { } } + if (!on_floor && !on_wall) { + // Add last platform velocity when just left a moving platform. + linear_velocity += current_floor_velocity; + } + if (!was_on_floor || snap == Vector2()) { return; } @@ -1093,6 +1095,29 @@ void CharacterBody2D::move_and_slide() { } } +void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResult &p_result) { + on_floor = false; + on_ceiling = false; + on_wall = false; + if (up_direction == Vector2()) { + //all is a wall + on_wall = true; + } else { + if (Math::acos(p_result.collision_normal.dot(up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //floor + on_floor = true; + floor_normal = p_result.collision_normal; + on_floor_body = p_result.collider; + floor_velocity = p_result.collider_velocity; + } else if (Math::acos(p_result.collision_normal.dot(-up_direction)) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) { //ceiling + on_ceiling = true; + } else { + on_wall = true; + on_floor_body = p_result.collider; + floor_velocity = p_result.collider_velocity; + } + } +} + bool CharacterBody2D::separate_raycast_shapes(PhysicsServer2D::MotionResult &r_result) { PhysicsServer2D::SeparationResult sep_res[8]; //max 8 rays diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 5a5417eaf3..52e432f005 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -50,7 +50,7 @@ protected: Ref<KinematicCollision2D> _move(const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false, real_t p_margin = 0.08); public: - bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true); + bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, PhysicsServer2D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true, const Set<RID> &p_exclude = Set<RID>()); bool test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, const Ref<KinematicCollision2D> &r_collision = Ref<KinematicCollision2D>(), real_t p_margin = 0.08); TypedArray<PhysicsBody2D> get_collision_exceptions(); @@ -308,6 +308,7 @@ private: const Vector2 &get_up_direction() const; void set_up_direction(const Vector2 &p_up_direction); + void _set_collision_direction(const PhysicsServer2D::MotionResult &p_result); protected: void _notification(int p_what); diff --git a/servers/physics_2d/physics_server_2d_sw.cpp b/servers/physics_2d/physics_server_2d_sw.cpp index 155dda4394..467c664302 100644 --- a/servers/physics_2d/physics_server_2d_sw.cpp +++ b/servers/physics_2d/physics_server_2d_sw.cpp @@ -946,7 +946,7 @@ void PhysicsServer2DSW::body_set_pickable(RID p_body, bool p_pickable) { body->set_pickable(p_pickable); } -bool PhysicsServer2DSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, MotionResult *r_result, bool p_exclude_raycast_shapes) { +bool PhysicsServer2DSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, MotionResult *r_result, bool p_exclude_raycast_shapes, const Set<RID> &p_exclude) { Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); @@ -954,7 +954,7 @@ bool PhysicsServer2DSW::body_test_motion(RID p_body, const Transform2D &p_from, _update_shapes(); - return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes); + return body->get_space()->test_body_motion(body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes, p_exclude); } int PhysicsServer2DSW::body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin) { diff --git a/servers/physics_2d/physics_server_2d_sw.h b/servers/physics_2d/physics_server_2d_sw.h index 5002bf5fc8..f40b5a7c42 100644 --- a/servers/physics_2d/physics_server_2d_sw.h +++ b/servers/physics_2d/physics_server_2d_sw.h @@ -247,7 +247,7 @@ public: virtual void body_set_pickable(RID p_body, bool p_pickable) override; - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) override; + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true, const Set<RID> &p_exclude = Set<RID>()) override; virtual int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin = 0.08) override; // this function only works on physics process, errors and returns null otherwise diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h index a8f7ff3393..fb7235c031 100644 --- a/servers/physics_2d/physics_server_2d_wrap_mt.h +++ b/servers/physics_2d/physics_server_2d_wrap_mt.h @@ -253,9 +253,9 @@ public: FUNC2(body_set_pickable, RID, bool); - bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) override { + bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true, const Set<RID> &p_exclude = Set<RID>()) override { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), false); - return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes); + return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r_result, p_exclude_raycast_shapes, p_exclude); } int body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, real_t p_margin = 0.08) override { diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index cbde7144b7..82da5774db 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -709,7 +709,7 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t return rays_found; } -bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer2D::MotionResult *r_result, bool p_exclude_raycast_shapes) { +bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer2D::MotionResult *r_result, bool p_exclude_raycast_shapes, const Set<RID> &p_exclude) { //give me back regular physics engine logic //this is madness //and most people using this function will think @@ -801,6 +801,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j); for (int i = 0; i < amount; i++) { const CollisionObject2DSW *col_obj = intersection_query_results[i]; + if (p_exclude.has(col_obj->get_self())) { + continue; + } int shape_idx = intersection_query_subindex_results[i]; if (CollisionObject2DSW::TYPE_BODY == col_obj->get_type()) { @@ -930,6 +933,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co for (int i = 0; i < amount; i++) { const CollisionObject2DSW *col_obj = intersection_query_results[i]; + if (p_exclude.has(col_obj->get_self())) { + continue; + } int col_shape_idx = intersection_query_subindex_results[i]; Shape2DSW *against_shape = col_obj->get_shape(col_shape_idx); @@ -1086,6 +1092,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co for (int i = 0; i < amount; i++) { const CollisionObject2DSW *col_obj = intersection_query_results[i]; + if (p_exclude.has(col_obj->get_self())) { + continue; + } int shape_idx = intersection_query_subindex_results[i]; if (CollisionObject2DSW::TYPE_BODY == col_obj->get_type()) { diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 4d737d622f..f7224e4661 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -183,7 +183,7 @@ public: int get_collision_pairs() const { return collision_pairs; } - bool test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer2D::MotionResult *r_result, bool p_exclude_raycast_shapes = true); + bool test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, PhysicsServer2D::MotionResult *r_result, bool p_exclude_raycast_shapes = true, const Set<RID> &p_exclude = Set<RID>()); int test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, PhysicsServer2D::SeparationResult *r_results, int p_result_max, real_t p_margin); void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); } diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index ec0ff57a5e..e8272f377e 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -498,12 +498,16 @@ void PhysicsTestMotionResult2D::_bind_methods() { /////////////////////////////////////// -bool PhysicsServer2D::_body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) { +bool PhysicsServer2D::_body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, const Ref<PhysicsTestMotionResult2D> &p_result, bool p_exclude_raycast_shapes, const Vector<RID> &p_exclude) { MotionResult *r = nullptr; if (p_result.is_valid()) { r = p_result->get_result_ptr(); } - return body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r); + Set<RID> exclude; + for (int i = 0; i < p_exclude.size(); i++) { + exclude.insert(p_exclude[i]); + } + return body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r, p_exclude_raycast_shapes, exclude); } void PhysicsServer2D::_bind_methods() { @@ -630,7 +634,7 @@ void PhysicsServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_force_integration_callback", "body", "callable", "userdata"), &PhysicsServer2D::body_set_force_integration_callback, DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "infinite_inertia", "margin", "result"), &PhysicsServer2D::_body_test_motion, DEFVAL(0.08), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "infinite_inertia", "margin", "result", "exclude_raycast_shapes", "exclude"), &PhysicsServer2D::_body_test_motion, DEFVAL(0.08), DEFVAL(Variant()), DEFVAL(true), DEFVAL(Array())); ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer2D::body_get_direct_state); diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index e2bff2975e..8542b54838 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -208,7 +208,7 @@ class PhysicsServer2D : public Object { static PhysicsServer2D *singleton; - virtual bool _body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, const Ref<PhysicsTestMotionResult2D> &p_result = Ref<PhysicsTestMotionResult2D>()); + virtual bool _body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, const Ref<PhysicsTestMotionResult2D> &p_result = Ref<PhysicsTestMotionResult2D>(), bool p_exclude_raycast_shapes = true, const Vector<RID> &p_exclude = Vector<RID>()); protected: static void _bind_methods(); @@ -481,7 +481,7 @@ public: Variant collider_metadata; }; - virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) = 0; + virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin = 0.08, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true, const Set<RID> &p_exclude = Set<RID>()) = 0; struct SeparationResult { real_t collision_depth; |