mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Localize global planner state
For UI responsiveness, we need to be able to run the planner in the background. This needs the planner state to be localized (and we need to pass a pointer around). In order to not let too many lines overrun (and to save typing in the future) I have renamed instances of struct deco_state to ds. Yes this should have gone to a separate commit but I accidentally commit --amend'ed it. Computing of planner variations is temporarily disabled. Unlock the planner when returning early So we don't deadlock in add dive and recreational mode (which use the planner without actually planning). Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
a9ceecc2e3
commit
8e21a65653
14 changed files with 298 additions and 286 deletions
|
@ -11,8 +11,8 @@
|
|||
|
||||
// testing the dive plan algorithm
|
||||
struct decostop stoptable[60];
|
||||
extern bool plan(struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer);
|
||||
extern struct deco_state *deco_state;
|
||||
struct deco_state test_deco_state;
|
||||
extern bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer);
|
||||
void setupPrefs()
|
||||
{
|
||||
copy_prefs(&default_prefs, &prefs);
|
||||
|
@ -363,7 +363,7 @@ void TestPlan::testMetric()
|
|||
struct diveplan testPlan = {};
|
||||
setupPlan(&testPlan);
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -403,7 +403,7 @@ void TestPlan::testImperial()
|
|||
struct diveplan testPlan = {};
|
||||
setupPlan(&testPlan);
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -443,7 +443,7 @@ void TestPlan::testVpmbMetric45m30minTx()
|
|||
setupPlanVpmb45m30mTx(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -456,7 +456,7 @@ void TestPlan::testVpmbMetric45m30minTx()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 108l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes
|
||||
//QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u));
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ void TestPlan::testVpmbMetric60m10minTx()
|
|||
setupPlanVpmb60m10mTx(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -486,7 +486,7 @@ void TestPlan::testVpmbMetric60m10minTx()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 162l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes
|
||||
//QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u));
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ void TestPlan::testVpmbMetric60m30minAir()
|
|||
setupPlanVpmb60m30minAir(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -516,7 +516,7 @@ void TestPlan::testVpmbMetric60m30minAir()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 180l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check benchmark run time of 141 minutes, and known Subsurface runtime of 139 minutes
|
||||
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 141u * 60u + 20u, 139u * 60u + 20u));
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ void TestPlan::testVpmbMetric60m30minEan50()
|
|||
setupPlanVpmb60m30minEan50(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -546,7 +546,7 @@ void TestPlan::testVpmbMetric60m30minEan50()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 155l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check first gas change to EAN50 at 21m
|
||||
struct event *ev = displayed_dive.dc.events;
|
||||
QVERIFY(ev != NULL);
|
||||
|
@ -569,7 +569,7 @@ void TestPlan::testVpmbMetric60m30minTx()
|
|||
setupPlanVpmb60m30minTx(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -582,7 +582,7 @@ void TestPlan::testVpmbMetric60m30minTx()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 159l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check first gas change to EAN50 at 21m
|
||||
struct event *ev = displayed_dive.dc.events;
|
||||
QVERIFY(ev != NULL);
|
||||
|
@ -605,7 +605,7 @@ void TestPlan::testVpmbMetric100m60min()
|
|||
setupPlanVpmb100m60min(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -618,7 +618,7 @@ void TestPlan::testVpmbMetric100m60min()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 157l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check first gas change to EAN50 at 21m
|
||||
struct event *ev = displayed_dive.dc.events;
|
||||
QVERIFY(ev != NULL);
|
||||
|
@ -647,7 +647,7 @@ void TestPlan::testVpmbMetricMultiLevelAir()
|
|||
setupPlanVpmbMultiLevelAir(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -660,7 +660,7 @@ void TestPlan::testVpmbMetricMultiLevelAir()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 101l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check benchmark run time of 167 minutes, and known Subsurface runtime of 169 minutes
|
||||
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 167u * 60u + 20u, 169u * 60u + 20u));
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ void TestPlan::testVpmbMetric100m10min()
|
|||
setupPlanVpmb100m10min(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -690,7 +690,7 @@ void TestPlan::testVpmbMetric100m10min()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 175l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check first gas change to EAN50 at 21m
|
||||
struct event *ev = displayed_dive.dc.events;
|
||||
QVERIFY(ev != NULL);
|
||||
|
@ -723,7 +723,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
setupPlanVpmb30m20min(&testPlan);
|
||||
setCurrentAppState("PlanDive");
|
||||
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -736,14 +736,14 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 61l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check benchmark run time of 27 minutes, and known Subsurface runtime of 28 minutes
|
||||
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 27u * 60u + 20u, 27u * 60u + 20u));
|
||||
|
||||
int firstDiveRunTimeSeconds = displayed_dive.dc.duration.seconds;
|
||||
|
||||
setupPlanVpmb100mTo70m30min(&testPlan);
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -756,7 +756,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 80l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
// check first gas change to 21/35 at 66m
|
||||
struct event *ev = displayed_dive.dc.events;
|
||||
QVERIFY(ev != NULL);
|
||||
|
@ -779,7 +779,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
QVERIFY(compareDecoTime(displayed_dive.dc.duration.seconds, 127u * 60u + 20u, 127u * 60u + 20u));
|
||||
|
||||
setupPlanVpmb30m20min(&testPlan);
|
||||
plan(&testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
plan(&test_deco_state, &testPlan, &displayed_dive, 60, stoptable, &cache, 1, 0);
|
||||
|
||||
#if DEBUG
|
||||
free(displayed_dive.notes);
|
||||
|
@ -792,7 +792,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
while(!dp->minimum_gas.mbar && dp->next) dp = dp->next;
|
||||
QCOMPARE(lrint(dp->minimum_gas.mbar / 1000.0), 61l);
|
||||
// print first ceiling
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(deco_state->first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
printf("First ceiling %.1f m\n", (mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar, &displayed_dive) * 0.001));
|
||||
|
||||
// check runtime is exactly the same as the first time
|
||||
int finalDiveRunTimeSeconds = displayed_dive.dc.duration.seconds;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue