Web version, stage 2: Stockfish 19 in workers, live analysis, game review on N workers, My games, files, keys
game-review: what the job does for one target (the full search, the second best without the move played, the shallow ones) becomes a machine without I/O (job/work.rs), driven by the engine processes on a computer (job/engines.rs, the same searches as before) and by Web Workers in a browser (job/workers.rs: a dispatcher polled from the frames, never blocking). The analysis cache goes through a CacheStore (a folder, or the program's files of the platform). The browser's engine: Stockfish.js 19.0.1 (npm stockfish, GPL-3.0), its single-threaded build served beside /app/ (engine/, build.sh checks the package's sha512), its 99 MB wasm downloaded only through the engine offer, checked against its SHA-256 and kept in Cache Storage; workers get it as a blob: address. Live analysis (lines, arrows, the bar) and the review run on it; the review uses one worker per logical CPU, at most 8. My games (the web version): a PGN in the browser's storage, always on the shelf; Ctrl+S puts a game there (its own record, or a new one); deleting with undo. chess-core's store gives the bytes of append/replace/remove/restore, so the platform writes them into the browser's files; on a computer the files are written as before. Settings: Browser data (used and free space, keeping the data for good, Download all as PGN, deleting the engine). Files: a file of the last visit offers Choose the file again; Keep a copy in the browser (refused with the room it needs when the browser gives too little); files over 1 GB are not opened, with a word on why. No reference tab and no search by position in the web version. Keys: Alt+Left, plain 1-6, Ctrl+C, N in the library (the browser keeps Ctrl+W/N/1-6/Shift+C). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4ccf8099a5
commit
61ccd763bc
34 changed files with 2063 additions and 253 deletions
|
|
@ -66,11 +66,14 @@ fn asset() -> Option<Asset> {
|
|||
|
||||
/// Whether a download is offered on this platform at all.
|
||||
pub fn available() -> bool {
|
||||
asset().is_some()
|
||||
cfg!(web) || asset().is_some()
|
||||
}
|
||||
|
||||
/// Size of the download in megabytes (rounded), for the offer.
|
||||
pub fn size_mb() -> u64 {
|
||||
#[cfg(web)]
|
||||
return crate::platform::web::engine::DOWNLOAD_MB;
|
||||
#[cfg(not(web))]
|
||||
asset().map_or(0, |a| a.size.div_ceil(1_000_000))
|
||||
}
|
||||
|
||||
|
|
@ -98,14 +101,25 @@ pub fn clean_leftovers() {
|
|||
}
|
||||
}
|
||||
|
||||
/// The downloaded engine, if it is there.
|
||||
/// The downloaded engine, if it is there (in a browser: the address of its worker).
|
||||
pub fn installed() -> Option<PathBuf> {
|
||||
let p = dir()?.join(EXE);
|
||||
p.is_file().then_some(p)
|
||||
#[cfg(web)]
|
||||
return crate::platform::web::engine::worker_script().map(PathBuf::from);
|
||||
#[cfg(not(web))]
|
||||
{
|
||||
let p = dir()?.join(EXE);
|
||||
p.is_file().then_some(p)
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the downloaded engine (frees its space).
|
||||
pub fn remove() -> std::io::Result<()> {
|
||||
#[cfg(web)]
|
||||
{
|
||||
crate::platform::web::engine::remove();
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(not(web))]
|
||||
match dir() {
|
||||
Some(d) if d.exists() => std::fs::remove_dir_all(d),
|
||||
_ => Ok(()),
|
||||
|
|
@ -154,14 +168,42 @@ impl Download {
|
|||
Download::spawn(ctx, total, run)
|
||||
}
|
||||
|
||||
/// A browser downloads no engine programs: there is no download for it, as for a
|
||||
/// computer without a published build.
|
||||
/// The browser's engine: Stockfish 19 in WebAssembly from our site, into the
|
||||
/// browser's cache (`platform::web::engine`).
|
||||
#[cfg(web)]
|
||||
pub fn start(_ctx: &egui::Context) -> Download {
|
||||
Download::unsupported()
|
||||
pub fn start(ctx: &egui::Context) -> Download {
|
||||
use crate::platform::web::engine::{self, Fetch};
|
||||
let total = engine::WASM_BYTES;
|
||||
let stage = Arc::new(Mutex::new(Stage::Downloading { done: 0, total }));
|
||||
let cancel = Arc::new(AtomicBool::new(false));
|
||||
let (s, c, ctx) = (stage.clone(), cancel.clone(), ctx.clone());
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
let report = |st: Stage| {
|
||||
if let Ok(mut g) = s.lock() {
|
||||
*g = st;
|
||||
}
|
||||
ctx.request_repaint();
|
||||
};
|
||||
let end =
|
||||
match engine::download(|done, total| report(Stage::Downloading { done, total }), c)
|
||||
.await
|
||||
{
|
||||
Ok(()) => match installed() {
|
||||
Some(p) => Stage::Done(p),
|
||||
None => Stage::Failed(Failure::Disk("not kept".into())),
|
||||
},
|
||||
Err(Fetch::Cancelled) => Stage::Cancelled,
|
||||
Err(Fetch::Network(e)) => Stage::Failed(Failure::Network(e)),
|
||||
Err(Fetch::Server(code)) => Stage::Failed(Failure::Server(code)),
|
||||
Err(Fetch::Checksum) => Stage::Failed(Failure::Checksum),
|
||||
Err(Fetch::Storage(e)) => Stage::Failed(Failure::Disk(e)),
|
||||
};
|
||||
report(end);
|
||||
});
|
||||
Download { stage, cancel }
|
||||
}
|
||||
|
||||
/// The download of a platform that has none.
|
||||
/// The download of a platform that has none (Rodent and the like in a browser).
|
||||
#[cfg(web)]
|
||||
pub fn unsupported() -> Download {
|
||||
Download {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue