nuclear@6: #include nuclear@6: #include nuclear@6: #include nuclear@6: #include nuclear@6: #include "pattr.h" nuclear@6: #include "psys_gl.h" nuclear@6: nuclear@6: static void *tex_cls; nuclear@6: static unsigned int (*load_texture)(const char*, void*) = psys_gl_load_texture; nuclear@6: static void (*unload_texture)(unsigned int, void*) = psys_gl_unload_texture; nuclear@6: nuclear@6: void psys_texture_loader(unsigned int (*load)(const char*, void*), void (*unload)(unsigned int, void*), void *cls) nuclear@6: { nuclear@6: load_texture = load; nuclear@6: unload_texture = unload; nuclear@6: tex_cls = cls; nuclear@6: } nuclear@6: nuclear@6: int psys_init_attr(struct psys_attributes *attr) nuclear@6: { nuclear@6: memset(attr, 0, sizeof *attr); nuclear@6: nuclear@6: if(psys_init_track3(&attr->spawn_range) == -1) nuclear@6: goto err; nuclear@6: if(psys_init_track(&attr->rate) == -1) nuclear@6: goto err; nuclear@6: if(psys_init_anm_rnd(&attr->life) == -1) nuclear@6: goto err; nuclear@6: if(psys_init_anm_rnd(&attr->size) == -1) nuclear@6: goto err; nuclear@6: if(psys_init_anm_rnd3(&attr->dir) == -1) nuclear@6: goto err; nuclear@6: if(psys_init_track3(&attr->grav) == -1) nuclear@6: goto err; nuclear@6: nuclear@6: attr->max_particles = -1; nuclear@8: nuclear@8: anm_set_track_default(&attr->size.value.trk, 1.0); nuclear@8: anm_set_track_default(&attr->life.value.trk, 1.0); nuclear@8: nuclear@6: return 0; nuclear@6: nuclear@6: err: nuclear@6: psys_destroy_attr(attr); nuclear@6: return -1; nuclear@6: } nuclear@6: nuclear@6: void psys_destroy_attr(struct psys_attributes *attr) nuclear@6: { nuclear@6: psys_destroy_track3(&attr->spawn_range); nuclear@6: psys_destroy_track(&attr->rate); nuclear@6: psys_destroy_anm_rnd(&attr->life); nuclear@6: psys_destroy_anm_rnd(&attr->size); nuclear@6: psys_destroy_anm_rnd3(&attr->dir); nuclear@6: psys_destroy_track3(&attr->grav); nuclear@6: nuclear@6: if(attr->tex && unload_texture) { nuclear@6: unload_texture(attr->tex, tex_cls); nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: void psys_eval_attr(struct psys_attributes *attr, anm_time_t tm) nuclear@6: { nuclear@6: psys_eval_track3(&attr->spawn_range, tm); nuclear@6: psys_eval_track(&attr->rate, tm); nuclear@6: psys_eval_anm_rnd(&attr->life, tm); nuclear@6: psys_eval_anm_rnd(&attr->size, tm); nuclear@6: psys_eval_anm_rnd3(&attr->dir, tm); nuclear@6: psys_eval_track3(&attr->grav, tm); nuclear@6: } nuclear@6: nuclear@6: int psys_load_attr(struct psys_attributes *attr, const char *fname) nuclear@6: { nuclear@6: FILE *fp; nuclear@6: int res; nuclear@6: nuclear@6: if(!(fp = fopen(fname, "r"))) { nuclear@6: fprintf(stderr, "%s: failed to read file: %s: %s\n", __func__, fname, strerror(errno)); nuclear@6: return -1; nuclear@6: } nuclear@6: res = psys_load_attr_stream(attr, fp); nuclear@6: fclose(fp); nuclear@6: return res; nuclear@6: } nuclear@6: nuclear@6: int psys_load_attr_stream(struct psys_attributes *attr, FILE *fp) nuclear@6: { nuclear@6: return -1; /* TODO */ nuclear@6: } nuclear@6: nuclear@6: nuclear@6: int psys_save_attr(struct psys_attributes *attr, const char *fname) nuclear@6: { nuclear@6: FILE *fp; nuclear@6: int res; nuclear@6: nuclear@6: if(!(fp = fopen(fname, "w"))) { nuclear@6: fprintf(stderr, "%s: failed to write file: %s: %s\n", __func__, fname, strerror(errno)); nuclear@6: return -1; nuclear@6: } nuclear@6: res = psys_save_attr_stream(attr, fp); nuclear@6: fclose(fp); nuclear@6: return res; nuclear@6: } nuclear@6: nuclear@6: int psys_save_attr_stream(struct psys_attributes *attr, FILE *fp) nuclear@6: { nuclear@6: return -1; /* TODO */ nuclear@6: }