diff options
Diffstat (limited to 'src/modules/sparkler')
-rw-r--r-- | src/modules/sparkler/burst.c | 7 | ||||
-rw-r--r-- | src/modules/sparkler/particle.h | 1 | ||||
-rw-r--r-- | src/modules/sparkler/particles.c | 62 | ||||
-rw-r--r-- | src/modules/sparkler/rocket.c | 1 | ||||
-rw-r--r-- | src/modules/sparkler/simple.c | 1 | ||||
-rw-r--r-- | src/modules/sparkler/spark.c | 1 | ||||
-rw-r--r-- | src/modules/sparkler/xplode.c | 1 |
7 files changed, 44 insertions, 30 deletions
diff --git a/src/modules/sparkler/burst.c b/src/modules/sparkler/burst.c index 828ca02..72cde03 100644 --- a/src/modules/sparkler/burst.c +++ b/src/modules/sparkler/burst.c @@ -23,8 +23,7 @@ static int burst_init(particles_t *particles, particle_t *p) burst_ctxt_t *ctxt = p->ctxt; ctxt->longevity = ctxt->lifetime = BURST_MAX_LIFETIME; - p->props->velocity = 0; /* burst should be stationary */ - p->props->mass = 0; /* no mass prevents gravity's effects */ + p->props->virtual = 1; return 1; } @@ -66,8 +65,8 @@ static void burst_cb(bsp_t *bsp, list_head_t *occupants, void *_s) particle_t *p = container_of(o, particle_t, occupant); float d_sq; - if (p == s->center) { - /* leave ourselves alone */ + if (p->props->virtual) { + /* don't move virtual particles (includes ourself) */ continue; } diff --git a/src/modules/sparkler/particle.h b/src/modules/sparkler/particle.h index 95c117e..c63024d 100644 --- a/src/modules/sparkler/particle.h +++ b/src/modules/sparkler/particle.h @@ -12,6 +12,7 @@ typedef struct particle_props_t { float mass; /* mass of particle */ float drag; /* drag of particle */ int of_use:1; /* are these properties of use/meaningful? */ + int virtual:1; /* is this a virtual particle? (not to be moved or otherwise acted upon) */ } particle_props_t; typedef enum particle_status_t { diff --git a/src/modules/sparkler/particles.c b/src/modules/sparkler/particles.c index 0eb260e..e504adb 100644 --- a/src/modules/sparkler/particles.c +++ b/src/modules/sparkler/particles.c @@ -283,7 +283,40 @@ particle_status_t particles_sim(particles_t *particles) } -static inline void _particles_age(particles_t *particles, list_head_t *list) +/* "age" the particle by applying its properties for one step */ +static inline void _particle_age(particles_t *particles, _particle_t *p) +{ +#if 1 + if (p->props.mass > 0.0f) { + /* gravity, TODO: mass isn't applied. */ + static v3f_t gravity = v3f_init(0.0f, -0.05f, 0.0f); + + p->props.direction = v3f_add(&p->props.direction, &gravity); + p->props.direction = v3f_normalize(&p->props.direction); + } +#endif + +#if 1 + /* some drag/resistance proportional to velocity TODO: integrate mass */ + if (p->props.velocity > 0.0f) { + p->props.velocity -= ((p->props.velocity * p->props.velocity * p->props.drag)); + if (p->props.velocity < 0.0f) { + p->props.velocity = 0; + } + } +#endif + + /* regular movement */ + if (p->props.velocity > 0.0f) { + v3f_t movement = v3f_mult_scalar(&p->props.direction, p->props.velocity); + + p->props.position = v3f_add(&p->props.position, &movement); + bsp_move_occupant(particles->bsp, &p->public.occupant, &p->props.position); + } +} + + +static void _particles_age(particles_t *particles, list_head_t *list) { _particle_t *p; @@ -297,32 +330,9 @@ static inline void _particles_age(particles_t *particles, list_head_t *list) * particularly good for cache utilization. */ list_for_each_entry(p, list, siblings) { -#if 1 - if (p->props.mass > 0.0f) { - /* gravity, TODO: mass isn't applied. */ - static v3f_t gravity = v3f_init(0.0f, -0.05f, 0.0f); - - p->props.direction = v3f_add(&p->props.direction, &gravity); - p->props.direction = v3f_normalize(&p->props.direction); - } -#endif - -#if 1 - /* some drag/resistance proportional to velocity TODO: integrate mass */ - if (p->props.velocity > 0.0f) { - p->props.velocity -= ((p->props.velocity * p->props.velocity * p->props.drag)); - if (p->props.velocity < 0.0f) { - p->props.velocity = 0; - } - } -#endif - - /* regular movement */ - if (p->props.velocity > 0.0f) { - v3f_t movement = v3f_mult_scalar(&p->props.direction, p->props.velocity); - p->props.position = v3f_add(&p->props.position, &movement); - bsp_move_occupant(particles->bsp, &p->public.occupant, &p->props.position); + if (!p->props.virtual) { + _particle_age(particles, p); } if (!list_empty(&p->children)) { diff --git a/src/modules/sparkler/rocket.c b/src/modules/sparkler/rocket.c index ae628d3..b56c324 100644 --- a/src/modules/sparkler/rocket.c +++ b/src/modules/sparkler/rocket.c @@ -48,6 +48,7 @@ static int rocket_init(particles_t *particles, particle_t *p) ctxt->last_velocity = p->props->velocity; p->props->drag = 0.4; p->props->mass = 0.8; + p->props->virtual = 0; return 1; } diff --git a/src/modules/sparkler/simple.c b/src/modules/sparkler/simple.c index 5524282..7c7d415 100644 --- a/src/modules/sparkler/simple.c +++ b/src/modules/sparkler/simple.c @@ -46,6 +46,7 @@ static int simple_init(particles_t *particles, particle_t *p) p->props->drag = 0.03; p->props->mass = 0.3; + p->props->virtual = 0; p->props->of_use = 1; } /* else { we've been given properties, manipulate them or run with them? } */ diff --git a/src/modules/sparkler/spark.c b/src/modules/sparkler/spark.c index aa449c6..16268a9 100644 --- a/src/modules/sparkler/spark.c +++ b/src/modules/sparkler/spark.c @@ -24,6 +24,7 @@ static int spark_init(particles_t *particles, particle_t *p) p->props->drag = 20.0; p->props->mass = 0.1; + p->props->virtual = 0; ctxt->decay_rate = rand_within_range(SPARK_MIN_DECAY_RATE, SPARK_MAX_DECAY_RATE); ctxt->lifetime = ctxt->longevity = rand_within_range(SPARK_MIN_LIFETIME, SPARK_MAX_LIFETIME); diff --git a/src/modules/sparkler/xplode.c b/src/modules/sparkler/xplode.c index 3e3beb4..8b191cd 100644 --- a/src/modules/sparkler/xplode.c +++ b/src/modules/sparkler/xplode.c @@ -30,6 +30,7 @@ static int xplode_init(particles_t *particles, particle_t *p) p->props->drag = 10.9; p->props->mass = 0.3; + p->props->virtual = 0; return 1; } |