From 91e5956932d17de17c0c75be20c834cf7a6c6ed9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 3 Feb 2017 13:06:26 -0800 Subject: rototiller: extricate draw_pixel() bounds checking If a z-buffer is added these checks will need to be done independent from and prior to drawing. Also it's silly to makergb() pixels which can't be drawn. --- src/modules/sparkler/spark.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/modules/sparkler/spark.c') diff --git a/src/modules/sparkler/spark.c b/src/modules/sparkler/spark.c index ea68ac2..786be78 100644 --- a/src/modules/sparkler/spark.c +++ b/src/modules/sparkler/spark.c @@ -1,6 +1,7 @@ #include #include "draw.h" +#include "fb.h" #include "particle.h" #include "particles.h" @@ -47,10 +48,15 @@ static void spark_draw(particles_t *particles, particle_t *p, int x, int y, fb_f { spark_ctxt_t *ctxt = p->ctxt; - if (!draw_pixel(f, x, y, makergb(0xff, 0xa0, 0x20, ((float)ctxt->longevity / ctxt->lifetime)))) { + if (!fb_fragment_contains(f, x, y)) { /* offscreen */ ctxt->longevity = 0; + + return; } + + draw_pixel(f, x, y, makergb(0xff, 0xa0, 0x20, ((float)ctxt->longevity / ctxt->lifetime))); + } -- cgit v1.2.3 From 90fde2df2d8c59b0b885e6e02b5e89dbe966a5e9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 3 Feb 2017 15:43:51 -0800 Subject: sparkler: use fb.h put_pixel helpers discards draw_pixel(), introduces helpers.h and a convenience function for bounds checking and oob extermination. Move makergb to helpers.h, draw.h gets removed in a later commit. --- src/modules/sparkler/spark.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/modules/sparkler/spark.c') diff --git a/src/modules/sparkler/spark.c b/src/modules/sparkler/spark.c index 786be78..aa449c6 100644 --- a/src/modules/sparkler/spark.c +++ b/src/modules/sparkler/spark.c @@ -1,7 +1,7 @@ #include -#include "draw.h" #include "fb.h" +#include "helpers.h" #include "particle.h" #include "particles.h" @@ -48,15 +48,11 @@ static void spark_draw(particles_t *particles, particle_t *p, int x, int y, fb_f { spark_ctxt_t *ctxt = p->ctxt; - if (!fb_fragment_contains(f, x, y)) { + if (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->longevity)) /* offscreen */ - ctxt->longevity = 0; - return; - } - - draw_pixel(f, x, y, makergb(0xff, 0xa0, 0x20, ((float)ctxt->longevity / ctxt->lifetime))); + fb_fragment_put_pixel_unchecked(f, x, y, makergb(0xff, 0xa0, 0x20, ((float)ctxt->longevity / ctxt->lifetime))); } -- cgit v1.2.3