Compare commits
No commits in common. "410c3cf504f54d47f2088e0c6eb5691bf692d334" and "af8df2bd6fd3eabd4b7015174c49ce7746bdfa89" have entirely different histories.
410c3cf504
...
af8df2bd6f
|
|
@ -173,5 +173,3 @@ dist
|
||||||
|
|
||||||
# Finder (MacOS) folder config
|
# Finder (MacOS) folder config
|
||||||
.DS_Store
|
.DS_Store
|
||||||
error.log
|
|
||||||
package-lock.json
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { plugin, $, type BunPlugin } from "bun";
|
import { plugin, $, type BunPlugin } from "bun";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import asc from 'assemblyscript/asc';
|
||||||
|
|
||||||
interface WasmLoaderConfig {
|
interface WasmLoaderConfig {
|
||||||
production?: boolean;
|
production?: boolean;
|
||||||
|
|
@ -10,7 +11,7 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin
|
||||||
const p: BunPlugin = {
|
const p: BunPlugin = {
|
||||||
name: "WASM loader",
|
name: "WASM loader",
|
||||||
async setup(build) {
|
async setup(build) {
|
||||||
build.onLoad({ filter: /\.(c(pp)?|wasm)$/ }, async (args) => {
|
build.onLoad({ filter: /\.(c(pp)?|wasm(\.ts)?)$/ }, async (args) => {
|
||||||
let wasmPath = path.resolve(import.meta.dir, '..', 'dist', 'tmp.wasm');
|
let wasmPath = path.resolve(import.meta.dir, '..', 'dist', 'tmp.wasm');
|
||||||
let jsContent: string = `
|
let jsContent: string = `
|
||||||
async function instantiate(url) {
|
async function instantiate(url) {
|
||||||
|
|
@ -44,7 +45,29 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin
|
||||||
|
|
||||||
export default module;
|
export default module;
|
||||||
`;
|
`;
|
||||||
if (args.path.endsWith('.wasm')) {
|
if (args.path.endsWith('.ts')) {
|
||||||
|
if (portable) {
|
||||||
|
const contents = await Bun.file(args.path).text();
|
||||||
|
return {
|
||||||
|
contents: `import "assemblyscript/std/portable/index.js";\n${contents}`,
|
||||||
|
loader: 'tsx',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const jsPath = wasmPath.replace(/\.wasm$/, '.js');
|
||||||
|
const ascArgs = [
|
||||||
|
args.path,
|
||||||
|
'--outFile', wasmPath,
|
||||||
|
'--bindings', 'esm',
|
||||||
|
'-Ospeed'
|
||||||
|
];
|
||||||
|
|
||||||
|
const { error, stderr } = await asc.main(ascArgs);
|
||||||
|
if (error) {
|
||||||
|
console.error(stderr.toString(), error.message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
jsContent = await Bun.file(jsPath).text();
|
||||||
|
} else if (args.path.endsWith('.wasm')) {
|
||||||
wasmPath = args.path;
|
wasmPath = args.path;
|
||||||
} else {
|
} else {
|
||||||
const buildAssets = path.resolve(import.meta.dir, 'assets');
|
const buildAssets = path.resolve(import.meta.dir, 'assets');
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"@types/html-minifier": "4.0.5",
|
"@types/html-minifier": "4.0.5",
|
||||||
"@types/inquirer": "9.0.7",
|
"@types/inquirer": "9.0.7",
|
||||||
|
"assemblyscript": "0.27.29",
|
||||||
"browser-detect": "0.2.28",
|
"browser-detect": "0.2.28",
|
||||||
"eruda": "3.2.3",
|
"eruda": "3.2.3",
|
||||||
"html-minifier": "4.0.0",
|
"html-minifier": "4.0.0",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
export function awoo(a: i32, b: i32): void {
|
||||||
|
console.log((a * b).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
export function testTemplate(a: i32, f: f64): string {
|
||||||
|
return `${a} + ${f} = ${a + f}`;
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
|
import { awoo, testTemplate } from "./awoo.wasm";
|
||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
import attack from './assets/attack.wav';
|
import attack from './assets/attack.wav';
|
||||||
|
|
||||||
export default function main() {
|
export default function main() {
|
||||||
|
awoo(42, 69);
|
||||||
|
console.log(testTemplate(420, 69));
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<button onClick={() => attack.play()}>
|
<button onClick={() => attack.play()}>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { nextFrame } from "@common/utils";
|
import { delay, nextFrame } from "@common/utils";
|
||||||
import { Color, GAME_HEIGHT, GAME_WIDTH } from "./const";
|
import { Color, GAME_HEIGHT, GAME_WIDTH } from "./const";
|
||||||
import type { IChar, IColorLike, IRegion } from "./types";
|
import type { IChar, IColorLike, IRegion } from "./types";
|
||||||
import { generateColors, randChar } from "./utils";
|
import { generateColors, randChar } from "./utils";
|
||||||
|
|
@ -222,7 +222,7 @@ export async function tick(desiredFPS = 60) {
|
||||||
const totalDelay = 1000 / desiredFPS;
|
const totalDelay = 1000 / desiredFPS;
|
||||||
const remainingDelay = totalDelay - dt;
|
const remainingDelay = totalDelay - dt;
|
||||||
if (remainingDelay > 4) {
|
if (remainingDelay > 4) {
|
||||||
await Bun.sleep(remainingDelay);
|
await delay(remainingDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue