@cazala/party 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +598 -0
  3. package/dist/engine.d.ts +113 -0
  4. package/dist/engine.d.ts.map +1 -0
  5. package/dist/index.d.ts +8 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +9628 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/interfaces.d.ts +223 -0
  10. package/dist/interfaces.d.ts.map +1 -0
  11. package/dist/module.d.ts +259 -0
  12. package/dist/module.d.ts.map +1 -0
  13. package/dist/modules/forces/behavior.d.ts +78 -0
  14. package/dist/modules/forces/behavior.d.ts.map +1 -0
  15. package/dist/modules/forces/boundary.d.ts +58 -0
  16. package/dist/modules/forces/boundary.d.ts.map +1 -0
  17. package/dist/modules/forces/collisions.d.ts +34 -0
  18. package/dist/modules/forces/collisions.d.ts.map +1 -0
  19. package/dist/modules/forces/environment.d.ts +62 -0
  20. package/dist/modules/forces/environment.d.ts.map +1 -0
  21. package/dist/modules/forces/fluids.d.ts +73 -0
  22. package/dist/modules/forces/fluids.d.ts.map +1 -0
  23. package/dist/modules/forces/grab.d.ts +56 -0
  24. package/dist/modules/forces/grab.d.ts.map +1 -0
  25. package/dist/modules/forces/interaction.d.ts +59 -0
  26. package/dist/modules/forces/interaction.d.ts.map +1 -0
  27. package/dist/modules/forces/joints.d.ts +87 -0
  28. package/dist/modules/forces/joints.d.ts.map +1 -0
  29. package/dist/modules/forces/sensors.d.ts +81 -0
  30. package/dist/modules/forces/sensors.d.ts.map +1 -0
  31. package/dist/modules/index.d.ts +13 -0
  32. package/dist/modules/index.d.ts.map +1 -0
  33. package/dist/modules/render/lines.d.ts +55 -0
  34. package/dist/modules/render/lines.d.ts.map +1 -0
  35. package/dist/modules/render/particles.d.ts +53 -0
  36. package/dist/modules/render/particles.d.ts.map +1 -0
  37. package/dist/modules/render/trails.d.ts +36 -0
  38. package/dist/modules/render/trails.d.ts.map +1 -0
  39. package/dist/oscillators.d.ts +66 -0
  40. package/dist/oscillators.d.ts.map +1 -0
  41. package/dist/particle.d.ts +19 -0
  42. package/dist/particle.d.ts.map +1 -0
  43. package/dist/runtimes/cpu/engine.d.ts +60 -0
  44. package/dist/runtimes/cpu/engine.d.ts.map +1 -0
  45. package/dist/runtimes/cpu/spatial-grid.d.ts +56 -0
  46. package/dist/runtimes/cpu/spatial-grid.d.ts.map +1 -0
  47. package/dist/runtimes/webgpu/builders/program.d.ts +56 -0
  48. package/dist/runtimes/webgpu/builders/program.d.ts.map +1 -0
  49. package/dist/runtimes/webgpu/builders/render-pass.d.ts +26 -0
  50. package/dist/runtimes/webgpu/builders/render-pass.d.ts.map +1 -0
  51. package/dist/runtimes/webgpu/engine.d.ts +73 -0
  52. package/dist/runtimes/webgpu/engine.d.ts.map +1 -0
  53. package/dist/runtimes/webgpu/gpu-resources.d.ts +141 -0
  54. package/dist/runtimes/webgpu/gpu-resources.d.ts.map +1 -0
  55. package/dist/runtimes/webgpu/module-registry.d.ts +53 -0
  56. package/dist/runtimes/webgpu/module-registry.d.ts.map +1 -0
  57. package/dist/runtimes/webgpu/particle-store.d.ts +43 -0
  58. package/dist/runtimes/webgpu/particle-store.d.ts.map +1 -0
  59. package/dist/runtimes/webgpu/render-pipeline.d.ts +49 -0
  60. package/dist/runtimes/webgpu/render-pipeline.d.ts.map +1 -0
  61. package/dist/runtimes/webgpu/shaders.d.ts +8 -0
  62. package/dist/runtimes/webgpu/shaders.d.ts.map +1 -0
  63. package/dist/runtimes/webgpu/simulation-pipeline.d.ts +22 -0
  64. package/dist/runtimes/webgpu/simulation-pipeline.d.ts.map +1 -0
  65. package/dist/runtimes/webgpu/spacial-grid.d.ts +27 -0
  66. package/dist/runtimes/webgpu/spacial-grid.d.ts.map +1 -0
  67. package/dist/spawner.d.ts +40 -0
  68. package/dist/spawner.d.ts.map +1 -0
  69. package/dist/vector.d.ts +61 -0
  70. package/dist/vector.d.ts.map +1 -0
  71. package/dist/view.d.ts +43 -0
  72. package/dist/view.d.ts.map +1 -0
  73. package/package.json +67 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Trails (Render Module)
