summaryrefslogtreecommitdiffstats
path: root/scene/2d/cpu_particles_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/cpu_particles_2d.cpp')
-rw-r--r--scene/2d/cpu_particles_2d.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 115104adff..1c193f991e 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -30,9 +30,12 @@
#include "cpu_particles_2d.h"
-#include "core/core_string_names.h"
#include "scene/2d/gpu_particles_2d.h"
+#include "scene/resources/atlas_texture.h"
+#include "scene/resources/curve_texture.h"
+#include "scene/resources/gradient_texture.h"
#include "scene/resources/particle_process_material.h"
+#include "scene/scene_string_names.h"
void CPUParticles2D::set_emitting(bool p_emitting) {
if (emitting == p_emitting) {
@@ -41,6 +44,7 @@ void CPUParticles2D::set_emitting(bool p_emitting) {
emitting = p_emitting;
if (emitting) {
+ active = true;
set_process_internal(true);
}
}
@@ -202,13 +206,13 @@ void CPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) {
}
if (texture.is_valid()) {
- texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed));
+ texture->disconnect_changed(callable_mp(this, &CPUParticles2D::_texture_changed));
}
texture = p_texture;
if (texture.is_valid()) {
- texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed));
+ texture->connect_changed(callable_mp(this, &CPUParticles2D::_texture_changed));
}
queue_redraw();
@@ -259,7 +263,6 @@ PackedStringArray CPUParticles2D::get_configuration_warnings() const {
void CPUParticles2D::restart() {
time = 0;
- inactive_time = 0;
frame_remainder = 0;
cycle = 0;
emitting = false;
@@ -561,21 +564,15 @@ void CPUParticles2D::_update_internal() {
}
double delta = get_process_delta_time();
- if (emitting) {
- inactive_time = 0;
- } else {
- inactive_time += delta;
- if (inactive_time > lifetime * 1.2) {
- set_process_internal(false);
- _set_do_redraw(false);
+ if (!active && !emitting) {
+ set_process_internal(false);
+ _set_do_redraw(false);
- //reset variables
- time = 0;
- inactive_time = 0;
- frame_remainder = 0;
- cycle = 0;
- return;
- }
+ //reset variables
+ time = 0;
+ frame_remainder = 0;
+ cycle = 0;
+ return;
}
_set_do_redraw(true);
@@ -650,6 +647,7 @@ void CPUParticles2D::_particles_process(double p_delta) {
double system_phase = time / lifetime;
+ bool should_be_active = false;
for (int i = 0; i < pcount; i++) {
Particle &p = parray[i];
@@ -994,6 +992,12 @@ void CPUParticles2D::_particles_process(double p_delta) {
p.transform.columns[1] *= base_scale.y;
p.transform[2] += p.velocity * local_delta;
+
+ should_be_active = true;
+ }
+ if (!Math::is_equal_approx(time, 0.0) && active && !should_be_active) {
+ active = false;
+ emit_signal(SceneStringNames::get_singleton()->finished);
}
}
@@ -1364,6 +1368,8 @@ void CPUParticles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles2D::convert_from_particles);
+ ADD_SIGNAL(MethodInfo("finished"));
+
ADD_GROUP("Emission Shape", "emission_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Sphere Surface,Rectangle,Points,Directed Points", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01,suffix:px"), "set_emission_sphere_radius", "get_emission_sphere_radius");