nuclear@0: #ifndef LIBPSYS_H_ nuclear@0: #define LIBPSYS_H_ nuclear@0: nuclear@7: #include nuclear@3: #include nuclear@3: #include "rndval.h" nuclear@5: #include "pattr.h" nuclear@3: nuclear@5: struct psys_particle; nuclear@5: struct psys_emitter; nuclear@5: nuclear@5: typedef int (*psys_spawn_func_t)(struct psys_emitter*, struct psys_particle*, void*); nuclear@5: typedef void (*psys_update_func_t)(struct psys_emitter*, struct psys_particle*, float, float, void*); nuclear@5: nuclear@5: typedef void (*psys_draw_func_t)(struct psys_emitter*, struct psys_particle*, void*); nuclear@5: typedef void (*psys_draw_start_func_t)(struct psys_emitter*, void*); nuclear@5: typedef void (*psys_draw_end_func_t)(struct psys_emitter*, void*); nuclear@5: nuclear@3: nuclear@3: struct psys_plane { nuclear@3: plane_t p; nuclear@3: float elasticity; nuclear@3: struct psys_plane *next; nuclear@3: }; nuclear@3: nuclear@0: nuclear@3: struct psys_emitter { nuclear@5: struct anm_node prs; nuclear@5: vec3_t cur_pos; nuclear@3: nuclear@5: struct psys_attributes attr; nuclear@3: nuclear@3: /* list of active particles */ nuclear@3: struct psys_particle *plist; nuclear@5: int pcount; /* number of active particles */ nuclear@3: nuclear@3: /* list of collision planes */ nuclear@5: struct psys_plane *planes; nuclear@3: nuclear@3: /* custom spawn closure */ nuclear@3: void *spawn_cls; nuclear@3: psys_spawn_func_t spawn; nuclear@3: nuclear@3: /* custom particle update closure */ nuclear@3: void *upd_cls; nuclear@3: psys_update_func_t update; nuclear@3: nuclear@3: /* custom draw closure */ nuclear@3: void *draw_cls; nuclear@3: psys_draw_func_t draw; nuclear@3: psys_draw_start_func_t draw_start; nuclear@3: psys_draw_end_func_t draw_end; nuclear@3: nuclear@5: float spawn_acc; /* partial spawn accumulator */ nuclear@5: float last_update; /* last update time (to calc dt) */ nuclear@3: }; nuclear@3: nuclear@3: nuclear@3: struct psys_particle { nuclear@3: vec3_t pos, vel; nuclear@9: float life, max_life; nuclear@9: float base_size; nuclear@9: nuclear@9: struct psys_particle_attributes *pattr; nuclear@9: nuclear@9: /* current particle attr values calculated during update */ nuclear@9: vec3_t color; nuclear@9: float alpha, size; nuclear@3: nuclear@3: struct psys_particle *next; nuclear@3: }; nuclear@3: nuclear@3: 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@5: 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: 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(struct psys_emitter *em); nuclear@0: nuclear@0: #endif /* LIBPSYS_H_ */