summaryrefslogtreecommitdiff
path: root/src/modules/sparkler/sparkler.c
blob: deb3c53153bcb6523d2bc267596b6ec8b362eea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

#include "fb.h"
#include "rototiller.h"
#include "util.h"

#include "particles.h"

/* particle system gadget (C) Vito Caputo <vcaputo@pengaru.com> 2/15/2014 */
/* 1/10/2015 added octree bsp (though not yet leveraged) */
/* 11/25/2016 refactor and begun adapting to rototiller */

#define INIT_PARTS 100

extern particle_ops_t	simple_ops;


/* Render a 3D particle system */
static void sparkler_render_fragment(void *context, fb_fragment_t *fragment)
{
	static particles_t	*particles;
	static int		initialized;
	uint32_t		*buf = fragment->buf;

	if (!initialized) {
		srand(time(NULL) + getpid());

		particles = particles_new();
		particles_add_particles(particles, NULL, &simple_ops, INIT_PARTS);

		initialized = 1;
	}

	fb_fragment_zero(fragment);

	particles_age(particles);
	particles_draw(particles, fragment);
	particles_sim(particles);
	particles_add_particles(particles, NULL, &simple_ops, INIT_PARTS / 4);
}


rototiller_module_t	sparkler_module = {
	.render_fragment = sparkler_render_fragment,
	.name = "sparkler",
	.description = "Particle system with spatial interactions",
	.author = "Vito Caputo <vcaputo@pengaru.com>",
	.license = "GPLv2",
};
© All Rights Reserved