libpsys
changeset 13:1b0db53d5b5b
started writting config file for the particle system attributes
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 06 Sep 2012 02:32:58 +0300 |
parents | 55a2aa4443f7 |
children | 4f36bbbcc82f |
files | examples/simple/simple.psys src/pattr.c src/pattr_parser.c src/pattr_parser.h |
diffstat | 4 files changed, 104 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/examples/simple/simple.psys Thu Sep 06 02:32:58 2012 +0300 1.3 @@ -0,0 +1,36 @@ 1.4 +# Particle system definition file format example 1.5 +# 1.6 +# lines of key = value pairs. 1.7 +# animated attributes can be defined as key(time) = value. 1.8 +# time defaults to 0 if missing. time values can have an optional s suffix, 1.9 +# signifying seconds, otherwise they are assumed to be in milliseconds. 1.10 +# 1.11 +# string values enclosed in double quotes 1.12 +# vector values enclosed in square brackets [x y z] 1.13 +# randomized values have a pair of values/vectors separated by a tilde: 1.14 +# center ~ range. If the range is missing, it's assumed to be 0. 1.15 + 1.16 +# texture: string 1.17 +texture = "pimg.png" 1.18 +# spawn_range: track3 1.19 +spawn_range = [0.3 0.3 0.3] 1.20 +# rate: track 1.21 +# life: randomized track 1.22 +life = 2 1.23 +# size: randomized track 1.24 +# dir: randomized track3 1.25 +dir = [0 0 0] ~ [4 4 4] 1.26 +# grav: track3 1.27 +grav = [0 -4 0] 1.28 +# drag: val 1.29 +drag = 2 1.30 + 1.31 +# particle attributes 1.32 +# pcolor: track3 1.33 +pcolor(0) = [1 0.6 0.4] 1.34 +pcolor(1000) = [0.6 0.3 1] 1.35 +# palpha: track 1.36 +palpha(0) = 1 1.37 +palpha(700) = 1 1.38 +palpha(1000) = 0 1.39 +# psize: track
2.1 --- a/src/pattr.c Wed Aug 29 05:11:47 2012 +0300 2.2 +++ b/src/pattr.c Thu Sep 06 02:32:58 2012 +0300 2.3 @@ -7,6 +7,7 @@ 2.4 2.5 static int init_particle_attr(struct psys_particle_attributes *pattr); 2.6 static void destroy_particle_attr(struct psys_particle_attributes *pattr); 2.7 +static char *stripspace(char *str); 2.8 2.9 static void *tex_cls; 2.10 static unsigned int (*load_texture)(const char*, void*) = psys_gl_load_texture; 2.11 @@ -125,7 +126,30 @@ 2.12 2.13 int psys_load_attr_stream(struct psys_attributes *attr, FILE *fp) 2.14 { 2.15 - return -1; /* TODO */ 2.16 + int lineno = 0; 2.17 + char buf[512]; 2.18 + 2.19 + psys_init_attr(attr); 2.20 + 2.21 + while(fgets(buf, sizeof buf, fp)) { 2.22 + char *key, *valstr; 2.23 + 2.24 + lineno++; 2.25 + 2.26 + key = stripspace(buf); 2.27 + if(key[0] == '#' || !key[0]) { 2.28 + continue; // skip empty lines and comments 2.29 + } 2.30 + 2.31 + if(!(valstr = strchr(buf, '='))) { 2.32 + fprintf(stderr "%s: invalid input: %s\n", __func__, line); 2.33 + return -1; 2.34 + } 2.35 + *valstr++ = 0; 2.36 + valstr = stripspace(valstr); 2.37 + 2.38 + 2.39 + } 2.40 } 2.41 2.42 2.43 @@ -147,3 +171,19 @@ 2.44 { 2.45 return -1; /* TODO */ 2.46 } 2.47 + 2.48 + 2.49 +static char *stripspace(char *str) 2.50 +{ 2.51 + char *end; 2.52 + 2.53 + while(*str && isspace(*str)) { 2.54 + str++; 2.55 + } 2.56 + 2.57 + end = str + strlen(str); 2.58 + while(end >= str && isspace(*end)) { 2.59 + *end-- = 0; 2.60 + } 2.61 + return str; 2.62 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/pattr_parser.c Thu Sep 06 02:32:58 2012 +0300 3.3 @@ -0,0 +1,6 @@ 3.4 +#include "pattr_parser.h" 3.5 + 3.6 +struct cfg_node *psys_parse(const char *buf) 3.7 +{ 3.8 + 3.9 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/pattr_parser.h Thu Sep 06 02:32:58 2012 +0300 4.3 @@ -0,0 +1,21 @@ 4.4 +#ifndef PATTR_PARSER_H_ 4.5 +#define PATTR_PARSER_H_ 4.6 + 4.7 +struct cfg_value { 4.8 + int nelem; 4.9 + float v[4]; 4.10 +}; 4.11 + 4.12 +struct cfg_node { 4.13 + char *name, *valstr; 4.14 + 4.15 + long tm; 4.16 + struct cfg_value val, range; 4.17 + 4.18 + struct cfg_node *next; 4.19 +}; 4.20 + 4.21 +struct cfg_node *psys_parse(const char *buf); 4.22 + 4.23 + 4.24 +#endif /* PATTR_PARSER_H_ */