libpsys

changeset 15:5678915dc2c7

probably done with the psys loader
author John Tsiombikas <nuclear@mutantstargoat.com>
date Mon, 10 Sep 2012 21:57:49 +0300
parents 4f36bbbcc82f
children 3871a45a4e4b
files src/pattr.c
diffstat 1 files changed, 46 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/src/pattr.c	Mon Sep 10 05:58:03 2012 +0300
     1.2 +++ b/src/pattr.c	Mon Sep 10 21:57:49 2012 +0300
     1.3 @@ -2,6 +2,14 @@
     1.4  #include <stdlib.h>
     1.5  #include <string.h>
     1.6  #include <errno.h>
     1.7 +#include <ctype.h>
     1.8 +
     1.9 +#ifdef _MSC_VER
    1.10 +#include <malloc.h>
    1.11 +#else
    1.12 +#include <alloca.h>
    1.13 +#endif
    1.14 +
    1.15  #include "pattr.h"
    1.16  #include "psys_gl.h"
    1.17  
    1.18 @@ -23,6 +31,7 @@
    1.19  
    1.20  static int init_particle_attr(struct psys_particle_attributes *pattr);
    1.21  static void destroy_particle_attr(struct psys_particle_attributes *pattr);
    1.22 +static int get_cfg_opt(const char *line, struct cfgopt *opt);
    1.23  static char *stripspace(char *str);
    1.24  
    1.25  static void *tex_cls;
    1.26 @@ -161,10 +170,43 @@
    1.27  			if(opt.type != OPT_STR) {
    1.28  				goto err;
    1.29  			}
    1.30 -			/* XXX cont. */
    1.31 +			if(!(attr->tex = load_texture(opt.valstr, tex_cls))) {
    1.32 +				fprintf(stderr, "failed to load texture: %s\n", opt.valstr);
    1.33 +				goto err;
    1.34 +			}
    1.35 +		} else if(opt.type == OPT_STR) {
    1.36 +			fprintf(stderr, "invalid particle config: %s\n", opt.name);
    1.37 +			goto err;
    1.38 +		}
    1.39 +
    1.40 +		if(strcmp(opt.name, "spawn_range") == 0) {
    1.41 +			psys_set_value3(&attr->spawn_range, opt.tm, opt.val);
    1.42 +		} else if(strcmp(opt.name, "rate") == 0) {
    1.43 +			psys_set_value(&attr->rate, opt.tm, opt.val.x);
    1.44 +		} else if(strcmp(opt.name, "life") == 0) {
    1.45 +			psys_set_anm_rnd(&attr->life, opt.tm, opt.val.x, opt.valrng.x);
    1.46 +		} else if(strcmp(opt.name, "size") == 0) {
    1.47 +			psys_set_anm_rnd(&attr->size, opt.tm, opt.val.x, opt.valrng.x);
    1.48 +		} else if(strcmp(opt.name, "dir") == 0) {
    1.49 +			psys_set_anm_rnd3(&attr->dir, opt.tm, opt.val, opt.valrng);
    1.50 +		} else if(strcmp(opt.name, "grav") == 0) {
    1.51 +			psys_set_value3(&attr->grav, opt.tm, opt.val);
    1.52 +		} else if(strcmp(opt.name, "drag") == 0) {
    1.53 +			attr->drag = opt.val.x;
    1.54 +		} else if(strcmp(opt.name, "pcolor") == 0) {
    1.55 +			psys_set_value3(&attr->part_attr.color, opt.tm, opt.val);
    1.56 +		} else if(strcmp(opt.name, "palpha") == 0) {
    1.57 +			psys_set_value(&attr->part_attr.alpha, opt.tm, opt.val.x);
    1.58 +		} else if(strcmp(opt.name, "psize") == 0) {
    1.59 +			psys_set_value(&attr->part_attr.size, opt.tm, opt.val.x);
    1.60 +		} else {
    1.61 +			fprintf(stderr, "unrecognized particle config option: %s\n", opt.name);
    1.62 +			goto err;
    1.63  		}
    1.64  	}
    1.65  
    1.66 +	return 0;
    1.67 +
    1.68  err:
    1.69  	fprintf(stderr, "Line %d: error parsing particle definition\n", lineno);
    1.70  	psys_destroy_attr(attr);
    1.71 @@ -172,19 +214,14 @@
    1.72  }
    1.73  
    1.74  /* strdup on the stack with alloca */
    1.75 -#define strdup_stack(s) \
    1.76 -	do { \
    1.77 -		size_t len = strlen(s); \
    1.78 -		char *res = alloca(len + 1); \
    1.79 -		memcpy(res, s, len + 1); \
    1.80 -	} while(0)
    1.81 +#define strdup_stack(s)  strcpy(alloca(strlen(s) + 1), s)
    1.82  
    1.83  static int get_cfg_opt(const char *line, struct cfgopt *opt)
    1.84  {
    1.85  	char *buf;
    1.86  	float tmsec;
    1.87  
    1.88 -	line = stripspace(line);
    1.89 +	line = stripspace((char*)line);
    1.90  	if(line[0] == '#' || !line[0]) {
    1.91  		return 0;	/* skip empty lines and comments */
    1.92  	}
    1.93 @@ -216,7 +253,7 @@
    1.94  		/* value is a number range */
    1.95  		opt->type = OPT_NUM_RANGE;
    1.96  		opt->val.y = opt->val.z = opt->val.x;
    1.97 -		opt->valrng.y = opt->valrng.z = opt->valrgn.x;
    1.98 +		opt->valrng.y = opt->valrng.z = opt->valrng.x;
    1.99  
   1.100  	} else if(sscanf(opt->valstr, "[%f %f %f]", &opt->val.x, &opt->val.y, &opt->val.z) == 3) {
   1.101  		/* value is a vector */