Skip to content

Commit

Permalink
Merge pull request #60347 from lawnjelly/interpolation_cpuparticles_p…
Browse files Browse the repository at this point in the history
…rocess

Fix CPUParticles emission updating using physics interpolation
  • Loading branch information
akien-mga authored Apr 25, 2022
2 parents 40ad013 + fbbb208 commit 4fc1a57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions scene/3d/cpu_particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ PoolVector<Face3> CPUParticles::get_faces(uint32_t p_usage_flags) const {
return PoolVector<Face3>();
}

void CPUParticles::_set_particles_processing(bool p_enable) {
if (_interpolated) {
set_physics_process_internal(p_enable);
} else {
set_process_internal(p_enable);
}
}

void CPUParticles::set_emitting(bool p_emitting) {
if (emitting == p_emitting) {
return;
}

emitting = p_emitting;
if (emitting) {
set_process_internal(true);
_set_particles_processing(true);

// first update before rendering to avoid one frame delay after emitting starts
if ((time == 0) && !_interpolated) {
Expand Down Expand Up @@ -534,7 +542,7 @@ void CPUParticles::_update_internal(bool p_on_physics_tick) {
} else {
inactive_time += delta;
if (inactive_time > lifetime * 1.2) {
set_process_internal(false);
_set_particles_processing(false);
_set_redraw(false);

//reset variables
Expand Down Expand Up @@ -1206,8 +1214,14 @@ void CPUParticles::_refresh_interpolation_state() {
_set_redraw(false);

_interpolated = interpolated;
set_process_internal(!_interpolated);
set_physics_process_internal(_interpolated);

if (_interpolated) {
set_process_internal(false);
set_physics_process_internal(emitting);
} else {
set_physics_process_internal(false);
set_process_internal(emitting);
}

// re-establish all connections
_set_redraw(curr_redraw);
Expand Down
1 change: 1 addition & 0 deletions scene/3d/cpu_particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class CPUParticles : public GeometryInstance {
void _update_render_thread();

void _set_redraw(bool p_redraw);
void _set_particles_processing(bool p_enable);
void _refresh_interpolation_state();

void _fill_particle_data(const ParticleBase &p_source, float *r_dest, bool p_active) const {
Expand Down

0 comments on commit 4fc1a57

Please sign in to comment.