planner: return decotable from plan()

The old return code was not used by any caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-09-07 15:32:06 +02:00 committed by Michael Keller
parent 22b232661a
commit 1287880be0
4 changed files with 29 additions and 34 deletions

View file

@ -602,7 +602,7 @@ static void average_max_depth(const struct diveplan &dive, int *avg_depth, int *
*avg_depth = *max_depth = 0;
}
bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, std::vector<decostop> &decostoptable, deco_state_cache &cache, bool is_planner, bool show_disclaimer)
std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, deco_state_cache &cache, bool is_planner, bool show_disclaimer)
{
int bottom_depth;
@ -631,7 +631,6 @@ bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, i
int break_cylinder = -1, breakfrom_cylinder = 0;
bool last_segment_min_switch = false;
planner_error_t error = PLAN_OK;
bool decodive = false;
int first_stop_depth = 0;
int laststoptime = timestep;
bool o2breaking = false;
@ -701,7 +700,7 @@ bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, i
transitiontime = lrint(depth / (double)prefs.ascratelast6m);
plan_add_segment(diveplan, transitiontime, 0, current_cylinder, po2, false, divemode);
create_dive_from_plan(diveplan, dive, dc, is_planner);
return false;
return {};
}
#if DEBUG_PLAN & 4
@ -783,7 +782,7 @@ bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, i
diveplan.add_plan_to_notes(*dive, show_disclaimer, error);
fixup_dc_duration(*dc);
return false;
return {};
}
if (best_first_ascend_cylinder != -1 && best_first_ascend_cylinder != current_cylinder) {
@ -817,6 +816,7 @@ bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, i
bottom_stopidx = stopidx;
//CVA
std::vector<decostop> decostoptable;
do {
decostoptable.clear();
is_final_plan = (decoMode(true) == BUEHLMANN) || (previous_deco_time - ds->deco_time < 10); // CVA time converges
@ -831,7 +831,7 @@ bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, i
clock = previous_point_time = bottom_time;
gas = bottom_gas;
stopping = false;
decodive = false;
bool decodive = false;
first_stop_depth = 0;
stopidx = bottom_stopidx;
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(
@ -1059,6 +1059,5 @@ bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, i
create_dive_from_plan(diveplan, dive, dc, is_planner);
diveplan.add_plan_to_notes(*dive, show_disclaimer, error);
fixup_dc_duration(*dc);
return decodive;
return decostoptable;
}

View file

@ -66,5 +66,5 @@ struct decostop {
};
extern std::string get_planner_disclaimer_formatted();
extern bool plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, std::vector<decostop> &decostoptable, deco_state_cache &cache, bool is_planner, bool show_disclaimer);
extern std::vector<decostop> plan(struct deco_state *ds, struct diveplan &diveplan, struct dive *dive, int dcNr, int timestep, deco_state_cache &cache, bool is_planner, bool show_disclaimer);
#endif // PLANNER_H

View file

@ -1119,10 +1119,9 @@ void DivePlannerPointsModel::updateDiveProfile()
return;
deco_state_cache cache;
std::vector<decostop> stoptable;
struct deco_state plan_deco_state;
plan(&plan_deco_state, diveplan, d, dcNr, decotimestep, stoptable, cache, isPlanner(), false);
plan(&plan_deco_state, diveplan, d, dcNr, decotimestep, cache, isPlanner(), false);
updateMaxDepth();
if (isPlanner() && shouldComputeVariations()) {
@ -1217,7 +1216,6 @@ void DivePlannerPointsModel::computeVariations(std::unique_ptr<struct diveplan>
auto dive = std::make_unique<struct dive>();
copy_dive(d, dive.get());
std::vector<decostop> original, deeper, shallower, shorter, longer;
deco_state_cache cache, save;
struct diveplan plan_copy;
struct deco_state ds = *previous_ds;
@ -1243,7 +1241,7 @@ void DivePlannerPointsModel::computeVariations(std::unique_ptr<struct diveplan>
return;
if (my_instance != instanceCounter)
return;
plan(&ds, plan_copy, dive.get(), dcNr, 1, original, cache, true, false);
auto original = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
plan_copy = *original_plan;
@ -1251,27 +1249,27 @@ void DivePlannerPointsModel::computeVariations(std::unique_ptr<struct diveplan>
plan_copy.dp.back().depth.mm += delta_depth.mm;
if (my_instance != instanceCounter)
return;
plan(&ds, plan_copy, dive.get(), dcNr, 1, deeper, cache, true, false);
auto deeper = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
second_to_last(plan_copy.dp).depth.mm -= delta_depth.mm;
plan_copy.dp.back().depth.mm -= delta_depth.mm;
if (my_instance != instanceCounter)
return;
plan(&ds, plan_copy, dive.get(), dcNr, 1, shallower, cache, true, false);
auto shallower = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
plan_copy = *original_plan;
plan_copy.dp.back().time += delta_time.seconds;
if (my_instance != instanceCounter)
return;
plan(&ds, plan_copy, dive.get(), dcNr, 1, longer, cache, true, false);
auto longer = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
plan_copy.dp.back().time -= delta_time.seconds;
if (my_instance != instanceCounter)
return;
plan(&ds, plan_copy, dive.get(), dcNr, 1, shorter, cache, true, false);
auto shorter = plan(&ds, plan_copy, dive.get(), dcNr, 1, cache, true, false);
save.restore(&ds, false);
char buf[200];
@ -1311,8 +1309,7 @@ void DivePlannerPointsModel::createPlan(bool saveAsNew)
removeDeco();
createTemporaryPlan();
std::vector<decostop> stoptable;
plan(&ds_after_previous_dives, diveplan, d, dcNr, decotimestep, stoptable, cache, isPlanner(), true);
plan(&ds_after_previous_dives, diveplan, d, dcNr, decotimestep, cache, isPlanner(), true);
if (shouldComputeVariations()) {
auto plan_copy = std::make_unique<struct diveplan>();

View file

@ -13,7 +13,6 @@
// testing the dive plan algorithm
static struct dive dive;
static std::vector<decostop> stoptable;
static struct deco_state test_deco_state;
void setupPrefs()
{
@ -495,7 +494,7 @@ void TestPlan::testMetric()
auto testPlan = setupPlan();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -532,7 +531,7 @@ void TestPlan::testImperial()
auto testPlan = setupPlan();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -568,7 +567,7 @@ void TestPlan::testVpmbMetric45m30minTx()
auto testPlan = setupPlanVpmb45m30mTx();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -594,7 +593,7 @@ void TestPlan::testVpmbMetric60m10minTx()
auto testPlan = setupPlanVpmb60m10mTx();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -620,7 +619,7 @@ void TestPlan::testVpmbMetric60m30minAir()
auto testPlan = setupPlanVpmb60m30minAir();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -646,7 +645,7 @@ void TestPlan::testVpmbMetric60m30minEan50()
auto testPlan = setupPlanVpmb60m30minEan50();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -678,7 +677,7 @@ void TestPlan::testVpmbMetric60m30minTx()
auto testPlan = setupPlanVpmb60m30minTx();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -710,7 +709,7 @@ void TestPlan::testVpmbMetric100m60min()
auto testPlan = setupPlanVpmb100m60min();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -748,7 +747,7 @@ void TestPlan::testMultipleGases()
auto testPlan = setupPlanSeveralGases();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -770,7 +769,7 @@ void TestPlan::testVpmbMetricMultiLevelAir()
auto testPlan = setupPlanVpmbMultiLevelAir();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -796,7 +795,7 @@ void TestPlan::testVpmbMetric100m10min()
auto testPlan = setupPlanVpmb100m10min();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -839,7 +838,7 @@ void TestPlan::testVpmbMetricRepeat()
auto testPlan = setupPlanVpmb30m20min();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -857,7 +856,7 @@ void TestPlan::testVpmbMetricRepeat()
int firstDiveRunTimeSeconds = dive.dcs[0].duration.seconds;
testPlan = setupPlanVpmb100mTo70m30min();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -892,7 +891,7 @@ void TestPlan::testVpmbMetricRepeat()
QVERIFY(compareDecoTime(dive.dcs[0].duration.seconds, 127u * 60u + 20u, 127u * 60u + 20u));
testPlan = setupPlanVpmb30m20min();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, 1, 0);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, 1, 0);
#if DEBUG
dive.notes.clear();
@ -927,7 +926,7 @@ void TestPlan::testCcrBailoutGasSelection()
auto testPlan = setupPlanCcr();
plan(&test_deco_state, testPlan, &dive, 0, 60, stoptable, cache, true, false);
plan(&test_deco_state, testPlan, &dive, 0, 60, cache, true, false);
#if DEBUG
dive.notes.clear();