diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-25 12:38:39 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-25 12:38:39 +0200 |
| commit | 87852933851674cacbc8b2295d046831db27ab81 (patch) | |
| tree | e67a8b8d3ff9d41c927887483f62882da6258fb6 | |
| parent | 2852d47c0e7b0da72259ddcec693270d52110578 (diff) | |
| download | nissy-core-87852933851674cacbc8b2295d046831db27ab81.tar.gz nissy-core-87852933851674cacbc8b2295d046831db27ab81.zip | |
Cleanup
| -rw-r--r-- | src/solvers/h48/solve.h | 3 | ||||
| -rw-r--r-- | web/adapter.cpp | 38 | ||||
| -rw-r--r-- | web/http/worker.mjs | 8 |
3 files changed, 9 insertions, 40 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 7210478..8716bb0 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -567,7 +567,8 @@ solve_h48( | |||
| 567 | 567 | ||
| 568 | if (poll_status != NULL) { | 568 | if (poll_status != NULL) { |
| 569 | status = poll_status(poll_status_data); | 569 | status = poll_status(poll_status_data); |
| 570 | if (status == NISSY_STATUS_PAUSE && fp) { | 570 | if (status == NISSY_STATUS_PAUSE && fp) |
| 571 | { | ||
| 571 | LOG("[H48 solve] Paused\n"); | 572 | LOG("[H48 solve] Paused\n"); |
| 572 | fp = false; | 573 | fp = false; |
| 573 | } | 574 | } |
diff --git a/web/adapter.cpp b/web/adapter.cpp index c3134e9..71a34ab 100644 --- a/web/adapter.cpp +++ b/web/adapter.cpp | |||
| @@ -114,8 +114,6 @@ int poll_status(void *arg) | |||
| 114 | return callFunctionInt(*(int *)arg); | 114 | return callFunctionInt(*(int *)arg); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | #if 1 | ||
| 118 | |||
| 119 | nissy::solver::solve_result solve(std::string name, | 117 | nissy::solver::solve_result solve(std::string name, |
| 120 | nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, | 118 | nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, |
| 121 | unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, | 119 | unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, |
| @@ -137,35 +135,6 @@ nissy::solver::solve_result solve(std::string name, | |||
| 137 | maxmoves, maxsols, optimal, threads, NULL, &poll_status_id); | 135 | maxmoves, maxsols, optimal, threads, NULL, &poll_status_id); |
| 138 | } | 136 | } |
| 139 | 137 | ||
| 140 | #else | ||
| 141 | |||
| 142 | std::string solve(std::string name, | ||
| 143 | nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, | ||
| 144 | unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, | ||
| 145 | int poll_status_id) | ||
| 146 | { | ||
| 147 | // Here we use a dirty trick to make this function always return the | ||
| 148 | // same kind of JavaScript object. If we did not do this, the returned | ||
| 149 | // object would be a Promise on the first run of the solver for each | ||
| 150 | // session (because when loading the table some async JS code is | ||
| 151 | // called), and a regular object otherwise. | ||
| 152 | // TODO figure out if there is a better way to do this. | ||
| 153 | fake_async(); | ||
| 154 | |||
| 155 | if (!solver_valid(name)) | ||
| 156 | return ""; | ||
| 157 | /* | ||
| 158 | return nissy::solver::solve_result | ||
| 159 | {.err = nissy::error::INVALID_SOLVER}; | ||
| 160 | */ | ||
| 161 | |||
| 162 | return loaded_solvers.at(name).solve(cube, nissflag, minmoves, | ||
| 163 | maxmoves, maxsols, optimal, threads, NULL, &poll_status_id) | ||
| 164 | .solutions[0]; | ||
| 165 | } | ||
| 166 | |||
| 167 | #endif | ||
| 168 | |||
| 169 | EMSCRIPTEN_BINDINGS(Nissy) | 138 | EMSCRIPTEN_BINDINGS(Nissy) |
| 170 | { | 139 | { |
| 171 | emscripten::class_<nissy::nissflag>("NissFlag") | 140 | emscripten::class_<nissy::nissflag>("NissFlag") |
| @@ -208,13 +177,6 @@ EMSCRIPTEN_BINDINGS(Nissy) | |||
| 208 | .function("toString", &nissy::cube::to_string) | 177 | .function("toString", &nissy::cube::to_string) |
| 209 | ; | 178 | ; |
| 210 | 179 | ||
| 211 | /* | ||
| 212 | emscripten::register_vector<std::string>("StringVector"); | ||
| 213 | emscripten::value_array<nissy::solver::solve_result>("SolveResult") | ||
| 214 | .element(&nissy::solver::solve_result::err) | ||
| 215 | .element(&nissy::solver::solve_result::solutions) | ||
| 216 | ; | ||
| 217 | */ | ||
| 218 | emscripten::class_<nissy::solver::solve_result>("SolveResult") | 180 | emscripten::class_<nissy::solver::solve_result>("SolveResult") |
| 219 | .property("err", &nissy::solver::solve_result::err) | 181 | .property("err", &nissy::solver::solve_result::err) |
| 220 | .property("solutions", &nissy::solver::solve_result::solutions) | 182 | .property("solutions", &nissy::solver::solve_result::solutions) |
diff --git a/web/http/worker.mjs b/web/http/worker.mjs index 5756598..831ef09 100644 --- a/web/http/worker.mjs +++ b/web/http/worker.mjs | |||
| @@ -7,5 +7,11 @@ onmessage = (e) => { | |||
| 7 | var cube = new nissy.Cube(); | 7 | var cube = new nissy.Cube(); |
| 8 | cube.move(e.data.scramble); | 8 | cube.move(e.data.scramble); |
| 9 | nissy.solve(e.data.solver, cube, nissy.NissFlag.normal, 0, 17, 1, 99, 4, -1) | 9 | nissy.solve(e.data.solver, cube, nissy.NissFlag.normal, 0, 17, 1, 99, 4, -1) |
| 10 | .then((sol) => postMessage(sol)) | 10 | .then((solve_result) => { |
| 11 | if (!solve_result.err.ok()) | ||
| 12 | posMessage("Error while solving (solve returned " + | ||
| 13 | solve_result.err.value + ")"); | ||
| 14 | else | ||
| 15 | postMessage(solve_result.solutions) | ||
| 16 | }); | ||
| 11 | }; | 17 | }; |
