mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-06-02 19:47:21 -04:00
added esbuild to web
This commit is contained in:
parent
efa67a2992
commit
48719fe011
62
web/app/main.js
Normal file
62
web/app/main.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
import init from '../pkg/web.js';
|
||||
import gamepad from './gamepad.js';
|
||||
|
||||
const canvas = document.querySelector('canvas');
|
||||
const ctx = canvas.getContext('2d', { alpha: false });
|
||||
const img = ctx.createImageData(320, 240);
|
||||
|
||||
(async () => {
|
||||
const emu = await init('web_bg.wasm');
|
||||
|
||||
function draw() {
|
||||
const buffer = new Uint8ClampedArray(
|
||||
emu.memory.buffer, emu.screen(), 320 * 240 * 3
|
||||
);
|
||||
for (let i = 0; i < 320*240; i++) {
|
||||
const bufferIndex = i * 3;
|
||||
const imgIndex = i * 4;
|
||||
img.data[imgIndex+0] = buffer[bufferIndex+0];
|
||||
img.data[imgIndex+1] = buffer[bufferIndex+1];
|
||||
img.data[imgIndex+2] = buffer[bufferIndex+2];
|
||||
img.data[imgIndex+3] = 255;
|
||||
}
|
||||
|
||||
ctx.putImageData(img, 0, 0);
|
||||
|
||||
// ctx.putImageData(new ImageData(buffer, 320), 0, 0);
|
||||
|
||||
// TODO: webgl
|
||||
}
|
||||
|
||||
// TODO: sonic 1 & 2
|
||||
|
||||
const frameCount = document.querySelector('.frameCount');
|
||||
const epoch = performance.now();
|
||||
let framesDone = 0;
|
||||
const loop = () => {
|
||||
requestAnimationFrame(loop);
|
||||
|
||||
const diff = performance.now() - epoch;
|
||||
const frames = diff * 0.05992274 | 0;
|
||||
const frameAmount = frames - framesDone;
|
||||
frameCount.textContent = String(frameAmount);
|
||||
|
||||
if (document.visibilityState !== 'hidden') {
|
||||
|
||||
emu.gamepad_p1(gamepad());
|
||||
|
||||
if (frameAmount > 5) {
|
||||
emu.frame(true);
|
||||
} else {
|
||||
for (let i = 0; i < frameAmount; i++) {
|
||||
emu.frame(i === frameAmount - 1);
|
||||
}
|
||||
}
|
||||
if (frameAmount > 0) {
|
||||
draw();
|
||||
}
|
||||
}
|
||||
framesDone = frames;
|
||||
};
|
||||
loop();
|
||||
})();
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/sh
|
||||
wasm-pack build --release --target web --out-dir static/pkg
|
||||
wasm-pack build --release --target web --out-dir pkg
|
||||
cp pkg/web_bg.wasm static/web_bg.wasm
|
||||
|
||||
# develop
|
||||
# https://www.npmjs.com/package/local-web-server
|
||||
|
|
9
web/package.json
Normal file
9
web/package.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"scripts": {
|
||||
"watch": "esbuild app/main.js --bundle --watch --outfile=static/main.js",
|
||||
"build": "esbuild app/main.js --bundle --minify --outfile=static/main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"esbuild": "^0.14.23"
|
||||
}
|
||||
}
|
2
web/static/.gitignore
vendored
Normal file
2
web/static/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.js
|
||||
*.wasm
|
|
@ -52,69 +52,6 @@
|
|||
<h1>DEMO</h1>
|
||||
<span class="frameCount"></span>
|
||||
</main>
|
||||
<script type="module">
|
||||
import init from './pkg/web.js';
|
||||
import gamepad from './gamepad.js';
|
||||
|
||||
const canvas = document.querySelector('canvas');
|
||||
const ctx = canvas.getContext('2d', { alpha: false });
|
||||
const img = ctx.createImageData(320, 240);
|
||||
|
||||
(async () => {
|
||||
const emu = await init();
|
||||
|
||||
function draw() {
|
||||
const buffer = new Uint8ClampedArray(
|
||||
emu.memory.buffer, emu.screen(), 320 * 240 * 3
|
||||
);
|
||||
for (let i = 0; i < 320*240; i++) {
|
||||
const bufferIndex = i * 3;
|
||||
const imgIndex = i * 4;
|
||||
img.data[imgIndex+0] = buffer[bufferIndex+0];
|
||||
img.data[imgIndex+1] = buffer[bufferIndex+1];
|
||||
img.data[imgIndex+2] = buffer[bufferIndex+2];
|
||||
img.data[imgIndex+3] = 255;
|
||||
}
|
||||
|
||||
ctx.putImageData(img, 0, 0);
|
||||
|
||||
// ctx.putImageData(new ImageData(buffer, 320), 0, 0);
|
||||
|
||||
// TODO: webgl
|
||||
}
|
||||
|
||||
// TODO: sonic 1 & 2
|
||||
|
||||
const frameCount = document.querySelector('.frameCount');
|
||||
const epoch = performance.now();
|
||||
let framesDone = 0;
|
||||
const loop = () => {
|
||||
requestAnimationFrame(loop);
|
||||
|
||||
const diff = performance.now() - epoch;
|
||||
const frames = diff * 0.05992274 | 0;
|
||||
const frameAmount = frames - framesDone;
|
||||
frameCount.textContent = String(frameAmount);
|
||||
|
||||
if (document.visibilityState !== 'hidden') {
|
||||
|
||||
emu.gamepad_p1(gamepad());
|
||||
|
||||
if (frameAmount > 5) {
|
||||
emu.frame(true);
|
||||
} else {
|
||||
for (let i = 0; i < frameAmount; i++) {
|
||||
emu.frame(i === frameAmount - 1);
|
||||
}
|
||||
}
|
||||
if (frameAmount > 0) {
|
||||
draw();
|
||||
}
|
||||
}
|
||||
framesDone = frames;
|
||||
};
|
||||
loop();
|
||||
})();
|
||||
</script>
|
||||
<script src="./main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
123
web/yarn.lock
Normal file
123
web/yarn.lock
Normal file
|
@ -0,0 +1,123 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
esbuild-android-arm64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.14.23.tgz#c89b3c50b4f47668dcbeb0b34ee4615258818e71"
|
||||
integrity sha512-k9sXem++mINrZty1v4FVt6nC5BQCFG4K2geCIUUqHNlTdFnuvcqsY7prcKZLFhqVC1rbcJAr9VSUGFL/vD4vsw==
|
||||
|
||||
esbuild-darwin-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.14.23.tgz#1c131e8cb133ed935ca32f824349a117c896a15b"
|
||||
integrity sha512-lB0XRbtOYYL1tLcYw8BoBaYsFYiR48RPrA0KfA/7RFTr4MV7Bwy/J4+7nLsVnv9FGuQummM3uJ93J3ptaTqFug==
|
||||
|
||||
esbuild-darwin-arm64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.23.tgz#3c6245a50109dd84953f53d7833bd3b4f0e8c6fa"
|
||||
integrity sha512-yat73Z/uJ5tRcfRiI4CCTv0FSnwErm3BJQeZAh+1tIP0TUNh6o+mXg338Zl5EKChD+YGp6PN+Dbhs7qa34RxSw==
|
||||
|
||||
esbuild-freebsd-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.23.tgz#0cdc54e72d3dd9cd992f9c2960055e68a7f8650c"
|
||||
integrity sha512-/1xiTjoLuQ+LlbfjJdKkX45qK/M7ARrbLmyf7x3JhyQGMjcxRYVR6Dw81uH3qlMHwT4cfLW4aEVBhP1aNV7VsA==
|
||||
|
||||
esbuild-freebsd-arm64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.23.tgz#1d11faed3a0c429e99b7dddef84103eb509788b2"
|
||||
integrity sha512-uyPqBU/Zcp6yEAZS4LKj5jEE0q2s4HmlMBIPzbW6cTunZ8cyvjG6YWpIZXb1KK3KTJDe62ltCrk3VzmWHp+iLg==
|
||||
|
||||
esbuild-linux-32@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.14.23.tgz#fd9f033fc27dcab61100cb1eb1c936893a68c841"
|
||||
integrity sha512-37R/WMkQyUfNhbH7aJrr1uCjDVdnPeTHGeDhZPUNhfoHV0lQuZNCKuNnDvlH/u/nwIYZNdVvz1Igv5rY/zfrzQ==
|
||||
|
||||
esbuild-linux-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.14.23.tgz#c04c438514f1359ecb1529205d0c836d4165f198"
|
||||
integrity sha512-H0gztDP60qqr8zoFhAO64waoN5yBXkmYCElFklpd6LPoobtNGNnDe99xOQm28+fuD75YJ7GKHzp/MLCLhw2+vQ==
|
||||
|
||||
esbuild-linux-arm64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.23.tgz#d1b3ab2988ab0734886eb9e811726f7db099ab96"
|
||||
integrity sha512-c4MLOIByNHR55n3KoYf9hYDfBRghMjOiHLaoYLhkQkIabb452RWi+HsNgB41sUpSlOAqfpqKPFNg7VrxL3UX9g==
|
||||
|
||||
esbuild-linux-arm@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.14.23.tgz#df7558b6a5076f5eb9fd387c8704f768b61d97fb"
|
||||
integrity sha512-x64CEUxi8+EzOAIpCUeuni0bZfzPw/65r8tC5cy5zOq9dY7ysOi5EVQHnzaxS+1NmV+/RVRpmrzGw1QgY2Xpmw==
|
||||
|
||||
esbuild-linux-mips64le@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.23.tgz#bb4c47fccc9493d460ffeb1f88e8a97a98a14f8b"
|
||||
integrity sha512-kHKyKRIAedYhKug2EJpyJxOUj3VYuamOVA1pY7EimoFPzaF3NeY7e4cFBAISC/Av0/tiV0xlFCt9q0HJ68IBIw==
|
||||
|
||||
esbuild-linux-ppc64le@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.23.tgz#a332dbc8a1b4e30cfe1261bfaa5cef57c9c8c02a"
|
||||
integrity sha512-7ilAiJEPuJJnJp/LiDO0oJm5ygbBPzhchJJh9HsHZzeqO+3PUzItXi+8PuicY08r0AaaOe25LA7sGJ0MzbfBag==
|
||||
|
||||
esbuild-linux-riscv64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.23.tgz#85675f3f931f5cd7cfb238fd82f77a62ffcb6d86"
|
||||
integrity sha512-fbL3ggK2wY0D8I5raPIMPhpCvODFE+Bhb5QGtNP3r5aUsRR6TQV+ZBXIaw84iyvKC8vlXiA4fWLGhghAd/h/Zg==
|
||||
|
||||
esbuild-linux-s390x@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.23.tgz#a526282a696e6d846f4c628f5315475518c0c0f0"
|
||||
integrity sha512-GHMDCyfy7+FaNSO8RJ8KCFsnax8fLUsOrj9q5Gi2JmZMY0Zhp75keb5abTFCq2/Oy6KVcT0Dcbyo/bFb4rIFJA==
|
||||
|
||||
esbuild-netbsd-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.23.tgz#8e456605694719aa1be4be266d6cd569c06dfaf5"
|
||||
integrity sha512-ovk2EX+3rrO1M2lowJfgMb/JPN1VwVYrx0QPUyudxkxLYrWeBxDKQvc6ffO+kB4QlDyTfdtAURrVzu3JeNdA2g==
|
||||
|
||||
esbuild-openbsd-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.23.tgz#f2fc51714b4ddabc86e4eb30ca101dd325db2f7d"
|
||||
integrity sha512-uYYNqbVR+i7k8ojP/oIROAHO9lATLN7H2QeXKt2H310Fc8FJj4y3Wce6hx0VgnJ4k1JDrgbbiXM8rbEgQyg8KA==
|
||||
|
||||
esbuild-sunos-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.14.23.tgz#a408f33ea20e215909e20173a0fd78b1aaad1f8e"
|
||||
integrity sha512-hAzeBeET0+SbScknPzS2LBY6FVDpgE+CsHSpe6CEoR51PApdn2IB0SyJX7vGelXzlyrnorM4CAsRyb9Qev4h9g==
|
||||
|
||||
esbuild-windows-32@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.14.23.tgz#b9005bbff54dac3975ff355d5de2b5e37165d128"
|
||||
integrity sha512-Kttmi3JnohdaREbk6o9e25kieJR379TsEWF0l39PQVHXq3FR6sFKtVPgY8wk055o6IB+rllrzLnbqOw/UV60EA==
|
||||
|
||||
esbuild-windows-64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.14.23.tgz#2b5a99befeaca6aefdad32d738b945730a60a060"
|
||||
integrity sha512-JtIT0t8ymkpl6YlmOl6zoSWL5cnCgyLaBdf/SiU/Eg3C13r0NbHZWNT/RDEMKK91Y6t79kTs3vyRcNZbfu5a8g==
|
||||
|
||||
esbuild-windows-arm64@0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.23.tgz#edc560bbadb097eb45fc235aeacb942cb94a38c0"
|
||||
integrity sha512-cTFaQqT2+ik9e4hePvYtRZQ3pqOvKDVNarzql0VFIzhc0tru/ZgdLoXd6epLiKT+SzoSce6V9YJ+nn6RCn6SHw==
|
||||
|
||||
esbuild@^0.14.23:
|
||||
version "0.14.23"
|
||||
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.14.23.tgz#95e842cb22bc0c7d82c140adc16788aac91469fe"
|
||||
integrity sha512-XjnIcZ9KB6lfonCa+jRguXyRYcldmkyZ99ieDksqW/C8bnyEX299yA4QH2XcgijCgaddEZePPTgvx/2imsq7Ig==
|
||||
optionalDependencies:
|
||||
esbuild-android-arm64 "0.14.23"
|
||||
esbuild-darwin-64 "0.14.23"
|
||||
esbuild-darwin-arm64 "0.14.23"
|
||||
esbuild-freebsd-64 "0.14.23"
|
||||
esbuild-freebsd-arm64 "0.14.23"
|
||||
esbuild-linux-32 "0.14.23"
|
||||
esbuild-linux-64 "0.14.23"
|
||||
esbuild-linux-arm "0.14.23"
|
||||
esbuild-linux-arm64 "0.14.23"
|
||||
esbuild-linux-mips64le "0.14.23"
|
||||
esbuild-linux-ppc64le "0.14.23"
|
||||
esbuild-linux-riscv64 "0.14.23"
|
||||
esbuild-linux-s390x "0.14.23"
|
||||
esbuild-netbsd-64 "0.14.23"
|
||||
esbuild-openbsd-64 "0.14.23"
|
||||
esbuild-sunos-64 "0.14.23"
|
||||
esbuild-windows-32 "0.14.23"
|
||||
esbuild-windows-64 "0.14.23"
|
||||
esbuild-windows-arm64 "0.14.23"
|
Loading…
Reference in a new issue