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