# HG changeset patch # User John Tsiombikas # Date 1313815696 -10800 # Node ID 34d90cd9ef9b9709516af6b8c53c3efb31300fad starting a new demosystem diff -r 000000000000 -r 34d90cd9ef9b .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Aug 20 07:48:16 2011 +0300 @@ -0,0 +1,3 @@ +\.d$ +\.o$ +\.swp$ diff -r 000000000000 -r 34d90cd9ef9b Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sat Aug 20 07:48:16 2011 +0300 @@ -0,0 +1,25 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +dep = $(obj:.o=.d) + +lib_a = libdsys2.a + +CC = gcc +AR = ar +CFLAGS = -pedantic -Wall -g + +$(lib_a): $(obj) + $(AR) rcs $@ $(obj) + +-include $(dep) + +%.d: %.c + @$(CPP) $(CFLAGS) -MM -MT $(@:.d=.o) $< >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + +.PHONY: cleandep +cleandep: + rm -f $(dep) diff -r 000000000000 -r 34d90cd9ef9b src/dsys2.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dsys2.h Sat Aug 20 07:48:16 2011 +0300 @@ -0,0 +1,62 @@ +#ifndef DSYS2_H_ +#define DSYS2_H_ + +#include + +struct dsys_demo; +struct dsys_event; + +typedef float demotime_t; + +enum dsys_evtype { + DSYS_SINGLE, + DSYS_PERIODIC +}; + + +struct dsys_demo *dsys_open(const char *fname); +struct dsys_demo *dsys_open_stream(FILE *fp); +void dsys_close(struct dsys_demo *demo); + +void dsys_update(struct dsys_demo *demo, demotime_t tm); + + +void dsys_start(struct dsys_demo *demo); +void dsys_stop(struct dsys_demo *demo); +int dsys_is_running(struct dsys_demo *demo); + + +demotime_t dsys_duration(struct dsys_demo *demo); +demotime_t dsys_time(struct dsys_demo *demo); +float dsys_progress(struct dsys_demo *demo); + +/* seek without continuity */ +void dsys_seek(struct dsys_demo *demo, demotime_t tm); +void dsys_seek_norm(struct dsys_demo *demo, float t); + +/* seek by accelerating time */ +void dsys_warp(struct dsys_demo *demo, demotime_t tm); +void dsys_warp_norm(struct dsys_demo *demo, float t); + + +/* events */ +struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name); + +enum dsys_evtype dsys_event_type(struct dsys_event *ev); +float dsys_event_value(struct dsys_event *ev); + +void dsys_event_callback(struct dsys_event *ev, void (*func)(void*), void *cls); +void dsys_event_link(struct dsys_event *ev, float *link); + + +/* time conversion */ +demotime_t dsys_sec_to_dtime(float sec); +demotime_t dsys_msec_to_dtime(unsigned long msec); +demotime_t dsys_norm_to_dtime(float t); + +float dsys_dtime_to_sec(demotime_t tm); +unsigned long dsys_dtime_to_msec(demotime_t tm); +float dsys_dtime_to_norm(demotime_t tm); + + +#endif /* DSYS2_H_ */ diff -r 000000000000 -r 34d90cd9ef9b src/dsys_impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dsys_impl.h Sat Aug 20 07:48:16 2011 +0300 @@ -0,0 +1,54 @@ +#ifndef DSYS_IMPL_H_ +#define DSYS_IMPL_H_ + +#include "dsys2.h" + +static float eval_step(struct dsys_event *ev, demotime_t t); +static float eval_lerp(struct dsys_event *ev, demotime_t t); +static float eval_sigmoid(struct dsys_event *ev, demotime_t t); + + +struct dsys_demo { + demotime_t srctime; + + struct dsys_event *ev; + int num_ev; +}; + +struct callback { + void (*func)(struct dsys_event*, void*); + void *cls; + + struct callback *next; +}; + + +struct dsys_event { + enum dsys_evtype type; + + demotime_t t0, t1; + float val; + + float (*eval_func)(struct dsys_event*); + + struct callback *cblist; +}; + + +static float eval_step(struct dsys_event *ev, demotime_t t) +{ + return t >= ev->t1 ? 1.0 : 0.0; +} + +static float eval_lerp(struct dsys_event *ev, demotime_t t) +{ + return (t - ev->t0) / (ev->t1 - ev->t0); +} + +static float eval_sigmoid(struct dsys_event *ev, demotime_t t) +{ + t = eval_lerp(ev, t); + return 1.0 - (cos(t * M_PI) * 0.5 + 0.5); +} + +#endif /* DSYS_IMPL_H_ */