From a76b515b808a9f7c18146d095728e805486e6ad9 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 21 May 2023 11:01:31 +0100 Subject: [PATCH] Update helpers --- src/utils/array.ts | 1 - src/utils/graphics/initialize-context.ts | 17 +++++++++++++++++ src/utils/pretty-print.ts | 4 ---- src/utils/random.ts | 3 +-- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 src/utils/graphics/initialize-context.ts delete mode 100644 src/utils/pretty-print.ts diff --git a/src/utils/array.ts b/src/utils/array.ts index fcdc8f3..a5261bf 100644 --- a/src/utils/array.ts +++ b/src/utils/array.ts @@ -11,7 +11,6 @@ const setIndexAlias = (name: string, index: number, type: any) => { } }; -/** @internal */ export const applyArrayPlugins = () => { setIndexAlias('x', 0, Array); setIndexAlias('y', 1, Array); diff --git a/src/utils/graphics/initialize-context.ts b/src/utils/graphics/initialize-context.ts new file mode 100644 index 0000000..5e21820 --- /dev/null +++ b/src/utils/graphics/initialize-context.ts @@ -0,0 +1,17 @@ +export const initializeContext = ({ + device, + canvas, +}: { + device: GPUDevice; + canvas: HTMLCanvasElement; +}): GPUCanvasContext => { + const context = canvas.getContext('webgpu') as any as GPUCanvasContext; + + context.configure({ + device: device, + format: navigator.gpu.getPreferredCanvasFormat(), + alphaMode: 'premultiplied', + }); + + return context; +}; diff --git a/src/utils/pretty-print.ts b/src/utils/pretty-print.ts deleted file mode 100644 index 48fd593..0000000 --- a/src/utils/pretty-print.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const prettyPrint = (o: any): string => - JSON.stringify(o, (_, v) => (v?.toFixed ? Number(v.toFixed(3)) : v), ' ') - .replace(/("|,|{|^\n)/g, '') - .replace(/(\W*}\n?)+/g, '\n\n'); diff --git a/src/utils/random.ts b/src/utils/random.ts index a793a91..2d7e258 100644 --- a/src/utils/random.ts +++ b/src/utils/random.ts @@ -1,6 +1,5 @@ +// https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript, Mulberry32 export abstract class Random { - // https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript, Mulberry32 - private static _seed = 42; public static set seed(value: number) {