diff --git a/engine/engine_conf.h b/engine/engine_conf.h index 8184773..15baff0 100644 --- a/engine/engine_conf.h +++ b/engine/engine_conf.h @@ -12,7 +12,7 @@ #define MAX_EMITTER_CONF 8 //#define MAX_PARTICLE_EMITTER 8 #define MAX_ACTIVE_PARTICLE_EMITTER 32 -#define MAX_PARTICLES 10 +#define MAX_PARTICLES 32 #define MAX_TILE_TYPES 16 diff --git a/engine/particle_sys.c b/engine/particle_sys.c index 068e10f..fc241a2 100644 --- a/engine/particle_sys.c +++ b/engine/particle_sys.c @@ -43,6 +43,7 @@ static inline void spawn_particle(ParticleEmitter_t* emitter, uint32_t idx) emitter->particles[idx].rotation = angle; emitter->particles[idx].angular_vel = -10 + 20 * (float)rand() / (float)RAND_MAX; emitter->particles[idx].size = 10 + 20 * (float)rand() / (float)RAND_MAX; + emitter->particles[idx].spawned = true; ; } @@ -82,6 +83,14 @@ void play_emitter_handle(ParticleSystem_t* system, uint16_t handle) { // TODO: deal with stream type //spawn_particle(emitter, 0); + uint32_t incr = 0; + for (uint32_t i = 0; i < emitter->n_particles; ++i) + { + emitter->particles[i].timer = incr; + emitter->particles[i].alive = false; + emitter->particles[i].spawned = false; + incr += emitter->config->initial_spawn_delay; + } } system->emitter_list[system->tail_idx].next = handle; system->tail_idx = handle; @@ -97,7 +106,7 @@ void play_emitter_handle(ParticleSystem_t* system, uint16_t handle) void pause_emitter_handle(ParticleSystem_t* system, uint16_t handle) { if (handle == 0) return; - if (!system->emitter_list[handle].playing) return; + //if (!system->emitter_list[handle].playing) return; system->emitters[handle].active = false; } @@ -146,21 +155,32 @@ void update_particle_system(ParticleSystem_t* system) emitter->update_func(emitter->particles + i, emitter->user_data); } - // Lifetime update - if (emitter->particles[i].timer > 0) emitter->particles[i].timer--; - if (emitter->particles[i].timer == 0) + } + // Lifetime update + if (emitter->particles[i].timer > 0) emitter->particles[i].timer--; + if (emitter->particles[i].timer == 0) + { + if (emitter->particles[i].spawned) { emitter->particles[i].alive = false; } + else + { + emitter->particles[i].spawned = true; + } } if (!emitter->particles[i].alive) { - if (emitter->config->one_shot || !emitter->active) + if (!emitter->active) { inactive_count++; } - else + else if (emitter->config->one_shot) + { + inactive_count++; + } + else if (emitter->particles[i].spawned) { // If not one shot, immediately revive the particle spawn_particle(emitter, i); diff --git a/engine/particle_sys.h b/engine/particle_sys.h index eccf8b5..5452929 100644 --- a/engine/particle_sys.h +++ b/engine/particle_sys.h @@ -36,6 +36,7 @@ typedef struct EmitterConfig float launch_range[2]; float speed_range[2]; uint32_t particle_lifetime[2]; + uint32_t initial_spawn_delay; PartEmitterType_t type; bool one_shot; }EmitterConfig_t; diff --git a/particle_test.c b/particle_test.c index dd7907f..cdf364d 100644 --- a/particle_test.c +++ b/particle_test.c @@ -81,10 +81,11 @@ int main(void) EmitterConfig_t conf2 ={ .one_shot = false, - .launch_range = {0, 360}, + .launch_range = {45, 135}, .speed_range = {300, 800}, .particle_lifetime = {15, 30}, - .type = EMITTER_BURST, + .initial_spawn_delay = 5, + .type = EMITTER_STREAM, }; ParticleEmitter_t emitter2 = {