summaryrefslogtreecommitdiff
path: root/src/modules/sparkler
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/sparkler')
-rw-r--r--src/modules/sparkler/draw.h32
-rw-r--r--src/modules/sparkler/helpers.h36
-rw-r--r--src/modules/sparkler/rocket.c10
-rw-r--r--src/modules/sparkler/simple.c10
-rw-r--r--src/modules/sparkler/spark.c10
-rw-r--r--src/modules/sparkler/sparkler.c2
-rw-r--r--src/modules/sparkler/xplode.c11
7 files changed, 61 insertions, 50 deletions
diff --git a/src/modules/sparkler/draw.h b/src/modules/sparkler/draw.h
deleted file mode 100644
index 5010374..0000000
--- a/src/modules/sparkler/draw.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef _DRAW_H
-#define _DRAW_H
-
-#include <stdint.h>
-
-#include "fb.h"
-
-/* helper for scaling rgb colors and packing them into an pixel */
-static inline uint32_t makergb(uint32_t r, uint32_t g, uint32_t b, float intensity)
-{
- r = (((float)intensity) * r);
- g = (((float)intensity) * g);
- b = (((float)intensity) * b);
-
- 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)
-{
- 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/helpers.h b/src/modules/sparkler/helpers.h
new file mode 100644
index 0000000..e263d36
--- /dev/null
+++ b/src/modules/sparkler/helpers.h
@@ -0,0 +1,36 @@
+#ifndef _HELPERS_H
+#define _HELPERS_H
+
+#include <stdint.h>
+
+#include "fb.h"
+#include "particle.h"
+#include "particles.h"
+
+
+/* helper for scaling rgb colors and packing them into an pixel */
+static inline uint32_t makergb(uint32_t r, uint32_t g, uint32_t b, float intensity)
+{
+ r = (((float)intensity) * r);
+ g = (((float)intensity) * g);
+ b = (((float)intensity) * b);
+
+ return (((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff));
+}
+
+
+/* return if the particle should be drawn, and set *longevity to 0 if out of bounds */
+static inline int should_draw_expire_if_oob(particles_t *particles, particle_t *p, int x, int y, fb_fragment_t *f, int *longevity)
+{
+ if (!fb_fragment_contains(f, x, y)) {
+ /* offscreen */
+ if (longevity)
+ *longevity = 0;
+
+ return 0;
+ }
+
+ return 1;
+}
+
+#endif
diff --git a/src/modules/sparkler/rocket.c b/src/modules/sparkler/rocket.c
index 6b9dc5e..ae628d3 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 "helpers.h"
#include "particle.h"
#include "particles.h"
@@ -122,10 +123,11 @@ 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 (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->longevity))
/* kill off parts that wander off screen */
- ctxt->longevity = 0;
- }
+ return;
+
+ fb_fragment_put_pixel_unchecked(f, x, y, 0xff0000);
}
diff --git a/src/modules/sparkler/simple.c b/src/modules/sparkler/simple.c
index e453e46..5524282 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 "helpers.h"
#include "particle.h"
#include "particles.h"
@@ -97,10 +98,11 @@ 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 (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->longevity))
/* immediately kill off stars that wander off screen */
- ctxt->longevity = 0;
- }
+ return;
+
+ fb_fragment_put_pixel_unchecked(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..aa449c6 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 "helpers.h"
#include "particle.h"
#include "particles.h"
@@ -47,10 +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 (!draw_pixel(f, x, y, makergb(0xff, 0xa0, 0x20, ((float)ctxt->longevity / ctxt->lifetime)))) {
+ if (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->longevity))
/* offscreen */
- ctxt->longevity = 0;
- }
+ return;
+
+ fb_fragment_put_pixel_unchecked(f, x, y, makergb(0xff, 0xa0, 0x20, ((float)ctxt->longevity / ctxt->lifetime)));
}
diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c
index 0bb0fcf..e2ff76e 100644
--- a/src/modules/sparkler/sparkler.c
+++ b/src/modules/sparkler/sparkler.c
@@ -35,7 +35,7 @@ static void sparkler(fb_fragment_t *fragment)
initialized = 1;
}
- memset(buf, 0, ((fragment->width << 2) + fragment->stride) * fragment->height);
+ fb_fragment_zero(fragment);
particles_age(particles);
particles_draw(particles, fragment);
diff --git a/src/modules/sparkler/xplode.c b/src/modules/sparkler/xplode.c
index 24a436e..3e3beb4 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 "helpers.h"
#include "particle.h"
#include "particles.h"
@@ -60,16 +61,16 @@ 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 (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->longevity))
+ 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;
- }
+ fb_fragment_put_pixel_unchecked(f, x, y, color);
}
© All Rights Reserved