libpsys

diff src/pattr.c @ 9:9c24273f211b

first test is done
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 28 Sep 2011 03:42:01 +0300
parents a10f19674147
children 1b0db53d5b5b
line diff
     1.1 --- a/src/pattr.c	Tue Sep 27 21:47:27 2011 +0300
     1.2 +++ b/src/pattr.c	Wed Sep 28 03:42:01 2011 +0300
     1.3 @@ -5,6 +5,9 @@
     1.4  #include "pattr.h"
     1.5  #include "psys_gl.h"
     1.6  
     1.7 +static int init_particle_attr(struct psys_particle_attributes *pattr);
     1.8 +static void destroy_particle_attr(struct psys_particle_attributes *pattr);
     1.9 +
    1.10  static void *tex_cls;
    1.11  static unsigned int (*load_texture)(const char*, void*) = psys_gl_load_texture;
    1.12  static void (*unload_texture)(unsigned int, void*) = psys_gl_unload_texture;
    1.13 @@ -33,6 +36,9 @@
    1.14  	if(psys_init_track3(&attr->grav) == -1)
    1.15  		goto err;
    1.16  
    1.17 +	if(init_particle_attr(&attr->part_attr) == -1)
    1.18 +		goto err;
    1.19 +
    1.20  	attr->max_particles = -1;
    1.21  
    1.22  	anm_set_track_default(&attr->size.value.trk, 1.0);
    1.23 @@ -45,6 +51,31 @@
    1.24  	return -1;
    1.25  }
    1.26  
    1.27 +
    1.28 +static int init_particle_attr(struct psys_particle_attributes *pattr)
    1.29 +{
    1.30 +	if(psys_init_track3(&pattr->color) == -1) {
    1.31 +		return -1;
    1.32 +	}
    1.33 +	if(psys_init_track(&pattr->alpha) == -1) {
    1.34 +		psys_destroy_track3(&pattr->color);
    1.35 +		return -1;
    1.36 +	}
    1.37 +	if(psys_init_track(&pattr->size) == -1) {
    1.38 +		psys_destroy_track3(&pattr->color);
    1.39 +		psys_destroy_track(&pattr->alpha);
    1.40 +		return -1;
    1.41 +	}
    1.42 +
    1.43 +	anm_set_track_default(&pattr->color.x, 1.0);
    1.44 +	anm_set_track_default(&pattr->color.y, 1.0);
    1.45 +	anm_set_track_default(&pattr->color.z, 1.0);
    1.46 +	anm_set_track_default(&pattr->alpha.trk, 1.0);
    1.47 +	anm_set_track_default(&pattr->size.trk, 1.0);
    1.48 +	return 0;
    1.49 +}
    1.50 +
    1.51 +
    1.52  void psys_destroy_attr(struct psys_attributes *attr)
    1.53  {
    1.54  	psys_destroy_track3(&attr->spawn_range);
    1.55 @@ -54,11 +85,20 @@
    1.56  	psys_destroy_anm_rnd3(&attr->dir);
    1.57  	psys_destroy_track3(&attr->grav);
    1.58  
    1.59 +	destroy_particle_attr(&attr->part_attr);
    1.60 +
    1.61  	if(attr->tex && unload_texture) {
    1.62  		unload_texture(attr->tex, tex_cls);
    1.63  	}
    1.64  }
    1.65  
    1.66 +static void destroy_particle_attr(struct psys_particle_attributes *pattr)
    1.67 +{
    1.68 +	psys_destroy_track3(&pattr->color);
    1.69 +	psys_destroy_track(&pattr->alpha);
    1.70 +	psys_destroy_track(&pattr->size);
    1.71 +}
    1.72 +
    1.73  void psys_eval_attr(struct psys_attributes *attr, anm_time_t tm)
    1.74  {
    1.75  	psys_eval_track3(&attr->spawn_range, tm);