3
+ *
4
+ * Two compute image passes over the scene texture:
5
+ * - decay: exponential fade toward clear color with alpha decay
6
+ * - diffuse: gaussian-like blur with configurable radius
7
+ * Both read from input texture and write to output, participating in ping-pong.
8
+ */
9
+ import { Module, type WebGPUDescriptor, ModuleRole, CPUDescriptor, DataType } from "../../module";
10
+ export declare const DEFAULT_TRAILS_TRAIL_DECAY = 10;
11
+ export declare const DEFAULT_TRAILS_TRAIL_DIFFUSE = 0;
12
+ type TrailsInputs = {
13
+ trailDecay: number;
14
+ trailDiffuse: number;
15
+ };
16
+ export declare class Trails extends Module<"trails", TrailsInputs> {
17
+ readonly name: "trails";
18
+ readonly role = ModuleRole.Render;
19
+ readonly inputs: {
20
+ readonly trailDecay: DataType.NUMBER;
21
+ readonly trailDiffuse: DataType.NUMBER;
22
+ };
23
+ constructor(opts?: {
24
+ enabled?: boolean;
25
+ trailDecay?: number;
26
+ trailDiffuse?: number;
27
+ });
28
+ setTrailDecay(value: number): void;
29
+ setTrailDiffuse(value: number): void;
30
+ getTrailDecay(): number;
31
+ getTrailDiffuse(): number;
32
+ webgpu(): WebGPUDescriptor<TrailsInputs>;
33
+ cpu(): CPUDescriptor<TrailsInputs>;
34
+ }
35
+ export {};
36
+ //# sourceMappingURL=trails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trails.d.ts","sourceRoot":"","sources":["../../../src/modules/render/trails.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,MAAM,EACN,KAAK,gBAAgB,EACrB,UAAU,EAEV,aAAa,EAEb,QAAQ,EACT,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAC7C,eAAO,MAAM,4BAA4B,IAAM,CAAC;AAEhD,KAAK,YAAY,GAAG;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,qBAAa,MAAO,SAAQ,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC;IACxD,QAAQ,CAAC,IAAI,EAAG,QAAQ,CAAU;IAClC,QAAQ,CAAC,IAAI,qBAAqB;IAClC,QAAQ,CAAC,MAAM;;;MAGJ;gBAEC,IAAI,CAAC,EAAE;QACjB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;IAYD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIlC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC,aAAa,IAAI,MAAM;IAGvB,eAAe,IAAI,MAAM;IAIzB,MAAM,IAAI,gBAAgB,CAAC,YAAY,CAAC;IAkExC,GAAG,IAAI,aAAa,CAAC,YAAY,CAAC;CA2CnC"}
@@ -0,0 +1,66 @@
1
+ export type OscillatorKey = string;
2
+ export interface AddOscillatorOptions {
3
+ curveExponent?: number;
4
+ jitter?: boolean | number;
5
+ initialDirection?: -1 | 1;
6
+ currentValue?: number;
7
+ phaseOffset?: number;
8
+ }
9
+ export interface OscillatorConfigInternal {
10
+ moduleName: string;
11
+ inputName: string;
12
+ min: number;
13
+ max: number;
14
+ speedHz: number;
15
+ curveExponent: number;
16
+ jitterMultiplier: number;
17
+ phaseOffset: number;
18
+ lastValue: number;
19
+ lastDirection: -1 | 0 | 1;
20
+ active: boolean;
21
+ }
22
+ export interface OscillatorPublicConfig {
23
+ moduleName: string;
24
+ inputName: string;
25
+ min: number;
26
+ max: number;
27
+ speedHz: number;
28
+ curveExponent: number;
29
+ jitterMultiplier: number;
30
+ phaseOffset: number;
31
+ lastDirection: -1 | 0 | 1;
32
+ lastValue: number;
33
+ active: boolean;
34
+ }
35
+ export declare class OscillatorManager {
36
+ private keyToIndex;
37
+ private oscillators;
38
+ private elapsedSeconds;
39
+ private setInput;
40
+ private listeners;
41
+ constructor(setInput: (moduleName: string, inputName: string, value: number) => void);
42
+ private static makeKey;
43
+ addOscillator(params: {
44
+ moduleName: string;
45
+ inputName: string;
46
+ min: number;
47
+ max: number;
48
+ speedHz: number;
49
+ options?: AddOscillatorOptions;
50
+ }): OscillatorKey;
51
+ removeOscillator(moduleName: string, inputName: string): void;
52
+ updateOscillatorSpeed(moduleName: string, inputName: string, speedHz: number): void;
53
+ updateOscillatorBounds(moduleName: string, inputName: string, min: number, max: number): void;
54
+ hasOscillator(moduleName: string, inputName: string): boolean;
55
+ getOscillator(moduleName: string, inputName: string): OscillatorPublicConfig | undefined;
56
+ clear(): void;
57
+ getElapsedSeconds(): number;
58
+ setElapsedSeconds(seconds: number): void;
59
+ clearModule(moduleName: string): void;
60
+ updateAll(dtSeconds: number): void;
61
+ private recalculatePhaseOffset;
62
+ addOscillatorListener(moduleName: string, inputName: string, handler: (value: number) => void): void;
63
+ removeOscillatorListener(moduleName: string, inputName: string, handler: (value: number) => void): void;
64
+ setOscillatorState(moduleName: string, inputName: string, lastValue: number, lastDirection: -1 | 0 | 1): boolean;
65
+ }
66
+ //# sourceMappingURL=oscillators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oscillators.d.ts","sourceRoot":"","sources":["../src/oscillators.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,MAAM,WAAW,oBAAoB;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC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vector";
3
+ export declare class Particle implements IParticle {
4
+ id: number;
5
+ position: Vector;
6
+ velocity: Vector;
7
+ acceleration: Vector;
8
+ size: number;
9
+ mass: number;
10
+ color: {
11
+ r: number;
12
+ g: number;
13
+ b: number;
14
+ a: number;
15
+ };
16
+ constructor(options: IParticle);
17
+ toJSON(): IParticle;
18
+ }
19
+ //# sourceMappingURL=particle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"particle.d.ts","sourceRoot":"","sources":["../src/particle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,qBAAa,QAAS,YAAW,SAAS;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;gBAEjD,OAAO,EAAE,SAAS;IAU9B,MAAM,IAAI,SAAS;CASpB"}
@@ -0,0 +1,60 @@
1
+ import { AbstractEngine, IParticle } from "../../interfaces";
2
+ import { Module } from "../../module";
3
+ export declare class CPUEngine extends AbstractEngine {
4
+ private particles;
5
+ private canvas;
6
+ private grid;
7
+ private animationId;
8
+ constructor(options: {
9
+ canvas: HTMLCanvasElement;
10
+ forces: Module[];
11
+ render: Module[];
12
+ constrainIterations?: number;
13
+ clearColor?: {
14
+ r: number;
15
+ g: number;
16
+ b: number;
17
+ a: number;
18
+ };
19
+ cellSize?: number;
20
+ });
21
+ initialize(): Promise<void>;
22
+ protected startAnimationLoop(): void;
23
+ protected stopAnimationLoop(): void;
24
+ /**
25
+ * Resets animation timing to prevent large deltaTime spikes.
26
+ * Useful when starting after engine restoration or long pauses.
27
+ */
28
+ resetTiming(): void;
29
+ /**
30
+ * Resets the simulation to its initial state.
31
+ *
32
+ * This method:
33
+ * - Pauses the simulation
34
+ * - Clears all particles
35
+ * - Resets timing and FPS data
36
+ * - Clears force-specific caches
37
+ */
38
+ reset(): void;
39
+ clear(): void;
40
+ getCount(): number;
41
+ protected getEffectiveCount(): number;
42
+ setSize(width: number, height: number): void;
43
+ setParticles(particle: IParticle[]): void;
44
+ addParticle(particle: IParticle): void;
45
+ getParticles(): Promise<IParticle[]>;
46
+ getParticle(index: number): Promise<IParticle>;
47
+ destroy(): Promise<void>;
48
+ protected onClearColorChanged(): void;
49
+ protected onCellSizeChanged(): void;
50
+ protected onConstrainIterationsChanged(): void;
51
+ protected onMaxNeighborsChanged(): void;
52
+ protected onMaxParticlesChanged(): void;
53
+ private animate;
54
+ private getNeighbors;
55
+ private getImageData;
56
+ private update;
57
+ private createRenderUtils;
58
+ private render;
59
+ }
60
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/runtimes/cpu/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACL,MAAM,EAKP,MAAM,cAAc,CAAC;AAKtB,qBAAa,SAAU,SAAQ,cAAc;IAC3C,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,WAAW,CAAuB;gBAE9B,OAAO,EAAE;QACnB,MAAM,EAAE,iBAAiB,CAAC;QAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,UAAU,CAA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import { Vector } from "../../vector";
3
+ export interface SpatialGridOptions {
4
+ width: number;
5
+ height: number;
6
+ cellSize: number;
7
+ }
8
+ export declare class SpatialGrid {
9
+ private width;
10
+ private height;
11
+ private cellSize;
12
+ private cols;
13
+ private rows;
14
+ private grid;
15
+ private minX;
16
+ private minY;
17
+ private maxX;
18
+ private maxY;
19
+ private cameraX;
20
+ private cameraY;
21
+ private zoom;
22
+ private particlePositions;
23
+ constructor(options: SpatialGridOptions);
24
+ private updateBounds;
25
+ setCamera(cameraX: number, cameraY: number, zoom: number): void;
26
+ private initializeGrid;
27
+ clear(): void;
28
+ /**
29
+ * Incrementally clear only cells that contained particles
30
+ * Much more efficient than full clear for sparse grids
31
+ */
32
+ clearIncremental(_particles: Particle[]): void;
33
+ insert(particle: Particle): void;
34
+ getParticles(point: Vector, radius: number, maxNeighbors?: number): Particle[];
35
+ getCellParticleCount(col: number, row: number): number;
36
+ getGridDimensions(): {
37
+ cols: number;
38
+ rows: number;
39
+ cellSize: number;
40
+ };
41
+ getGridBounds(): {
42
+ minX: number;
43
+ minY: number;
44
+ maxX: number;
45
+ maxY: number;
46
+ };
47
+ getSize(): {
48
+ width: number;
49
+ height: number;
50
+ };
51
+ setSize(width: number, height: number): void;
52
+ getCellSize(): number;
53
+ setCellSize(cellSize: number): void;
54
+ getAllParticles(): Particle[];
55
+ }
56
+ //# sourceMappingURL=spatial-grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spatial-grid.d.ts","sourceRoot":"","sources":["../../../src/runtimes/cpu/spatial-grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW;IACtB,OAAO,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AAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAO5C,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAQ5C,WAAW,IAAI,MAAM;IAIrB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMnC,eAAe,IAAI,QAAQ,EAAE;CAS9B"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Module Builder (Program generator)
3
+ *
4
+ * Builds a single WGSL Program from a list of `Module` instances by:
5
+ * - Creating a packed uniform layout per module and mapping named fields to `vec4` slots
6
+ * - Emitting internal global helpers (simulation/grid) and optional force module globals
7
+ * - Generating optional state/apply/constrain/correct functions for force modules
8
+ * - Defining simulation entrypoints and grid entrypoints (inlined internally)
9
+ * - Assigning extra bind group bindings (grid, sim state, scene texture)
10
+ *
11
+ * Output:
12
+ * - `Program.code`: complete WGSL source for all compute passes
13
+ * - `Program.layouts`: uniform layout/offset metadata for writing uniforms from CPU
14
+ * - `Program.simStateStride`: size of the shared SIM_STATE row per particle
15
+ * - `Program.extraBindings`: indices for additional buffers/textures bound by pipelines
16
+ */
17
+ import { Module, ModuleRole } from "../../../module";
18
+ export declare const PARTICLE_STRUCT = "\nstruct Particle {\n position: vec2<f32>,\n velocity: vec2<f32>,\n acceleration: vec2<f32>,\n size: f32,\n mass: f32,\n color: vec4<f32>,\n}";
19
+ export declare const STORAGE_DECL = "@group(0) @binding(0) var<storage, read_write> particles: array<Particle>;";
20
+ export interface ModuleUniformLayout {
21
+ moduleName: string;
22
+ moduleRole: ModuleRole;
23
+ bindingIndex: number;
24
+ uniformsVar: string;
25
+ structName: string;
26
+ sizeBytes: number;
27
+ vec4Count: number;
28
+ mapping: Record<string, {
29
+ flatIndex: number;
30
+ expr: string;
31
+ offsetExpr?: string;
32
+ }>;
33
+ }
34
+ export interface Program {
35
+ code: string;
36
+ layouts: ModuleUniformLayout[];
37
+ simStateStride: number;
38
+ extraBindings: {
39
+ grid?: {
40
+ countsBinding: number;
41
+ indicesBinding: number;
42
+ };
43
+ simState?: {
44
+ stateBinding: number;
45
+ };
46
+ sceneTexture?: {
47
+ textureBinding: number;
48
+ };
49
+ arrays?: Record<string, {
50
+ arrayBinding: number;
51
+ lengthBinding: number;
52
+ }>;
53
+ };
54
+ }
55
+ export declare function buildProgram(modules: readonly Module[]): Program;
56
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/webgpu/builders/program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,MAAM,EACN,UAAU,EAGX,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,eAAe,wJAQ1B,CAAC;AAEH,eAAO,MAAM,YAAY,+EAA+E,CAAC;AAMzG,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CACzD,CAAC;CACH;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE;QACb,IAAI,CAAC,EAAE;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,MAAM,CAAA;SAAE,CAAC;QACzD,QAAQ,CAAC,EAAE;YAAE,YAAY,EAAE,MAAM,CAAA;SAAE,CAAC;QACpC,YAAY,CAAC,EAAE;YAAE,cAAc,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,YAAY,EAAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC1E,CAAC;CACH;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAoiBhE"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Render Pass Builder
3
+ *
4
+ * Translates `RenderModuleDescriptor` passes into standalone WGSL programs:
5
+ * - Fullscreen (raster) pass: draws a screen-aligned quad; optionally instanced per particle
6
+ * - Compute image pass: reads from an input scene texture and writes to an output scene texture
7
+ *
8
+ * Provides helpers to resolve module uniforms (`getUniform`), sample/read/write scene
9
+ * textures, and injects default vertex logic for instanced vs non-instanced fullscreen draws.
10
+ */
11
+ import type { FullscreenRenderPass, ComputeRenderPass } from "../../../module";
12
+ import { DataType } from "../../../module";
13
+ import { ModuleUniformLayout } from "./program";
14
+ export declare function buildFullscreenPassWGSL<Inputs extends Record<string, number | number[]> = Record<string, number | number[]>>(pass: FullscreenRenderPass<Inputs>, moduleName: string, layout: ModuleUniformLayout, moduleInputs: Record<keyof Inputs, DataType>, clearColor: {
15
+ r: number;
16
+ g: number;
17
+ b: number;
18
+ a: number;
19
+ }): string;
20
+ export declare function buildComputeImagePassWGSL<Inputs extends Record<string, number | number[]> = Record<string, number | number[]>>(pass: ComputeRenderPass<Inputs>, moduleName: string, layout: ModuleUniformLayout, moduleInputs: Record<keyof Inputs, DataType>, clearColor: {
21
+ r: number;
22
+ g: number;
23
+ b: number;
24
+ a: number;
25
+ }, workgroup?: [number, number, number]): string;
26
+ //# sourceMappingURL=render-pass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-pass.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/webgpu/builders/render-pass.ts"],"names":[],"mappings":"AAAA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+ /**
2
+ * WebGPU Engine
3
+ *
4
+ * High-level orchestrator that wires together GPU resources, the simulation pipeline,
5
+ * the render pipeline, the spatial grid, and the view controller. It owns the main
6
+ * animation loop and exposes a minimal API for sizing, camera/zoom control, particle
7
+ * data management, and play/pause lifecycle.
8
+ *
9
+ * Responsibilities:
10
+ * - Initialize GPU device/context and allocate core buffers via GPUResources
11
+ * - Build the WGSL program and per-module uniform buffers via ModuleRegistry
12
+ * - Initialize compute (simulation) and render pipelines
13
+ * - Maintain and sync the spatial grid to match the current view/camera
14
+ * - Drive per-frame simulation passes and render passes into ping-pong scene textures
15
+ * - Present the final texture to the canvas, tracking an EMA FPS estimate
16
+ */
17
+ import type { Module } from "../../module";
18
+ import { AbstractEngine, IParticle } from "../../interfaces";
19
+ export declare class WebGPUEngine extends AbstractEngine {
20
+ private resources;
21
+ private particles;
22
+ private registry;
23
+ private sim;
24
+ private render;
25
+ private grid;
26
+ private bufferMaxParticles;
27
+ private workgroupSize;
28
+ private simStrideValue;
29
+ private shouldSyncNextTick;
30
+ private animationId;
31
+ constructor(options: {
32
+ canvas: HTMLCanvasElement;
33
+ forces: Module[];
34
+ render: Module[];
35
+ constrainIterations?: number;
36
+ clearColor?: {
37
+ r: number;
38
+ g: number;
39
+ b: number;
40
+ a: number;
41
+ };
42
+ cellSize?: number;
43
+ maxParticles?: number;
44
+ workgroupSize?: number;
45
+ maxNeighbors?: number;
46
+ });
47
+ initialize(): Promise<void>;
48
+ protected startAnimationLoop(): void;
49
+ protected stopAnimationLoop(): void;
50
+ destroy(): Promise<void>;
51
+ setSize(width: number, height: number): void;
52
+ protected onViewChanged(): void;
53
+ setParticles(p: IParticle[]): void;
54
+ addParticle(p: IParticle): Promise<void>;
55
+ /**
56
+ * Forces GPU-to-CPU synchronization and returns current particle data.
57
+ * Use this when you need the most up-to-date particle positions from GPU.
58
+ */
59
+ getParticles(): Promise<IParticle[]>;
60
+ getParticle(index: number): Promise<IParticle>;
61
+ getCount(): number;
62
+ clear(): void;
63
+ private animate;
64
+ private waitForNextTick;
65
+ export(): Record<string, Record<string, number>>;
66
+ protected onModuleSettingsChanged(): void;
67
+ protected onClearColorChanged(): void;
68
+ protected onCellSizeChanged(): void;
69
+ protected onConstrainIterationsChanged(): void;
70
+ protected onMaxNeighborsChanged(): void;
71
+ protected onMaxParticlesChanged(): void;
72
+ }
73
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/runtimes/webgpu/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAM7D,qBAAa,YAAa,SAAQ,cAAc;IAC9C,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,OAAO,EAAE;QACnB,MAAM,EAAE,iBAAiB,CAAC;QAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,UAAU,CAAC,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;IAkBK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCjC,SAAS,CAAC,kBAAkB,IAAI,IAAI;IAQpC,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAK7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAW9B,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAa5C,SAAS,CAAC,aAAa,IAAI,IAAI;IAQ/B,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,IAAI;IAU5B,WAAW,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9C;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAKpC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAKpD,QAAQ,IAAI,MAAM;IAQlB,KAAK,IAAI,IAAI;IAUb,OAAO,CAAC,OAAO,CA2Eb;IAEF,OAAO,CAAC,eAAe;IASvB,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAUhD,SAAS,CAAC,uBAAuB,IAAI,IAAI;IAKzC,SAAS,CAAC,mBAAmB,IAAI,IAAI;IAKrC,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAenC,SAAS,CAAC,4BAA4B,IAAI,IAAI;IAK9C,SAAS,CAAC,qBAAqB,IAAI,IAAI;IAIvC,SAAS,CAAC,qBAAqB,IAAI,IAAI;CAGxC"}
@@ -0,0 +1,141 @@
1
+ import type { Program, ModuleUniformLayout } from "./builders/program";
2
+ import { ViewSnapshot } from "../../view";
3
+ export interface SceneTextures {
4
+ a: GPUTexture;
5
+ b: GPUTexture;
6
+ viewA: GPUTextureView;
7
+ viewB: GPUTextureView;
8
+ sampler: GPUSampler;
9
+ }
10
+ export type ModuleUniformBuffer = {
11
+ buffer: GPUBuffer;
12
+ layout: ModuleUniformLayout;
13
+ };
14
+ export interface SimulationPipelines {
15
+ gridClear?: GPUComputePipeline;
16
+ gridBuild?: GPUComputePipeline;
17
+ state?: GPUComputePipeline;
18
+ apply?: GPUComputePipeline;
19
+ integrate?: GPUComputePipeline;
20
+ constrain?: GPUComputePipeline;
21
+ correct?: GPUComputePipeline;
22
+ main?: GPUComputePipeline;
23
+ }
24
+ export declare class GPUResources {
25
+ private particleBuffer;
26
+ private moduleUniformBuffers;
27
+ private combinedArrayStorageBuffers;
28
+ private arrayStorageBuffers;
29
+ private arrayLengthBuffers;
30
+ private renderUniformBuffer;
31
+ private renderBindGroupLayoutCache;
32
+ private computeBindGroupLayout;
33
+ private computePipelineLayout;
34
+ private simulationPipelines;
35
+ private gridCountsBuffer;
36
+ private gridIndicesBuffer;
37
+ private simStateBuffer;
38
+ private scene;
39
+ private currentScene;
40
+ private sceneSize;
41
+ private copyPipelines;
42
+ private simUniformCache;
43
+ private fullscreenPipelines;
44
+ private imageComputePipelines;
45
+ private hashWGSL;
46
+ canvas: HTMLCanvasElement;
47
+ requiredFeatures: GPUFeatureName[];
48
+ device: GPUDevice | null;
49
+ context: GPUCanvasContext | null;
50
+ adapter: GPUAdapter | null;
51
+ format: GPUTextureFormat;
52
+ private disposePromise;
53
+ constructor(options: {
54
+ canvas: HTMLCanvasElement;
55
+ requiredFeatures?: GPUFeatureName[];
56
+ });
57
+ initialize(): Promise<void>;
58
+ /**
59
+ * Starts disposal (idempotent) and returns a promise you can await *optionally*.
60
+ * We keep the public destroy()/dispose() calls synchronous to avoid breaking runtime toggle,
61
+ * but callers that care (like runtime toggle) can await this promise.
62
+ */
63
+ isInitialized(): boolean;
64
+ getDevice(): GPUDevice;
65
+ getContext(): GPUCanvasContext;
66
+ getParticleBuffer(): GPUBuffer | null;
67
+ getModuleUniformBuffers(): ModuleUniformBuffer[];
68
+ getRenderUniformBuffer(): GPUBuffer | null;
69
+ getGridCountsBuffer(): GPUBuffer | null;
70
+ getGridIndicesBuffer(): GPUBuffer | null;
71
+ getSimStateBuffer(): GPUBuffer | null;
72
+ createParticleBuffer(maxParticles: number, floatsPerParticle: number): void;
73
+ writeParticleSlice(offsetFloats: number, data: Float32Array): void;
74
+ writeParticleBuffer(data: Float32Array): void;
75
+ /**
76
+ * Reads particle data back from GPU to CPU
77
+ */
78
+ readParticleBuffer(sizeFloats: number): Promise<Float32Array>;
79
+ createModuleUniformBuffers(layouts: ModuleUniformLayout[]): void;
80
+ createRenderUniformBuffer(byteSize: number): void;
81
+ writeRenderUniforms(snapshot: ViewSnapshot): void;
82
+ writeModuleUniform(index: number, data: ArrayBufferView, offset?: number): void;
83
+ /**
84
+ * Writes simulation uniforms (dt, count, simStride) into the internal
85
+ * 'simulation' uniform buffer using the provided Program's layout.
86
+ */
87
+ writeSimulationUniform(program: Program, values: {
88
+ dt?: number;
89
+ count?: number;
90
+ simStride?: number;
91
+ maxSize?: number;
92
+ iteration?: number;
93
+ maxNeighbors?: number;
94
+ maxParticles?: number;
95
+ }): void;
96
+ ensureSceneTextures(width: number, height: number): void;
97
+ createGridStorage(totalCells: number, maxPerCell: number): void;
98
+ createSimStateBuffer(maxParticles: number, strideFloats: number): void;
99
+ getCurrentSceneTextureView(): GPUTextureView;
100
+ getOtherSceneTextureView(): GPUTextureView;
101
+ getSceneSampler(): GPUSampler;
102
+ swapSceneTextures(): void;
103
+ getRenderBindGroupLayout(arrayInputs?: string[], fragmentParticleAccess?: boolean): GPUBindGroupLayout;
104
+ buildComputeLayouts(compute: Program): void;
105
+ getComputeBindGroupLayout(): GPUBindGroupLayout;
106
+ buildComputePipelines(code: string): void;
107
+ getSimulationPipelines(): SimulationPipelines;
108
+ getCopyPipeline(format: GPUTextureFormat): GPURenderPipeline;
109
+ getOrCreateFullscreenRenderPipeline(shaderCode: string, arrayInputs?: string[], fragmentParticleAccess?: boolean): GPURenderPipeline;
110
+ getOrCreateImageComputePipeline(shaderCode: string): GPUComputePipeline;
111
+ createFullscreenBindGroup(particleBuffer: GPUBuffer, renderUniformBuffer: GPUBuffer, readSceneView: GPUTextureView, sceneSampler: GPUSampler, moduleUniformBuffer: GPUBuffer, moduleName: string, arrayInputs?: string[], fragmentParticleAccess?: boolean): GPUBindGroup;
112
+ createComputeBindGroup(compute: Program): GPUBindGroup;
113
+ createImageComputeBindGroup(pipeline: GPUComputePipeline, readView: GPUTextureView, writeView: GPUTextureView, moduleUniformBuffer: GPUBuffer, moduleName: string, arrayInputs?: string[]): GPUBindGroup;
114
+ /**
115
+ * Create combined array storage buffer for a module's array inputs
116
+ */
117
+ createCombinedArrayStorageBuffer(moduleName: string, arrayInputs: string[]): void;
118
+ /**
119
+ * Create array storage buffers for a module's array inputs
120
+ */
121
+ createArrayStorageBuffers(moduleName: string, arrayInputs: string[]): void;
122
+ /**
123
+ * Write combined array data to storage buffer
124
+ */
125
+ writeCombinedArrayStorage(moduleName: string, arrayDataMap: Record<string, number[]>, arrayOffsets: Record<string, number>): void;
126
+ /**
127
+ * Write array data to storage buffer
128
+ */
129
+ writeArrayStorage(moduleName: string, arrayKey: string, data: number[]): void;
130
+ /**
131
+ * Get array storage buffer for a module's array input
132
+ */
133
+ getArrayStorageBuffer(moduleName: string, arrayKey: string): GPUBuffer | undefined;
134
+ /**
135
+ * Get array length buffer for a module's array input
136
+ */
137
+ getArrayLengthBuffer(moduleName: string, arrayKey: string): GPUBuffer | undefined;
138
+ dispose(): Promise<void>;
139
+ private disposeAsync;
140
+ }
141
+ //# sourceMappingURL=gpu-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-resources.d.ts","sourceRoot":"","sources":["../../../src/runtimes/webgpu/gpu-resources.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACvE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AG,SAAS;IAIxB;;OAEG;IACH,oBAAoB,CAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,SAAS,GAAG,SAAS;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAQV,YAAY;CAuE3B"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * ModuleRegistry
3
+ *
4
+ * Central registry for modules. It builds the combined WGSL Program and manages
5
+ * per-module uniform state on the CPU, mirroring it into GPU uniform buffers.
6
+ *
7
+ * Key behaviors:
8
+ * - Builds `Program` via the builders (uniform layouts + generated WGSL code)
9
+ * - Allocates module uniform buffers and seeds default CPU-side uniform values
10
+ * - Attaches uniform writers/readers to each Module instance
11
+ * - Exposes helpers to get enabled render descriptors for the render pipeline
12
+ * - Flushes uniform state to GPU upon writes and on initialization
13
+ */
14
+ import type { GPUResources } from "./gpu-resources";
15
+ import { type Program } from "./builders/program";
16
+ import { Module, type WebGPURenderDescriptor } from "../../module";
17
+ /**
18
+ * Manages module enablement/state, builds the Program, and exposes uniform writers/readers.
19
+ */
20
+ export declare class ModuleRegistry {
21
+ private readonly modules;
22
+ private program;
23
+ private moduleUniformState;
24
+ private moduleArrayState;
25
+ private nameToIndex;
26
+ private resources;
27
+ constructor(modules: readonly Module[]);
28
+ /**
29
+ * Build WGSL program and allocate per-module uniform buffers.
30
+ * Also seeds CPU-side uniform state and attaches writers/readers to modules.
31
+ */
32
+ initialize(resources: GPUResources): void;
33
+ getProgram(): Program;
34
+ /** Returns a writer for the given module name. */
35
+ getUniformWriter(name: string): (values: Partial<Record<string, number | number[]>>) => void;
36
+ /** Returns a reader for the given module name. */
37
+ getUniformReader(name: string): () => Partial<Record<string, number | number[]>>;
38
+ /** Filter enabled render module descriptors for the render pipeline. */
39
+ getEnabledRenderDescriptors(): WebGPURenderDescriptor[];
40
+ /** Get enabled render modules for the render pipeline.
41
+ * Includes any module that provides render passes in its descriptor, regardless of role.
42
+ */
43
+ getEnabledRenderModules(): Module[];
44
+ /** Get all modules. */
45
+ getModules(): readonly Module[];
46
+ /** Write the current CPU state for all module uniforms to GPU buffers. */
47
+ writeAllModuleUniforms(): void;
48
+ private readModuleUniform;
49
+ private writeModuleUniform;
50
+ private flushModuleUniform;
51
+ private getModuleIndex;
52
+ }
53
+ //# sourceMappingURL=module-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-registry.d.ts","sourceRoot":"","sources":["../../../src/runtimes/webgpu/module-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EACL,MAAM,EAEN,KAAK,sBAAsB,EAE5B,MAAM,cAAc,CAAC;AAEtB;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,kBAAkB,CAAgC;IAC1D,OAAO,CAAC,gBAAgB,CAAgD;IACxE,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,SAAS,CAA6B;gBAElC,OAAO,EAAE,SAAS,MAAM,EAAE;IAItC;;;OAGG;IACH,UAAU,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IA2DzC,UAAU,IAAI,OAAO;IAKrB,kDAAkD;IAClD,gBAAgB,CACd,IAAI,EAAE,MAAM,GACX,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI;IAI/D,kDAAkD;IAClD,gBAAgB,CACd,IAAI,EAAE,MAAM,GACX,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAInD,wEAAwE;IACxE,2BAA2B,IAAI,sBAAsB,EAAE;IAUvD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