From 238702e7dd860af59d22f33cbfe163f28c3beb4e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 25 May 2025 12:11:34 +0200 Subject: Cleanup --- web/adapter.cpp | 16 ++++++---------- web/examples/solve.mjs | 12 ------------ web/storage.cpp | 46 +++++++++++++++++++++++----------------------- 3 files changed, 29 insertions(+), 45 deletions(-) delete mode 100644 web/examples/solve.mjs (limited to 'web') diff --git a/web/adapter.cpp b/web/adapter.cpp index 3613730..c3134e9 100644 --- a/web/adapter.cpp +++ b/web/adapter.cpp @@ -108,17 +108,13 @@ bool solver_valid(const std::string& name) int poll_status(void *arg) { - return nissy::status::RUN.value; -/* -TODO: reintroduce poll status - int id = *(int *)arg; - if (id == -1) + if (arg == NULL || *(int *)arg == -1) return nissy::status::RUN.value; - return callFunctionInt(id); -*/ + + return callFunctionInt(*(int *)arg); } -#if 0 +#if 1 nissy::solver::solve_result solve(std::string name, nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, @@ -212,17 +208,17 @@ EMSCRIPTEN_BINDINGS(Nissy) .function("toString", &nissy::cube::to_string) ; +/* emscripten::register_vector("StringVector"); emscripten::value_array("SolveResult") .element(&nissy::solver::solve_result::err) .element(&nissy::solver::solve_result::solutions) ; -/* +*/ emscripten::class_("SolveResult") .property("err", &nissy::solver::solve_result::err) .property("solutions", &nissy::solver::solve_result::solutions) ; -*/ emscripten::function("countMoves", &nissy::count_moves); emscripten::function("solve", &solve, diff --git a/web/examples/solve.mjs b/web/examples/solve.mjs deleted file mode 100644 index 8ff59c0..0000000 --- a/web/examples/solve.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import Nissy from '../nissy_web_module.mjs' - -const nissy = await Nissy(); - -var log = process.stdout.write.bind(process.stdout); -//var log = console.log -nissy.setLogger(nissy._addCallbackFunction(log)) - -var cube = new nissy.Cube(); -cube.move('R\' U\' F'); - -nissy.solve('h48h0k4', cube, nissy.NissFlag.normal, 0, 8, 2, 99, 4, -1); diff --git a/web/storage.cpp b/web/storage.cpp index 4be3066..4d0959f 100644 --- a/web/storage.cpp +++ b/web/storage.cpp @@ -13,29 +13,29 @@ std::string getprefix() { } EM_ASYNC_JS(int, loadfs, (), { - const dir = '/tables'; - const inBrowser = typeof window !== 'undefined'; - const inWorker = typeof WorkerGlobalScope !== 'undefined' && - self instanceof WorkerGlobalScope; - - if (!(inBrowser || inWorker)) return; - - if (!FS.analyzePath(dir).exists) - FS.mkdir(dir); - - if (FS.analyzePath(dir).object.mount.mountpoint != dir) { - FS.mount(IDBFS, { autoPersist: true }, dir); - - await new Promise((resolve, reject) => { - FS.syncfs(true, function (err) { - if (err) { - reject(err); - } else { - resolve(true); - } - }); - }); - } + const dir = '/tables'; + const inBrowser = typeof window !== 'undefined'; + const inWorker = typeof WorkerGlobalScope !== 'undefined' && + self instanceof WorkerGlobalScope; + + if (!(inBrowser || inWorker)) + return; + + if (!FS.analyzePath(dir).exists) + FS.mkdir(dir); + + if (FS.analyzePath(dir).object.mount.mountpoint != dir) { + FS.mount(IDBFS, { autoPersist: true }, dir); + + await new Promise((resolve, reject) => { + FS.syncfs(true, function (err) { + if (err) + reject(err); + else + resolve(true); + }); + }); + } }); bool storage::read(std::string key, size_t data_size, char *data) -- cgit v1.3