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 | 12 | ||||
-rw-r--r-- | scene/2d/canvas_item.cpp | 7 | ||||
-rw-r--r-- | scene/2d/cpu_particles_2d.cpp | 30 | ||||
-rw-r--r-- | scene/2d/cpu_particles_2d.h | 11 | ||||
-rw-r--r-- | scene/2d/particles_2d.cpp | 14 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 15 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 6 | ||||
-rw-r--r-- | scene/2d/tile_map.cpp | 4 |
9 files changed, 70 insertions, 37 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 48537f3cfc..ae5891fa50 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -399,7 +399,7 @@ void Area2D::set_monitoring(bool p_enable) { if (p_enable == monitoring) return; if (locked) { - ERR_EXPLAIN("Function blocked during in/out signal. Use call_deferred(\"set_monitoring\",true/false)"); + ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitoring\",true/false)"); } ERR_FAIL_COND(locked); @@ -424,10 +424,10 @@ bool Area2D::is_monitoring() const { void Area2D::set_monitorable(bool p_enable) { - if (locked) { - ERR_EXPLAIN("This function can't be used during the in/out signal."); + if (locked || Physics2DServer::get_singleton()->is_flushing_queries()) { + ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)"); } - ERR_FAIL_COND(locked); + ERR_FAIL_COND(locked || Physics2DServer::get_singleton()->is_flushing_queries()); if (p_enable == monitorable) return; diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 9de72a4fcd..a092ef826f 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -92,6 +92,9 @@ void AudioStreamPlayer2D::_mix_audio() { int cc = AudioServer::get_singleton()->get_channel_count(); if (cc == 1) { + if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, 0)) + continue; //may have been removed + AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, 0); for (int j = 0; j < buffer_size; j++) { @@ -102,11 +105,20 @@ void AudioStreamPlayer2D::_mix_audio() { } else { AudioFrame *targets[4]; + bool valid = true; for (int k = 0; k < cc; k++) { + if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k)) { + valid = false; //may have been removed + break; + } + targets[k] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k); } + if (!valid) + continue; + for (int j = 0; j < buffer_size; j++) { AudioFrame frame = buffer[j] * vol; diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 7c734d6af5..0ea2e85dfa 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -123,7 +123,7 @@ void CanvasItemMaterial::_update_shader() { code += "\tfloat h_frames = float(particles_anim_h_frames);\n"; code += "\tfloat v_frames = float(particles_anim_v_frames);\n"; - code += "\tVERTEX.xy /= TEXTURE_PIXEL_SIZE * vec2(h_frames, v_frames);\n"; + code += "\tVERTEX.xy /= vec2(h_frames, v_frames);\n"; code += "\tint total_frames = particles_anim_h_frames * particles_anim_v_frames;\n"; code += "\tint frame = int(float(total_frames) * INSTANCE_CUSTOM.z);\n"; @@ -136,7 +136,7 @@ void CanvasItemMaterial::_update_shader() { code += "\tfloat frame_w = 1.0 / h_frames;\n"; code += "\tfloat frame_h = 1.0 / v_frames;\n"; code += "\tUV.x = UV.x * frame_w + frame_w * float(frame % particles_anim_h_frames);\n"; - code += "\tUV.y = UV.y * frame_h + frame_h * float(frame / particles_anim_v_frames);\n"; + code += "\tUV.y = UV.y * frame_h + frame_h * float(frame / particles_anim_h_frames);\n"; code += "}\n"; } @@ -376,6 +376,9 @@ bool CanvasItem::is_visible_in_tree() const { void CanvasItem::_propagate_visibility_changed(bool p_visible) { + if (p_visible && first_draw) { //avoid propagating it twice + first_draw = false; + } notification(NOTIFICATION_VISIBILITY_CHANGED); if (p_visible) diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index b6e2f4f5cd..a1b624a246 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -153,13 +153,19 @@ CPUParticles2D::DrawOrder CPUParticles2D::get_draw_order() const { return draw_order; } -void CPUParticles2D::_generate_mesh_texture() { +void CPUParticles2D::_update_mesh_texture() { + Size2 tex_size; + if (texture.is_valid()) { + tex_size = texture->get_size(); + } else { + tex_size = Size2(1, 1); + } PoolVector<Vector2> vertices; - vertices.push_back(Vector2(-0.5, -0.5)); - vertices.push_back(Vector2(0.5, -0.5)); - vertices.push_back(Vector2(0.5, 0.5)); - vertices.push_back(Vector2(-0.5, 0.5)); + vertices.push_back(-tex_size * 0.5); + vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, 0)); + vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, tex_size.y)); + vertices.push_back(-tex_size * 0.5 + Vector2(0, tex_size.y)); PoolVector<Vector2> uvs; uvs.push_back(Vector2(0, 0)); uvs.push_back(Vector2(1, 0)); @@ -193,6 +199,7 @@ void CPUParticles2D::set_texture(const Ref<Texture> &p_texture) { texture = p_texture; update(); + _update_mesh_texture(); } Ref<Texture> CPUParticles2D::get_texture() const { @@ -234,9 +241,12 @@ String CPUParticles2D::get_configuration_warning() const { CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); if (get_material().is_null() || (mat && !mat->get_particles_animation())) { - if (warnings != String()) - warnings += "\n"; - warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); + if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 || + get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) { + if (warnings != String()) + warnings += "\n"; + warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); + } } return warnings; @@ -1265,7 +1275,7 @@ void CPUParticles2D::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "initial_velocity", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater"), "set_param", "get_param", PARAM_INITIAL_LINEAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "initial_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_INITIAL_LINEAR_VELOCITY); ADD_GROUP("Angular Velocity", "angular_"); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_velocity", PROPERTY_HINT_RANGE, "-360,360,0.01"), "set_param", "get_param", PARAM_ANGULAR_VELOCITY); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_velocity", PROPERTY_HINT_RANGE, "-720,720,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGULAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGULAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angular_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_param_curve", "get_param_curve", PARAM_ANGULAR_VELOCITY); /* @@ -1396,7 +1406,7 @@ CPUParticles2D::CPUParticles2D() { update_mutex = Mutex::create(); #endif - _generate_mesh_texture(); + _update_mesh_texture(); } CPUParticles2D::~CPUParticles2D() { diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h index 15b7642b5e..d967c3be26 100644 --- a/scene/2d/cpu_particles_2d.h +++ b/scene/2d/cpu_particles_2d.h @@ -177,7 +177,7 @@ private: void _update_render_thread(); - void _generate_mesh_texture(); + void _update_mesh_texture(); protected: static void _bind_methods(); @@ -222,15 +222,6 @@ public: void set_texture(const Ref<Texture> &p_texture); Ref<Texture> get_texture() const; - void set_h_frames(int p_frames); - int get_h_frames(); - - void set_v_frames(int p_frames); - int get_v_frames(); - - void set_loop_animation(bool p_loop); - bool get_loop_animation() const; - void set_normalmap(const Ref<Texture> &p_normalmap); Ref<Texture> get_normalmap() const; diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 9c01d81c11..35b7e7da3e 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -219,6 +219,20 @@ String Particles2D::get_configuration_warning() const { if (warnings != String()) warnings += "\n"; warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted."); + } else { + + CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); + + if (get_material().is_null() || (mat && !mat->get_particles_animation())) { + const ParticlesMaterial *process = Object::cast_to<ParticlesMaterial>(process_material.ptr()); + if (process && + (process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 || + process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) { + if (warnings != String()) + warnings += "\n"; + warnings += "- " + TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); + } + } } return warnings; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 33c5fef151..929b4624ee 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1226,7 +1226,7 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ //so, if you pass 45 as limit, avoid numerical precision erros when angle is 45. #define FLOOR_ANGLE_THRESHOLD 0.01 -Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, bool p_infinite_inertia, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle) { +Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { Vector2 floor_motion = floor_velocity; if (on_floor && on_floor_body.is_valid()) { @@ -1237,7 +1237,8 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const } } - Vector2 motion = (floor_motion + p_linear_velocity) * get_physics_process_delta_time(); + // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky + Vector2 motion = (floor_motion + p_linear_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time()); Vector2 lv = p_linear_velocity; on_floor = false; @@ -1332,11 +1333,11 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const return lv; } -Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction, bool p_infinite_inertia, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle) { +Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { bool was_on_floor = on_floor; - Vector2 ret = move_and_slide(p_linear_velocity, p_floor_direction, p_infinite_inertia, p_stop_on_slope, p_max_slides, p_floor_max_angle); + Vector2 ret = move_and_slide(p_linear_velocity, p_floor_direction, p_stop_on_slope, p_max_slides, p_floor_max_angle, p_infinite_inertia); if (!was_on_floor || p_snap == Vector2()) { return ret; } @@ -1470,10 +1471,10 @@ void KinematicBody2D::_notification(int p_what) { void KinematicBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody2D::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "infinite_inertia", "stop_on_slope", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); - ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "floor_normal", "infinite_inertia", "stop_on_slope", "max_bounces", "floor_max_angle"), &KinematicBody2D::move_and_slide_with_snap, DEFVAL(Vector2(0, 0)), DEFVAL(true), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45))); + ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "floor_normal", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody2D::move_and_slide_with_snap, DEFVAL(Vector2(0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody2D::test_move); + ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody2D::test_move, DEFVAL(true)); ClassDB::bind_method(D_METHOD("is_on_floor"), &KinematicBody2D::is_on_floor); ClassDB::bind_method(D_METHOD("is_on_ceiling"), &KinematicBody2D::is_on_ceiling); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index ddd55f7b7f..c7b42add84 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -332,15 +332,15 @@ protected: public: bool move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes = true, bool p_test_only = false); - bool test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia); + bool test_move(const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia = true); bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision); void set_safe_margin(float p_margin); float get_safe_margin() const; - Vector2 move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); - Vector2 move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_infinite_inertia = true, bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45)); + Vector2 move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true); + Vector2 move_and_slide_with_snap(const Vector2 &p_linear_velocity, const Vector2 &p_snap, const Vector2 &p_floor_direction = Vector2(0, 0), bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true); bool is_on_floor() const; bool is_on_wall() const; bool is_on_ceiling() const; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index a7ac2bb982..8fe65f53a9 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -1114,6 +1114,8 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) { */ set_cell(x, y, v, flip_h, flip_v, transpose, Vector2(coord_x, coord_y)); } + + format = FORMAT_2; } PoolVector<int> TileMap::_get_tile_data() const { @@ -1403,7 +1405,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) { bool TileMap::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "format") { - r_ret = FORMAT_2; + r_ret = format; return true; } else if (p_name == "tile_data") { r_ret = _get_tile_data(); |