diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/area_2d.cpp | 8 | ||||
-rw-r--r-- | scene/2d/audio_stream_player_2d.cpp | 56 | ||||
-rw-r--r-- | scene/2d/audio_stream_player_2d.h | 11 | ||||
-rw-r--r-- | scene/2d/camera_2d.cpp | 42 | ||||
-rw-r--r-- | scene/2d/camera_2d.h | 14 | ||||
-rw-r--r-- | scene/2d/collision_polygon_2d.cpp | 55 | ||||
-rw-r--r-- | scene/2d/collision_shape_2d.cpp | 1 | ||||
-rw-r--r-- | scene/2d/cpu_particles_2d.cpp | 104 | ||||
-rw-r--r-- | scene/2d/joints_2d.cpp | 18 | ||||
-rw-r--r-- | scene/2d/joints_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/light_2d.cpp | 7 | ||||
-rw-r--r-- | scene/2d/light_2d.h | 1 | ||||
-rw-r--r-- | scene/2d/line_2d.cpp | 1 | ||||
-rw-r--r-- | scene/2d/polygon_2d.cpp | 7 | ||||
-rw-r--r-- | scene/2d/polygon_2d.h | 1 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 69 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/sprite_2d.cpp | 5 | ||||
-rw-r--r-- | scene/2d/touch_screen_button.cpp | 16 |
19 files changed, 252 insertions, 168 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 68d5b4b540..49d1654e3f 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -590,10 +590,10 @@ void Area2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_body_inout"), &Area2D::_body_inout); ClassDB::bind_method(D_METHOD("_area_inout"), &Area2D::_area_inout); - ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape"))); - ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape"))); - ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); - ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node2D"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape"))); + ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node2D"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape"))); + ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node2D"))); + ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node2D"))); ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area2D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "local_shape"))); ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area2D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "local_shape"))); diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 4e7eec906c..6d8d6058eb 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -35,14 +35,14 @@ #include "scene/main/window.h" void AudioStreamPlayer2D::_mix_audio() { - if (!stream_playback.is_valid() || !active || + if (!stream_playback.is_valid() || !active.is_set() || (stream_paused && !stream_paused_fade_out)) { return; } - if (setseek >= 0.0) { - stream_playback->start(setseek); - setseek = -1.0; //reset seek + if (setseek.get() >= 0.0) { + stream_playback->start(setseek.get()); + setseek.set(-1.0); //reset seek } //get data @@ -57,7 +57,8 @@ void AudioStreamPlayer2D::_mix_audio() { stream_playback->mix(buffer, pitch_scale, buffer_size); //write all outputs - for (int i = 0; i < output_count; i++) { + int oc = output_count.get(); + for (int i = 0; i < oc; i++) { Output current = outputs[i]; //see if current output exists, to keep volume ramp @@ -130,14 +131,14 @@ void AudioStreamPlayer2D::_mix_audio() { prev_outputs[i] = current; } - prev_output_count = output_count; + prev_output_count = oc; //stream is no longer active, disable this. if (!stream_playback->is_playing()) { - active = false; + active.clear(); } - output_ready = false; + output_ready.clear(); stream_paused_fade_in = false; stream_paused_fade_out = false; } @@ -168,7 +169,7 @@ void AudioStreamPlayer2D::_notification(int p_what) { if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { //update anything related to position first, if possible of course - if (!output_ready) { + if (!output_ready.is_set()) { List<Viewport *> viewports; Ref<World2D> world_2d = get_world_2d(); ERR_FAIL_COND(world_2d.is_null()); @@ -240,19 +241,19 @@ void AudioStreamPlayer2D::_notification(int p_what) { } } - output_count = new_output_count; - output_ready = true; + output_count.set(new_output_count); + output_ready.set(); } //start playing if requested - if (setplay >= 0.0) { - setseek = setplay; - active = true; - setplay = -1; + if (setplay.get() >= 0.0) { + setseek.set(setplay.get()); + active.set(); + setplay.set(-1); } //stop playing if no longer active - if (!active) { + if (!active.is_set()) { set_physics_process_internal(false); emit_signal("finished"); } @@ -267,8 +268,8 @@ void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) { if (stream_playback.is_valid()) { stream_playback.unref(); stream.unref(); - active = false; - setseek = -1; + active.clear(); + setseek.set(-1); } if (p_stream.is_valid()) { @@ -311,30 +312,29 @@ void AudioStreamPlayer2D::play(float p_from_pos) { } if (stream_playback.is_valid()) { - active = true; - setplay = p_from_pos; - output_ready = false; + setplay.set(p_from_pos); + output_ready.clear(); set_physics_process_internal(true); } } void AudioStreamPlayer2D::seek(float p_seconds) { if (stream_playback.is_valid()) { - setseek = p_seconds; + setseek.set(p_seconds); } } void AudioStreamPlayer2D::stop() { if (stream_playback.is_valid()) { - active = false; + active.clear(); set_physics_process_internal(false); - setplay = -1; + setplay.set(-1); } } bool AudioStreamPlayer2D::is_playing() const { if (stream_playback.is_valid()) { - return active; // && stream_playback->is_playing(); + return active.is_set() || setplay.get() >= 0; } return false; @@ -342,6 +342,10 @@ bool AudioStreamPlayer2D::is_playing() const { float AudioStreamPlayer2D::get_playback_position() { if (stream_playback.is_valid()) { + float ss = setseek.get(); + if (ss >= 0.0) { + return ss; + } return stream_playback->get_playback_position(); } @@ -381,7 +385,7 @@ void AudioStreamPlayer2D::_set_playing(bool p_enable) { } bool AudioStreamPlayer2D::_is_active() const { - return active; + return active.is_set(); } void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const { diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h index 6fb8cc414c..21f524c703 100644 --- a/scene/2d/audio_stream_player_2d.h +++ b/scene/2d/audio_stream_player_2d.h @@ -31,6 +31,7 @@ #ifndef AUDIO_STREAM_PLAYER_2D_H #define AUDIO_STREAM_PLAYER_2D_H +#include "core/templates/safe_refcount.h" #include "scene/2d/node_2d.h" #include "servers/audio/audio_stream.h" #include "servers/audio_server.h" @@ -52,8 +53,8 @@ private: }; Output outputs[MAX_OUTPUTS]; - volatile int output_count = 0; - volatile bool output_ready = false; + SafeNumeric<int> output_count; + SafeFlag output_ready; //these are used by audio thread to have a reference of previous volumes (for ramping volume and avoiding clicks) Output prev_outputs[MAX_OUTPUTS]; @@ -63,9 +64,9 @@ private: Ref<AudioStream> stream; Vector<AudioFrame> mix_buffer; - volatile float setseek = -1.0; - volatile bool active = false; - volatile float setplay = -1.0; + SafeNumeric<float> setseek{ -1.0 }; + SafeFlag active; + SafeNumeric<float> setplay{ -1.0 }; float volume_db = 0.0; float pitch_scale = 1.0; diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 853e92780b..9030cc4263 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -63,11 +63,11 @@ void Camera2D::_update_scroll() { }; } -void Camera2D::_update_process_mode() { +void Camera2D::_update_process_callback() { if (Engine::get_singleton()->is_editor_hint()) { set_process_internal(false); set_physics_process_internal(false); - } else if (process_mode == CAMERA2D_PROCESS_IDLE) { + } else if (process_callback == CAMERA2D_PROCESS_IDLE) { set_process_internal(true); set_physics_process_internal(false); } else { @@ -157,7 +157,7 @@ Transform2D Camera2D::get_camera_transform() { } if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) { - float c = smoothing * (process_mode == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); + float c = smoothing * (process_callback == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos; ret_camera_pos = smoothed_camera_pos; //camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing; @@ -247,7 +247,7 @@ void Camera2D::_notification(int p_what) { add_to_group(group_name); add_to_group(canvas_group_name); - _update_process_mode(); + _update_process_callback(); _update_scroll(); first = true; @@ -263,6 +263,7 @@ void Camera2D::_notification(int p_what) { viewport = nullptr; } break; +#ifdef TOOLS_ENABLED case NOTIFICATION_DRAW: { if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) { break; @@ -339,8 +340,8 @@ void Camera2D::_notification(int p_what) { draw_line(inv_transform.xform(margin_endpoints[i]), inv_transform.xform(margin_endpoints[(i + 1) % 4]), margin_drawing_color, margin_drawing_width); } } - } break; +#endif } } @@ -375,17 +376,17 @@ bool Camera2D::is_rotating() const { return rotating; } -void Camera2D::set_process_mode(Camera2DProcessMode p_mode) { - if (process_mode == p_mode) { +void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) { + if (process_callback == p_mode) { return; } - process_mode = p_mode; - _update_process_mode(); + process_callback = p_mode; + _update_process_callback(); } -Camera2D::Camera2DProcessMode Camera2D::get_process_mode() const { - return process_mode; +Camera2D::Camera2DProcessCallback Camera2D::get_process_callback() const { + return process_callback; } void Camera2D::_make_current(Object *p_which) { @@ -568,6 +569,7 @@ void Camera2D::_set_old_smoothing(float p_enable) { void Camera2D::set_enable_follow_smoothing(bool p_enabled) { smoothing_enabled = p_enabled; + notify_property_list_changed(); } bool Camera2D::is_follow_smoothing_enabled() const { @@ -610,7 +612,9 @@ Node *Camera2D::get_custom_viewport() const { void Camera2D::set_screen_drawing_enabled(bool enable) { screen_drawing_enabled = enable; +#ifdef TOOLS_ENABLED update(); +#endif } bool Camera2D::is_screen_drawing_enabled() const { @@ -619,7 +623,9 @@ bool Camera2D::is_screen_drawing_enabled() const { void Camera2D::set_limit_drawing_enabled(bool enable) { limit_drawing_enabled = enable; +#ifdef TOOLS_ENABLED update(); +#endif } bool Camera2D::is_limit_drawing_enabled() const { @@ -628,13 +634,21 @@ bool Camera2D::is_limit_drawing_enabled() const { void Camera2D::set_margin_drawing_enabled(bool enable) { margin_drawing_enabled = enable; +#ifdef TOOLS_ENABLED update(); +#endif } bool Camera2D::is_margin_drawing_enabled() const { return margin_drawing_enabled; } +void Camera2D::_validate_property(PropertyInfo &property) const { + if (!smoothing_enabled && property.name == "smoothing_speed") { + property.usage = PROPERTY_USAGE_NOEDITOR; + } +} + void Camera2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Camera2D::set_offset); ClassDB::bind_method(D_METHOD("get_offset"), &Camera2D::get_offset); @@ -651,8 +665,8 @@ void Camera2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll); - ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Camera2D::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &Camera2D::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &Camera2D::set_process_callback); + ClassDB::bind_method(D_METHOD("get_process_callback"), &Camera2D::get_process_callback); ClassDB::bind_method(D_METHOD("_set_current", "current"), &Camera2D::_set_current); ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current); @@ -714,7 +728,7 @@ void Camera2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "_set_current", "is_current"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom"), "set_zoom", "get_zoom"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", 0), "set_custom_viewport", "get_custom_viewport"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback"); ADD_GROUP("Limit", "limit_"); ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left"), "set_limit", "get_limit", SIDE_LEFT); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 3a7d01901d..220e208eb0 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -43,7 +43,7 @@ public: ANCHOR_MODE_DRAG_CENTER }; - enum Camera2DProcessMode { + enum Camera2DProcessCallback { CAMERA2D_PROCESS_PHYSICS, CAMERA2D_PROCESS_IDLE }; @@ -79,7 +79,7 @@ protected: bool drag_vertical_offset_changed = false; Point2 camera_screen_center; - void _update_process_mode(); + void _update_process_callback(); void _update_scroll(); void _make_current(Object *p_which); @@ -91,14 +91,16 @@ protected: bool limit_drawing_enabled = false; bool margin_drawing_enabled = false; - Camera2DProcessMode process_mode = CAMERA2D_PROCESS_IDLE; + Camera2DProcessCallback process_callback = CAMERA2D_PROCESS_IDLE; Size2 _get_camera_screen_size() const; protected: virtual Transform2D get_camera_transform(); + void _notification(int p_what); static void _bind_methods(); + void _validate_property(PropertyInfo &property) const override; public: void set_offset(const Vector2 &p_offset); @@ -137,8 +139,8 @@ public: void set_follow_smoothing(float p_speed); float get_follow_smoothing() const; - void set_process_mode(Camera2DProcessMode p_mode); - Camera2DProcessMode get_process_mode() const; + void set_process_callback(Camera2DProcessCallback p_mode); + Camera2DProcessCallback get_process_callback() const; void make_current(); void clear_current(); @@ -170,6 +172,6 @@ public: }; VARIANT_ENUM_CAST(Camera2D::AnchorMode); -VARIANT_ENUM_CAST(Camera2D::Camera2DProcessMode); +VARIANT_ENUM_CAST(Camera2D::Camera2DProcessCallback); #endif // CAMERA_2D_H diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 39d7705226..38198c496e 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -41,13 +41,13 @@ void CollisionPolygon2D::_build_polygon() { parent->shape_owner_clear_shapes(owner_id); - if (polygon.size() == 0) { - return; - } - bool solids = build_mode == BUILD_SOLIDS; if (solids) { + if (polygon.size() < 3) { + return; + } + //here comes the sun, lalalala //decompose concave into multiple convex polygons and add them Vector<Vector<Vector2>> decomp = _decompose_in_convex(); @@ -58,6 +58,10 @@ void CollisionPolygon2D::_build_polygon() { } } else { + if (polygon.size() < 2) { + return; + } + Ref<ConcavePolygonShape2D> concave = memnew(ConcavePolygonShape2D); Vector<Vector2> segments; @@ -132,25 +136,28 @@ void CollisionPolygon2D::_notification(int p_what) { break; } - for (int i = 0; i < polygon.size(); i++) { + int polygon_count = polygon.size(); + for (int i = 0; i < polygon_count; i++) { Vector2 p = polygon[i]; - Vector2 n = polygon[(i + 1) % polygon.size()]; + Vector2 n = polygon[(i + 1) % polygon_count]; // draw line with width <= 1, so it does not scale with zoom and break pixel exact editing draw_line(p, n, Color(0.9, 0.2, 0.0, 0.8), 1); } + + if (polygon_count > 2) { #define DEBUG_DECOMPOSE #if defined(TOOLS_ENABLED) && defined(DEBUG_DECOMPOSE) + Vector<Vector<Vector2>> decomp = _decompose_in_convex(); - Vector<Vector<Vector2>> decomp = _decompose_in_convex(); - - Color c(0.4, 0.9, 0.1); - for (int i = 0; i < decomp.size(); i++) { - c.set_hsv(Math::fmod(c.get_h() + 0.738, 1), c.get_s(), c.get_v(), 0.5); - draw_colored_polygon(decomp[i], c); - } + Color c(0.4, 0.9, 0.1); + for (int i = 0; i < decomp.size(); i++) { + c.set_hsv(Math::fmod(c.get_h() + 0.738, 1), c.get_s(), c.get_v(), 0.5); + draw_colored_polygon(decomp[i], c); + } #else - draw_colored_polygon(polygon, get_tree()->get_debug_collisions_color()); + draw_colored_polygon(polygon, get_tree()->get_debug_collisions_color()); #endif + } if (one_way_collision) { Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4); @@ -211,6 +218,8 @@ void CollisionPolygon2D::set_build_mode(BuildMode p_mode) { _build_polygon(); _update_in_shape_owner(); } + update(); + update_configuration_warning(); } CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const { @@ -241,11 +250,27 @@ String CollisionPolygon2D::get_configuration_warning() const { warning += TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."); } - if (polygon.is_empty()) { + int polygon_count = polygon.size(); + if (polygon_count == 0) { if (!warning.is_empty()) { warning += "\n\n"; } warning += TTR("An empty CollisionPolygon2D has no effect on collision."); + } else { + bool solids = build_mode == BUILD_SOLIDS; + if (solids) { + if (polygon_count < 3) { + if (!warning.is_empty()) { + warning += "\n\n"; + } + warning += TTR("Invalid polygon. At least 3 points are needed in 'Solids' build mode."); + } + } else if (polygon_count < 2) { + if (!warning.is_empty()) { + warning += "\n\n"; + } + warning += TTR("Invalid polygon. At least 2 points are needed in 'Segments' build mode."); + } } return warning; diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 4d1d274542..93949f741b 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -110,6 +110,7 @@ void CollisionShape2D::_notification(int p_what) { draw_col.r = g; draw_col.g = g; draw_col.b = g; + draw_col.a *= 0.5; } shape->draw(get_canvas_item(), draw_col); diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 0e51264171..48acee1bc4 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -1032,66 +1032,64 @@ void CPUParticles2D::_update_render_thread() { } void CPUParticles2D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - set_process_internal(emitting); - } - - if (p_what == NOTIFICATION_EXIT_TREE) { - _set_redraw(false); - } - - if (p_what == NOTIFICATION_DRAW) { - // first update before rendering to avoid one frame delay after emitting starts - if (emitting && (time == 0)) { - _update_internal(); - } - - if (!redraw) { - return; // don't add to render list - } - - RID texrid; - if (texture.is_valid()) { - texrid = texture->get_rid(); - } - - RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid); - } - - if (p_what == NOTIFICATION_INTERNAL_PROCESS) { - _update_internal(); - } - - if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - inv_emission_transform = get_global_transform().affine_inverse(); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + set_process_internal(emitting); + } break; + case NOTIFICATION_EXIT_TREE: { + _set_redraw(false); + } break; + case NOTIFICATION_DRAW: { + // first update before rendering to avoid one frame delay after emitting starts + if (emitting && (time == 0)) { + _update_internal(); + } - if (!local_coords) { - int pc = particles.size(); + if (!redraw) { + return; // don't add to render list + } - float *w = particle_data.ptrw(); - const Particle *r = particles.ptr(); - float *ptr = w; + RID texrid; + if (texture.is_valid()) { + texrid = texture->get_rid(); + } - for (int i = 0; i < pc; i++) { - Transform2D t = inv_emission_transform * r[i].transform; + RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid); + } break; + case NOTIFICATION_INTERNAL_PROCESS: { + _update_internal(); + } break; + case NOTIFICATION_TRANSFORM_CHANGED: { + inv_emission_transform = get_global_transform().affine_inverse(); - if (r[i].active) { - ptr[0] = t.elements[0][0]; - ptr[1] = t.elements[1][0]; - ptr[2] = 0; - ptr[3] = t.elements[2][0]; - ptr[4] = t.elements[0][1]; - ptr[5] = t.elements[1][1]; - ptr[6] = 0; - ptr[7] = t.elements[2][1]; + if (!local_coords) { + int pc = particles.size(); + + float *w = particle_data.ptrw(); + const Particle *r = particles.ptr(); + float *ptr = w; + + for (int i = 0; i < pc; i++) { + Transform2D t = inv_emission_transform * r[i].transform; + + if (r[i].active) { + ptr[0] = t.elements[0][0]; + ptr[1] = t.elements[1][0]; + ptr[2] = 0; + ptr[3] = t.elements[2][0]; + ptr[4] = t.elements[0][1]; + ptr[5] = t.elements[1][1]; + ptr[6] = 0; + ptr[7] = t.elements[2][1]; + + } else { + zeromem(ptr, sizeof(float) * 8); + } - } else { - zeromem(ptr, sizeof(float) * 8); + ptr += 16; } - - ptr += 16; } - } + } break; } } diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index f4f08674c9..7d9cdd52ac 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -49,19 +49,9 @@ void Joint2D::_disconnect_signals() { } } -void Joint2D::_body_exit_tree(const ObjectID &p_body_id) { +void Joint2D::_body_exit_tree() { _disconnect_signals(); - Object *object = ObjectDB::get_instance(p_body_id); - PhysicsBody2D *body = Object::cast_to<PhysicsBody2D>(object); - ERR_FAIL_NULL(body); - RID body_rid = body->get_rid(); - if (ba == body_rid) { - a = NodePath(); - } - if (bb == body_rid) { - b = NodePath(); - } - _update_joint(); + _update_joint(true); } void Joint2D::_update_joint(bool p_only_free) { @@ -142,8 +132,8 @@ void Joint2D::_update_joint(bool p_only_free) { ba = body_a->get_rid(); bb = body_b->get_rid(); - body_a->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint2D::_body_exit_tree), make_binds(body_a->get_instance_id())); - body_b->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint2D::_body_exit_tree), make_binds(body_b->get_instance_id())); + body_a->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint2D::_body_exit_tree)); + body_b->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Joint2D::_body_exit_tree)); PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h index 3607a6c176..08e02ee29d 100644 --- a/scene/2d/joints_2d.h +++ b/scene/2d/joints_2d.h @@ -51,7 +51,7 @@ class Joint2D : public Node2D { protected: void _disconnect_signals(); - void _body_exit_tree(const ObjectID &p_body_id); + void _body_exit_tree(); void _update_joint(bool p_only_free = false); void _notification(int p_what); diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 15fcb08422..58e15e3cca 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -159,6 +159,7 @@ int Light2D::get_item_shadow_cull_mask() const { void Light2D::set_shadow_enabled(bool p_enabled) { shadow = p_enabled; RS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow); + notify_property_list_changed(); } bool Light2D::is_shadow_enabled() const { @@ -221,6 +222,12 @@ float Light2D::get_shadow_smooth() const { return shadow_smooth; } +void Light2D::_validate_property(PropertyInfo &property) const { + if (!shadow && (property.name == "shadow_color" || property.name == "shadow_filter" || property.name == "shadow_filter_smooth" || property.name == "shadow_item_cull_mask")) { + property.usage = PROPERTY_USAGE_NOEDITOR; + } +} + void Light2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Light2D::set_enabled); ClassDB::bind_method(D_METHOD("is_enabled"), &Light2D::is_enabled); diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 4279baf15b..de8a2bb6d0 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -77,6 +77,7 @@ protected: _FORCE_INLINE_ RID _get_light() const { return canvas_light; } void _notification(int p_what); static void _bind_methods(); + void _validate_property(PropertyInfo &property) const override; public: void set_enabled(bool p_enabled); diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 2959ea1a36..37eb45c21d 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -116,6 +116,7 @@ Vector<Vector2> Line2D::get_points() const { } void Line2D::set_point_position(int i, Vector2 p_pos) { + ERR_FAIL_INDEX(i, _points.size()); _points.set(i, p_pos); update(); } diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index ecc05fb931..2bb75e5967 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -90,6 +90,12 @@ bool Polygon2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toler } #endif +void Polygon2D::_validate_property(PropertyInfo &property) const { + if (!invert && property.name == "invert_border") { + property.usage = PROPERTY_USAGE_NOEDITOR; + } +} + void Polygon2D::_skeleton_bone_setup_changed() { update(); } @@ -455,6 +461,7 @@ Size2 Polygon2D::get_texture_scale() const { void Polygon2D::set_invert(bool p_invert) { invert = p_invert; update(); + notify_property_list_changed(); } bool Polygon2D::get_invert() const { diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h index ab01a4ffd0..b329251277 100644 --- a/scene/2d/polygon_2d.h +++ b/scene/2d/polygon_2d.h @@ -75,6 +75,7 @@ class Polygon2D : public Node2D { protected: void _notification(int p_what); static void _bind_methods(); + void _validate_property(PropertyInfo &property) const override; public: #ifdef TOOLS_ENABLED diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 2cc3a74270..50625a0f39 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -159,30 +159,7 @@ void RayCast2D::_notification(int p_what) { if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; } - Transform2D xf; - xf.rotate(target_position.angle()); - xf.translate(Vector2(target_position.length(), 0)); - - // Draw an arrow indicating where the RayCast is pointing to - Color draw_col = get_tree()->get_debug_collisions_color(); - if (!enabled) { - float g = draw_col.get_v(); - draw_col.r = g; - draw_col.g = g; - draw_col.b = g; - } - draw_line(Vector2(), target_position, draw_col, 2); - Vector<Vector2> pts; - float tsize = 8.0; - pts.push_back(xf.xform(Vector2(tsize, 0))); - pts.push_back(xf.xform(Vector2(0, Math_SQRT12 * tsize))); - pts.push_back(xf.xform(Vector2(0, -Math_SQRT12 * tsize))); - Vector<Color> cols; - for (int i = 0; i < 3; i++) { - cols.push_back(draw_col); - } - - draw_primitive(pts, cols, Vector<Vector2>()); + _draw_debug_shape(); } break; @@ -212,7 +189,7 @@ void RayCast2D::_update_raycast_state() { } PhysicsDirectSpaceState2D::RayResult rr; - + bool prev_collision_state = collided; if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { collided = true; against = rr.collider_id; @@ -224,6 +201,48 @@ void RayCast2D::_update_raycast_state() { against = ObjectID(); against_shape = 0; } + + if (prev_collision_state != collided) { + update(); + } +} + +void RayCast2D::_draw_debug_shape() { + Color draw_col = collided ? Color(1.0, 0.01, 0) : get_tree()->get_debug_collisions_color(); + if (!enabled) { + float g = draw_col.get_v(); + draw_col.r = g; + draw_col.g = g; + draw_col.b = g; + } + + // Draw an arrow indicating where the RayCast is pointing to + const float max_arrow_size = 6; + const float line_width = 1.4; + bool no_line = target_position.length() < line_width; + float arrow_size = CLAMP(target_position.length() * 2 / 3, line_width, max_arrow_size); + + if (no_line) { + arrow_size = target_position.length(); + } else { + draw_line(Vector2(), target_position - target_position.normalized() * arrow_size, draw_col, line_width); + } + + Transform2D xf; + xf.rotate(target_position.angle()); + xf.translate(Vector2(no_line ? 0 : target_position.length() - arrow_size, 0)); + + Vector<Vector2> pts; + pts.push_back(xf.xform(Vector2(arrow_size, 0))); + pts.push_back(xf.xform(Vector2(0, 0.5 * arrow_size))); + pts.push_back(xf.xform(Vector2(0, -0.5 * arrow_size))); + + Vector<Color> cols; + for (int i = 0; i < 3; i++) { + cols.push_back(draw_col); + } + + draw_primitive(pts, cols, Vector<Vector2>()); } void RayCast2D::force_raycast_update() { diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h index dab3302e25..984c6bda49 100644 --- a/scene/2d/ray_cast_2d.h +++ b/scene/2d/ray_cast_2d.h @@ -51,6 +51,8 @@ class RayCast2D : public Node2D { bool collide_with_areas = false; bool collide_with_bodies = true; + void _draw_debug_shape(); + protected: void _notification(int p_what); void _update_raycast_state(); diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index dde9790b44..31040020dd 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -206,6 +206,7 @@ void Sprite2D::set_region(bool p_region) { region = p_region; update(); + notify_property_list_changed(); } bool Sprite2D::is_region() const { @@ -383,6 +384,10 @@ void Sprite2D::_validate_property(PropertyInfo &property) const { if (property.name == "frame_coords") { property.usage |= PROPERTY_USAGE_KEYING_INCREMENTS; } + + if (!region && (property.name == "region_rect" || property.name == "region_filter_clip")) { + property.usage = PROPERTY_USAGE_NOEDITOR; + } } void Sprite2D::_texture_changed() { diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index fccf126dad..9d6868a1b2 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -129,8 +129,11 @@ void TouchScreenButton::_notification(int p_what) { if (shape.is_valid()) { Color draw_col = get_tree()->get_debug_collisions_color(); - Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size(); - Vector2 pos = shape_centered ? size * 0.5f : Vector2(); + Vector2 pos; + if (shape_centered && texture.is_valid()) { + pos = texture->get_size() * 0.5; + } + draw_set_transform_matrix(get_canvas_transform().translated(pos)); shape->draw(get_canvas_item(), draw_col); } @@ -251,9 +254,12 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) { if (shape.is_valid()) { check_rect = false; - Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size(); - Transform2D xform = shape_centered ? Transform2D().translated(size * 0.5f) : Transform2D(); - touched = shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5))); + Vector2 pos; + if (shape_centered && texture.is_valid()) { + pos = texture->get_size() * 0.5; + } + + touched = shape->collide(Transform2D().translated(pos), unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5))); } if (bitmask.is_valid()) { |