Files
feuerwerk/src/viewport/ParticleLibrary.ts
T
adminandClaude Fable 5.1 cc6db5f350
game-maker / gate (push) Successful in 1m33s
game-maker / suite (push) Successful in 5m46s
Three stores, three importers and three pickers that differ only in their type are one of each (#85)
Refactoring round one: HttpFontStore/HttpSoundStore/HttpTextureStore collapse into a generic
HttpFileStore over a FileStore contract; fontImport/soundImport/textureImport share assetImport
with an ImportKind per sort; ImagePicker/FontPicker/SoundPicker sit on FilePicker and describe
only their row. The group/comment drag logic leaves GraphCanvas for annotationDrag.ts (with its
own unit test), declaredRows.ts replaces the duplicated row build in particles.ts and shaders.ts,
and dead code in font/sound/compile/emission/transform/actions is gone. README: asset list,
check count 958, the two-job CI, the Scenes wiki page.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:38:54 +02:00

38 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { ParticlesAsset } from '../core/model/Asset';
import { graphFingerprint } from '../core/graph/Graph';
import { compileParticles, type ParticlesBuild } from '../core/particles/compile';
import { gameClock } from '../core/time';
/**
* Compiled particle graphs, one per asset, recompiled when the graph's content changes – the same
* contract the `ShaderLibrary` keeps, including its own freeze so a test can hold particle time
* still without freezing the shaders too.
*/
export class ParticleLibrary {
private readonly builds = new Map<string, { fingerprint: string; build: ParticlesBuild }>();
/** How often a graph went through the compiler – what the checks read to prove a move did not. */
compiles = 0;
private frozenAt: number | null = null;
/** The clock every source's age is measured on: the global one, so a pause reaches the fields. */
now(): number {
return this.frozenAt ?? gameClock.now;
}
freezeTime(at: number | null): void {
this.frozenAt = at;
}
buildFor(asset: ParticlesAsset): ParticlesBuild {
const fingerprint = graphFingerprint(asset.graph);
const cached = this.builds.get(asset.id);
if (cached && cached.fingerprint === fingerprint) return cached.build;
this.compiles += 1;
const build = compileParticles(asset.graph);
this.builds.set(asset.id, { fingerprint, build });
return build;
}
}
export const particleLibrary = new ParticleLibrary();