2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation, either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 * Copyright (C) 2010 Pavel Herrmann (morpheus.ibis@gmail.com)
27 struct frameconfig_s
* frames
=NULL
;
28 struct frameconfig_s
* current_frame
=NULL
;
29 struct frameconfig_s last_frame
;
33 struct light_s
* lightlist
=NULL
;
36 char * scenefile
=NULL
;
40 #define ISWHITE(x) ((x==' ')||(x=='\t'))
41 #define ISEOL(x) ((x=='0')||(x=='#')||(x=='\n'))
42 #define MAX(x,y) (x>y?x:y)
45 int config_load(char* filename
)
47 FILE * f
= fopen(filename
, "r");
54 while ( (read
=getline(&line
,&linelength
,f
))!=-1)
56 //don't want the newline char at the end of lines
57 if(line
[read
-1]=='\n')
62 while(ISWHITE(tline
[0]))
67 if(!strncmp(tline
,"target",6))
70 while(ISWHITE(tline
[0]))
72 int len
= strlen(tline
);
73 outname
= malloc(sizeof(char)*(len
+1));
74 strncpy(outname
,tline
,len
+1);
78 if(!strncmp(tline
,"objfile",7))
81 while(ISWHITE(tline
[0]))
83 int len
= strlen(tline
);
84 scenefile
= malloc(sizeof(char)*(len
+1));
85 strncpy(scenefile
,tline
,len
+1);
89 if(!strncmp(tline
,"density",7))
92 while(ISWHITE(tline
[0]))
94 sscanf(tline
,"%f",&density
);
98 if(!strncmp(tline
,"tiles",5))
101 while(ISWHITE(tline
[0]))
103 sscanf(tline
,"%d %d",&(tiles
.x
),&(tiles
.y
) );
107 if(!strncmp(tline
,"resolution",10))
110 while(ISWHITE(tline
[0]))
112 sscanf(tline
,"%zd %zd",&(tilesize
[0]),&(tilesize
[1]) );
116 if(!strncmp(tline
,"worksize",8))
119 while(ISWHITE(tline
[0]))
121 sscanf(tline
,"%zd %zd",&(lwsize
[0]),&(lwsize
[1]) );
125 if(!strncmp(tline
,"frames",6))
128 while(ISWHITE(tline
[0]))
130 if (!strncmp(tline
,"interactive",11))
137 sscanf(tline
,"%d",&framecount
);
140 frames
= malloc(sizeof(struct frameconfig_s
)*framecount
);
141 current_frame
= frames
;
145 if(!strncmp(tline
,"frame",5))
149 while(ISWHITE(tline
[0]))
151 sscanf(tline
,"%d",&framenum
);
152 if (current_frame
!= NULL
)
154 last_frame
= *current_frame
;
155 current_frame
= &(frames
[framenum
]);
156 *current_frame
= last_frame
;
159 current_frame
= &(frames
[framenum
]);
163 if(!strncmp(tline
,"lookat",6))
166 while(ISWHITE(tline
[0]))
168 sscanf(tline
,"%f %f %f",&(current_frame
->lookat
.x
),&(current_frame
->lookat
.y
),&(current_frame
->lookat
.z
) );
172 if(!strncmp(tline
,"eyepoint",8))
175 while(ISWHITE(tline
[0]))
177 sscanf(tline
,"%f %f %f",&(current_frame
->eyepoint
.x
),&(current_frame
->eyepoint
.y
),&(current_frame
->eyepoint
.z
) );
181 if(!strncmp(tline
,"upvector",8))
184 while(ISWHITE(tline
[0]))
186 sscanf(tline
,"%f %f %f",&(current_frame
->upvector
.x
),&(current_frame
->upvector
.y
),&(current_frame
->upvector
.z
) );
190 if(!strncmp(tline
,"viewangle",9))
193 while(ISWHITE(tline
[0]))
195 sscanf(tline
,"%f %f",&(current_frame
->angles
.x
),&(current_frame
->angles
.y
) );
199 if(!strncmp(tline
,"accelstruct",11))
202 while(ISWHITE(tline
[0]))
204 if (!strncmp(tline
,"grid",4))
206 accelstruct
=ACCEL_GRID
;
209 if (!strncmp(tline
,"dummy",5))
211 accelstruct
=ACCEL_DUMMY
;
217 if(!strncmp(tline
,"lights",6))
220 while(ISWHITE(tline
[0]))
222 sscanf(tline
,"%d",&lightcount
);
223 lightlist
= malloc(sizeof(struct light_s
)*lightcount
);
227 if(!strncmp(tline
,"light",5))
231 struct light_s
* currlight
=NULL
;
233 while(ISWHITE(tline
[0]))
235 sscanf(tline
,"%d %n",&lightnum
,&charcount
);
236 currlight
=&(lightlist
[lightnum
]);
238 while(ISWHITE(tline
[0]))
240 if (!strncmp(tline
,"ambient",7))
242 currlight
->type
=LIGHT_AMBIENT
;
245 else if (!strncmp(tline
,"omni",4))
247 currlight
->type
=LIGHT_OMNI
;
250 else if (!strncmp(tline
,"directional",11))
252 currlight
->type
=LIGHT_DIRECTIONAL
;
255 else if (!strncmp(tline
,"spot",4))
257 currlight
->type
=LIGHT_SPOT
;
260 while(ISWHITE(tline
[0]))
262 sscanf(tline
,"%f [%f %f %f] %n", &currlight
->intensity
, &currlight
->color
.x
, &currlight
->color
.y
, &currlight
->color
.z
,&charcount
);
264 while(ISWHITE(tline
[0]))
266 switch (currlight
->type
)
271 sscanf(tline
,"[%f %f %f]", &currlight
->omni
.position
.x
, &currlight
->omni
.position
.y
, &currlight
->omni
.position
.z
);
273 case LIGHT_DIRECTIONAL
:
274 sscanf(tline
,"[%f %f %f]", &currlight
->directional
.direction
.x
, &currlight
->directional
.direction
.y
, &currlight
->directional
.direction
.z
);
277 sscanf(tline
,"[%f %f %f] [%f %f %f] %f %f", &currlight
->omni
.position
.x
, &currlight
->omni
.position
.y
, &currlight
->omni
.position
.z
,
278 &currlight
->spot
.direction
.x
, &currlight
->spot
.direction
.y
, &currlight
->spot
.direction
.z
, &currlight
->spot
.coneangle
, &currlight
->spot
.cutoff
);
292 void config_cleanup(void)