Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CPUParticles emission updating using physics interpolation #60347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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