Plugin free
API
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();
}
}
Web Workers
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] -> 3
typed[2] = "Firefox"; // typed[2] -> 0
typed[3] = 127; // typed[3] -> 127
typed[4] = 128; // typed[4] -> —128
typed[32] = 32; // typed[32] -> undefined
Sahred Array Buffer
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: 1024
worker.postMessage(uInt8Array.buffer, [uInt8Array.buffer]);
console.log(uInt8Array.byteLength); // after transferring: 0
var sab = new SharedArrayBuffer(1024);
// before transferring
console.log(sab.byteLength); // 1024
worker.postMessage(sab, [sab]);
// after transferring
console.log(sab.byteLength); // 1024
function fib(n){
if(n < 2){
return 1;
}
return fib(n - 1) + fib(n - 2);
}
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)))
))))
Firefox Developer Edition
MozVR
Mozilla とブラウザゲーム
Mozilla とブラウザゲーム
Mozilla とブラウザゲーム

Mozilla とブラウザゲーム

  • 2.
  • 11.
  • 17.
  • 19.
    window.addEventListener("gamepadconnected", function(e) { console.log("connectedat 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); });
  • 20.
    function pollGamepads() { vargamepads = 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); } } }
  • 22.
    canvas.onclick = function(){ canvas.requestPointerLock(); } function canvasLoop(e) { x += e.movementX; y += e.movementY; canvasDraw(); requestAnimationFrame(canvasLoop); }
  • 24.
  • 25.
  • 26.
    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); }
  • 27.
    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 イベントを使用していますので必須ではありません }
  • 29.
    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"]
  • 32.
    var buf =new ArrayBuffer(32); var typed = new Int8Array(buf); typed[0] = 1; // typed[0] -> 1 typed[1] = 3.14; // typed[1] -> 3 typed[2] = "Firefox"; // typed[2] -> 0 typed[3] = 127; // typed[3] -> 127 typed[4] = 128; // typed[4] -> —128 typed[32] = 32; // typed[32] -> undefined
  • 34.
  • 35.
    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: 1024 worker.postMessage(uInt8Array.buffer, [uInt8Array.buffer]); console.log(uInt8Array.byteLength); // after transferring: 0
  • 36.
    var sab =new SharedArrayBuffer(1024); // before transferring console.log(sab.byteLength); // 1024 worker.postMessage(sab, [sab]); // after transferring console.log(sab.byteLength); // 1024
  • 38.
    function fib(n){ if(n <2){ return 1; } return fib(n - 1) + fib(n - 2); }
  • 39.
    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; }
  • 46.
    -rw-r--r-- 1 chikostaff 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
  • 48.
    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; }
  • 49.
    (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))) ))))
  • 52.
  • 53.