-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup pong to be working as an external module and fix otlp ext…
…ernal env var
- Loading branch information
Showing
10 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,5 @@ npm-debug.log | |
yarn-error.log | ||
|
||
trace.log | ||
*.sarif | ||
*.sarif | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { defineStore } from 'pinia'; | ||
|
||
export interface WasmState { | ||
wasmLoading: boolean; | ||
loadingError?: string; | ||
wasm?: unknown; | ||
moduleNames?: string; | ||
} | ||
|
||
const getUrl = (moduleName: string, extension: string) => { | ||
const url = new URL('/api/media', import.meta.env.VITE_API_URL); | ||
url.searchParams.append( | ||
'path', | ||
`${moduleName}/${moduleName}${extension === 'wasm' ? '_bg' : ''}.${extension}`, | ||
); | ||
return url.toString(); | ||
}; | ||
|
||
export const useWasmStore = defineStore({ | ||
id: 'wasm', | ||
state: (): WasmState => ({ | ||
wasmLoading: false, | ||
}), | ||
actions: { | ||
fetchWasm(moduleName: string) { | ||
if (this.wasmLoading) return new Promise<void>((resolve) => resolve()); | ||
this.wasmLoading = true; | ||
this.moduleNames = moduleName; | ||
const jsModuleUrl = getUrl(moduleName, 'js'); | ||
|
||
return import(/* @vite-ignore */ jsModuleUrl) | ||
.then((wasm) => { | ||
this.wasm = wasm; | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
this.loadingError = 'Failed to load wasm'; | ||
this.moduleNames = ''; | ||
}) | ||
.finally(() => { | ||
this.wasmLoading = false; | ||
}); | ||
}, | ||
runWasm() { | ||
if (this.wasmLoading) return new Promise<void>((resolve) => resolve()); | ||
this.wasmLoading = true; | ||
const wasmModuleUrl = getUrl(`${this.moduleNames}`, 'wasm'); | ||
this.wasm.default({ module_or_path: wasmModuleUrl }); | ||
this.wasmLoading = false; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
<script lang="ts" setup> | ||
import { useWasmStore } from '../stores/wasm'; | ||
// Import from the backend the pong wasm game | ||
const wasmStore = useWasmStore(); | ||
const loadPong = async () => { | ||
if (!wasmStore.wasmLoading && wasmStore.moduleNames !== 'pong') { | ||
await wasmStore.fetchWasm('pong'); | ||
wasmStore.runWasm(); | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="min-w-full flex justify-center"> | ||
<div> | ||
<Button v-if="wasmStore.moduleNames !== 'pong'" @click="loadPong" label="Load Pong" /> | ||
<ProgressSpinner v-if="wasmStore.wasmLoading" /> | ||
</div> | ||
</div> | ||
<canvas id="pong-bevy" width="800" height="600"></canvas> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pong |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters