summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2017-02-03 13:06:26 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2017-02-03 13:06:26 -0800
commit91e5956932d17de17c0c75be20c834cf7a6c6ed9 (patch)
tree19bb0846dbcb091b3a28949605733bc431f45917
parentc2e4a7977349f5b4b69cc39829c50512a9503f15 (diff)
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.
-rw-r--r--src/modules/sparkler/draw.h8
-rw-r--r--src/modules/sparkler/rocket.c7
-rw-r--r--src/modules/sparkler/simple.c7
-rw-r--r--src/modules/sparkler/spark.c8
-rw-r--r--src/modules/sparkler/xplode.c12
5 files changed, 28 insertions, 14 deletions
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 <stdlib.h>
#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 <stdlib.h>
#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 <stdlib.h>
#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 <stdlib.h>
#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);
}
© All Rights Reserved