rev |
line source |
nuclear@6
|
1 #include <stdio.h>
|
nuclear@6
|
2 #include <stdlib.h>
|
nuclear@6
|
3 #include <string.h>
|
nuclear@6
|
4 #include <errno.h>
|
nuclear@6
|
5 #include "pattr.h"
|
nuclear@6
|
6 #include "psys_gl.h"
|
nuclear@6
|
7
|
nuclear@6
|
8 static void *tex_cls;
|
nuclear@6
|
9 static unsigned int (*load_texture)(const char*, void*) = psys_gl_load_texture;
|
nuclear@6
|
10 static void (*unload_texture)(unsigned int, void*) = psys_gl_unload_texture;
|
nuclear@6
|
11
|
nuclear@6
|
12 void psys_texture_loader(unsigned int (*load)(const char*, void*), void (*unload)(unsigned int, void*), void *cls)
|
nuclear@6
|
13 {
|
nuclear@6
|
14 load_texture = load;
|
nuclear@6
|
15 unload_texture = unload;
|
nuclear@6
|
16 tex_cls = cls;
|
nuclear@6
|
17 }
|
nuclear@6
|
18
|
nuclear@6
|
19 int psys_init_attr(struct psys_attributes *attr)
|
nuclear@6
|
20 {
|
nuclear@6
|
21 memset(attr, 0, sizeof *attr);
|
nuclear@6
|
22
|
nuclear@6
|
23 if(psys_init_track3(&attr->spawn_range) == -1)
|
nuclear@6
|
24 goto err;
|
nuclear@6
|
25 if(psys_init_track(&attr->rate) == -1)
|
nuclear@6
|
26 goto err;
|
nuclear@6
|
27 if(psys_init_anm_rnd(&attr->life) == -1)
|
nuclear@6
|
28 goto err;
|
nuclear@6
|
29 if(psys_init_anm_rnd(&attr->size) == -1)
|
nuclear@6
|
30 goto err;
|
nuclear@6
|
31 if(psys_init_anm_rnd3(&attr->dir) == -1)
|
nuclear@6
|
32 goto err;
|
nuclear@6
|
33 if(psys_init_track3(&attr->grav) == -1)
|
nuclear@6
|
34 goto err;
|
nuclear@6
|
35
|
nuclear@6
|
36 attr->max_particles = -1;
|
nuclear@8
|
37
|
nuclear@8
|
38 anm_set_track_default(&attr->size.value.trk, 1.0);
|
nuclear@8
|
39 anm_set_track_default(&attr->life.value.trk, 1.0);
|
nuclear@8
|
40
|
nuclear@6
|
41 return 0;
|
nuclear@6
|
42
|
nuclear@6
|
43 err:
|
nuclear@6
|
44 psys_destroy_attr(attr);
|
nuclear@6
|
45 return -1;
|
nuclear@6
|
46 }
|
nuclear@6
|
47
|
nuclear@6
|
48 void psys_destroy_attr(struct psys_attributes *attr)
|
nuclear@6
|
49 {
|
nuclear@6
|
50 psys_destroy_track3(&attr->spawn_range);
|
nuclear@6
|
51 psys_destroy_track(&attr->rate);
|
nuclear@6
|
52 psys_destroy_anm_rnd(&attr->life);
|
nuclear@6
|
53 psys_destroy_anm_rnd(&attr->size);
|
nuclear@6
|
54 psys_destroy_anm_rnd3(&attr->dir);
|
nuclear@6
|
55 psys_destroy_track3(&attr->grav);
|
nuclear@6
|
56
|
nuclear@6
|
57 if(attr->tex && unload_texture) {
|
nuclear@6
|
58 unload_texture(attr->tex, tex_cls);
|
nuclear@6
|
59 }
|
nuclear@6
|
60 }
|
nuclear@6
|
61
|
nuclear@6
|
62 void psys_eval_attr(struct psys_attributes *attr, anm_time_t tm)
|
nuclear@6
|
63 {
|
nuclear@6
|
64 psys_eval_track3(&attr->spawn_range, tm);
|
nuclear@6
|
65 psys_eval_track(&attr->rate, tm);
|
nuclear@6
|
66 psys_eval_anm_rnd(&attr->life, tm);
|
nuclear@6
|
67 psys_eval_anm_rnd(&attr->size, tm);
|
nuclear@6
|
68 psys_eval_anm_rnd3(&attr->dir, tm);
|
nuclear@6
|
69 psys_eval_track3(&attr->grav, tm);
|
nuclear@6
|
70 }
|
nuclear@6
|
71
|
nuclear@6
|
72 int psys_load_attr(struct psys_attributes *attr, const char *fname)
|
nuclear@6
|
73 {
|
nuclear@6
|
74 FILE *fp;
|
nuclear@6
|
75 int res;
|
nuclear@6
|
76
|
nuclear@6
|
77 if(!(fp = fopen(fname, "r"))) {
|
nuclear@6
|
78 fprintf(stderr, "%s: failed to read file: %s: %s\n", __func__, fname, strerror(errno));
|
nuclear@6
|
79 return -1;
|
nuclear@6
|
80 }
|
nuclear@6
|
81 res = psys_load_attr_stream(attr, fp);
|
nuclear@6
|
82 fclose(fp);
|
nuclear@6
|
83 return res;
|
nuclear@6
|
84 }
|
nuclear@6
|
85
|
nuclear@6
|
86 int psys_load_attr_stream(struct psys_attributes *attr, FILE *fp)
|
nuclear@6
|
87 {
|
nuclear@6
|
88 return -1; /* TODO */
|
nuclear@6
|
89 }
|
nuclear@6
|
90
|
nuclear@6
|
91
|
nuclear@6
|
92 int psys_save_attr(struct psys_attributes *attr, const char *fname)
|
nuclear@6
|
93 {
|
nuclear@6
|
94 FILE *fp;
|
nuclear@6
|
95 int res;
|
nuclear@6
|
96
|
nuclear@6
|
97 if(!(fp = fopen(fname, "w"))) {
|
nuclear@6
|
98 fprintf(stderr, "%s: failed to write file: %s: %s\n", __func__, fname, strerror(errno));
|
nuclear@6
|
99 return -1;
|
nuclear@6
|
100 }
|
nuclear@6
|
101 res = psys_save_attr_stream(attr, fp);
|
nuclear@6
|
102 fclose(fp);
|
nuclear@6
|
103 return res;
|
nuclear@6
|
104 }
|
nuclear@6
|
105
|
nuclear@6
|
106 int psys_save_attr_stream(struct psys_attributes *attr, FILE *fp)
|
nuclear@6
|
107 {
|
nuclear@6
|
108 return -1; /* TODO */
|
nuclear@6
|
109 }
|