From 92dadbc1d4bacd5af4eb1b2e5bb3e6d2f0e954fa Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Thu, 20 Oct 2022 20:33:43 +0200 Subject: Change waypoint callback from function-only to function+arg combination --- src/schedule.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/schedule.c') diff --git a/src/schedule.c b/src/schedule.c index 5630ffb..1a002e0 100644 --- a/src/schedule.c +++ b/src/schedule.c @@ -37,7 +37,7 @@ int direct_ascent(const decostate_t *ds, const double depth, const double time, return gauge_depth(ceiling(&ds_, ds_.gfhi)) <= 0; } -void simulate_dive(decostate_t *ds, waypoint_t *waypoints, const int nof_waypoints, waypoint_callback_t wp_cb) +void simulate_dive(decostate_t *ds, waypoint_t *waypoints, const int nof_waypoints, waypoint_callback_t *wp_cb) { double depth = abs_depth(0); @@ -53,8 +53,8 @@ void simulate_dive(decostate_t *ds, waypoint_t *waypoints, const int nof_waypoin depth = d; - if (wp_cb) - wp_cb(ds, (waypoint_t){.depth = d, .time = t, .gas = g}, SEG_DIVE); + if (wp_cb && wp_cb->fn) + wp_cb->fn(ds, (waypoint_t){.depth = d, .time = t, .gas = g}, SEG_DIVE, wp_cb->arg); } } @@ -125,7 +125,7 @@ static int surfaced(const double depth) } decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *start_gas, const gas_t *deco_gasses, - const int nof_gasses, waypoint_callback_t wp_cb) + const int nof_gasses, waypoint_callback_t *wp_cb) { decoinfo_t ret = {.tts = 0, .ndl = 0}; @@ -157,8 +157,9 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta /* emit waypoint */ waypoint_time = fabs(last_waypoint_depth - depth) / asc_per_min; - if (wp_cb) - wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_TRAVEL); + if (wp_cb && wp_cb->fn) + wp_cb->fn(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_TRAVEL, + wp_cb->arg); last_waypoint_depth = depth; @@ -167,8 +168,8 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta ret.tts += add_segment_const(ds, depth, 1, gas); - if (wp_cb) - wp_cb(ds, (waypoint_t){.depth = depth, .time = 1, .gas = gas}, SEG_GAS_SWITCH); + if (wp_cb && wp_cb->fn) + wp_cb->fn(ds, (waypoint_t){.depth = depth, .time = 1, .gas = gas}, SEG_GAS_SWITCH, wp_cb->arg); continue; } @@ -205,8 +206,8 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta waypoint_time = fabs(last_waypoint_depth - depth) / asc_per_min; enum segtype_t segtype = surfaced(depth) ? SEG_SURFACE : SEG_TRAVEL; - if (wp_cb && waypoint_time) - wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, segtype); + if (wp_cb && wp_cb->fn && waypoint_time) + wp_cb->fn(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, segtype, wp_cb->arg); /* terminate if we surfaced */ if (surfaced(depth)) @@ -223,7 +224,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta ret.tts += stoplen; - if (wp_cb) - wp_cb(ds, (waypoint_t){.depth = depth, .time = stoplen, .gas = gas}, SEG_DECO_STOP); + if (wp_cb && wp_cb->fn) + wp_cb->fn(ds, (waypoint_t){.depth = depth, .time = stoplen, .gas = gas}, SEG_DECO_STOP, wp_cb->arg); } } -- cgit v1.2.3-70-g09d2