dungeon_crawler

diff prototype/psys/psys.h @ 67:2560a7ab0243

internalized libanim, libimago2, and libpsys
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Oct 2012 02:04:00 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prototype/psys/psys.h	Sun Oct 07 02:04:00 2012 +0300
     1.3 @@ -0,0 +1,111 @@
     1.4 +#ifndef LIBPSYS_H_
     1.5 +#define LIBPSYS_H_
     1.6 +
     1.7 +#include <vmath/vmath.h>
     1.8 +#include <anim/anim.h>
     1.9 +#include "rndval.h"
    1.10 +#include "pattr.h"
    1.11 +
    1.12 +struct psys_particle;
    1.13 +struct psys_emitter;
    1.14 +
    1.15 +typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*);
    1.16 +typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, float, float, void*);
    1.17 +
    1.18 +typedef void (*psys_draw_func_t)(struct psys_emitter*, struct psys_particle*, void*);
    1.19 +typedef void (*psys_draw_start_func_t)(struct psys_emitter*, void*);
    1.20 +typedef void (*psys_draw_end_func_t)(struct psys_emitter*, void*);
    1.21 +
    1.22 +
    1.23 +struct psys_plane {
    1.24 +	plane_t p;
    1.25 +	float elasticity;
    1.26 +	struct psys_plane *next;
    1.27 +};
    1.28 +
    1.29 +
    1.30 +struct psys_emitter {
    1.31 +	struct anm_node prs;
    1.32 +	vec3_t cur_pos;
    1.33 +
    1.34 +	struct psys_attributes attr;
    1.35 +
    1.36 +	/* list of active particles */
    1.37 +	struct psys_particle *plist;
    1.38 +	int pcount;	/* number of active particles */
    1.39 +
    1.40 +	/* list of collision planes */
    1.41 +	struct psys_plane *planes;
    1.42 +
    1.43 +	/* custom spawn closure */
    1.44 +	void *spawn_cls;
    1.45 +	psys_spawn_func_t spawn;
    1.46 +
    1.47 +	/* custom particle update closure */
    1.48 +	void *upd_cls;
    1.49 +	psys_update_func_t update;
    1.50 +
    1.51 +	/* custom draw closure */
    1.52 +	void *draw_cls;
    1.53 +	psys_draw_func_t draw;
    1.54 +	psys_draw_start_func_t draw_start;
    1.55 +	psys_draw_end_func_t draw_end;
    1.56 +
    1.57 +	float spawn_acc;	/* partial spawn accumulator */
    1.58 +	float last_update;	/* last update time (to calc dt) */
    1.59 +};
    1.60 +
    1.61 +
    1.62 +struct psys_particle {
    1.63 +	vec3_t pos, vel;
    1.64 +	float life, max_life;
    1.65 +	float base_size;
    1.66 +
    1.67 +	struct psys_particle_attributes *pattr;
    1.68 +
    1.69 +	/* current particle attr values calculated during update */
    1.70 +	vec3_t color;
    1.71 +	float alpha, size;
    1.72 +
    1.73 +	struct psys_particle *next;
    1.74 +};
    1.75 +
    1.76 +#ifdef __cplusplus
    1.77 +extern "C" {
    1.78 +#endif
    1.79 +
    1.80 +struct psys_emitter *psys_create(void);
    1.81 +void psys_free(struct psys_emitter *em);
    1.82 +
    1.83 +int psys_init(struct psys_emitter *em);
    1.84 +void psys_destroy(struct psys_emitter *em);
    1.85 +
    1.86 +/* set properties */
    1.87 +void psys_set_pos(struct psys_emitter *em, vec3_t pos, float tm);
    1.88 +void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm);
    1.89 +void psys_set_pivot(struct psys_emitter *em, vec3_t pivot);
    1.90 +
    1.91 +vec3_t psys_get_pos(struct psys_emitter *em, float tm);
    1.92 +quat_t psys_get_rot(struct psys_emitter *em, float tm);
    1.93 +vec3_t psys_get_pivot(struct psys_emitter *em);
    1.94 +
    1.95 +void psys_clear_collision_planes(struct psys_emitter *em);
    1.96 +int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast);
    1.97 +
    1.98 +void psys_add_particle(struct psys_emitter *em, struct psys_particle *p);
    1.99 +
   1.100 +void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls);
   1.101 +void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls);
   1.102 +void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw,
   1.103 +		psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls);
   1.104 +
   1.105 +/* update and render */
   1.106 +
   1.107 +void psys_update(struct psys_emitter *em, float tm);
   1.108 +void psys_draw(struct psys_emitter *em);
   1.109 +
   1.110 +#ifdef __cplusplus
   1.111 +}
   1.112 +#endif
   1.113 +
   1.114 +#endif	/* LIBPSYS_H_ */