dungeon_crawler
view prototype/psys/psys.h @ 70:f55ddab0f3a4
"fixed" the disappearing lights issue
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 09 Oct 2012 02:54:01 +0300 |
parents | |
children |
line source
1 #ifndef LIBPSYS_H_
2 #define LIBPSYS_H_
4 #include <vmath/vmath.h>
5 #include <anim/anim.h>
6 #include "rndval.h"
7 #include "pattr.h"
9 struct psys_particle;
10 struct psys_emitter;
12 typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*);
13 typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, float, float, void*);
15 typedef void (*psys_draw_func_t)(struct psys_emitter*, struct psys_particle*, void*);
16 typedef void (*psys_draw_start_func_t)(struct psys_emitter*, void*);
17 typedef void (*psys_draw_end_func_t)(struct psys_emitter*, void*);
20 struct psys_plane {
21 plane_t p;
22 float elasticity;
23 struct psys_plane *next;
24 };
27 struct psys_emitter {
28 struct anm_node prs;
29 vec3_t cur_pos;
31 struct psys_attributes attr;
33 /* list of active particles */
34 struct psys_particle *plist;
35 int pcount; /* number of active particles */
37 /* list of collision planes */
38 struct psys_plane *planes;
40 /* custom spawn closure */
41 void *spawn_cls;
42 psys_spawn_func_t spawn;
44 /* custom particle update closure */
45 void *upd_cls;
46 psys_update_func_t update;
48 /* custom draw closure */
49 void *draw_cls;
50 psys_draw_func_t draw;
51 psys_draw_start_func_t draw_start;
52 psys_draw_end_func_t draw_end;
54 float spawn_acc; /* partial spawn accumulator */
55 float last_update; /* last update time (to calc dt) */
56 };
59 struct psys_particle {
60 vec3_t pos, vel;
61 float life, max_life;
62 float base_size;
64 struct psys_particle_attributes *pattr;
66 /* current particle attr values calculated during update */
67 vec3_t color;
68 float alpha, size;
70 struct psys_particle *next;
71 };
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
77 struct psys_emitter *psys_create(void);
78 void psys_free(struct psys_emitter *em);
80 int psys_init(struct psys_emitter *em);
81 void psys_destroy(struct psys_emitter *em);
83 /* set properties */
84 void psys_set_pos(struct psys_emitter *em, vec3_t pos, float tm);
85 void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm);
86 void psys_set_pivot(struct psys_emitter *em, vec3_t pivot);
88 vec3_t psys_get_pos(struct psys_emitter *em, float tm);
89 quat_t psys_get_rot(struct psys_emitter *em, float tm);
90 vec3_t psys_get_pivot(struct psys_emitter *em);
92 void psys_clear_collision_planes(struct psys_emitter *em);
93 int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast);
95 void psys_add_particle(struct psys_emitter *em, struct psys_particle *p);
97 void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls);
98 void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls);
99 void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw,
100 psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls);
102 /* update and render */
104 void psys_update(struct psys_emitter *em, float tm);
105 void psys_draw(struct psys_emitter *em);
107 #ifdef __cplusplus
108 }
109 #endif
111 #endif /* LIBPSYS_H_ */