dsys2

changeset 10:5ba9dd6742a0

fixed a crash
author John Tsiombikas <nuclear@siggraph.org>
date Sun, 04 Sep 2011 06:44:49 +0300
parents 61cc1a525023
children 65da828bc218
files Makefile src/dsys.c src/dsys2.h
diffstat 3 files changed, 31 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Fri Sep 02 19:12:12 2011 +0300
     1.2 +++ b/Makefile	Sun Sep 04 06:44:49 2011 +0300
     1.3 @@ -1,3 +1,5 @@
     1.4 +PREFIX = /usr/local
     1.5 +
     1.6  src = $(wildcard src/*.c)
     1.7  obj = $(src:.c=.o)
     1.8  dep = $(obj:.o=.d)
     1.9 @@ -32,3 +34,13 @@
    1.10  .PHONY: cleandep
    1.11  cleandep:
    1.12  	rm -f $(dep)
    1.13 +
    1.14 +.PHONY: install
    1.15 +install:
    1.16 +	mkdir -p $(PREFIX)/include $(PREFIX)/lib
    1.17 +	cp $(lib_a) $(PREFIX)/lib/$(lib_a)
    1.18 +	cp src/dsys2.h $(PREFIX)/include/dsys2.h
    1.19 +
    1.20 +.PHONY: uninstall
    1.21 +uninstall:
    1.22 +	rm -f $(PREFIX)/include/dsys2.h $(PREFIX)/lib/$(lib_a)
     2.1 --- a/src/dsys.c	Fri Sep 02 19:12:12 2011 +0300
     2.2 +++ b/src/dsys.c	Sun Sep 04 06:44:49 2011 +0300
     2.3 @@ -128,6 +128,7 @@
     2.4  			perror("read_script: failed to allocate memory for an event\n");
     2.5  			return -1;
     2.6  		}
     2.7 +		memset(ev, 0, sizeof *ev);
     2.8  		ev->t0 = dsys_msec_to_dtime(t0);
     2.9  		ev->t1 = dsys_msec_to_dtime(t1);
    2.10  
    2.11 @@ -155,7 +156,7 @@
    2.12  
    2.13  	demo->evlist = sort_evlist(demo->evlist, demo->num_ev);
    2.14  
    2.15 -	dbg_print_events(demo->evlist);
    2.16 +	/*dbg_print_events(demo->evlist);*/
    2.17  
    2.18  	return 0;
    2.19  }
    2.20 @@ -214,7 +215,7 @@
    2.21  		return;	/* nothing changes */
    2.22  	}
    2.23  
    2.24 -	while(demo->active->t1 <= demo->tm) {
    2.25 +	while(demo->active && demo->active->t1 <= demo->tm) {
    2.26  		proc_event(demo->active, demo->tm);
    2.27  		demo->active = demo->active->next;
    2.28  	}
    2.29 @@ -239,11 +240,12 @@
    2.30  	if(ev->val != val) {
    2.31  		struct callback *cb = ev->cblist;
    2.32  
    2.33 +		ev->val = val;
    2.34 +
    2.35  		while(cb) {
    2.36  			cb->func(ev, cb->cls);
    2.37  			cb = cb->next;
    2.38  		}
    2.39 -		ev->val = val;
    2.40  	}
    2.41  }
    2.42  
    2.43 @@ -306,10 +308,15 @@
    2.44  		tm = demo->duration;
    2.45  	}
    2.46  
    2.47 +	if(tm < demo->tm) {
    2.48 +		/* on backwards seek, invalidate the sliding window */
    2.49 +		demo->nextev = demo->active = demo->evlist;
    2.50 +	}
    2.51 +
    2.52  	demo->start_tm = demo->src_tm - tm;
    2.53  	demo->stoppage_tm = 0;
    2.54 -
    2.55 -	demo->nextev = demo->active = demo->evlist;
    2.56 +	demo->stop_tm = demo->src_tm;
    2.57 +	demo->tm = tm;
    2.58  
    2.59  	/* recalculate events */
    2.60  	ev = demo->evlist;
     3.1 --- a/src/dsys2.h	Fri Sep 02 19:12:12 2011 +0300
     3.2 +++ b/src/dsys2.h	Sun Sep 04 06:44:49 2011 +0300
     3.3 @@ -13,6 +13,9 @@
     3.4  	DSYS_PERIODIC
     3.5  };
     3.6  
     3.7 +#ifdef __cplusplus
     3.8 +extern "C" {
     3.9 +#endif
    3.10  
    3.11  struct dsys_demo *dsys_open(const char *fname);
    3.12  struct dsys_demo *dsys_open_stream(FILE *fp);
    3.13 @@ -60,5 +63,9 @@
    3.14  float dsys_dtime_to_sec(demotime_t tm);
    3.15  unsigned long dsys_dtime_to_msec(demotime_t tm);
    3.16  
    3.17 +#ifdef __cplusplus
    3.18 +}
    3.19 +#endif
    3.20 +
    3.21  
    3.22  #endif	/* DSYS2_H_ */