aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbuild17
-rw-r--r--web/adapter.cpp3
-rw-r--r--web/http/index.html9
-rw-r--r--web/http/nissyapp.mjs26
-rw-r--r--web/worker.mjs16
5 files changed, 58 insertions, 13 deletions
diff --git a/build b/build
index da71227..9d3c1e0 100755
--- a/build
+++ b/build
@@ -126,13 +126,20 @@ DFLAGS="-DDEBUG -g3 $(parsesanitize "$SANITIZE")"
126MFLAGS="-DTHREADS=$THREADS -D$ARCH" 126MFLAGS="-DTHREADS=$THREADS -D$ARCH"
127CPPFLAGS="-std=c++20 -pthread" 127CPPFLAGS="-std=c++20 -pthread"
128 128
129# TODO:
130# MEMORY64 is supported on Firefox (from version 134) and Chrome (from 133),
131# but not on Safari (nor on e.g. Firefox 128 ESR, current default on Debian).
132# See also https://webassembly.org/features
133# When it becomes widely available, we can support it by adding -sMEMORY64
134# to the WASMCFLAGS, WASMCPPFLAGS and WASMLINKFLAGS variables below, and
135# -sMAXIMUM_MEMORY=10737418240 to WASMLINKFLAGS. This way we can enable
136# solvers larger than h48h6k2 in the web version.
137
129# Build flags for emscripten (WASM target) 138# Build flags for emscripten (WASM target)
130WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread \ 139WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread"
131 -sMEMORY64 -sMAXIMUM_MEMORY=10737418240 -sASSERTIONS" 140WASMCPPFLAGS="-std=c++20 -pthread"
132WASMCPPFLAGS="-std=c++20 -pthread -sMEMORY64 -sMAXIMUM_MEMORY=10737418240 \
133 -sASSERTIONS"
134WASMMFLAGS="-DTHREADS=$THREADS -DWASMSIMD" 141WASMMFLAGS="-DTHREADS=$THREADS -DWASMSIMD"
135WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE -sMEMORY64 \ 142WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE
136 -sALLOW_MEMORY_GROWTH -sSTACK_SIZE=5MB -sPTHREAD_POOL_SIZE=$THREADS \ 143 -sALLOW_MEMORY_GROWTH -sSTACK_SIZE=5MB -sPTHREAD_POOL_SIZE=$THREADS \
137 -sFETCH -sASYNCIFY -sLINKABLE -sEXPORT_ALL" 144 -sFETCH -sASYNCIFY -sLINKABLE -sEXPORT_ALL"
138 145
diff --git a/web/adapter.cpp b/web/adapter.cpp
index 676390c..31d00fe 100644
--- a/web/adapter.cpp
+++ b/web/adapter.cpp
@@ -23,7 +23,8 @@ const std::set<std::string> available_solvers
23 "h48h1k2", 23 "h48h1k2",
24 "h48h2k2", 24 "h48h2k2",
25 "h48h3k2", 25 "h48h3k2",
26 "h48h7k2", 26 "h48h4k2",
27 "h48h5k2",
27}; 28};
28 29
29std::map<std::string, nissy::solver> loaded_solvers; 30std::map<std::string, nissy::solver> loaded_solvers;
diff --git a/web/http/index.html b/web/http/index.html
index 47ccc0d..04ddf4c 100644
--- a/web/http/index.html
+++ b/web/http/index.html
@@ -9,9 +9,12 @@
9 <body> 9 <body>
10 <input id="scrambleText" placeholder="Type the scramble here..."> 10 <input id="scrambleText" placeholder="Type the scramble here...">
11 <select id="solverSelector"> 11 <select id="solverSelector">
12 <option value="h48h0k4">h48 h=0 k=4 (59Mb)</option> 12 <option value="h48h3k2" selected="selected">
13 <option value="h48h3k2" selected="selected">h48 h=3 k=2 (283Mb)</option> 13 h48 h=4 k=2 (300 Mb) - light
14 <option value="h48h7k2">h48 h=7 k=2 (3.6Gb)</option> 14 </option>
15 <option value="h48h5k2" selected="selected">
16 h48 h=5 k=2 (1 Gb) - fastest
17 </option>
15 </select> 18 </select>
16 <button id="solveButton">Solve</button> 19 <button id="solveButton">Solve</button>
17 <div id="confirmDownload" style="display:none"> 20 <div id="confirmDownload" style="display:none">
diff --git a/web/http/nissyapp.mjs b/web/http/nissyapp.mjs
index 55ca198..1f9fa72 100644
--- a/web/http/nissyapp.mjs
+++ b/web/http/nissyapp.mjs
@@ -30,8 +30,8 @@ worker.onmessage = (event) => {
30function updateResults(label, results, enable) { 30function updateResults(label, results, enable) {
31 resultsLabel.innerText = label; 31 resultsLabel.innerText = label;
32 resultsText.innerText = results; 32 resultsText.innerText = results;
33 solveButton.disable = !enable; 33 solveButton.disabled = !enable;
34 solverSelector.disable = !enable; 34 solverSelector.disabled = !enable;
35} 35}
36 36
37var logVisible = false; 37var logVisible = false;
@@ -49,7 +49,27 @@ toggleLog.addEventListener("click", () => {
49solveButton.addEventListener("click", () => { 49solveButton.addEventListener("click", () => {
50 const solver = solverSelector.options[solverSelector.selectedIndex].value; 50 const solver = solverSelector.options[solverSelector.selectedIndex].value;
51 const scramble = scrField.value; 51 const scramble = scrField.value;
52 loadDataThenSolve(solver, scramble); 52
53 const callbackId = ++lastCallbackId;
54 callbacks.set(callbackId, {
55 f: (callbackArg, validateResult) => {
56 if (validateResult) {
57 loadDataThenSolve(callbackArg.solver, callbackArg.scramble);
58 } else {
59 updateResults("Scramble is invalid", "", true);
60 }
61 },
62 arg: {
63 solver: solver,
64 scramble: scramble
65 }
66 });
67
68 worker.postMessage({
69 command: "validate scramble",
70 id: lastCallbackId,
71 arg: scramble
72 });
53}); 73});
54 74
55function loadDataThenSolve(solver, scramble) { 75function loadDataThenSolve(solver, scramble) {
diff --git a/web/worker.mjs b/web/worker.mjs
index 0cb618b..12de1dc 100644
--- a/web/worker.mjs
+++ b/web/worker.mjs
@@ -8,6 +8,7 @@ const commands = [
8 { name: "load solver data", exec: loadSolverDataFromStorage }, 8 { name: "load solver data", exec: loadSolverDataFromStorage },
9 { name: "download solver data", exec: downloadSolverData }, 9 { name: "download solver data", exec: downloadSolverData },
10 { name: "generate solver data", exec: generateSolverData }, 10 { name: "generate solver data", exec: generateSolverData },
11 { name: "validate scramble", exec: validateScramble },
11 { name: "solve", exec: solve }, 12 { name: "solve", exec: solve },
12]; 13];
13 14
@@ -45,7 +46,7 @@ async function loadSolverDataFromStorage(id, solver) {
45 }); 46 });
46 47
47 if (!(await nissy.isSolverAvailable(solver))) { 48 if (!(await nissy.isSolverAvailable(solver))) {
48 async_return(false, "Error: solver " + arg.solver + 49 async_return(false, "Error: solver " + solver +
49 " is not available in this version of nissy."); 50 " is not available in this version of nissy.");
50 return; 51 return;
51 } 52 }
@@ -113,6 +114,19 @@ async function generateSolverData(id, solver) {
113 } 114 }
114} 115}
115 116
117// Check if the scramble is valid.
118// Argument: string (the scramble).
119async function validateScramble(id, arg) {
120 const async_return = (success) => postMessage({
121 command: "validate scramble",
122 id: id,
123 arg: success
124 });
125
126 var cube = new nissy.Cube();
127 async_return(cube.move(arg).ok());
128}
129
116// Solve the cube with the given options. 130// Solve the cube with the given options.
117// Argument: { 131// Argument: {
118// solver: string 132// solver: string

Generated with cgit - Back to sebastiano.tronto.net