diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-25 08:01:15 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-06-25 08:01:50 -0300 |
commit | 83ae9a5e2859a1dc2393aebeb9f9efdf12c53e73 (patch) | |
tree | 34a97197db8ae976f4ee4d8ac6ca2c44df65a218 /drivers | |
parent | 87fd71244be7b185f0525c6b33850f7075b1425a (diff) |
Ability to restart particle system with a function call
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 31 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 7 |
2 files changed, 38 insertions, 0 deletions
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index f7e1fdee9d..24a57b772b 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -5068,6 +5068,14 @@ void RasterizerStorageGLES3::particles_set_lifetime(RID p_particles, float p_lif ERR_FAIL_COND(!particles); particles->lifetime = p_lifetime; } + +void RasterizerStorageGLES3::particles_set_one_shot(RID p_particles, bool p_one_shot) { + + Particles *particles = particles_owner.getornull(p_particles); + ERR_FAIL_COND(!particles); + particles->one_shot = p_one_shot; +} + void RasterizerStorageGLES3::particles_set_pre_process_time(RID p_particles, float p_time) { Particles *particles = particles_owner.getornull(p_particles); @@ -5199,6 +5207,14 @@ void RasterizerStorageGLES3::particles_set_draw_pass_mesh(RID p_particles, int p particles->draw_passes[p_pass] = p_mesh; } +void RasterizerStorageGLES3::particles_restart(RID p_particles) { + + Particles *particles = particles_owner.getornull(p_particles); + ERR_FAIL_COND(!particles); + + particles->restart_request = true; +} + void RasterizerStorageGLES3::particles_request_process(RID p_particles) { Particles *particles = particles_owner.getornull(p_particles); @@ -5290,6 +5306,10 @@ void RasterizerStorageGLES3::_particles_process(Particles *particles, float p_de particles->cycle_number = 0; particles->random_seed = Math::rand(); } else if (new_phase < particles->phase) { + if (particles->one_shot) { + particles->emitting = false; + shaders.particles.set_uniform(ParticlesShaderGLES3::EMITTING, false); + } particles->cycle_number++; } @@ -5356,6 +5376,17 @@ void RasterizerStorageGLES3::update_particles() { Particles *particles = particle_update_list.first()->self(); + if (particles->restart_request) { + particles->emitting = true; //restart from zero + particles->prev_ticks = 0; + particles->phase = 0; + particles->prev_phase = 0; + particles->clear = true; + particles->particle_valid_histories[0] = false; + particles->particle_valid_histories[1] = false; + particles->restart_request = false; + } + if (particles->inactive && !particles->emitting) { particle_update_list.remove(particle_update_list.first()); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 79abebae5b..2ef47fe2cb 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -1036,11 +1036,13 @@ public: bool inactive; float inactive_time; bool emitting; + bool one_shot; int amount; float lifetime; float pre_process_time; float explosiveness; float randomness; + bool restart_request; Rect3 custom_aabb; bool use_local_coords; RID process_material; @@ -1080,6 +1082,7 @@ public: : particle_element(this) { cycle_number = 0; emitting = false; + one_shot = false; amount = 0; lifetime = 1.0; pre_process_time = 0.0; @@ -1093,6 +1096,8 @@ public: speed_scale = 1.0; random_seed = 0; + restart_request = false; + custom_aabb = Rect3(Vector3(-4, -4, -4), Vector3(8, 8, 8)); draw_order = VS::PARTICLES_DRAW_ORDER_INDEX; @@ -1131,6 +1136,7 @@ public: virtual void particles_set_emitting(RID p_particles, bool p_emitting); virtual void particles_set_amount(RID p_particles, int p_amount); virtual void particles_set_lifetime(RID p_particles, float p_lifetime); + virtual void particles_set_one_shot(RID p_particles, bool p_one_shot); virtual void particles_set_pre_process_time(RID p_particles, float p_time); virtual void particles_set_explosiveness_ratio(RID p_particles, float p_ratio); virtual void particles_set_randomness_ratio(RID p_particles, float p_ratio); @@ -1140,6 +1146,7 @@ public: virtual void particles_set_process_material(RID p_particles, RID p_material); virtual void particles_set_fixed_fps(RID p_particles, int p_fps); virtual void particles_set_fractional_delta(RID p_particles, bool p_enable); + virtual void particles_restart(RID p_particles); virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order); |