diff options
35 files changed, 297 insertions, 112 deletions
diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index e6ec6fb4fd..047eaaf0ac 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -317,9 +317,17 @@ void RasterizerCanvasGLES2::_draw_polygon(const int *p_indices, int p_index_coun } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.polygon_index_buffer); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(int) * p_index_count, p_indices); - - glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, 0); + if (storage->config.support_32_bits_indices) { //should check for + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(int) * p_index_count, p_indices); + glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_INT, 0); + } else { + uint16_t *index16 = (uint16_t *)alloca(sizeof(uint16_t) * p_index_count); + for (int i = 0; i < p_index_count; i++) { + index16[i] = uint16_t(p_indices[i]); + } + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(uint16_t) * p_index_count, index16); + glDrawElements(GL_TRIANGLES, p_index_count, GL_UNSIGNED_SHORT, 0); + } glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index af698f3988..0622a353df 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -4658,6 +4658,13 @@ void RasterizerStorageGLES2::initialize() { #else config.use_rgba_2d_shadows = !(config.float_texture_supported && config.extensions.has("GL_EXT_texture_rg")); #endif + +#ifdef GLES_OVER_GL + config.support_32_bits_indices = true; +#else + config.support_32_bits_indices = config.extensions.has("GL_OES_element_index_uint"); +#endif + frame.count = 0; frame.delta = 0; frame.current_rt = NULL; diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index 6f3ea25cc9..ae14aaa9c0 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -78,6 +78,8 @@ public: bool force_vertex_shading; bool use_rgba_2d_shadows; + + bool support_32_bits_indices; } config; struct Resources { diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 0e030d13a5..d1d063ad5b 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -2677,6 +2677,11 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr glBindBuffer(GL_UNIFORM_BUFFER, 0); } +// Drop -O3 for this function as it triggers a GCC bug up until at least GCC 8.2.1. +// This refers to GH issue #19633. +// The bug has been reported to the GCC project. +#pragma GCC push_options +#pragma GCC optimize ("-O2") void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform &p_camera_inverse_transform, bool p_use_shadows) { LightInstance *li = directional_lights[p_index]; @@ -2794,6 +2799,7 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform glBindBufferBase(GL_UNIFORM_BUFFER, 3, state.directional_ubo); } +#pragma GCC pop_options void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform, const CameraMatrix &p_camera_projection, RID p_shadow_atlas) { diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index d2eb58a863..0e5fd3a999 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -80,6 +80,11 @@ Size2 EditorProperty::get_minimum_size() const { return ms; } +void EditorProperty::emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field, bool p_changing) { + + emit_signal("property_changed", p_property, p_value, p_field, p_changing); +} + void EditorProperty::_notification(int p_what) { if (p_what == NOTIFICATION_SORT_CHILDREN) { @@ -634,7 +639,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { emit_signal("property_keyed", property, use_keying_next()); if (use_keying_next()) { - call_deferred("emit_signal", "property_changed", property, object->get(property).operator int64_t() + 1); + call_deferred("emit_changed", property, object->get(property).operator int64_t() + 1, "", false); call_deferred("update_property"); } } @@ -646,14 +651,14 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { Node *node = Object::cast_to<Node>(object); if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instanced_node_original_property(node, property, vorig)) { - emit_signal("property_changed", property, vorig.duplicate(true)); + emit_changed(property, vorig.duplicate(true)); update_property(); return; } if (object->call("property_can_revert", property).operator bool()) { Variant rev = object->call("property_get_revert", property); - emit_signal("property_changed", property, rev); + emit_changed(property, rev); update_property(); return; } @@ -662,7 +667,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { Ref<Script> scr = object->get_script(); Variant orig_value; if (scr->get_property_default_value(property, orig_value)) { - emit_signal("property_changed", property, orig_value); + emit_changed(property, orig_value); update_property(); return; } @@ -670,7 +675,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property); if (default_value != Variant()) { - emit_signal("property_changed", property, default_value); + emit_changed(property, default_value); update_property(); return; } @@ -792,6 +797,8 @@ void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tooltip_text"), &EditorProperty::get_tooltip_text); + ClassDB::bind_method(D_METHOD("emit_changed", "property", "value", "field", "changing"), &EditorProperty::emit_changed, DEFVAL(StringName()), DEFVAL(false)); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "checkable"), "set_checkable", "is_checkable"); @@ -1965,14 +1972,14 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo } } -void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, bool changing) { +void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool changing) { // The "changing" variable must be true for properties that trigger events as typing occurs, // like "text_changed" signal. eg: Text property of Label, Button, RichTextLabel, etc. if (changing) this->changing++; - _edit_set(p_path, p_value, false, ""); + _edit_set(p_path, p_value, false, p_name); if (changing) this->changing--; @@ -2199,7 +2206,7 @@ String EditorInspector::get_object_class() const { void EditorInspector::_bind_methods() { - ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(false)); + ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(""), DEFVAL(false)); ClassDB::bind_method("_multiple_properties_changed", &EditorInspector::_multiple_properties_changed); ClassDB::bind_method("_property_changed_update_all", &EditorInspector::_property_changed_update_all); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index b39b62bdce..d64a78be57 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -102,6 +102,8 @@ protected: void _gui_input(const Ref<InputEvent> &p_event); public: + void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false); + virtual Size2 get_minimum_size() const; void set_label(const String &p_label); @@ -299,7 +301,7 @@ class EditorInspector : public ScrollContainer { void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field); - void _property_changed(const String &p_path, const Variant &p_value, bool changing = false); + void _property_changed(const String &p_path, const Variant &p_value, const String &p_name = "", bool changing = false); void _property_changed_update_all(const String &p_path, const Variant &p_value); void _multiple_properties_changed(Vector<String> p_paths, Array p_values); void _property_keyed(const String &p_path, bool p_advance); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index e33b26d9cb..c5d0f13c60 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -61,7 +61,7 @@ void EditorPropertyText::_text_changed(const String &p_string) { if (updating) return; - emit_signal("property_changed", get_edited_property(), p_string, true); + emit_changed(get_edited_property(), p_string, "", true); } void EditorPropertyText::update_property() { @@ -96,11 +96,11 @@ EditorPropertyText::EditorPropertyText() { void EditorPropertyMultilineText::_big_text_changed() { text->set_text(big_text->get_text()); - emit_signal("property_changed", get_edited_property(), big_text->get_text(), true); + emit_changed(get_edited_property(), big_text->get_text(), "", true); } void EditorPropertyMultilineText::_text_changed() { - emit_signal("property_changed", get_edited_property(), text->get_text(), true); + emit_changed(get_edited_property(), text->get_text(), "", true); } void EditorPropertyMultilineText::_open_big_text() { @@ -168,7 +168,7 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() { void EditorPropertyTextEnum::_option_selected(int p_which) { - emit_signal("property_changed", get_edited_property(), options->get_item_text(p_which)); + emit_changed(get_edited_property(), options->get_item_text(p_which)); } void EditorPropertyTextEnum::update_property() { @@ -207,7 +207,7 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() { void EditorPropertyPath::_path_selected(const String &p_path) { - emit_signal("property_changed", get_edited_property(), p_path); + emit_changed(get_edited_property(), p_path); update_property(); } void EditorPropertyPath::_path_pressed() { @@ -327,7 +327,7 @@ void EditorPropertyClassName::_property_selected() { void EditorPropertyClassName::_dialog_created() { selected_type = dialog->get_selected_type(); - emit_signal("property_changed", get_edited_property(), selected_type); + emit_changed(get_edited_property(), selected_type); update_property(); } @@ -353,7 +353,7 @@ EditorPropertyClassName::EditorPropertyClassName() { void EditorPropertyMember::_property_selected(const String &p_selected) { - emit_signal("property_changed", get_edited_property(), p_selected); + emit_changed(get_edited_property(), p_selected); update_property(); } @@ -457,7 +457,7 @@ EditorPropertyMember::EditorPropertyMember() { ///////////////////// CHECK ///////////////////////// void EditorPropertyCheck::_checkbox_pressed() { - emit_signal("property_changed", get_edited_property(), checkbox->is_pressed()); + emit_changed(get_edited_property(), checkbox->is_pressed()); } void EditorPropertyCheck::update_property() { @@ -484,7 +484,7 @@ EditorPropertyCheck::EditorPropertyCheck() { void EditorPropertyEnum::_option_selected(int p_which) { int val = options->get_item_metadata(p_which); - emit_signal("property_changed", get_edited_property(), val); + emit_changed(get_edited_property(), val); } void EditorPropertyEnum::update_property() { @@ -543,7 +543,7 @@ void EditorPropertyFlags::_flag_toggled() { } } - emit_signal("property_changed", get_edited_property(), value); + emit_changed(get_edited_property(), value); } void EditorPropertyFlags::update_property() { @@ -691,7 +691,7 @@ public: }; void EditorPropertyLayers::_grid_changed(uint32_t p_grid) { - emit_signal("property_changed", get_edited_property(), p_grid); + emit_changed(get_edited_property(), p_grid); } void EditorPropertyLayers::update_property() { @@ -801,7 +801,7 @@ EditorPropertyLayers::EditorPropertyLayers() { void EditorPropertyInteger::_value_changed(double val) { if (setting) return; - emit_signal("property_changed", get_edited_property(), int(val)); + emit_changed(get_edited_property(), int(val)); } void EditorPropertyInteger::update_property() { @@ -878,7 +878,7 @@ void EditorPropertyFloat::_value_changed(double val) { if (setting) return; - emit_signal("property_changed", get_edited_property(), val); + emit_changed(get_edited_property(), val); } void EditorPropertyFloat::update_property() { @@ -948,7 +948,7 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { if (sg) val = -val; - emit_signal("property_changed", get_edited_property(), val); + emit_changed(get_edited_property(), val); easing_draw->update(); } } @@ -999,7 +999,7 @@ void EditorPropertyEasing::update_property() { void EditorPropertyEasing::_set_preset(int p_preset) { static const float preset_value[EASING_MAX] = { 0.0, 1.0, 2.0, 0.5, -2.0, -0.5 }; - emit_signal("property_changed", get_edited_property(), preset_value[p_preset]); + emit_changed(get_edited_property(), preset_value[p_preset]); easing_draw->update(); } @@ -1056,14 +1056,14 @@ EditorPropertyEasing::EditorPropertyEasing() { ///////////////////// VECTOR2 ///////////////////////// -void EditorPropertyVector2::_value_changed(double val) { +void EditorPropertyVector2::_value_changed(double val, const String &p_name) { if (setting) return; Vector2 v2; v2.x = spin[0]->get_value(); v2.y = spin[1]->get_value(); - emit_signal("property_changed", get_edited_property(), v2); + emit_changed(get_edited_property(), v2, p_name); } void EditorPropertyVector2::update_property() { @@ -1123,7 +1123,7 @@ EditorPropertyVector2::EditorPropertyVector2() { spin[i]->set_label(desc[i]); bc->add_child(spin[i]); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); if (horizontal) { spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); } @@ -1137,7 +1137,7 @@ EditorPropertyVector2::EditorPropertyVector2() { ///////////////////// RECT2 ///////////////////////// -void EditorPropertyRect2::_value_changed(double val) { +void EditorPropertyRect2::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1146,7 +1146,7 @@ void EditorPropertyRect2::_value_changed(double val) { r2.position.y = spin[1]->get_value(); r2.size.x = spin[2]->get_value(); r2.size.y = spin[3]->get_value(); - emit_signal("property_changed", get_edited_property(), r2); + emit_changed(get_edited_property(), r2, p_name); } void EditorPropertyRect2::update_property() { @@ -1207,7 +1207,7 @@ EditorPropertyRect2::EditorPropertyRect2() { spin[i]->set_flat(true); bc->add_child(spin[i]); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); if (horizontal) { spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); } @@ -1221,7 +1221,7 @@ EditorPropertyRect2::EditorPropertyRect2() { ///////////////////// VECTOR3 ///////////////////////// -void EditorPropertyVector3::_value_changed(double val) { +void EditorPropertyVector3::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1229,7 +1229,7 @@ void EditorPropertyVector3::_value_changed(double val) { v3.x = spin[0]->get_value(); v3.y = spin[1]->get_value(); v3.z = spin[2]->get_value(); - emit_signal("property_changed", get_edited_property(), v3); + emit_changed(get_edited_property(), v3, p_name); } void EditorPropertyVector3::update_property() { @@ -1288,7 +1288,7 @@ EditorPropertyVector3::EditorPropertyVector3() { spin[i]->set_label(desc[i]); bc->add_child(spin[i]); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); if (horizontal) { spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); } @@ -1301,7 +1301,7 @@ EditorPropertyVector3::EditorPropertyVector3() { } ///////////////////// PLANE ///////////////////////// -void EditorPropertyPlane::_value_changed(double val) { +void EditorPropertyPlane::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1310,7 +1310,7 @@ void EditorPropertyPlane::_value_changed(double val) { p.normal.y = spin[1]->get_value(); p.normal.z = spin[2]->get_value(); p.d = spin[3]->get_value(); - emit_signal("property_changed", get_edited_property(), p); + emit_changed(get_edited_property(), p, p_name); } void EditorPropertyPlane::update_property() { @@ -1371,7 +1371,7 @@ EditorPropertyPlane::EditorPropertyPlane() { spin[i]->set_label(desc[i]); bc->add_child(spin[i]); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); if (horizontal) { spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); } @@ -1385,7 +1385,7 @@ EditorPropertyPlane::EditorPropertyPlane() { ///////////////////// QUAT ///////////////////////// -void EditorPropertyQuat::_value_changed(double val) { +void EditorPropertyQuat::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1394,7 +1394,7 @@ void EditorPropertyQuat::_value_changed(double val) { p.y = spin[1]->get_value(); p.z = spin[2]->get_value(); p.w = spin[3]->get_value(); - emit_signal("property_changed", get_edited_property(), p); + emit_changed(get_edited_property(), p, p_name); } void EditorPropertyQuat::update_property() { @@ -1454,7 +1454,7 @@ EditorPropertyQuat::EditorPropertyQuat() { spin[i]->set_label(desc[i]); bc->add_child(spin[i]); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); if (horizontal) { spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); } @@ -1468,7 +1468,7 @@ EditorPropertyQuat::EditorPropertyQuat() { ///////////////////// AABB ///////////////////////// -void EditorPropertyAABB::_value_changed(double val) { +void EditorPropertyAABB::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1480,7 +1480,7 @@ void EditorPropertyAABB::_value_changed(double val) { p.size.y = spin[4]->get_value(); p.size.z = spin[5]->get_value(); - emit_signal("property_changed", get_edited_property(), p); + emit_changed(get_edited_property(), p, p_name); } void EditorPropertyAABB::update_property() { @@ -1536,7 +1536,7 @@ EditorPropertyAABB::EditorPropertyAABB() { g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); } set_bottom_editor(g); setting = false; @@ -1544,7 +1544,7 @@ EditorPropertyAABB::EditorPropertyAABB() { ///////////////////// TRANSFORM2D ///////////////////////// -void EditorPropertyTransform2D::_value_changed(double val) { +void EditorPropertyTransform2D::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1556,7 +1556,7 @@ void EditorPropertyTransform2D::_value_changed(double val) { p[2][0] = spin[4]->get_value(); p[2][1] = spin[5]->get_value(); - emit_signal("property_changed", get_edited_property(), p); + emit_changed(get_edited_property(), p, p_name); } void EditorPropertyTransform2D::update_property() { @@ -1611,7 +1611,7 @@ EditorPropertyTransform2D::EditorPropertyTransform2D() { g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); } set_bottom_editor(g); setting = false; @@ -1619,7 +1619,7 @@ EditorPropertyTransform2D::EditorPropertyTransform2D() { ///////////////////// BASIS ///////////////////////// -void EditorPropertyBasis::_value_changed(double val) { +void EditorPropertyBasis::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1634,7 +1634,7 @@ void EditorPropertyBasis::_value_changed(double val) { p[1][2] = spin[7]->get_value(); p[2][2] = spin[8]->get_value(); - emit_signal("property_changed", get_edited_property(), p); + emit_changed(get_edited_property(), p, p_name); } void EditorPropertyBasis::update_property() { @@ -1692,7 +1692,7 @@ EditorPropertyBasis::EditorPropertyBasis() { g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); } set_bottom_editor(g); setting = false; @@ -1700,7 +1700,7 @@ EditorPropertyBasis::EditorPropertyBasis() { ///////////////////// TRANSFORM ///////////////////////// -void EditorPropertyTransform::_value_changed(double val) { +void EditorPropertyTransform::_value_changed(double val, const String &p_name) { if (setting) return; @@ -1718,7 +1718,7 @@ void EditorPropertyTransform::_value_changed(double val) { p.origin[1] = spin[10]->get_value(); p.origin[2] = spin[11]->get_value(); - emit_signal("property_changed", get_edited_property(), p); + emit_changed(get_edited_property(), p, p_name); } void EditorPropertyTransform::update_property() { @@ -1779,7 +1779,7 @@ EditorPropertyTransform::EditorPropertyTransform() { g->add_child(spin[i]); spin[i]->set_h_size_flags(SIZE_EXPAND_FILL); add_focusable(spin[i]); - spin[i]->connect("value_changed", this, "_value_changed"); + spin[i]->connect("value_changed", this, "_value_changed", varray(desc[i])); } set_bottom_editor(g); setting = false; @@ -1789,12 +1789,12 @@ EditorPropertyTransform::EditorPropertyTransform() { void EditorPropertyColor::_color_changed(const Color &p_color) { - emit_signal("property_changed", get_edited_property(), p_color, true); + emit_changed(get_edited_property(), p_color, "", true); } void EditorPropertyColor::_popup_closed() { - emit_signal("property_changed", get_edited_property(), picker->get_pick_color(), false); + emit_changed(get_edited_property(), picker->get_pick_color(), "", false); } void EditorPropertyColor::_bind_methods() { @@ -1855,7 +1855,7 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) { if (base_node) { // for AnimationTrackKeyEdit path = base_node->get_path().rel_path_to(p_path); } - emit_signal("property_changed", get_edited_property(), path); + emit_changed(get_edited_property(), path); update_property(); } @@ -1872,7 +1872,7 @@ void EditorPropertyNodePath::_node_assign() { void EditorPropertyNodePath::_node_clear() { - emit_signal("property_changed", get_edited_property(), NodePath()); + emit_changed(get_edited_property(), NodePath()); update_property(); } @@ -2005,7 +2005,7 @@ void EditorPropertyResource::_file_selected(const String &p_path) { EditorNode::get_singleton()->show_warning(vformat(TTR("The selected resource (%s) does not match any type expected for this property (%s)."), res->get_class(), property_types)); } - emit_signal("property_changed", get_edited_property(), res); + emit_changed(get_edited_property(), res); update_property(); } @@ -2054,7 +2054,7 @@ void EditorPropertyResource::_menu_option(int p_which) { } break; case OBJ_MENU_CLEAR: { - emit_signal("property_changed", get_edited_property(), RES()); + emit_changed(get_edited_property(), RES()); update_property(); } break; @@ -2096,7 +2096,7 @@ void EditorPropertyResource::_menu_option(int p_which) { res->set(p.first, p.second); } - emit_signal("property_changed", get_edited_property(), res); + emit_changed(get_edited_property(), res); update_property(); } break; @@ -2117,7 +2117,7 @@ void EditorPropertyResource::_menu_option(int p_which) { case OBJ_MENU_PASTE: { RES res = EditorSettings::get_singleton()->get_resource_clipboard(); - emit_signal("property_changed", get_edited_property(), res); + emit_changed(get_edited_property(), res); update_property(); } break; @@ -2151,7 +2151,7 @@ void EditorPropertyResource::_menu_option(int p_which) { Ref<Resource> new_res = conversions[to_type]->convert(res); - emit_signal("property_changed", get_edited_property(), new_res); + emit_changed(get_edited_property(), new_res); update_property(); break; } @@ -2202,7 +2202,7 @@ void EditorPropertyResource::_menu_option(int p_which) { } res = Ref<Resource>(resp); - emit_signal("property_changed", get_edited_property(), res); + emit_changed(get_edited_property(), res); update_property(); } break; @@ -2585,7 +2585,7 @@ void EditorPropertyResource::_viewport_selected(const NodePath &p_path) { vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node)); vt->setup_local_to_scene(); - emit_signal("property_changed", get_edited_property(), vt); + emit_changed(get_edited_property(), vt); update_property(); } @@ -2671,7 +2671,7 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant & if (drag_data.has("type") && String(drag_data["type"]) == "resource") { Ref<Resource> res = drag_data["resource"]; if (res.is_valid()) { - emit_signal("property_changed", get_edited_property(), res); + emit_changed(get_edited_property(), res); update_property(); return; } @@ -2685,7 +2685,7 @@ void EditorPropertyResource::drop_data_fw(const Point2 &p_point, const Variant & String file = files[0]; RES res = ResourceLoader::load(file); if (res.is_valid()) { - emit_signal("property_changed", get_edited_property(), res); + emit_changed(get_edited_property(), res); update_property(); return; } diff --git a/editor/editor_properties.h b/editor/editor_properties.h index ea4986626e..df01ee83b5 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -338,7 +338,7 @@ class EditorPropertyVector2 : public EditorProperty { GDCLASS(EditorPropertyVector2, EditorProperty) EditorSpinSlider *spin[2]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -354,7 +354,7 @@ class EditorPropertyRect2 : public EditorProperty { GDCLASS(EditorPropertyRect2, EditorProperty) EditorSpinSlider *spin[4]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -370,7 +370,7 @@ class EditorPropertyVector3 : public EditorProperty { GDCLASS(EditorPropertyVector3, EditorProperty) EditorSpinSlider *spin[3]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -386,7 +386,7 @@ class EditorPropertyPlane : public EditorProperty { GDCLASS(EditorPropertyPlane, EditorProperty) EditorSpinSlider *spin[4]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -402,7 +402,7 @@ class EditorPropertyQuat : public EditorProperty { GDCLASS(EditorPropertyQuat, EditorProperty) EditorSpinSlider *spin[4]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -418,7 +418,7 @@ class EditorPropertyAABB : public EditorProperty { GDCLASS(EditorPropertyAABB, EditorProperty) EditorSpinSlider *spin[6]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -434,7 +434,7 @@ class EditorPropertyTransform2D : public EditorProperty { GDCLASS(EditorPropertyTransform2D, EditorProperty) EditorSpinSlider *spin[6]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -450,7 +450,7 @@ class EditorPropertyBasis : public EditorProperty { GDCLASS(EditorPropertyBasis, EditorProperty) EditorSpinSlider *spin[9]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); @@ -466,7 +466,7 @@ class EditorPropertyTransform : public EditorProperty { GDCLASS(EditorPropertyTransform, EditorProperty) EditorSpinSlider *spin[12]; bool setting; - void _value_changed(double p_val); + void _value_changed(double p_val, const String &p_name); protected: void _notification(int p_what); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 20cb6ab534..0851485208 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -165,13 +165,13 @@ EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() { ///////////////////// ARRAY /////////////////////////// -void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value, bool changing) { +void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value, const String &p_name, bool changing) { if (p_prop.begins_with("indices")) { int idx = p_prop.get_slice("/", 1).to_int(); Variant array = object->get_array(); array.set(idx, p_value); - emit_signal("property_changed", get_edited_property(), array, true); + emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { array = array.call("duplicate"); //dupe, so undo/redo works better @@ -199,7 +199,7 @@ void EditorPropertyArray::_change_type_menu(int p_index) { Variant array = object->get_array(); array.set(changing_type_idx, value); - emit_signal("property_changed", get_edited_property(), array); + emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { array = array.call("duplicate"); //dupe, so undo/redo works better @@ -419,7 +419,7 @@ void EditorPropertyArray::_length_changed(double p_page) { Variant array = object->get_array(); array.call("resize", int(p_page)); - emit_signal("property_changed", get_edited_property(), array); + emit_changed(get_edited_property(), array, "", false); if (array.get_type() == Variant::ARRAY) { if (subtype != Variant::NIL) { @@ -461,7 +461,7 @@ void EditorPropertyArray::_bind_methods() { ClassDB::bind_method("_edit_pressed", &EditorPropertyArray::_edit_pressed); ClassDB::bind_method("_page_changed", &EditorPropertyArray::_page_changed); ClassDB::bind_method("_length_changed", &EditorPropertyArray::_length_changed); - ClassDB::bind_method("_property_changed", &EditorPropertyArray::_property_changed, DEFVAL(false)); + ClassDB::bind_method("_property_changed", &EditorPropertyArray::_property_changed, DEFVAL(String()), DEFVAL(false)); ClassDB::bind_method("_change_type", &EditorPropertyArray::_change_type); ClassDB::bind_method("_change_type_menu", &EditorPropertyArray::_change_type_menu); ClassDB::bind_method("_object_id_selected", &EditorPropertyArray::_object_id_selected); @@ -501,7 +501,7 @@ EditorPropertyArray::EditorPropertyArray() { ///////////////////// DICTIONARY /////////////////////////// -void EditorPropertyDictionary::_property_changed(const String &p_prop, Variant p_value, bool changing) { +void EditorPropertyDictionary::_property_changed(const String &p_prop, Variant p_value, const String &p_name, bool changing) { if (p_prop == "new_item_key") { @@ -515,7 +515,7 @@ void EditorPropertyDictionary::_property_changed(const String &p_prop, Variant p Variant key = dict.get_key_at_index(idx); dict[key] = p_value; - emit_signal("property_changed", get_edited_property(), dict, true); + emit_changed(get_edited_property(), dict, "", true); dict = dict.duplicate(); //dupe, so undo/redo works better object->set_dict(dict); @@ -546,7 +546,7 @@ void EditorPropertyDictionary::_add_key_value() { object->set_new_item_key(Variant()); object->set_new_item_value(Variant()); - emit_signal("property_changed", get_edited_property(), dict); + emit_changed(get_edited_property(), dict, "", false); dict = dict.duplicate(); //dupe, so undo/redo works better object->set_dict(dict); @@ -582,7 +582,7 @@ void EditorPropertyDictionary::_change_type_menu(int p_index) { dict.erase(key); } - emit_signal("property_changed", get_edited_property(), dict); + emit_changed(get_edited_property(), dict, "", false); dict = dict.duplicate(); //dupe, so undo/redo works better object->set_dict(dict); @@ -957,7 +957,7 @@ void EditorPropertyDictionary::_page_changed(double p_page) { void EditorPropertyDictionary::_bind_methods() { ClassDB::bind_method("_edit_pressed", &EditorPropertyDictionary::_edit_pressed); ClassDB::bind_method("_page_changed", &EditorPropertyDictionary::_page_changed); - ClassDB::bind_method("_property_changed", &EditorPropertyDictionary::_property_changed, DEFVAL(false)); + ClassDB::bind_method("_property_changed", &EditorPropertyDictionary::_property_changed, DEFVAL(String()), DEFVAL(false)); ClassDB::bind_method("_change_type", &EditorPropertyDictionary::_change_type); ClassDB::bind_method("_change_type_menu", &EditorPropertyDictionary::_change_type_menu); ClassDB::bind_method("_add_key_value", &EditorPropertyDictionary::_add_key_value); diff --git a/editor/editor_properties_array_dict.h b/editor/editor_properties_array_dict.h index 8aea1f8955..ff759105c3 100644 --- a/editor/editor_properties_array_dict.h +++ b/editor/editor_properties_array_dict.h @@ -100,7 +100,7 @@ class EditorPropertyArray : public EditorProperty { void _page_changed(double p_page); void _length_changed(double p_page); void _edit_pressed(); - void _property_changed(const String &p_prop, Variant p_value, bool changing = false); + void _property_changed(const String &p_prop, Variant p_value, const String &p_name = String(), bool changing = false); void _change_type(Object *p_button, int p_index); void _change_type_menu(int p_index); @@ -134,7 +134,7 @@ class EditorPropertyDictionary : public EditorProperty { void _page_changed(double p_page); void _edit_pressed(); - void _property_changed(const String &p_prop, Variant p_value, bool changing = false); + void _property_changed(const String &p_prop, Variant p_value, const String &p_name = String(), bool changing = false); void _change_type(Object *p_button, int p_index); void _change_type_menu(int p_index); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 62eac05cb7..13c80e5394 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -87,7 +87,7 @@ Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const { return Size2(10, 200); } -void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value) { +void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree(); updating = true; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index 6df62c33da..f2a77cecb4 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -104,7 +104,7 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { void _filter_toggled(); Ref<AnimationNode> _filter_edit; - void _property_changed(const StringName &p_property, const Variant &p_value); + void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); void _removed_from_graph(); EditorFileDialog *open_file; diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index a19e715d87..326e8394a0 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -39,7 +39,7 @@ void EditorPropertyRootMotion::_confirmed() { return; NodePath path = ti->get_metadata(0); - emit_signal("property_changed", get_edited_property(), path); + emit_changed(get_edited_property(), path); update_property(); filter_dialog->hide(); //may come from activated } @@ -195,7 +195,7 @@ void EditorPropertyRootMotion::_node_assign() { void EditorPropertyRootMotion::_node_clear() { - emit_signal("property_changed", get_edited_property(), NodePath()); + emit_changed(get_edited_property(), NodePath()); update_property(); } diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index becee4d633..628c2f714c 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -964,7 +964,7 @@ public: class VisualShaderNodePluginDefaultEditor : public VBoxContainer { GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer) public: - void _property_changed(const String &prop, const Variant &p_value, bool p_changing = false) { + void _property_changed(const String &prop, const Variant &p_value, const String &p_field, bool p_changing = false) { if (p_changing) return; @@ -1014,7 +1014,7 @@ public: } static void _bind_methods() { - ClassDB::bind_method("_property_changed", &VisualShaderNodePluginDefaultEditor::_property_changed, DEFVAL(false)); + ClassDB::bind_method("_property_changed", &VisualShaderNodePluginDefaultEditor::_property_changed, DEFVAL(String()), DEFVAL(false)); ClassDB::bind_method("_node_changed", &VisualShaderNodePluginDefaultEditor::_node_changed); ClassDB::bind_method("_refresh_request", &VisualShaderNodePluginDefaultEditor::_refresh_request); } diff --git a/editor/project_export.cpp b/editor/project_export.cpp index c2f9df9877..976eff0c56 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -512,7 +512,7 @@ Ref<EditorExportPreset> ProjectExportDialog::get_current_preset() const { return EditorExport::get_singleton()->get_export_preset(presets->get_current()); } -void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value) { +void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { if (updating) return; diff --git a/editor/project_export.h b/editor/project_export.h index d24c51509a..b292976a78 100644 --- a/editor/project_export.h +++ b/editor/project_export.h @@ -115,7 +115,7 @@ private: void _runnable_pressed(); void _update_parameters(const String &p_edited_property); void _name_changed(const String &p_string); - void _export_path_changed(const StringName &p_property, const Variant &p_value); + void _export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); void _add_preset(int p_platform); void _edit_preset(int p_index); void _duplicate_preset(); diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 554b8dbc3d..d54070df8d 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -163,7 +163,7 @@ void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool ShapeData &sd = shapes[p_owner]; sd.one_way_collision = p_enable; for (int i = 0; i < sd.shapes.size(); i++) { - Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, p_enable); + Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin); } } @@ -174,6 +174,27 @@ bool CollisionObject2D::is_shape_owner_one_way_collision_enabled(uint32_t p_owne return shapes[p_owner].one_way_collision; } +void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owner, float p_margin) { + + if (area) + return; //not for areas + + ERR_FAIL_COND(!shapes.has(p_owner)); + + ShapeData &sd = shapes[p_owner]; + sd.one_way_collision_margin = p_margin; + for (int i = 0; i < sd.shapes.size(); i++) { + Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin); + } +} + +float CollisionObject2D::get_shape_owner_one_way_collision_margin(uint32_t p_owner) const { + + ERR_FAIL_COND_V(!shapes.has(p_owner), 0); + + return shapes[p_owner].one_way_collision_margin; +} + void CollisionObject2D::get_shape_owners(List<uint32_t> *r_owners) { for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { @@ -390,6 +411,8 @@ void CollisionObject2D::_bind_methods() { ClassDB::bind_method(D_METHOD("is_shape_owner_disabled", "owner_id"), &CollisionObject2D::is_shape_owner_disabled); ClassDB::bind_method(D_METHOD("shape_owner_set_one_way_collision", "owner_id", "enable"), &CollisionObject2D::shape_owner_set_one_way_collision); ClassDB::bind_method(D_METHOD("is_shape_owner_one_way_collision_enabled", "owner_id"), &CollisionObject2D::is_shape_owner_one_way_collision_enabled); + ClassDB::bind_method(D_METHOD("shape_owner_set_one_way_collision_margin", "owner_id", "margin"), &CollisionObject2D::shape_owner_set_one_way_collision_margin); + ClassDB::bind_method(D_METHOD("get_shape_owner_one_way_collision_margin", "owner_id"), &CollisionObject2D::get_shape_owner_one_way_collision_margin); ClassDB::bind_method(D_METHOD("shape_owner_add_shape", "owner_id", "shape"), &CollisionObject2D::shape_owner_add_shape); ClassDB::bind_method(D_METHOD("shape_owner_get_shape_count", "owner_id"), &CollisionObject2D::shape_owner_get_shape_count); ClassDB::bind_method(D_METHOD("shape_owner_get_shape", "owner_id", "shape_id"), &CollisionObject2D::shape_owner_get_shape); diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index d796c171bf..8aa3330f37 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -54,10 +54,12 @@ class CollisionObject2D : public Node2D { Vector<Shape> shapes; bool disabled; bool one_way_collision; + float one_way_collision_margin; ShapeData() { disabled = false; one_way_collision = false; + one_way_collision_margin = 0; owner = NULL; } }; @@ -98,6 +100,9 @@ public: void shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable); bool is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const; + void shape_owner_set_one_way_collision_margin(uint32_t p_owner, float p_margin); + float get_shape_owner_one_way_collision_margin(uint32_t p_owner) const; + void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape); int shape_owner_get_shape_count(uint32_t p_owner) const; Ref<Shape2D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const; diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index ac99a598d4..5edd49b3a3 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -122,6 +122,7 @@ void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) { return; parent->shape_owner_set_disabled(owner_id, disabled); parent->shape_owner_set_one_way_collision(owner_id, one_way_collision); + parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); } void CollisionPolygon2D::_notification(int p_what) { @@ -311,6 +312,16 @@ bool CollisionPolygon2D::is_one_way_collision_enabled() const { return one_way_collision; } +void CollisionPolygon2D::set_one_way_collision_margin(float p_margin) { + one_way_collision_margin = p_margin; + if (parent) { + parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); + } +} + +float CollisionPolygon2D::get_one_way_collision_margin() const { + return one_way_collision_margin; +} void CollisionPolygon2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon2D::set_polygon); @@ -322,11 +333,14 @@ void CollisionPolygon2D::_bind_methods() { ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionPolygon2D::is_disabled); ClassDB::bind_method(D_METHOD("set_one_way_collision", "enabled"), &CollisionPolygon2D::set_one_way_collision); ClassDB::bind_method(D_METHOD("is_one_way_collision_enabled"), &CollisionPolygon2D::is_one_way_collision_enabled); + ClassDB::bind_method(D_METHOD("set_one_way_collision_margin", "margin"), &CollisionPolygon2D::set_one_way_collision_margin); + ClassDB::bind_method(D_METHOD("get_one_way_collision_margin"), &CollisionPolygon2D::get_one_way_collision_margin); ADD_PROPERTY(PropertyInfo(Variant::INT, "build_mode", PROPERTY_HINT_ENUM, "Solids,Segments"), "set_build_mode", "get_build_mode"); ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_way_collision"), "set_one_way_collision", "is_one_way_collision_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "one_way_collision_margin", PROPERTY_HINT_RANGE, "0,128,0.1"), "set_one_way_collision_margin", "get_one_way_collision_margin"); BIND_ENUM_CONSTANT(BUILD_SOLIDS); BIND_ENUM_CONSTANT(BUILD_SEGMENTS); @@ -341,4 +355,5 @@ CollisionPolygon2D::CollisionPolygon2D() { owner_id = 0; disabled = false; one_way_collision = false; + one_way_collision_margin = 1.0; } diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index 1e9bcf4646..b88679f15b 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -54,6 +54,7 @@ protected: CollisionObject2D *parent; bool disabled; bool one_way_collision; + float one_way_collision_margin; Vector<Vector<Vector2> > _decompose_in_convex(); @@ -84,6 +85,9 @@ public: void set_one_way_collision(bool p_enable); bool is_one_way_collision_enabled() const; + void set_one_way_collision_margin(float p_margin); + float get_one_way_collision_margin() const; + CollisionPolygon2D(); }; diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 1b648372c0..c756f49bbd 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -52,6 +52,7 @@ void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) { return; parent->shape_owner_set_disabled(owner_id, disabled); parent->shape_owner_set_one_way_collision(owner_id, one_way_collision); + parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); } void CollisionShape2D::_notification(int p_what) { @@ -219,6 +220,17 @@ bool CollisionShape2D::is_one_way_collision_enabled() const { return one_way_collision; } +void CollisionShape2D::set_one_way_collision_margin(float p_margin) { + one_way_collision_margin = p_margin; + if (parent) { + parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin); + } +} + +float CollisionShape2D::get_one_way_collision_margin() const { + return one_way_collision_margin; +} + void CollisionShape2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape2D::set_shape); @@ -227,11 +239,14 @@ void CollisionShape2D::_bind_methods() { ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionShape2D::is_disabled); ClassDB::bind_method(D_METHOD("set_one_way_collision", "enabled"), &CollisionShape2D::set_one_way_collision); ClassDB::bind_method(D_METHOD("is_one_way_collision_enabled"), &CollisionShape2D::is_one_way_collision_enabled); + ClassDB::bind_method(D_METHOD("set_one_way_collision_margin", "margin"), &CollisionShape2D::set_one_way_collision_margin); + ClassDB::bind_method(D_METHOD("get_one_way_collision_margin"), &CollisionShape2D::get_one_way_collision_margin); ClassDB::bind_method(D_METHOD("_shape_changed"), &CollisionShape2D::_shape_changed); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_way_collision"), "set_one_way_collision", "is_one_way_collision_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "one_way_collision_margin", PROPERTY_HINT_RANGE, "0,128,0.1"), "set_one_way_collision_margin", "get_one_way_collision_margin"); } CollisionShape2D::CollisionShape2D() { @@ -242,4 +257,5 @@ CollisionShape2D::CollisionShape2D() { parent = NULL; disabled = false; one_way_collision = false; + one_way_collision_margin = 1.0; } diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h index 8d74da0944..e913b4a866 100644 --- a/scene/2d/collision_shape_2d.h +++ b/scene/2d/collision_shape_2d.h @@ -46,6 +46,7 @@ class CollisionShape2D : public Node2D { void _shape_changed(); bool disabled; bool one_way_collision; + float one_way_collision_margin; void _update_in_shape_owner(bool p_xform_only = false); @@ -65,6 +66,9 @@ public: void set_one_way_collision(bool p_enable); bool is_one_way_collision_enabled() const; + void set_one_way_collision_margin(float p_margin); + float get_one_way_collision_margin() const; + virtual String get_configuration_warning() const; CollisionShape2D(); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index d61296b13f..44730062c4 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -481,7 +481,7 @@ void TileMap::update_dirty_quadrants() { } ps->body_add_shape(q.body, shape->get_rid(), xform); ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y)); - ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[i].one_way_collision); + ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[i].one_way_collision, shapes[i].one_way_collision_margin); shape_idx++; } } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0633d194f7..8df007dcc7 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1533,6 +1533,35 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu //_unblock(); } +void Viewport::_gui_call_notification(Control *p_control, int p_what) { + + CanvasItem *ci = p_control; + while (ci) { + + Control *control = Object::cast_to<Control>(ci); + if (control) { + + if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) { + control->notification(p_what); + } + + if (!control->is_inside_tree()) + break; + + if (!control->is_inside_tree() || control->is_set_as_toplevel()) + break; + if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) + break; + } + + if (ci->is_set_as_toplevel()) + break; + + ci = ci->get_parent_item(); + } + + //_unblock(); +} Control *Viewport::_gui_find_control(const Point2 &p_global) { _gui_prepare_subwindows(); @@ -1975,13 +2004,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (over != gui.mouse_over) { - if (gui.mouse_over) - gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT); + if (gui.mouse_over) { + _gui_call_notification(gui.mouse_over, Control::NOTIFICATION_MOUSE_EXIT); + } _gui_cancel_tooltip(); - if (over) - over->notification(Control::NOTIFICATION_MOUSE_ENTER); + if (over) { + _gui_call_notification(over, Control::NOTIFICATION_MOUSE_ENTER); + } } gui.mouse_over = over; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 0565fd3d18..cdb9d4afb5 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -305,6 +305,8 @@ private: bool disable_input; void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input); + void _gui_call_notification(Control *p_control, int p_what); + void _gui_prepare_subwindows(); void _gui_sort_subwindows(); void _gui_sort_roots(); diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 383f3f5d4e..3156e12c50 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1815,7 +1815,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { bool ok = false; - Variant res = _interpolate(vt->values, p_time, vt->update_mode == UPDATE_CONTINUOUS ? vt->interpolation : INTERPOLATION_NEAREST, vt->loop_wrap, &ok); + Variant res = _interpolate(vt->values, p_time, (vt->update_mode == UPDATE_CONTINUOUS || vt->update_mode == UPDATE_CAPTURE) ? vt->interpolation : INTERPOLATION_NEAREST, vt->loop_wrap, &ok); if (ok) { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 9cb4972a73..38a5f9714e 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -154,6 +154,8 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { tile_set_shape_transform(id, 0, p_value); else if (what == "shape_one_way") tile_set_shape_one_way(id, 0, p_value); + else if (what == "shape_one_way_margin") + tile_set_shape_one_way_margin(id, 0, p_value); else if (what == "shapes") _tile_set_shapes(id, p_value); else if (what == "occluder") @@ -266,6 +268,8 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { r_ret = tile_get_shape_transform(id, 0); else if (what == "shape_one_way") r_ret = tile_get_shape_one_way(id, 0); + else if (what == "shape_one_way_margin") + r_ret = tile_get_shape_one_way_margin(id, 0); else if (what == "shapes") r_ret = _tile_get_shapes(id); else if (what == "occluder") @@ -324,6 +328,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_EDITOR)); p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::REAL, pre + "shape_one_way_margin", PROPERTY_HINT_RANGE, "0,128,0.01", PROPERTY_USAGE_EDITOR)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1")); } @@ -715,6 +720,22 @@ bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const { return false; } +void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_margin) { + ERR_FAIL_COND(!tile_map.has(p_id)); + if (tile_map[p_id].shapes_data.size() <= p_shape_id) + tile_map[p_id].shapes_data.resize(p_shape_id + 1); + tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision_margin = p_margin; + emit_changed(); +} + +float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const { + ERR_FAIL_COND_V(!tile_map.has(p_id), 0); + if (tile_map[p_id].shapes_data.size() > p_shape_id) + return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin; + + return 0; +} + void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -884,6 +905,11 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { else s.one_way_collision = default_one_way; + if (d.has("one_way_margin") && d["one_way_margin"].is_num()) + s.one_way_collision_margin = d["one_way_margin"]; + else + s.one_way_collision = 1.0; + if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2) s.autotile_coord = d["autotile_coord"]; else @@ -911,6 +937,7 @@ Array TileSet::_tile_get_shapes(int p_id) const { shape_data["shape"] = data[i].shape; shape_data["shape_transform"] = data[i].shape_transform; shape_data["one_way"] = data[i].one_way_collision; + shape_data["one_way_margin"] = data[i].one_way_collision_margin; shape_data["autotile_coord"] = data[i].autotile_coord; arr.push_back(shape_data); } @@ -1034,6 +1061,8 @@ void TileSet::_bind_methods() { ClassDB::bind_method(D_METHOD("tile_get_shape_transform", "id", "shape_id"), &TileSet::tile_get_shape_transform); ClassDB::bind_method(D_METHOD("tile_set_shape_one_way", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way); ClassDB::bind_method(D_METHOD("tile_get_shape_one_way", "id", "shape_id"), &TileSet::tile_get_shape_one_way); + ClassDB::bind_method(D_METHOD("tile_set_shape_one_way_margin", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way_margin); + ClassDB::bind_method(D_METHOD("tile_get_shape_one_way_margin", "id", "shape_id"), &TileSet::tile_get_shape_one_way_margin); ClassDB::bind_method(D_METHOD("tile_add_shape", "id", "shape", "shape_transform", "one_way", "autotile_coord"), &TileSet::tile_add_shape, DEFVAL(false), DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("tile_get_shape_count", "id"), &TileSet::tile_get_shape_count); ClassDB::bind_method(D_METHOD("tile_set_shapes", "id", "shapes"), &TileSet::_tile_set_shapes); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index df162c9210..4800371d3c 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -48,9 +48,11 @@ public: Transform2D shape_transform; Vector2 autotile_coord; bool one_way_collision; + float one_way_collision_margin; ShapeData() { one_way_collision = false; + one_way_collision_margin = 1.0; } }; @@ -194,6 +196,9 @@ public: void tile_set_shape_one_way(int p_id, int p_shape_id, bool p_one_way); bool tile_get_shape_one_way(int p_id, int p_shape_id) const; + void tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_margin); + float tile_get_shape_one_way_margin(int p_id, int p_shape_id) const; + void tile_clear_shapes(int p_id); void tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way = false, const Vector2 &p_autotile_coord = Vector2()); int tile_get_shape_count(int p_id) const; diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp index 4fbc0769ba..4ec92497e7 100644 --- a/servers/physics_2d/collision_object_2d_sw.cpp +++ b/servers/physics_2d/collision_object_2d_sw.cpp @@ -40,6 +40,7 @@ void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Transform2D &p_tra s.bpid = 0; //needs update s.disabled = false; s.one_way_collision = false; + s.one_way_collision_margin = 0; shapes.push_back(s); p_shape->add_owner(this); _update_shapes(); diff --git a/servers/physics_2d/collision_object_2d_sw.h b/servers/physics_2d/collision_object_2d_sw.h index 6946217dbd..d5e815ff45 100644 --- a/servers/physics_2d/collision_object_2d_sw.h +++ b/servers/physics_2d/collision_object_2d_sw.h @@ -62,9 +62,11 @@ private: Variant metadata; bool disabled; bool one_way_collision; + float one_way_collision_margin; Shape() { disabled = false; one_way_collision = false; + one_way_collision_margin = 0; } }; @@ -150,15 +152,21 @@ public: return shapes[p_idx].disabled; } - _FORCE_INLINE_ void set_shape_as_one_way_collision(int p_idx, bool p_one_way_collision) { + _FORCE_INLINE_ void set_shape_as_one_way_collision(int p_idx, bool p_one_way_collision, float p_margin) { CRASH_BAD_INDEX(p_idx, shapes.size()); shapes.write[p_idx].one_way_collision = p_one_way_collision; + shapes.write[p_idx].one_way_collision_margin = p_margin; } _FORCE_INLINE_ bool is_shape_set_as_one_way_collision(int p_idx) const { CRASH_BAD_INDEX(p_idx, shapes.size()); return shapes[p_idx].one_way_collision; } + _FORCE_INLINE_ float get_shape_one_way_collision_margin(int p_idx) const { + CRASH_BAD_INDEX(p_idx, shapes.size()); + return shapes[p_idx].one_way_collision_margin; + } + void set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; } _FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; } diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index daea013d35..4d1c56b843 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -209,12 +209,14 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 & return; cbk->ptr[min_depth_idx * 2 + 0] = p_point_A; cbk->ptr[min_depth_idx * 2 + 1] = p_point_B; + cbk->passed++; } else { cbk->ptr[cbk->amount * 2 + 0] = p_point_A; cbk->ptr[cbk->amount * 2 + 1] = p_point_B; cbk->amount++; + cbk->passed++; } } @@ -233,6 +235,7 @@ bool Physics2DServerSW::shape_collide(RID p_shape_A, const Transform2D &p_xform_ CollCbkData cbk; cbk.max = p_result_max; cbk.amount = 0; + cbk.passed = 0; cbk.ptr = r_results; bool res = CollisionSolver2DSW::solve(shape_A, p_xform_A, p_motion_A, shape_B, p_xform_B, p_motion_B, _shape_col_cbk, &cbk); @@ -740,14 +743,14 @@ void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, boo body->set_shape_as_disabled(p_shape_idx, p_disabled); } -void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable) { +void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); - body->set_shape_as_one_way_collision(p_shape_idx, p_enable); + body->set_shape_as_one_way_collision(p_shape_idx, p_enable, p_margin); } void Physics2DServerSW::body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) { diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index da402ee16e..4beec41442 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -80,6 +80,7 @@ public: real_t valid_depth; int max; int amount; + int passed; int invalid_by_dir; Vector2 *ptr; }; @@ -188,7 +189,7 @@ public: virtual void body_clear_shapes(RID p_body); virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled); - virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable); + virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin); virtual void body_attach_object_instance_id(RID p_body, uint32_t p_ID); virtual uint32_t body_get_object_instance_id(RID p_body) const; diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 467d301ad5..5b9a102a1b 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -194,7 +194,7 @@ public: FUNC2RC(RID, body_get_shape, RID, int); FUNC3(body_set_shape_disabled, RID, int, bool); - FUNC3(body_set_shape_as_one_way_collision, RID, int, bool); + FUNC4(body_set_shape_as_one_way_collision, RID, int, bool, float); FUNC2(body_remove_shape, RID, int); FUNC1(body_clear_shapes, RID); diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 3d8005cd4d..77af0957e1 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -328,6 +328,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D & Physics2DServerSW::CollCbkData cbk; cbk.max = p_result_max; cbk.amount = 0; + cbk.passed = 0; cbk.ptr = r_results; CollisionSolver2DSW::CallbackResult cbkres = NULL; @@ -573,6 +574,7 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t int shape_idx = intersection_query_subindex_results[i]; cbk.amount = 0; + cbk.passed = 0; cbk.ptr = sr; cbk.invalid_by_dir = 0; @@ -720,6 +722,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co Physics2DServerSW::CollCbkData cbk; cbk.max = max_results; cbk.amount = 0; + cbk.passed = 0; cbk.ptr = sr; cbk.invalid_by_dir = 0; excluded_shape_pair_count = 0; //last step is the one valid @@ -759,7 +762,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co cbk.valid_dir = col_obj_shape_xform.get_axis(1).normalized(); - cbk.valid_depth = p_margin; //only valid depth is the collision margin + float owc_margin = col_obj->get_shape_one_way_collision_margin(shape_idx); + print_line("margin: " + rtos(owc_margin)); + cbk.valid_depth = MAX(owc_margin, p_margin); //user specified, but never less than actual margin or it wont work cbk.invalid_by_dir = 0; if (col_obj->get_type() == CollisionObject2DSW::TYPE_BODY) { @@ -780,12 +785,12 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co cbk.invalid_by_dir = 0; } - int current_collisions = cbk.amount; + int current_passed = cbk.passed; //save how many points passed collision bool did_collide = false; Shape2DSW *against_shape = col_obj->get_shape(shape_idx); if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), cbkres, cbkptr, NULL, separation_margin)) { - did_collide = cbk.amount > current_collisions; + did_collide = cbk.passed > current_passed; //more passed, so collision actually existed } if (!did_collide && cbk.invalid_by_dir > 0) { @@ -933,6 +938,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co Physics2DServerSW::CollCbkData cbk; cbk.max = 1; cbk.amount = 0; + cbk.passed = 0; cbk.ptr = cd; cbk.valid_dir = col_obj_shape_xform.get_axis(1).normalized(); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 86375b8e9e..df7fe46f76 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -398,7 +398,7 @@ public: virtual Variant body_get_shape_metadata(RID p_body, int p_shape_idx) const = 0; virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) = 0; - virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled) = 0; + virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, float p_margin = 0) = 0; virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0; virtual void body_clear_shapes(RID p_body) = 0; |