dsys2
changeset 5:94ce16dd20c0
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 02 Sep 2011 01:57:00 +0300 |
parents | 95f010f7eadc |
children | 80f86f0f67ec |
files | Makefile src/dsys.c src/dsys2.h |
diffstat | 3 files changed, 42 insertions(+), 15 deletions(-) [+] |
line diff
1.1 --- a/Makefile Thu Sep 01 07:55:22 2011 +0300 1.2 +++ b/Makefile Fri Sep 02 01:57:00 2011 +0300 1.3 @@ -8,8 +8,14 @@ 1.4 AR = ar 1.5 CFLAGS = -pedantic -Wall -g -Isrc 1.6 1.7 +ifeq ($(shell uname -s), Darwin) 1.8 + libgl = -framework OpenGL -framework GLUT 1.9 +else 1.10 + libgl = -lGL -lGLU -lglut 1.11 +endif 1.12 + 1.13 test: test.o $(lib_a) 1.14 - $(CC) $(CFLAGS) -o $@ test.o $(lib_a) -lGL -lGLU -lglut -lm 1.15 + $(CC) $(CFLAGS) -o $@ test.o $(lib_a) $(libgl) -lm 1.16 1.17 $(lib_a): $(obj) 1.18 $(AR) rcs $@ $(obj)
2.1 --- a/src/dsys.c Thu Sep 01 07:55:22 2011 +0300 2.2 +++ b/src/dsys.c Fri Sep 02 01:57:00 2011 +0300 2.3 @@ -8,10 +8,6 @@ 2.4 2.5 static int read_script(struct dsys_demo *demo, FILE *fp, const char *fname); 2.6 2.7 -static float eval_step(struct dsys_event *ev, demotime_t t); 2.8 -static float eval_lerp(struct dsys_event *ev, demotime_t t); 2.9 -static float eval_sigmoid(struct dsys_event *ev, demotime_t t); 2.10 - 2.11 static void free_event(struct dsys_event *ev); 2.12 2.13 static struct dsys_event *sort_evlist(struct dsys_event *list, int num_ev); 2.14 @@ -130,12 +126,12 @@ 2.15 2.16 if(!(ev->name = malloc(strlen(tok) + 1))) { 2.17 free(ev); 2.18 - sprintf("read_script: failed to allocate memory for the event name: %s\n", tok); 2.19 + fprintf(stderr, "read_script: failed to allocate memory for the event name: %s\n", tok); 2.20 return -1; 2.21 } 2.22 strcpy(ev->name, tok); 2.23 2.24 - ev->eval_func = t0 == t1 ? eval_step : eval_lerp; 2.25 + ev->eval_func = t0 == t1 ? dsys_eval_step : dsys_eval_lerp; 2.26 2.27 ev->next = demo->evlist; 2.28 ev->prev = 0; 2.29 @@ -230,12 +226,33 @@ 2.30 2.31 2.32 /* events */ 2.33 -struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name); 2.34 +struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name) 2.35 +{ 2.36 + struct dsys_event *iter = demo->evlist; 2.37 2.38 -enum dsys_evtype dsys_event_type(struct dsys_event *ev); 2.39 -float dsys_event_value(struct dsys_event *ev); 2.40 + while(iter) { 2.41 + if(strcmp(iter->name, name) == 0) { 2.42 + return iter; 2.43 + } 2.44 + iter = iter->next; 2.45 + } 2.46 + return 0; 2.47 +} 2.48 2.49 -void dsys_event_callback(struct dsys_event *ev, void (*func)(void*), void *cls); 2.50 +enum dsys_evtype dsys_event_type(struct dsys_event *ev) 2.51 +{ 2.52 + return ev->type; 2.53 +} 2.54 + 2.55 +float dsys_event_value(struct dsys_event *ev) 2.56 +{ 2.57 + return ev->value; 2.58 +} 2.59 + 2.60 +void dsys_event_callback(struct dsys_event *ev, void (*func)(void*), void *cls) 2.61 +{ 2.62 +} 2.63 + 2.64 void dsys_event_link(struct dsys_event *ev, float *link); 2.65 2.66 2.67 @@ -261,19 +278,19 @@ 2.68 } 2.69 2.70 2.71 -static float eval_step(struct dsys_event *ev, demotime_t t) 2.72 +float dsys_eval_step(struct dsys_event *ev, demotime_t t) 2.73 { 2.74 return t >= ev->t1 ? 1.0 : 0.0; 2.75 } 2.76 2.77 -static float eval_lerp(struct dsys_event *ev, demotime_t t) 2.78 +float dsys_eval_lerp(struct dsys_event *ev, demotime_t t) 2.79 { 2.80 return (t - ev->t0) / (ev->t1 - ev->t0); 2.81 } 2.82 2.83 -static float eval_sigmoid(struct dsys_event *ev, demotime_t t) 2.84 +float dsys_eval_sigmoid(struct dsys_event *ev, demotime_t t) 2.85 { 2.86 - t = eval_lerp(ev, t); 2.87 + t = dsys_eval_lerp(ev, t); 2.88 return 1.0 - (cos(t * M_PI) * 0.5 + 0.5); 2.89 } 2.90
3.1 --- a/src/dsys2.h Thu Sep 01 07:55:22 2011 +0300 3.2 +++ b/src/dsys2.h Fri Sep 02 01:57:00 2011 +0300 3.3 @@ -48,6 +48,10 @@ 3.4 void dsys_event_callback(struct dsys_event *ev, void (*func)(void*), void *cls); 3.5 void dsys_event_link(struct dsys_event *ev, float *link); 3.6 3.7 +/* event evaluators */ 3.8 +float dsys_eval_step(struct dsys_event *ev, demotime_t t); 3.9 +float dsys_eval_lerp(struct dsys_event *ev, demotime_t t); 3.10 +float dsys_eval_sigmoid(struct dsys_event *ev, demotime_t t); 3.11 3.12 /* time conversion */ 3.13 demotime_t dsys_sec_to_dtime(float sec);