Merge pull request #29937 from clayjohn/particles-one-shot-bug

Update emitting status on one-shot particles
This commit is contained in:
Rémi Verschelde 2019-06-27 17:29:40 +02:00 committed by GitHub
commit 0636f709af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 6 deletions

View file

@ -532,7 +532,8 @@ void CPUParticles2D::_particles_process(float p_delta) {
time = Math::fmod(time, lifetime); time = Math::fmod(time, lifetime);
cycle++; cycle++;
if (one_shot && cycle > 0) { if (one_shot && cycle > 0) {
emitting = false; set_emitting(false);
_change_notify();
} }
} }

View file

@ -41,6 +41,12 @@
void Particles2D::set_emitting(bool p_emitting) { void Particles2D::set_emitting(bool p_emitting) {
VS::get_singleton()->particles_set_emitting(particles, p_emitting); VS::get_singleton()->particles_set_emitting(particles, p_emitting);
if (p_emitting && one_shot) {
set_process_internal(true);
} else if (!p_emitting) {
set_process_internal(false);
}
} }
void Particles2D::set_amount(int p_amount) { void Particles2D::set_amount(int p_amount) {
@ -60,8 +66,16 @@ void Particles2D::set_one_shot(bool p_enable) {
one_shot = p_enable; one_shot = p_enable;
VS::get_singleton()->particles_set_one_shot(particles, one_shot); VS::get_singleton()->particles_set_one_shot(particles, one_shot);
if (!one_shot && is_emitting())
if (is_emitting()) {
set_process_internal(true);
if (!one_shot)
VisualServer::get_singleton()->particles_restart(particles); VisualServer::get_singleton()->particles_restart(particles);
}
if (!one_shot)
set_process_internal(false);
} }
void Particles2D::set_pre_process_time(float p_time) { void Particles2D::set_pre_process_time(float p_time) {
@ -314,6 +328,14 @@ void Particles2D::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
_update_particle_emission_transform(); _update_particle_emission_transform();
} }
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (one_shot && !is_emitting()) {
_change_notify();
set_process_internal(false);
}
}
} }
void Particles2D::_bind_methods() { void Particles2D::_bind_methods() {

View file

@ -505,7 +505,8 @@ void CPUParticles::_particles_process(float p_delta) {
time = Math::fmod(time, lifetime); time = Math::fmod(time, lifetime);
cycle++; cycle++;
if (one_shot && cycle > 0) { if (one_shot && cycle > 0) {
emitting = false; set_emitting(false);
_change_notify();
} }
} }

View file

@ -47,6 +47,12 @@ PoolVector<Face3> Particles::get_faces(uint32_t p_usage_flags) const {
void Particles::set_emitting(bool p_emitting) { void Particles::set_emitting(bool p_emitting) {
VS::get_singleton()->particles_set_emitting(particles, p_emitting); VS::get_singleton()->particles_set_emitting(particles, p_emitting);
if (p_emitting && one_shot) {
set_process_internal(true);
} else if (!p_emitting) {
set_process_internal(false);
}
} }
void Particles::set_amount(int p_amount) { void Particles::set_amount(int p_amount) {
@ -66,8 +72,16 @@ void Particles::set_one_shot(bool p_one_shot) {
one_shot = p_one_shot; one_shot = p_one_shot;
VS::get_singleton()->particles_set_one_shot(particles, one_shot); VS::get_singleton()->particles_set_one_shot(particles, one_shot);
if (!one_shot && is_emitting())
if (is_emitting()) {
set_process_internal(true);
if (!one_shot)
VisualServer::get_singleton()->particles_restart(particles); VisualServer::get_singleton()->particles_restart(particles);
}
if (!one_shot)
set_process_internal(false);
} }
void Particles::set_pre_process_time(float p_time) { void Particles::set_pre_process_time(float p_time) {
@ -307,6 +321,16 @@ void Particles::_notification(int p_what) {
VS::get_singleton()->particles_set_speed_scale(particles, 0); VS::get_singleton()->particles_set_speed_scale(particles, 0);
} }
} }
// Use internal process when emitting and one_shot are on so that when
// the shot ends the editor can properly update
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (one_shot && !is_emitting()) {
_change_notify();
set_process_internal(false);
}
}
} }
void Particles::_bind_methods() { void Particles::_bind_methods() {