Merge pull request #46536 from likeich/master

Refactored cpu_particles_2d.cpp _notification Method
This commit is contained in:
Rémi Verschelde 2021-03-01 09:42:08 +01:00 committed by GitHub
commit d9c7dd910f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1032,66 +1032,64 @@ void CPUParticles2D::_update_render_thread() {
}
void CPUParticles2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
set_process_internal(emitting);
}
if (p_what == NOTIFICATION_EXIT_TREE) {
_set_redraw(false);
}
if (p_what == NOTIFICATION_DRAW) {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
_update_internal();
}
if (!redraw) {
return; // don't add to render list
}
RID texrid;
if (texture.is_valid()) {
texrid = texture->get_rid();
}
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
}
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
_update_internal();
}
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
inv_emission_transform = get_global_transform().affine_inverse();
if (!local_coords) {
int pc = particles.size();
float *w = particle_data.ptrw();
const Particle *r = particles.ptr();
float *ptr = w;
for (int i = 0; i < pc; i++) {
Transform2D t = inv_emission_transform * r[i].transform;
if (r[i].active) {
ptr[0] = t.elements[0][0];
ptr[1] = t.elements[1][0];
ptr[2] = 0;
ptr[3] = t.elements[2][0];
ptr[4] = t.elements[0][1];
ptr[5] = t.elements[1][1];
ptr[6] = 0;
ptr[7] = t.elements[2][1];
} else {
zeromem(ptr, sizeof(float) * 8);
}
ptr += 16;
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(emitting);
} break;
case NOTIFICATION_EXIT_TREE: {
_set_redraw(false);
} break;
case NOTIFICATION_DRAW: {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
_update_internal();
}
}
if (!redraw) {
return; // don't add to render list
}
RID texrid;
if (texture.is_valid()) {
texrid = texture->get_rid();
}
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
_update_internal();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
inv_emission_transform = get_global_transform().affine_inverse();
if (!local_coords) {
int pc = particles.size();
float *w = particle_data.ptrw();
const Particle *r = particles.ptr();
float *ptr = w;
for (int i = 0; i < pc; i++) {
Transform2D t = inv_emission_transform * r[i].transform;
if (r[i].active) {
ptr[0] = t.elements[0][0];
ptr[1] = t.elements[1][0];
ptr[2] = 0;
ptr[3] = t.elements[2][0];
ptr[4] = t.elements[0][1];
ptr[5] = t.elements[1][1];
ptr[6] = 0;
ptr[7] = t.elements[2][1];
} else {
zeromem(ptr, sizeof(float) * 8);
}
ptr += 16;
}
}
} break;
}
}