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/draw.h | 8 +------- src/modules/sparkler/rocket.c | 7 ++++++- src/modules/sparkler/simple.c | 7 ++++++- src/modules/sparkler/spark.c | 8 +++++++- src/modules/sparkler/xplode.c | 12 ++++++++---- 5 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/modules/sparkler/draw.h b/src/modules/sparkler/draw.h index 5010374..b988319 100644 --- a/src/modules/sparkler/draw.h +++ b/src/modules/sparkler/draw.h @@ -15,18 +15,12 @@ static inline uint32_t makergb(uint32_t r, uint32_t g, uint32_t b, float intensi return (((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)); } -static inline int draw_pixel(fb_fragment_t *f, int x, int y, uint32_t pixel) +static inline void draw_pixel(fb_fragment_t *f, int x, int y, uint32_t pixel) { uint32_t *pixels = f->buf; - if (y < 0 || y >= f->height || x < 0 || x >= f->width) { - return 0; - } - /* FIXME this assumes stride is aligned to 4 */ pixels[(y * (f->width + (f->stride >> 2))) + x] = pixel; - - return 1; } #endif diff --git a/src/modules/sparkler/rocket.c b/src/modules/sparkler/rocket.c index 6b9dc5e..2088cc7 100644 --- a/src/modules/sparkler/rocket.c +++ b/src/modules/sparkler/rocket.c @@ -1,6 +1,7 @@ #include #include "draw.h" +#include "fb.h" #include "particle.h" #include "particles.h" @@ -122,10 +123,14 @@ static void rocket_draw(particles_t *particles, particle_t *p, int x, int y, fb_ { rocket_ctxt_t *ctxt = p->ctxt; - if (!draw_pixel(f, x, y, 0xff0000)) { + if (!fb_fragment_contains(f, x, y)) { /* kill off parts that wander off screen */ ctxt->longevity = 0; + + return; } + + draw_pixel(f, x, y, 0xff0000); } diff --git a/src/modules/sparkler/simple.c b/src/modules/sparkler/simple.c index e453e46..74edc24 100644 --- a/src/modules/sparkler/simple.c +++ b/src/modules/sparkler/simple.c @@ -1,6 +1,7 @@ #include #include "draw.h" +#include "fb.h" #include "particle.h" #include "particles.h" @@ -97,10 +98,14 @@ static void simple_draw(particles_t *particles, particle_t *p, int x, int y, fb_ { simple_ctxt_t *ctxt = p->ctxt; - if (!draw_pixel(f, x, y, makergb(0xff, 0xff, 0xff, ((float)ctxt->longevity / ctxt->lifetime)))) { + if (!fb_fragment_contains(f, x, y)) { /* immediately kill off stars that wander off screen */ ctxt->longevity = 0; + + return; } + + draw_pixel(f, x, y, makergb(0xff, 0xff, 0xff, ((float)ctxt->longevity / ctxt->lifetime))); } 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))); + } diff --git a/src/modules/sparkler/xplode.c b/src/modules/sparkler/xplode.c index 24a436e..5f99f7b 100644 --- a/src/modules/sparkler/xplode.c +++ b/src/modules/sparkler/xplode.c @@ -1,6 +1,7 @@ #include #include "draw.h" +#include "fb.h" #include "particle.h" #include "particles.h" @@ -60,16 +61,19 @@ static void xplode_draw(particles_t *particles, particle_t *p, int x, int y, fb_ xplode_ctxt_t *ctxt = p->ctxt; uint32_t color; + if (!fb_fragment_contains(f, x, y)) { + /* offscreen */ + ctxt->longevity = 0; + return; + } + if (ctxt->longevity == ctxt->lifetime) { color = makergb(0xff, 0xff, 0xa0, 1.0); } else { color = makergb(0xff, 0xff, 0x00, ((float)ctxt->longevity / ctxt->lifetime)); } - if (!draw_pixel(f, x, y, color)) { - /* offscreen */ - ctxt->longevity = 0; - } + draw_pixel(f, x, y, color); } -- cgit v1.2.1