dsys2

diff src/dsys.c @ 5:94ce16dd20c0

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 02 Sep 2011 01:57:00 +0300
parents 95f010f7eadc
children 80f86f0f67ec
line diff
     1.1 --- a/src/dsys.c	Thu Sep 01 07:55:22 2011 +0300
     1.2 +++ b/src/dsys.c	Fri Sep 02 01:57:00 2011 +0300
     1.3 @@ -8,10 +8,6 @@
     1.4  
     1.5  static int read_script(struct dsys_demo *demo, FILE *fp, const char *fname);
     1.6  
     1.7 -static float eval_step(struct dsys_event *ev, demotime_t t);
     1.8 -static float eval_lerp(struct dsys_event *ev, demotime_t t);
     1.9 -static float eval_sigmoid(struct dsys_event *ev, demotime_t t);
    1.10 -
    1.11  static void free_event(struct dsys_event *ev);
    1.12  
    1.13  static struct dsys_event *sort_evlist(struct dsys_event *list, int num_ev);
    1.14 @@ -130,12 +126,12 @@
    1.15  
    1.16  		if(!(ev->name = malloc(strlen(tok) + 1))) {
    1.17  			free(ev);
    1.18 -			sprintf("read_script: failed to allocate memory for the event name: %s\n", tok);
    1.19 +			fprintf(stderr, "read_script: failed to allocate memory for the event name: %s\n", tok);
    1.20  			return -1;
    1.21  		}
    1.22  		strcpy(ev->name, tok);
    1.23  
    1.24 -		ev->eval_func = t0 == t1 ? eval_step : eval_lerp;
    1.25 +		ev->eval_func = t0 == t1 ? dsys_eval_step : dsys_eval_lerp;
    1.26  
    1.27  		ev->next = demo->evlist;
    1.28  		ev->prev = 0;
    1.29 @@ -230,12 +226,33 @@
    1.30  
    1.31  
    1.32  /* events */
    1.33 -struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name);
    1.34 +struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name)
    1.35 +{
    1.36 +	struct dsys_event *iter = demo->evlist;
    1.37  
    1.38 -enum dsys_evtype dsys_event_type(struct dsys_event *ev);
    1.39 -float dsys_event_value(struct dsys_event *ev);
    1.40 +	while(iter) {
    1.41 +		if(strcmp(iter->name, name) == 0) {
    1.42 +			return iter;
    1.43 +		}
    1.44 +		iter = iter->next;
    1.45 +	}
    1.46 +	return 0;
    1.47 +}
    1.48  
    1.49 -void dsys_event_callback(struct dsys_event *ev, void (*func)(void*), void *cls);
    1.50 +enum dsys_evtype dsys_event_type(struct dsys_event *ev)
    1.51 +{
    1.52 +	return ev->type;
    1.53 +}
    1.54 +
    1.55 +float dsys_event_value(struct dsys_event *ev)
    1.56 +{
    1.57 +	return ev->value;
    1.58 +}
    1.59 +
    1.60 +void dsys_event_callback(struct dsys_event *ev, void (*func)(void*), void *cls)
    1.61 +{
    1.62 +}
    1.63 +
    1.64  void dsys_event_link(struct dsys_event *ev, float *link);
    1.65  
    1.66  
    1.67 @@ -261,19 +278,19 @@
    1.68  }
    1.69  
    1.70  
    1.71 -static float eval_step(struct dsys_event *ev, demotime_t t)
    1.72 +float dsys_eval_step(struct dsys_event *ev, demotime_t t)
    1.73  {
    1.74  	return t >= ev->t1 ? 1.0 : 0.0;
    1.75  }
    1.76  
    1.77 -static float eval_lerp(struct dsys_event *ev, demotime_t t)
    1.78 +float dsys_eval_lerp(struct dsys_event *ev, demotime_t t)
    1.79  {
    1.80  	return (t - ev->t0) / (ev->t1 - ev->t0);
    1.81  }
    1.82  
    1.83 -static float eval_sigmoid(struct dsys_event *ev, demotime_t t)
    1.84 +float dsys_eval_sigmoid(struct dsys_event *ev, demotime_t t)
    1.85  {
    1.86 -	t = eval_lerp(ev, t);
    1.87 +	t = dsys_eval_lerp(ev, t);
    1.88  	return 1.0 - (cos(t * M_PI) * 0.5 + 0.5);
    1.89  }
    1.90