diff options
Diffstat (limited to 'scene/2d/gpu_particles_2d.cpp')
-rw-r--r-- | scene/2d/gpu_particles_2d.cpp | 73 |
1 files changed, 28 insertions, 45 deletions
diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index de3f8fa09e..0814fbb549 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -39,7 +39,6 @@ #endif void GPUParticles2D::set_emitting(bool p_emitting) { - RS::get_singleton()->particles_set_emitting(particles, p_emitting); if (p_emitting && one_shot) { @@ -50,50 +49,49 @@ void GPUParticles2D::set_emitting(bool p_emitting) { } void GPUParticles2D::set_amount(int p_amount) { - ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1."); amount = p_amount; RS::get_singleton()->particles_set_amount(particles, amount); } -void GPUParticles2D::set_lifetime(float p_lifetime) { +void GPUParticles2D::set_lifetime(float p_lifetime) { ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; RS::get_singleton()->particles_set_lifetime(particles, lifetime); } void GPUParticles2D::set_one_shot(bool p_enable) { - one_shot = p_enable; RS::get_singleton()->particles_set_one_shot(particles, one_shot); if (is_emitting()) { - set_process_internal(true); - if (!one_shot) + if (!one_shot) { RenderingServer::get_singleton()->particles_restart(particles); + } } - if (!one_shot) + if (!one_shot) { set_process_internal(false); + } } -void GPUParticles2D::set_pre_process_time(float p_time) { +void GPUParticles2D::set_pre_process_time(float p_time) { pre_process_time = p_time; RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time); } -void GPUParticles2D::set_explosiveness_ratio(float p_ratio) { +void GPUParticles2D::set_explosiveness_ratio(float p_ratio) { explosiveness_ratio = p_ratio; RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio); } -void GPUParticles2D::set_randomness_ratio(float p_ratio) { +void GPUParticles2D::set_randomness_ratio(float p_ratio) { randomness_ratio = p_ratio; RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); } -void GPUParticles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { +void GPUParticles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { visibility_rect = p_visibility_rect; AABB aabb; aabb.position.x = p_visibility_rect.position.x; @@ -106,8 +104,8 @@ void GPUParticles2D::set_visibility_rect(const Rect2 &p_visibility_rect) { _change_notify("visibility_rect"); update(); } -void GPUParticles2D::set_use_local_coordinates(bool p_enable) { +void GPUParticles2D::set_use_local_coordinates(bool p_enable) { local_coords = p_enable; RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords); set_notify_transform(!p_enable); @@ -117,7 +115,6 @@ void GPUParticles2D::set_use_local_coordinates(bool p_enable) { } void GPUParticles2D::_update_particle_emission_transform() { - Transform2D xf2d = get_global_transform(); Transform xf; xf.basis.set_axis(0, Vector3(xf2d.get_axis(0).x, xf2d.get_axis(0).y, 0)); @@ -128,7 +125,6 @@ void GPUParticles2D::_update_particle_emission_transform() { } void GPUParticles2D::set_process_material(const Ref<Material> &p_material) { - process_material = p_material; Ref<ParticlesMaterial> pm = p_material; if (pm.is_valid() && !pm->get_flag(ParticlesMaterial::FLAG_DISABLE_Z) && pm->get_gravity() == Vector3(0, -9.8, 0)) { @@ -137,74 +133,69 @@ void GPUParticles2D::set_process_material(const Ref<Material> &p_material) { pm->set_gravity(Vector3(0, 98, 0)); } RID material_rid; - if (process_material.is_valid()) + if (process_material.is_valid()) { material_rid = process_material->get_rid(); + } RS::get_singleton()->particles_set_process_material(particles, material_rid); update_configuration_warning(); } void GPUParticles2D::set_speed_scale(float p_scale) { - speed_scale = p_scale; RS::get_singleton()->particles_set_speed_scale(particles, p_scale); } bool GPUParticles2D::is_emitting() const { - return RS::get_singleton()->particles_get_emitting(particles); } -int GPUParticles2D::get_amount() const { +int GPUParticles2D::get_amount() const { return amount; } -float GPUParticles2D::get_lifetime() const { +float GPUParticles2D::get_lifetime() const { return lifetime; } bool GPUParticles2D::get_one_shot() const { - return one_shot; } -float GPUParticles2D::get_pre_process_time() const { +float GPUParticles2D::get_pre_process_time() const { return pre_process_time; } -float GPUParticles2D::get_explosiveness_ratio() const { +float GPUParticles2D::get_explosiveness_ratio() const { return explosiveness_ratio; } -float GPUParticles2D::get_randomness_ratio() const { +float GPUParticles2D::get_randomness_ratio() const { return randomness_ratio; } -Rect2 GPUParticles2D::get_visibility_rect() const { +Rect2 GPUParticles2D::get_visibility_rect() const { return visibility_rect; } -bool GPUParticles2D::get_use_local_coordinates() const { +bool GPUParticles2D::get_use_local_coordinates() const { return local_coords; } -Ref<Material> GPUParticles2D::get_process_material() const { +Ref<Material> GPUParticles2D::get_process_material() const { return process_material; } float GPUParticles2D::get_speed_scale() const { - return speed_scale; } void GPUParticles2D::set_draw_order(DrawOrder p_order) { - draw_order = p_order; RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order)); } GPUParticles2D::DrawOrder GPUParticles2D::get_draw_order() const { - return draw_order; } @@ -227,7 +218,6 @@ bool GPUParticles2D::get_fractional_delta() const { } String GPUParticles2D::get_configuration_warning() const { - if (RenderingServer::get_singleton()->is_low_end()) { return TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose."); } @@ -235,11 +225,11 @@ String GPUParticles2D::get_configuration_warning() const { String warnings; if (process_material.is_null()) { - if (warnings != String()) + 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())) { @@ -247,8 +237,9 @@ String GPUParticles2D::get_configuration_warning() const { 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()) + if (warnings != String()) { warnings += "\n"; + } warnings += "- " + TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled."); } } @@ -258,7 +249,6 @@ String GPUParticles2D::get_configuration_warning() const { } Rect2 GPUParticles2D::capture_rect() const { - AABB aabb = RS::get_singleton()->particles_get_current_aabb(particles); Rect2 r; r.position.x = aabb.position.x; @@ -278,7 +268,6 @@ Ref<Texture2D> GPUParticles2D::get_texture() const { } void GPUParticles2D::set_normal_map(const Ref<Texture2D> &p_normal_map) { - normal_map = p_normal_map; update(); } @@ -296,21 +285,20 @@ void GPUParticles2D::restart() { } void GPUParticles2D::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - RID texture_rid; - if (texture.is_valid()) + if (texture.is_valid()) { texture_rid = texture->get_rid(); + } RID normal_rid; - if (normal_map.is_valid()) + if (normal_map.is_valid()) { normal_rid = normal_map->get_rid(); + } RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid); #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { - draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false); } #endif @@ -320,7 +308,6 @@ void GPUParticles2D::_notification(int p_what) { if (can_process()) { RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); } else { - RS::get_singleton()->particles_set_speed_scale(particles, 0); } } @@ -330,7 +317,6 @@ void GPUParticles2D::_notification(int p_what) { } if (p_what == NOTIFICATION_INTERNAL_PROCESS) { - if (one_shot && !is_emitting()) { _change_notify(); set_process_internal(false); @@ -339,7 +325,6 @@ void GPUParticles2D::_notification(int p_what) { } void GPUParticles2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles2D::set_emitting); ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles2D::set_amount); ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles2D::set_lifetime); @@ -407,7 +392,6 @@ void GPUParticles2D::_bind_methods() { } GPUParticles2D::GPUParticles2D() { - particles = RS::get_singleton()->particles_create(); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values @@ -427,6 +411,5 @@ GPUParticles2D::GPUParticles2D() { } GPUParticles2D::~GPUParticles2D() { - RS::get_singleton()->free(particles); } |