nuclear@67: #ifndef LIBPSYS_H_ nuclear@67: #define LIBPSYS_H_ nuclear@67: nuclear@67: #include nuclear@67: #include nuclear@67: #include "rndval.h" nuclear@67: #include "pattr.h" nuclear@67: nuclear@67: struct psys_particle; nuclear@67: struct psys_emitter; nuclear@67: nuclear@67: typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*); nuclear@67: typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, float, float, void*); nuclear@67: nuclear@67: typedef void (*psys_draw_func_t)(struct psys_emitter*, struct psys_particle*, void*); nuclear@67: typedef void (*psys_draw_start_func_t)(struct psys_emitter*, void*); nuclear@67: typedef void (*psys_draw_end_func_t)(struct psys_emitter*, void*); nuclear@67: nuclear@67: nuclear@67: struct psys_plane { nuclear@67: plane_t p; nuclear@67: float elasticity; nuclear@67: struct psys_plane *next; nuclear@67: }; nuclear@67: nuclear@67: nuclear@67: struct psys_emitter { nuclear@67: struct anm_node prs; nuclear@67: vec3_t cur_pos; nuclear@67: nuclear@67: struct psys_attributes attr; nuclear@67: nuclear@67: /* list of active particles */ nuclear@67: struct psys_particle *plist; nuclear@67: int pcount; /* number of active particles */ nuclear@67: nuclear@67: /* list of collision planes */ nuclear@67: struct psys_plane *planes; nuclear@67: nuclear@67: /* custom spawn closure */ nuclear@67: void *spawn_cls; nuclear@67: psys_spawn_func_t spawn; nuclear@67: nuclear@67: /* custom particle update closure */ nuclear@67: void *upd_cls; nuclear@67: psys_update_func_t update; nuclear@67: nuclear@67: /* custom draw closure */ nuclear@67: void *draw_cls; nuclear@67: psys_draw_func_t draw; nuclear@67: psys_draw_start_func_t draw_start; nuclear@67: psys_draw_end_func_t draw_end; nuclear@67: nuclear@67: float spawn_acc; /* partial spawn accumulator */ nuclear@67: float last_update; /* last update time (to calc dt) */ nuclear@67: }; nuclear@67: nuclear@67: nuclear@67: struct psys_particle { nuclear@67: vec3_t pos, vel; nuclear@67: float life, max_life; nuclear@67: float base_size; nuclear@67: nuclear@67: struct psys_particle_attributes *pattr; nuclear@67: nuclear@67: /* current particle attr values calculated during update */ nuclear@67: vec3_t color; nuclear@67: float alpha, size; nuclear@67: nuclear@67: struct psys_particle *next; nuclear@67: }; nuclear@67: nuclear@67: #ifdef __cplusplus nuclear@67: extern "C" { nuclear@67: #endif nuclear@67: nuclear@67: struct psys_emitter *psys_create(void); nuclear@67: void psys_free(struct psys_emitter *em); nuclear@67: nuclear@67: int psys_init(struct psys_emitter *em); nuclear@67: void psys_destroy(struct psys_emitter *em); nuclear@67: nuclear@67: /* set properties */ nuclear@67: void psys_set_pos(struct psys_emitter *em, vec3_t pos, float tm); nuclear@67: void psys_set_rot(struct psys_emitter *em, quat_t rot, float tm); nuclear@67: void psys_set_pivot(struct psys_emitter *em, vec3_t pivot); nuclear@67: nuclear@67: vec3_t psys_get_pos(struct psys_emitter *em, float tm); nuclear@67: quat_t psys_get_rot(struct psys_emitter *em, float tm); nuclear@67: vec3_t psys_get_pivot(struct psys_emitter *em); nuclear@67: nuclear@67: void psys_clear_collision_planes(struct psys_emitter *em); nuclear@67: int psys_add_collision_plane(struct psys_emitter *em, plane_t plane, float elast); nuclear@67: nuclear@67: void psys_add_particle(struct psys_emitter *em, struct psys_particle *p); nuclear@67: nuclear@67: void psys_spawn_func(struct psys_emitter *em, psys_spawn_func_t func, void *cls); nuclear@67: void psys_update_func(struct psys_emitter *em, psys_update_func_t func, void *cls); nuclear@67: void psys_draw_func(struct psys_emitter *em, psys_draw_func_t draw, nuclear@67: psys_draw_start_func_t start, psys_draw_end_func_t end, void *cls); nuclear@67: nuclear@67: /* update and render */ nuclear@67: nuclear@67: void psys_update(struct psys_emitter *em, float tm); nuclear@67: void psys_draw(struct psys_emitter *em); nuclear@67: nuclear@67: #ifdef __cplusplus nuclear@67: } nuclear@67: #endif nuclear@67: nuclear@67: #endif /* LIBPSYS_H_ */