diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-05 11:42:12 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-05 11:42:12 +0200 |
| commit | f1a2985897850321e0a9acb1b74bb41e016deb5c (patch) | |
| tree | bc0585a7bb629549bc3f7914027d62bb21bde30c | |
| parent | 52c74a1c33ce12b93ec5830f5a6348d9578c7c6e (diff) | |
| download | nissy-core-f1a2985897850321e0a9acb1b74bb41e016deb5c.tar.gz nissy-core-f1a2985897850321e0a9acb1b74bb41e016deb5c.zip | |
Added debug mode to web build and fixed a couple of bugs
Diffstat (limited to '')
| -rwxr-xr-x | build | 13 | ||||
| -rw-r--r-- | web/adapter.cpp | 6 | ||||
| -rw-r--r-- | web/http/nissyapp.mjs | 8 | ||||
| -rw-r--r-- | web/http/worker.mjs | 3 |
4 files changed, 20 insertions, 10 deletions
| @@ -142,6 +142,7 @@ CPPFLAGS="-std=c++20 -pthread" | |||
| 142 | WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread | 142 | WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread |
| 143 | -mfpu=neon -mrelaxed-simd" | 143 | -mfpu=neon -mrelaxed-simd" |
| 144 | WASMCPPFLAGS="-std=c++20 -pthread" | 144 | WASMCPPFLAGS="-std=c++20 -pthread" |
| 145 | WASMDBGFLAGS="-sASSERTIONS" | ||
| 145 | WASMMFLAGS="-DTHREADS=$THREADS -DNEON" | 146 | WASMMFLAGS="-DTHREADS=$THREADS -DNEON" |
| 146 | WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE | 147 | WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE |
| 147 | -sEXPORTED_RUNTIME_METHODS=addFunction,UTF8ToString | 148 | -sEXPORTED_RUNTIME_METHODS=addFunction,UTF8ToString |
| @@ -216,7 +217,7 @@ run() { | |||
| 216 | odflags() { | 217 | odflags() { |
| 217 | if [ "$debug" = "yes" ]; then | 218 | if [ "$debug" = "yes" ]; then |
| 218 | echo "$DFLAGS" | 219 | echo "$DFLAGS" |
| 219 | else | 220 | else |
| 220 | echo "$OFLAGS" | 221 | echo "$OFLAGS" |
| 221 | fi | 222 | fi |
| 222 | } | 223 | } |
| @@ -283,10 +284,16 @@ build_web() { | |||
| 283 | 284 | ||
| 284 | obj="nissy_web_module" | 285 | obj="nissy_web_module" |
| 285 | 286 | ||
| 286 | run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $(odflags) -c \ | 287 | if [ "$debug" = "yes" ]; then |
| 288 | ODFLAGS="$DFLAGS -sASSERTIONS" | ||
| 289 | else | ||
| 290 | ODFLAGS="$OFLAGS" | ||
| 291 | fi | ||
| 292 | |||
| 293 | run $EMCC $WASMCFLAGS $WFLAGS $WASMMFLAGS $ODFLAGS -c \ | ||
| 287 | -o nissy.o src/nissy.c || exit 1 | 294 | -o nissy.o src/nissy.c || exit 1 |
| 288 | run $EMCC -lembind -lidbfs.js \ | 295 | run $EMCC -lembind -lidbfs.js \ |
| 289 | $WASMCPPFLAGS $(odflags) $WASMLINKFLAGS -o web/"$obj".mjs \ | 296 | $WASMCPPFLAGS $ODFLAGS $WASMLINKFLAGS -o web/"$obj".mjs \ |
| 290 | cpp/nissy.cpp web/storage.cpp web/adapter.cpp nissy.o || exit 1 | 297 | cpp/nissy.cpp web/storage.cpp web/adapter.cpp nissy.o || exit 1 |
| 291 | cp web/"$obj".mjs web/http/ | 298 | cp web/"$obj".mjs web/http/ |
| 292 | cp web/"$obj".wasm web/http/ | 299 | cp web/"$obj".wasm web/http/ |
diff --git a/web/adapter.cpp b/web/adapter.cpp index 3df3a54..9cb2e2d 100644 --- a/web/adapter.cpp +++ b/web/adapter.cpp | |||
| @@ -151,13 +151,14 @@ int poll_status(void *arg) | |||
| 151 | if (arg == nullptr) | 151 | if (arg == nullptr) |
| 152 | return nissy::status::RUN.value; | 152 | return nissy::status::RUN.value; |
| 153 | 153 | ||
| 154 | std::function<int(void)> poll((int (*)(void))arg); | 154 | std::function<int(void)> poll((int (*)(void))*(int *)arg); |
| 155 | return poll(); | 155 | return poll(); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | // The parameter js_poll_status is of type int here, but actually it is a | 158 | // The parameter js_poll_status is of type int here, but actually it is a |
| 159 | // pointer to a JS function. The type will have to be changed to a 64-bit | 159 | // pointer to a JS function. The type will have to be changed to a 64-bit |
| 160 | // integer when we move to WASM64. | 160 | // integer when we move to WASM64. |
| 161 | int js_poll_status_global = 0; | ||
| 161 | nissy::solver::solve_result solve(std::string name, | 162 | nissy::solver::solve_result solve(std::string name, |
| 162 | nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, | 163 | nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, |
| 163 | unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, | 164 | unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, |
| @@ -179,9 +180,10 @@ nissy::solver::solve_result solve(std::string name, | |||
| 179 | 180 | ||
| 180 | // TODO: when running multiple solvers at the same time, we could use | 181 | // TODO: when running multiple solvers at the same time, we could use |
| 181 | // poll_status_id as intended (i.e. an id of some sort) | 182 | // poll_status_id as intended (i.e. an id of some sort) |
| 183 | js_poll_status_global = js_poll_status; | ||
| 182 | return loaded_solvers.at(name).solve(cube, nissflag, minmoves, | 184 | return loaded_solvers.at(name).solve(cube, nissflag, minmoves, |
| 183 | maxmoves, maxsols, optimal, threads, | 185 | maxmoves, maxsols, optimal, threads, |
| 184 | poll_status, &js_poll_status); | 186 | poll_status, &js_poll_status_global); |
| 185 | } | 187 | } |
| 186 | 188 | ||
| 187 | EMSCRIPTEN_BINDINGS(Nissy) | 189 | EMSCRIPTEN_BINDINGS(Nissy) |
diff --git a/web/http/nissyapp.mjs b/web/http/nissyapp.mjs index cdfd4d5..b056b5f 100644 --- a/web/http/nissyapp.mjs +++ b/web/http/nissyapp.mjs | |||
| @@ -267,10 +267,10 @@ function startSolve(solver, scramble) { | |||
| 267 | arg: { | 267 | arg: { |
| 268 | solver: solver, | 268 | solver: solver, |
| 269 | scramble: scramble, | 269 | scramble: scramble, |
| 270 | minmoves: minSlider.value, | 270 | minmoves: Number(minSlider.value), |
| 271 | maxmoves: maxSlider.value, | 271 | maxmoves: Number(maxSlider.value), |
| 272 | maxsolutions: maxSolsInput.value, | 272 | maxsolutions: Number(maxSolsInput.value), |
| 273 | optimal: optimalInput.value, | 273 | optimal: Number(optimalInput.value), |
| 274 | threads: window.navigator.hardwareConcurrency, | 274 | threads: window.navigator.hardwareConcurrency, |
| 275 | } | 275 | } |
| 276 | }); | 276 | }); |
diff --git a/web/http/worker.mjs b/web/http/worker.mjs index 0c1acb9..b988bdd 100644 --- a/web/http/worker.mjs +++ b/web/http/worker.mjs | |||
| @@ -3,7 +3,8 @@ import Nissy from "./nissy_web_module.mjs" | |||
| 3 | const nissy = await Nissy(); | 3 | const nissy = await Nissy(); |
| 4 | 4 | ||
| 5 | const log = (cstr) => postMessage({ | 5 | const log = (cstr) => postMessage({ |
| 6 | command: "log", id: -1, | 6 | command: "log", |
| 7 | id: -1, | ||
| 7 | object: nissy.UTF8ToString(cstr) | 8 | object: nissy.UTF8ToString(cstr) |
| 8 | }); | 9 | }); |
| 9 | nissy.setLogger(nissy.addFunction(log, "vp")); | 10 | nissy.setLogger(nissy.addFunction(log, "vp")); |
