wasmx: multi-variant support

pull/4693/head
Niklas Fiekas 2018-11-06 14:36:56 +01:00
parent 18deb1c3ed
commit 1c2628ca21
5 changed files with 20 additions and 4 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ public/trans
public/compiled
public/vendor/stockfish
public/vendor/stockfish.wasm
public/vendor/stockfish-mv.wasm
target
bin/.translate_version
data/

View File

@ -16,7 +16,7 @@ function sanIrreversible(variant: VariantKey, san: string): boolean {
}
function officialStockfish(variant: VariantKey): boolean {
return variant === 'standard' || variant === 'chess960' || variant === 'fromPosition';
return variant === 'standard' || variant === 'chess960';
}
export default function(opts: CevalOpts): CevalCtrl {
@ -27,7 +27,7 @@ export default function(opts: CevalOpts): CevalCtrl {
const pnaclSupported: boolean = !opts.failsafe && 'application/x-pnacl' in navigator.mimeTypes;
const wasmSupported = typeof WebAssembly === 'object' && WebAssembly.validate(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
const wasmThreadsSupported = officialStockfish(opts.variant.key) && wasmSupported && typeof SharedArrayBuffer === 'function' && new WebAssembly!.Memory({shared: true, initial: 8, maximum: 8}).buffer instanceof SharedArrayBuffer;
const wasmThreadsSupported = wasmSupported && typeof SharedArrayBuffer === 'function' && new WebAssembly!.Memory({shared: true, initial: 8, maximum: 8}).buffer instanceof SharedArrayBuffer;
const minDepth = 6;
const maxDepth = storedProp<number>(storageKey('ceval.max-depth'), 18);
const multiPv = storedProp(storageKey('ceval.multipv'), opts.multiPvDefault || 1);
@ -48,7 +48,7 @@ export default function(opts: CevalOpts): CevalCtrl {
asmjs: li.assetUrl(sfPath + '.js', {sameDomain: true}),
pnacl: pnaclSupported && li.assetUrl(sfPath + '.nmf'),
wasm: wasmSupported && li.assetUrl(sfPath + '.wasm.js', {sameDomain: true}),
wasmThreaded: wasmThreadsSupported && 'vendor/stockfish.wasm/stockfish.js',
wasmThreaded: wasmThreadsSupported && (officialStockfish(opts.variant.key) ? 'vendor/stockfish.wasm/stockfish.js' : 'vendor/stockfish-mv.wasm/stockfish.js'),
onCrash: opts.onCrash
}, {
minDepth,

View File

@ -74,6 +74,15 @@ gulp.task('stockfish.wasm', function() {
]).pipe(gulp.dest('../../public/vendor/stockfish.wasm/'));
});
gulp.task('stockfish-mv.wasm', function() {
gulp.src([
require.resolve('stockfish-mv.wasm/stockfish.js'),
require.resolve('stockfish-mv.wasm/stockfish.js.mem'),
require.resolve('stockfish-mv.wasm/stockfish.wasm'),
require.resolve('stockfish-mv.wasm/pthread-main.js')
]).pipe(gulp.dest('../../public/vendor/stockfish-mv.wasm/'));
});
gulp.task('prod-source', function() {
return browserify('src/index.ts', {
standalone: standalone
@ -147,7 +156,7 @@ gulp.task('user-mod', function() {
.pipe(gulp.dest(destination));
});
const tasks = ['git-sha', 'jquery-fill', 'ab', 'standalones', 'user-mod', 'stockfish.wasm'];
const tasks = ['git-sha', 'jquery-fill', 'ab', 'standalones', 'user-mod', 'stockfish.wasm', 'stockfish-mv.wasm'];
if (!process.env.TRAVIS || process.env.GITHUB_API_TOKEN) {
if (!process.env.NO_SF) { // to skip SF download
tasks.push('stockfish.pexe');

View File

@ -22,6 +22,7 @@
"vinyl-source-stream": "^1"
},
"dependencies": {
"stockfish-mv.wasm": "^0.2.0",
"stockfish.wasm": "^0.2.0",
"tablesort": "^5.0.0"
}

View File

@ -4425,6 +4425,11 @@ static-extend@^0.1.1:
define-property "^0.2.5"
object-copy "^0.1.0"
stockfish-mv.wasm@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/stockfish-mv.wasm/-/stockfish-mv.wasm-0.2.0.tgz#b402050ccca5455ed4419ffe2ad96d52a19c5f34"
integrity sha512-a2E/J0kBJIfoKdC8KPNy+xGQ4hvT/E10THMxjqmy1aHCgoV0pvOY+lgcLqvm6Q4c5IyFX5iDiY59ZrrtHedbEg==
stockfish.wasm@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/stockfish.wasm/-/stockfish.wasm-0.2.0.tgz#f92ee6a35c0ca3dacbd704adfec2df5101116503"