aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--web/adapter.cpp38
-rw-r--r--web/http/worker.mjs8
2 files changed, 7 insertions, 39 deletions
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
119nissy::solver::solve_result solve(std::string name, 117nissy::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
142std::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
169EMSCRIPTEN_BINDINGS(Nissy) 138EMSCRIPTEN_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};

Generated with cgit - Back to sebastiano.tronto.net