# HG changeset patch # User John Tsiombikas # Date 1346887978 -10800 # Node ID 1b0db53d5b5bf260db7173fc5016233ee411256f # Parent 55a2aa4443f7283acbed815a829aebbebf004603 started writting config file for the particle system attributes diff -r 55a2aa4443f7 -r 1b0db53d5b5b examples/simple/simple.psys --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/simple/simple.psys Thu Sep 06 02:32:58 2012 +0300 @@ -0,0 +1,36 @@ +# Particle system definition file format example +# +# lines of key = value pairs. +# animated attributes can be defined as key(time) = value. +# time defaults to 0 if missing. time values can have an optional s suffix, +# signifying seconds, otherwise they are assumed to be in milliseconds. +# +# string values enclosed in double quotes +# vector values enclosed in square brackets [x y z] +# randomized values have a pair of values/vectors separated by a tilde: +# center ~ range. If the range is missing, it's assumed to be 0. + +# texture: string +texture = "pimg.png" +# spawn_range: track3 +spawn_range = [0.3 0.3 0.3] +# rate: track +# life: randomized track +life = 2 +# size: randomized track +# dir: randomized track3 +dir = [0 0 0] ~ [4 4 4] +# grav: track3 +grav = [0 -4 0] +# drag: val +drag = 2 + +# particle attributes +# pcolor: track3 +pcolor(0) = [1 0.6 0.4] +pcolor(1000) = [0.6 0.3 1] +# palpha: track +palpha(0) = 1 +palpha(700) = 1 +palpha(1000) = 0 +# psize: track diff -r 55a2aa4443f7 -r 1b0db53d5b5b src/pattr.c --- a/src/pattr.c Wed Aug 29 05:11:47 2012 +0300 +++ b/src/pattr.c Thu Sep 06 02:32:58 2012 +0300 @@ -7,6 +7,7 @@ static int init_particle_attr(struct psys_particle_attributes *pattr); static void destroy_particle_attr(struct psys_particle_attributes *pattr); +static char *stripspace(char *str); static void *tex_cls; static unsigned int (*load_texture)(const char*, void*) = psys_gl_load_texture; @@ -125,7 +126,30 @@ int psys_load_attr_stream(struct psys_attributes *attr, FILE *fp) { - return -1; /* TODO */ + int lineno = 0; + char buf[512]; + + psys_init_attr(attr); + + while(fgets(buf, sizeof buf, fp)) { + char *key, *valstr; + + lineno++; + + key = stripspace(buf); + if(key[0] == '#' || !key[0]) { + continue; // skip empty lines and comments + } + + if(!(valstr = strchr(buf, '='))) { + fprintf(stderr "%s: invalid input: %s\n", __func__, line); + return -1; + } + *valstr++ = 0; + valstr = stripspace(valstr); + + + } } @@ -147,3 +171,19 @@ { return -1; /* TODO */ } + + +static char *stripspace(char *str) +{ + char *end; + + while(*str && isspace(*str)) { + str++; + } + + end = str + strlen(str); + while(end >= str && isspace(*end)) { + *end-- = 0; + } + return str; +} diff -r 55a2aa4443f7 -r 1b0db53d5b5b src/pattr_parser.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pattr_parser.c Thu Sep 06 02:32:58 2012 +0300 @@ -0,0 +1,6 @@ +#include "pattr_parser.h" + +struct cfg_node *psys_parse(const char *buf) +{ + +} diff -r 55a2aa4443f7 -r 1b0db53d5b5b src/pattr_parser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pattr_parser.h Thu Sep 06 02:32:58 2012 +0300 @@ -0,0 +1,21 @@ +#ifndef PATTR_PARSER_H_ +#define PATTR_PARSER_H_ + +struct cfg_value { + int nelem; + float v[4]; +}; + +struct cfg_node { + char *name, *valstr; + + long tm; + struct cfg_value val, range; + + struct cfg_node *next; +}; + +struct cfg_node *psys_parse(const char *buf); + + +#endif /* PATTR_PARSER_H_ */