aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/schedule.c
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2022-10-03 16:02:29 +0200
committerGravatar Tim Segers <tsegers@pm.me>2022-10-03 16:02:29 +0200
commitb6aaf32347e0859fae26f422d66deaac8e63b475 (patch)
tree12d36802f70b7123cc6397d496f392e48ef5c59a /schedule.c
parent082b09038d9834f8dccde97733eab6f3d90b7016 (diff)
downloadopendeco-b6aaf32347e0859fae26f422d66deaac8e63b475.tar.gz
Extract deco stop functionlity into function deco_stop
Diffstat (limited to 'schedule.c')
-rw-r--r--schedule.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/schedule.c b/schedule.c
index 4c111f2..66fb36e 100644
--- a/schedule.c
+++ b/schedule.c
@@ -7,6 +7,9 @@
#define SWITCH_INTERMEDIATE 1
+#define STOPLEN_ROUGH 10
+#define STOPLEN_FINE 1
+
const gas_t *best_gas(const double depth, const gas_t *gasses, const int nof_gasses)
{
const gas_t *best = NULL;
@@ -90,13 +93,13 @@ double calc_ndl(decostate_t *ds, const double depth, const double ascrate, const
return ndl;
}
-double calc_stoplen_rough(decostate_t *ds, const double depth, const double current_gf, const gas_t *gas)
+double calc_stoplen_rough(const decostate_t *ds, const double depth, const double current_gf, const gas_t *gas)
{
decostate_t ds_ = *ds;
double stoplen = 0;
- while (1) {
- double tmp = add_segment_const(&ds_, depth, 10, gas);
+ for (;;) {
+ double tmp = add_segment_const(&ds_, depth, STOPLEN_ROUGH, gas);
if (ceiling(&ds_, current_gf) != depth)
break;
@@ -107,6 +110,25 @@ double calc_stoplen_rough(decostate_t *ds, const double depth, const double curr
return stoplen;
}
+double deco_stop(decostate_t *ds, const double depth, const double current_gf, const gas_t *gas)
+{
+ double stoplen = 0;
+
+ /* rough steps */
+ double stoplen_rough = calc_stoplen_rough(ds, depth, current_gf, gas);
+
+ if (stoplen_rough) {
+ add_segment_const(ds, depth, stoplen_rough, gas);
+ stoplen += stoplen_rough;
+ }
+
+ /* fine steps */
+ while (ceiling(ds, current_gf) == depth)
+ stoplen += add_segment_const(ds, depth, STOPLEN_FINE, gas);
+
+ return stoplen;
+}
+
int should_switch(const gas_t **next, double *switch_depth, const decostate_t *ds, const double depth,
const double next_stop, const gas_t *deco_gasses, const int nof_gasses)
{
@@ -237,20 +259,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
gas = best;
/* stop */
- double stoplen = 0;
-
- /* rough steps */
- double stoplen_rough = calc_stoplen_rough(ds, depth, current_gf, gas);
-
- if (stoplen_rough) {
- add_segment_const(ds, depth, stoplen_rough, gas);
- stoplen += stoplen_rough;
- }
-
- /* fine steps */
- while (ceiling(ds, current_gf) == depth)
- stoplen += add_segment_const(ds, depth, 1, gas);
-
+ double stoplen = deco_stop(ds, depth, current_gf, gas);
ret.tts += stoplen;
if (wp_cb)