Implement stream-type particle emitter
parent
cb0a93ee70
commit
be75263c2c
|
@ -12,7 +12,7 @@
|
||||||
#define MAX_EMITTER_CONF 8
|
#define MAX_EMITTER_CONF 8
|
||||||
//#define MAX_PARTICLE_EMITTER 8
|
//#define MAX_PARTICLE_EMITTER 8
|
||||||
#define MAX_ACTIVE_PARTICLE_EMITTER 32
|
#define MAX_ACTIVE_PARTICLE_EMITTER 32
|
||||||
#define MAX_PARTICLES 10
|
#define MAX_PARTICLES 32
|
||||||
|
|
||||||
#define MAX_TILE_TYPES 16
|
#define MAX_TILE_TYPES 16
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ static inline void spawn_particle(ParticleEmitter_t* emitter, uint32_t idx)
|
||||||
emitter->particles[idx].rotation = angle;
|
emitter->particles[idx].rotation = angle;
|
||||||
emitter->particles[idx].angular_vel = -10 + 20 * (float)rand() / (float)RAND_MAX;
|
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].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
|
// TODO: deal with stream type
|
||||||
//spawn_particle(emitter, 0);
|
//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->emitter_list[system->tail_idx].next = handle;
|
||||||
system->tail_idx = 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)
|
void pause_emitter_handle(ParticleSystem_t* system, uint16_t handle)
|
||||||
{
|
{
|
||||||
if (handle == 0) return;
|
if (handle == 0) return;
|
||||||
if (!system->emitter_list[handle].playing) return;
|
//if (!system->emitter_list[handle].playing) return;
|
||||||
|
|
||||||
system->emitters[handle].active = false;
|
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);
|
emitter->update_func(emitter->particles + i, emitter->user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// Lifetime update
|
// Lifetime update
|
||||||
if (emitter->particles[i].timer > 0) emitter->particles[i].timer--;
|
if (emitter->particles[i].timer > 0) emitter->particles[i].timer--;
|
||||||
if (emitter->particles[i].timer == 0)
|
if (emitter->particles[i].timer == 0)
|
||||||
|
{
|
||||||
|
if (emitter->particles[i].spawned)
|
||||||
{
|
{
|
||||||
emitter->particles[i].alive = false;
|
emitter->particles[i].alive = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emitter->particles[i].spawned = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!emitter->particles[i].alive)
|
if (!emitter->particles[i].alive)
|
||||||
{
|
{
|
||||||
if (emitter->config->one_shot || !emitter->active)
|
if (!emitter->active)
|
||||||
{
|
{
|
||||||
inactive_count++;
|
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
|
// If not one shot, immediately revive the particle
|
||||||
spawn_particle(emitter, i);
|
spawn_particle(emitter, i);
|
||||||
|
|
|
@ -36,6 +36,7 @@ typedef struct EmitterConfig
|
||||||
float launch_range[2];
|
float launch_range[2];
|
||||||
float speed_range[2];
|
float speed_range[2];
|
||||||
uint32_t particle_lifetime[2];
|
uint32_t particle_lifetime[2];
|
||||||
|
uint32_t initial_spawn_delay;
|
||||||
PartEmitterType_t type;
|
PartEmitterType_t type;
|
||||||
bool one_shot;
|
bool one_shot;
|
||||||
}EmitterConfig_t;
|
}EmitterConfig_t;
|
||||||
|
|
|
@ -81,10 +81,11 @@ int main(void)
|
||||||
|
|
||||||
EmitterConfig_t conf2 ={
|
EmitterConfig_t conf2 ={
|
||||||
.one_shot = false,
|
.one_shot = false,
|
||||||
.launch_range = {0, 360},
|
.launch_range = {45, 135},
|
||||||
.speed_range = {300, 800},
|
.speed_range = {300, 800},
|
||||||
.particle_lifetime = {15, 30},
|
.particle_lifetime = {15, 30},
|
||||||
.type = EMITTER_BURST,
|
.initial_spawn_delay = 5,
|
||||||
|
.type = EMITTER_STREAM,
|
||||||
};
|
};
|
||||||
|
|
||||||
ParticleEmitter_t emitter2 = {
|
ParticleEmitter_t emitter2 = {
|
||||||
|
|
Loading…
Reference in New Issue