Mozilla とブラウザゲーム
-
Upload
noritada-shimizu -
Category
Technology
-
view
1.780 -
download
0
Transcript of Mozilla とブラウザゲーム
window.addEventListener("gamepadconnected", function(e) { console.log("connected at index %d: %s. %d buttons, %d axes.", e.gamepad.index, e.gamepad.id,
e.gamepad.buttons.length, e.gamepad.axes.length);});window.addEventListener("gamepaddisconnected", function(e) { console.log("Gamepad disconnected from index %d: %s", e.gamepad.index, e.gamepad.id);});
function pollGamepads() { var gamepads = navigator.getGamepads() || []; for (var i = 0; i < gamepads.length; i++) { var gp = gamepads[i]; if (gp) { gamepadInfo.innerHTML = "connected at index " + gp.index + ": " + gp.id + ". It has " + gp.buttons.length + " buttons and " + gp.axes.length + " axes."; gameLoop(); clearInterval(interval); } }}
canvas.onclick = function() { canvas.requestPointerLock();}
function canvasLoop(e) { x += e.movementX; y += e.movementY; canvasDraw(); requestAnimationFrame(canvasLoop);
}
function toggleFullScreen(elmenet){if(document.fullscreenElement){ document.exitFullscreen();
}else element.requestFullScreen();}}
var myWorker = new Worker("worker.js");myWorker.postMessage([first.value,second.value]);
onmessage = function(e) { console.log('Message received from main script'); var workerResult = 'Result: ' + (e.data[0] * e.data[1]); console.log('Posting message back to main script'); postMessage(workerResult);}
var myWorker = new SharedWorker("worker.js");myWorker.port.start(); myWorker.port.postMessage([squareNumber.value,squareNumber.value]);
onconnect = function(e) { var port = e.ports[0]; port.onmessage = function(e) { var workerResult = 'Result: ' + (e.data[0] * e.data[1]); port.postMessage(workerResult); } port.start(); // onmessage イベントを使用していますので必須ではありません
}
var x = 42;var y = "a string";var z = x + y; // z = "42a string"
eval("z = z.substr(1, 2)"); // z = "2a"[1, "two", { three: 3 }].forEach(function(item) { if (typeof item === typeof z) console.log([z, item]);}); // emits ["2a", "two"]
var buf = new ArrayBuffer(32);var typed = new Int8Array(buf);typed[0] = 1; // typed[0] -> 1
typed[1] = 3.14; // typed[1] -> 3typed[2] = "Firefox"; // typed[2] -> 0typed[3] = 127; // typed[3] -> 127typed[4] = 128; // typed[4] -> —128typed[32] = 32; // typed[32] -> undefined
var ab = new ArrayBuffer(1024);var uInt8Array = new Uint8Array(ab);for (var i = 0; i < uInt8Array.length; ++i) {
uInt8Array[i] = i;}var worker = new Worker("worker.js");console.log(uInt8Array.byteLength); // before transferring: 1024worker.postMessage(uInt8Array.buffer, [uInt8Array.buffer]);console.log(uInt8Array.byteLength); // after transferring: 0
var sab = new SharedArrayBuffer(1024);// before transferringconsole.log(sab.byteLength); // 1024
worker.postMessage(sab, [sab]);// after transferringconsole.log(sab.byteLength); // 1024
function fib(n){ n = n|0; if(n >>> 0 < 3){
return 1 | 0; } return ((fib(n - 1 | 0) | 0) + (fib(n - 2 | 0) | 0)) | 0;}
-rw-r--r-- 1 chiko staff 99B 12 22 17:38 Makefile-rw-r--r-- 1 chiko staff 1.9K 12 22 17:29 app.js-rw-r--r-- 1 chiko staff 247B 12 22 11:31 fib-asm.js
-rw-r--r-- 1 chiko staff 220B 12 21 17:36 fib.cpp-rw-r--r-- 1 chiko staff 184K 12 22 17:38 fib.js-rw-r--r-- 1 chiko staff 2.8K 12 22 17:38 fib.js.mem-rw-r--r-- 1 chiko staff 1.2K 12 22 17:10 index.html
function fib(n) { n = n|0; if(n >>> 0 < 3){
return 1 | 0; } return ((fib(n - 1 | 0) | 0) + (fib(n - 2 | 0) | 0)) | 0;}
(module (memory 16777216 16777216) (export "fib" $fib)
(func $fib (param $n i32) (result i32) (if (i32.lt_u
(get_local $n) (i32.const 3)) (return (i32.const 1)))
(return (i32.add (call $fib
(i32.sub (get_local $n) (i32.const 1))) (call $fib (i32.sub (get_local $n)
(i32.const 2))) ))))