diff options
-rw-r--r-- | src/modules/plato/plato.c | 4 | ||||
-rw-r--r-- | src/modules/stars/stars.c | 10 | ||||
-rw-r--r-- | src/til_tap.h | 64 |
3 files changed, 40 insertions, 38 deletions
diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c index c8977bf..259d5b0 100644 --- a/src/modules/plato/plato.c +++ b/src/modules/plato/plato.c @@ -640,8 +640,8 @@ static til_module_context_t * plato_create_context(const til_module_t *module, t ctxt->setup = *((plato_setup_t *)setup); - ctxt->taps.spin_rate = til_tap_init_float(&ctxt->spin_rate, 1, &ctxt->setup.spin_rate, "spin_rate"); - ctxt->taps.orbit_rate = til_tap_init_float(&ctxt->orbit_rate, 1, &ctxt->setup.orbit_rate, "orbit_rate"); + ctxt->taps.spin_rate = til_tap_init_float(ctxt, &ctxt->spin_rate, 1, &ctxt->setup.spin_rate, "spin_rate"); + ctxt->taps.orbit_rate = til_tap_init_float(ctxt, &ctxt->orbit_rate, 1, &ctxt->setup.orbit_rate, "orbit_rate"); return &ctxt->til_module_context; } diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c index e2c9a21..d64a3d8 100644 --- a/src/modules/stars/stars.c +++ b/src/modules/stars/stars.c @@ -89,11 +89,11 @@ static til_module_context_t * stars_create_context(const til_module_t *module, t ctxt->vars.offset_x = 0.5; ctxt->vars.offset_angle = 0.01; - ctxt->taps.rot_rate = til_tap_init_float(&ctxt->rot_rate, 1, &ctxt->vars.rot_rate, "rot_rate"); - ctxt->taps.rot_angle = til_tap_init_float(&ctxt->rot_angle, 1, &ctxt->vars.rot_angle, "rot_angle"); - ctxt->taps.offset_x = til_tap_init_float(&ctxt->offset_x, 1, &ctxt->vars.offset_x, "offset_x"); - ctxt->taps.offset_y = til_tap_init_float(&ctxt->offset_y, 1, &ctxt->vars.offset_y, "offset_y"); - ctxt->taps.offset_angle = til_tap_init_float(&ctxt->offset_angle, 1, &ctxt->vars.offset_angle, "offset_angle"); + ctxt->taps.rot_rate = til_tap_init_float(ctxt, &ctxt->rot_rate, 1, &ctxt->vars.rot_rate, "rot_rate"); + ctxt->taps.rot_angle = til_tap_init_float(ctxt, &ctxt->rot_angle, 1, &ctxt->vars.rot_angle, "rot_angle"); + ctxt->taps.offset_x = til_tap_init_float(ctxt, &ctxt->offset_x, 1, &ctxt->vars.offset_x, "offset_x"); + ctxt->taps.offset_y = til_tap_init_float(ctxt, &ctxt->offset_y, 1, &ctxt->vars.offset_y, "offset_y"); + ctxt->taps.offset_angle = til_tap_init_float(ctxt, &ctxt->offset_angle, 1, &ctxt->vars.offset_angle, "offset_angle"); //add a bunch of points for(z=0.01; z<1; z=z+0.01) { diff --git a/src/til_tap.h b/src/til_tap.h index 66f1d3e..6fa47f4 100644 --- a/src/til_tap.h +++ b/src/til_tap.h @@ -64,6 +64,7 @@ typedef enum til_tap_type_t { /* this is deliberately left entirely public so taps can be easily embedded in contexts */ typedef struct til_tap_t { til_tap_type_t type; + const void *owner; /* identity of tap's owner, primarily for stream/pipe-oriented cleanup purposes */ void **ptr; /* points at the caller-provided tap-managed indirection pointer */ size_t n_elems; /* when > 1, *ptr is an array of n_elems elements. Otherwise individual variable. */ void *elems; /* points at the first element of type type, may or may not be an array of them */ @@ -78,7 +79,7 @@ typedef struct v4f_t v4f_t; typedef struct m4f_t m4f_t; /* This is the bare tap initializer but use the type-checked wrappers below and add one if one's missing */ -static inline til_tap_t til_tap_init(til_tap_type_t type, void *ptr, size_t n_elems, void *elems, const char *name) +static inline til_tap_t til_tap_init(const void *owner, til_tap_type_t type, void *ptr, size_t n_elems, void *elems, const char *name) { assert(type < TIL_TAP_TYPE_MAX); assert(ptr); @@ -89,6 +90,7 @@ static inline til_tap_t til_tap_init(til_tap_type_t type, void *ptr, size_t n_el *((void **)ptr) = elems; return (til_tap_t){ + .owner = owner, .type = type, .ptr = ptr, .n_elems = n_elems, @@ -101,79 +103,79 @@ static inline til_tap_t til_tap_init(til_tap_type_t type, void *ptr, size_t n_el /* typed wrappers, just supply n_elems=1 for individual variables - note n_elems is just a defensive * programming sanity check to catch callers mismatching array sizes */ -static inline til_tap_t til_tap_init_i8(int8_t **ptr, size_t n_elems, int8_t *elems, const char *name) +static inline til_tap_t til_tap_init_i8(const void *owner, int8_t **ptr, size_t n_elems, int8_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_I8, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_I8, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_i16(int16_t **ptr, size_t n_elems, int16_t *elems, const char *name) +static inline til_tap_t til_tap_init_i16(const void *owner, int16_t **ptr, size_t n_elems, int16_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_I16, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_I16, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_i32(int32_t **ptr, size_t n_elems, int32_t *elems, const char *name) +static inline til_tap_t til_tap_init_i32(const void *owner, int32_t **ptr, size_t n_elems, int32_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_I32, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_I32, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_i64(int64_t **ptr, size_t n_elems, int64_t *elems, const char *name) +static inline til_tap_t til_tap_init_i64(const void *owner, int64_t **ptr, size_t n_elems, int64_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_I64, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_I64, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_u8(uint8_t **ptr, size_t n_elems, uint8_t *elems, const char *name) +static inline til_tap_t til_tap_init_u8(const void *owner, uint8_t **ptr, size_t n_elems, uint8_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_U8, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_U8, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_u16(uint16_t **ptr, size_t n_elems, uint16_t *elems, const char *name) +static inline til_tap_t til_tap_init_u16(const void *owner, uint16_t **ptr, size_t n_elems, uint16_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_U16, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_U16, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_u32(uint32_t **ptr, size_t n_elems, uint32_t *elems, const char *name) +static inline til_tap_t til_tap_init_u32(const void *owner, uint32_t **ptr, size_t n_elems, uint32_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_U32, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_U32, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_u64(uint64_t **ptr, size_t n_elems, uint64_t *elems, const char *name) +static inline til_tap_t til_tap_init_u64(const void *owner, uint64_t **ptr, size_t n_elems, uint64_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_U64, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_U64, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_float(float **ptr, size_t n_elems, float *elems, const char *name) +static inline til_tap_t til_tap_init_float(const void *owner, float **ptr, size_t n_elems, float *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_FLOAT, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_FLOAT, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_double(double **ptr, size_t n_elems, double *elems, const char *name) +static inline til_tap_t til_tap_init_double(const void *owner, double **ptr, size_t n_elems, double *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_DOUBLE, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_DOUBLE, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_v2f(v2f_t **ptr, size_t n_elems, v2f_t *elems, const char *name) +static inline til_tap_t til_tap_init_v2f(const void *owner, v2f_t **ptr, size_t n_elems, v2f_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_V2F, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_V2F, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_v3f(v3f_t **ptr, size_t n_elems, v3f_t *elems, const char *name) +static inline til_tap_t til_tap_init_v3f(const void *owner, v3f_t **ptr, size_t n_elems, v3f_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_V3F, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_V3F, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_v4f(v4f_t **ptr, size_t n_elems, v4f_t *elems, const char *name) +static inline til_tap_t til_tap_init_v4f(const void *owner, v4f_t **ptr, size_t n_elems, v4f_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_V4F, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_V4F, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_m4f(m4f_t **ptr, size_t n_elems, m4f_t *elems, const char *name) +static inline til_tap_t til_tap_init_m4f(const void *owner, m4f_t **ptr, size_t n_elems, m4f_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_M4F, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_M4F, ptr, n_elems, elems, name); } -static inline til_tap_t til_tap_init_til_tap_voidp(void **ptr, size_t n_elems, til_tap_t *elems, const char *name) +static inline til_tap_t til_tap_init_til_tap_voidp(const void *owner, void **ptr, size_t n_elems, til_tap_t *elems, const char *name) { - return til_tap_init(TIL_TAP_TYPE_VOIDP, ptr, n_elems, elems, name); + return til_tap_init(owner, TIL_TAP_TYPE_VOIDP, ptr, n_elems, elems, name); } #endif |