Skip to content

Commit 5f704fb

Browse files
docs: readme; fix: types for wasm exports
1 parent 3ca6266 commit 5f704fb

File tree

8 files changed

+43
-37
lines changed

8 files changed

+43
-37
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# Simple workflow for deploying static content to GitHub Pages
2-
name: Deploy static content to Pages
1+
name: Deploy
32

43
on:
5-
# Runs on pushes targeting the default branch
64
push:
75
branches: ['main']
86

9-
# Allows you to run this workflow manually from the Actions tab
107
workflow_dispatch:
118

129
# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
@@ -21,7 +18,6 @@ concurrency:
2118
cancel-in-progress: true
2219

2320
jobs:
24-
# Single deploy job since we're just deploying
2521
deploy:
2622
environment:
2723
name: github-pages
@@ -33,7 +29,7 @@ jobs:
3329
- name: Set up Node
3430
uses: actions/setup-node@v5
3531
with:
36-
node-version: lts/*
32+
node-version: 20
3733
cache: 'npm'
3834
- name: Install dependencies
3935
run: npm ci
@@ -44,7 +40,6 @@ jobs:
4440
- name: Upload artifact
4541
uses: actions/upload-pages-artifact@v4
4642
with:
47-
# Upload dist folder
4843
path: './dist'
4944
- name: Deploy to GitHub Pages
5045
id: deployment

Readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Canvas Point Simulation comparison
2+
___
3+
For points simulation we need to perform math/physics feature (calculate coordinates, speeds, acceleration and so on) and render stage.
4+
This application demonstrates combinations of 2 physics approaches and 2 render approaches:
5+
- Pure JS Physics + JS Render (Canvas 2D Api)
6+
- Web Assembly Physics + JS Render (Canvas 2D Api)
7+
- Pure JS Physics + WebGL Render (WebGL Canvas)
8+
- Web Assembly Physics + WebGL Render (WebGL Canvas)
9+
10+
___
11+
12+
## Technologies for this project:
13+
- _TypeScript_
14+
- _Pure Web Assembly basics_
15+
- _Pure GLSL basics_
16+
- _Canvas 2D API_
17+
- _Canvas WebGL API_
18+
- _HTML, CSS_

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ <h3>WASM Physics + JS Render</h3>
3131

3232
<div class="option">
3333
<div class="option-info">
34-
<h3>⚡⚡JS Physics + WebGl Render</h3>
34+
<h3>⚡⚡ JS Physics + WebGl Render</h3>
3535
</div>
3636
<a href="src/pages/js-physics-webgl-render/index.html" class="btn">Test</a>
3737
</div>
3838

3939
<div class="option">
4040
<div class="option-info">
41-
<h3>⚡⚡⚡ WASM Physics + WebGl Canvas</h3>
41+
<h3>⚡⚡⚡ WASM Physics + WebGl Canvas</h3>
4242
</div>
4343
<a href="src/pages/wasm-physics-webgl-render/index.html" class="btn">Test</a>
4444
</div>

package-lock.json

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@types/node": "^24.9.1",
1717
"gh-pages": "^6.3.0",
1818
"vite": "^7.1.12",
19-
"vite-plugin-glsl": "^1.5.4",
20-
"vite-plugin-wasm": "^3.5.0"
19+
"vite-plugin-glsl": "^1.5.4"
2120
}
2221
}

src/core/wasm/physics.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
import { Coordinate, Physics } from '../types';
22

3+
4+
type WasmExportsStructure = Omit<Physics, 'run'> & {
5+
mem: WebAssembly.Memory;
6+
run: (x: number, y: number) => void;
7+
}
8+
39
export class WebAssemblyPhysics implements Physics {
410
private points: Float32Array = new Float32Array();
11+
private readonly wasmExports: WasmExportsStructure;
512

6-
public constructor(private readonly wasmInstance: WebAssembly.Instance) {
7-
13+
public constructor(wasmInstance: WebAssembly.Instance) {
14+
this.wasmExports = wasmInstance.exports as unknown as WasmExportsStructure;
815
}
916

1017
public run(coordinate: Coordinate): void {
11-
return this.wasmInstance.exports.run(coordinate.x, coordinate.y);
18+
return this.wasmExports.run(coordinate.x, coordinate.y);
1219
}
1320

1421

1522
public tick(pointsCount: number): void {
16-
return this.wasmInstance.exports.tick(pointsCount);
23+
return this.wasmExports.tick(pointsCount);
1724
};
1825

1926

2027
public get data(): Readonly<Float32Array<ArrayBufferLike>> {
21-
const wasmExports = this.wasmInstance.exports;
28+
const wasmBuffer = this.wasmExports.mem.buffer;
2229

23-
if (wasmExports.mem.buffer !== this.points.buffer) {
24-
this.points = new Float32Array(wasmExports.mem.buffer);
30+
if (wasmBuffer !== this.points.buffer) {
31+
this.points = new Float32Array(wasmBuffer);
2532
}
2633

2734
return this.points;

tsconfig.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2020",
3+
"target": "ES2021",
44
"useDefineForClassFields": true,
55
"module": "ESNext",
6-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"lib": ["ES2024", "DOM", "DOM.Iterable"],
77
"skipLibCheck": true,
88

9-
/* Bundler mode */
109
"moduleResolution": "bundler",
1110
"allowImportingTsExtensions": true,
1211
"resolveJsonModule": true,
1312
"isolatedModules": true,
1413
"noEmit": true,
1514

16-
/* Linting */
1715
"strict": true,
1816
"noUnusedLocals": true,
1917
"noUnusedParameters": true,
2018
"noFallthroughCasesInSwitch": true,
19+
"noImplicitAny": true,
20+
"alwaysStrict": true,
2121

22-
/* Node.js types */
23-
"types": ["node", "DOM"]
22+
"types": ["node"]
2423
},
2524
"include": ["src", "vite.config.ts"]
2625
}

vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { defineConfig } from 'vite';
22
import path from 'node:path';
33
import glsl from 'vite-plugin-glsl';
4-
import wasm from 'vite-plugin-wasm';
54

65

76
export default defineConfig({

0 commit comments

Comments
 (0)