Optimise
All checks were successful
Check & deploy / build (pull_request) Successful in 1m51s

This commit is contained in:
Andras Schmelczer 2026-05-21 20:33:49 +01:00
commit ed5a4379db
76 changed files with 1418 additions and 988 deletions

View file

@ -29,18 +29,15 @@ jobs:
npm ci npm ci
npx playwright install --with-deps chromium npx playwright install --with-deps chromium
- name: Lint
run: npm run lint:check
- name: Typecheck
run: |
npm run unused:check
npm run typecheck
npm run typecheck:e2e
- name: Test - name: Test
run: | run: |
npm run lint:check
npm run typecheck
npm run typecheck:e2e
npm test npm test
- name: Test E2E
run: |
npm run test:e2e npm run test:e2e
- name: Upload Playwright report - name: Upload Playwright report

View file

@ -9,6 +9,6 @@ Check out the [agent logic](./src/pipelines/agents/agent.wgsl).
## Testing ## Testing
- `npm test` runs the Vitest unit suite. - `npm test` runs the Vitest unit suite.
- `npm run test:e2e` builds the production bundle and runs the Playwright Chromium - `npm run test:e2e` runs the Playwright Chromium smoke test. The Playwright
smoke test. config builds the production bundle before serving it.
- `npx playwright install chromium` installs the local browser binary when needed. - `npx playwright install chromium` installs the local browser binary when needed.

View file

@ -1,7 +1,7 @@
import js from '@eslint/js'; import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettierConfig from 'eslint-config-prettier'; import prettierConfig from 'eslint-config-prettier';
import globals from 'globals'; import globals from 'globals';
import tseslint from 'typescript-eslint';
export default tseslint.config( export default tseslint.config(
{ {

View file

@ -88,14 +88,14 @@
<div class="garden-prompt" aria-live="polite"></div> <div class="garden-prompt" aria-live="polite"></div>
<div class="loading-indicator" role="status"> <div class="loading-indicator" role="status">
<div class="splash"> <div class="splash" data-visible="true">
<h1 class="splash-title">Fleeting Garden</h1> <h1 class="splash-title">Fleeting Garden</h1>
<p class="splash-description"> <p class="splash-description">
Tend it while you can. The garden returns to weather either way. Tend it while you can. The garden returns to weather either way.
</p> </p>
<button class="start-button" type="button" disabled>Start</button> <button class="start-button" type="button" disabled>Start</button>
</div> </div>
<div class="loading-bar" hidden> <div class="loading-bar" data-visible="false" aria-hidden="true" inert>
<div class="loading-status">Starting up&hellip;</div> <div class="loading-status">Starting up&hellip;</div>
<div <div
class="loading-progress" class="loading-progress"
@ -160,7 +160,7 @@
<div class="toolbar-shell"> <div class="toolbar-shell">
<section class="garden-controls" aria-label="Garden controls"> <section class="garden-controls" aria-label="Garden controls">
<div class="swatches" aria-label="Drawing colours"> <div class="swatches" role="group" aria-label="Drawing colours">
<button <button
class="color-swatch" class="color-swatch"
aria-label="Draw colour 1" aria-label="Draw colour 1"
@ -193,24 +193,21 @@
<nav class="buttons" aria-label="App controls"> <nav class="buttons" aria-label="App controls">
<button <button
class="info" class="info"
data-control="info"
aria-label="About" aria-label="About"
aria-controls="info-panel" aria-controls="info-panel"
aria-expanded="false" aria-expanded="false"
title="About" title="About"
></button> ></button>
<button <button
class="maximize-full-screen" class="full-screen-toggle"
data-control="full-screen"
aria-label="Enter fullscreen" aria-label="Enter fullscreen"
title="Enter fullscreen" title="Enter fullscreen"
></button> ></button>
<button
class="minimize-full-screen"
aria-label="Exit fullscreen"
hidden
title="Exit fullscreen"
></button>
<button <button
class="settings" class="settings"
data-control="settings"
aria-label="Show config overlay" aria-label="Show config overlay"
aria-expanded="false" aria-expanded="false"
title="Show config overlay" title="Show config overlay"
@ -218,6 +215,7 @@
<div class="audio-control"> <div class="audio-control">
<button <button
class="sound" class="sound"
data-control="sound"
aria-label="Mute audio" aria-label="Mute audio"
aria-pressed="false" aria-pressed="false"
title="Mute audio" title="Mute audio"
@ -228,12 +226,14 @@
</div> </div>
<button <button
class="export-4k" class="export-4k"
data-control="export"
aria-label="Download internal buffer snapshot" aria-label="Download internal buffer snapshot"
title="Download internal buffer snapshot" title="Download internal buffer snapshot"
></button> ></button>
<span class="export-status" aria-live="polite"></span> <span class="export-status" aria-live="polite"></span>
<button <button
class="restart" class="restart"
data-control="restart"
aria-label="Restart simulation" aria-label="Restart simulation"
title="Restart simulation" title="Restart simulation"
></button> ></button>

View file

@ -8,15 +8,15 @@
"dev": "vite --host 0.0.0.0", "dev": "vite --host 0.0.0.0",
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"lint:check": "eslint \"src/**/*.ts\" && npm run unused:check", "lint:check": "eslint . && npm run unused:check",
"lint:fix": "eslint --fix \"src/**/*.ts\"", "lint:fix": "eslint . --fix",
"format": "prettier --write \"index.html\" \"src/**/*.{ts,scss,json,html}\" \"e2e/**/*.ts\" \".forgejo/workflows/*.yml\" \"*.{json,js,ts,md}\" \".prettierrc\"", "format": "prettier --write \"index.html\" \"public/manifest.webmanifest\" \"src/**/*.{ts,scss,json,html}\" \"e2e/**/*.ts\" \".forgejo/workflows/*.yml\" \"*.{json,js,ts,md}\" \".prettierrc\"",
"format:check": "prettier --check \"index.html\" \"src/**/*.{ts,scss,json,html}\" \"e2e/**/*.ts\" \".forgejo/workflows/*.yml\" \"*.{json,js,ts,md}\" \".prettierrc\"", "format:check": "prettier --check \"index.html\" \"public/manifest.webmanifest\" \"src/**/*.{ts,scss,json,html}\" \"e2e/**/*.ts\" \".forgejo/workflows/*.yml\" \"*.{json,js,ts,md}\" \".prettierrc\"",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"typecheck:e2e": "tsc --noEmit --project tsconfig.playwright.json", "typecheck:e2e": "tsc --noEmit --project tsconfig.playwright.json",
"test": "vitest run", "test": "vitest run",
"test:e2e": "npm run build && playwright test", "test:e2e": "playwright test",
"test:e2e:ui": "npm run build && playwright test --ui", "test:e2e:ui": "playwright test --ui",
"test:watch": "vitest", "test:watch": "vitest",
"unused:check": "knip --production --files --dependencies && knip --exports --include-entry-exports", "unused:check": "knip --production --files --dependencies && knip --exports --include-entry-exports",
"generate-icons": "pwa-assets-generator" "generate-icons": "pwa-assets-generator"

View file

@ -13,6 +13,11 @@
"sizes": "any", "sizes": "any",
"type": "image/svg+xml" "type": "image/svg+xml"
}, },
{
"src": "pwa-64x64.png",
"sizes": "64x64",
"type": "image/png"
},
{ {
"src": "pwa-192x192.png", "src": "pwa-192x192.png",
"sizes": "192x192", "sizes": "192x192",

View file

@ -22,12 +22,22 @@ export interface GardenAudioVibeProfile extends GardenAudioVibeSettings {
progression: Array<GardenAudioChord>; progression: Array<GardenAudioChord>;
} }
export const defaultGardenAudioVibeSettings: GardenAudioVibeSettings = {
idleIntensity: 0.08,
bpm: 74,
rampUpIntensity: 0.85,
rampUpTime: 0.08,
noteLength: 0.42,
notePitchOffset: 0,
brightness: 1,
};
export const createGardenAudioConfig = () => ({ export const createGardenAudioConfig = () => ({
masterVolume: DEFAULT_AUDIO_VOLUME, masterVolume: DEFAULT_AUDIO_VOLUME,
fadeInSeconds: 0.45, fadeInSeconds: 0.45,
updateRampSeconds: 0.08, updateRampSeconds: 0.08,
delay: { delay: {
timeSeconds: 0.46, timeSeconds: 0.405,
feedback: 0.12, feedback: 0.12,
wetGain: 0.044, wetGain: 0.044,
erasingActivity: 0.12, erasingActivity: 0.12,
@ -43,9 +53,9 @@ export const createGardenAudioConfig = () => ({
maxVoices: 24, maxVoices: 24,
gain: 0.48, gain: 0.48,
sustainSeconds: 0.42, sustainSeconds: 0.42,
sustainLevel: 0.32, sustainLevel: 0.26,
releaseSeconds: 0.24, releaseSeconds: 0.34,
lowpassHz: 7600, lowpassHz: 7000,
gainAttackSeconds: 0.006, gainAttackSeconds: 0.006,
lowpassMaxHz: 12000, lowpassMaxHz: 12000,
lowpassMinHz: 1400, lowpassMinHz: 1400,
@ -53,8 +63,8 @@ export const createGardenAudioConfig = () => ({
sustainVelocityRange: 0.55, sustainVelocityRange: 0.55,
}, },
rhythm: { rhythm: {
idleIntensity: 0.08, idleIntensity: defaultGardenAudioVibeSettings.idleIntensity,
bpm: 74, bpm: defaultGardenAudioVibeSettings.bpm,
stepsPerBeat: 4, stepsPerBeat: 4,
stepsPerBar: 16, stepsPerBar: 16,
sparseActivity: 0.055, sparseActivity: 0.055,
@ -69,9 +79,7 @@ export const createGardenAudioConfig = () => ({
pianoActivity: 0, pianoActivity: 0,
}, },
energy: { energy: {
attackSeconds: 0.08,
decaySeconds: 0.9, decaySeconds: 0.9,
immediateActivityScale: 0.85,
releaseSeconds: 1.15, releaseSeconds: 1.15,
strokeDecaySeconds: 0.32, strokeDecaySeconds: 0.32,
}, },

View file

@ -13,7 +13,10 @@ export const getStrokeMetrics = (stroke: GardenAudioStroke): GardenAudioStrokeMe
const dy = stroke.to[1] - stroke.from[1]; const dy = stroke.to[1] - stroke.from[1];
const distancePixels = Math.hypot(dx, dy); const distancePixels = Math.hypot(dx, dy);
const elapsedSeconds = Math.max(minElapsedSeconds, stroke.elapsedSeconds ?? 0); const elapsedSeconds = Math.max(minElapsedSeconds, stroke.elapsedSeconds ?? 0);
const normalizationPixels = Math.max(1, Math.min(stroke.canvasSize[0], stroke.canvasSize[1])); const normalizationPixels = Math.max(
1,
Math.min(stroke.canvasSize[0], stroke.canvasSize[1])
);
const normalizedDistance = distancePixels / normalizationPixels; const normalizedDistance = distancePixels / normalizationPixels;
return { return {

View file

@ -260,11 +260,10 @@ export class GardenAudio {
} }
public stroke(stroke: GardenAudioStroke): void { public stroke(stroke: GardenAudioStroke): void {
if (this.lifecycle === 'destroyed' || this.isMuted) { if (this.lifecycle !== 'started' || this.isMuted) {
return; return;
} }
this.start(stroke.vibe);
const context = this.graph.context; const context = this.graph.context;
if (!context) { if (!context) {
return; return;

View file

@ -207,8 +207,8 @@ export const generativePianoTuning: GenerativePianoTuning = {
}, },
{ {
midiMin: 62, midiMin: 62,
midiMax: 81, midiMax: 78,
preferredMidi: 72, preferredMidi: 70,
pan: 0.18, pan: 0.18,
scaleDegrees: [2, 3, 4, 6], scaleDegrees: [2, 3, 4, 6],
}, },
@ -254,10 +254,10 @@ export const generativePianoTuning: GenerativePianoTuning = {
expressionMultiplier: 0.9, expressionMultiplier: 0.9,
}, },
padChord: { padChord: {
velocities: [0.052, 0.041, 0.033], velocities: [0.046, 0.036, 0.029],
expressionVelocityWeight: 0.02, expressionVelocityWeight: 0.018,
delaySend: 0.008, delaySend: 0.008,
lowpassExpressionWeight: 0.28, lowpassExpressionWeight: 0.24,
}, },
supportNote: { supportNote: {
velocityBase: 0.105, velocityBase: 0.105,
@ -316,7 +316,7 @@ export const generativePianoTuning: GenerativePianoTuning = {
brushStream: { brushStream: {
inferredManiaThreshold: 0.82, inferredManiaThreshold: 0.82,
inferredManiaRange: 0.18, inferredManiaRange: 0.18,
registerManiaShift: 0.45, registerManiaShift: 0.3,
chordToneEverySteps: 4, chordToneEverySteps: 4,
durationBaseSeconds: 0.48, durationBaseSeconds: 0.48,
durationIntensitySeconds: 0.08, durationIntensitySeconds: 0.08,
@ -329,22 +329,22 @@ export const generativePianoTuning: GenerativePianoTuning = {
delaySendMin: 0.006, delaySendMin: 0.006,
delaySendMax: 0.032, delaySendMax: 0.032,
velocityBase: 0.1, velocityBase: 0.1,
velocityIntensityWeight: 0.13, velocityIntensityWeight: 0.1,
lowpassBaseExpression: 0.39, lowpassBaseExpression: 0.39,
lowpassIntensityWeight: 0.48, lowpassIntensityWeight: 0.48,
lowpassManiaWeight: 0.18, lowpassManiaWeight: 0.18,
intenseThreshold: 0.62, intenseThreshold: 0.68,
activeThreshold: 0.34, activeThreshold: 0.34,
}, },
brushStreamEcho: { brushStreamEcho: {
maniaThreshold: 0.86, maniaThreshold: 0.92,
stepModulo: 2, stepModulo: 3,
stepRemainder: 1, stepRemainder: 1,
intensityThreshold: 0.95, intensityThreshold: 0.95,
octaveSemitones: 12, octaveSemitones: 12,
maxMidi: 88, maxMidi: 84,
velocityBase: 0.045, velocityBase: 0.035,
velocityIntensityWeight: 0.05, velocityIntensityWeight: 0.04,
durationMinSeconds: 0.11, durationMinSeconds: 0.11,
durationScale: 0.68, durationScale: 0.68,
panScale: -0.75, panScale: -0.75,
@ -361,7 +361,7 @@ export const generativePianoTuning: GenerativePianoTuning = {
lowOffset: -1, lowOffset: -1,
}, },
registerBias: { registerBias: {
maniaShiftSemitones: 4, maniaShiftSemitones: 2,
midiMin: 36, midiMin: 36,
midiMaxForMin: 86, midiMaxForMin: 86,
minimumSpan: 4, minimumSpan: 4,
@ -375,7 +375,7 @@ export const generativePianoTuning: GenerativePianoTuning = {
lowpass: { lowpass: {
midiBase: 48, midiBase: 48,
midiRange: 33, midiRange: 33,
midiLiftHz: 720, midiLiftHz: 500,
expressionBase: 0.58, expressionBase: 0.58,
expressionWeight: 0.32, expressionWeight: 0.32,
}, },
@ -396,16 +396,16 @@ export const generativePianoTuning: GenerativePianoTuning = {
strokeAccentMinSteps: 12, strokeAccentMinSteps: 12,
strokeAccentThreshold: 0.58, strokeAccentThreshold: 0.58,
maxBrushPhraseLayers: 3, maxBrushPhraseLayers: 3,
maxBrushStreamNotesPerBar: 9, maxBrushStreamNotesPerBar: 7,
brushLayerBaseSeconds: 5.5, brushLayerBaseSeconds: 5.5,
brushLayerEnergySeconds: 2.5, brushLayerEnergySeconds: 2.5,
brushLayerMinIntensity: 0.12, brushLayerMinIntensity: 0.12,
brushStreamIdleIntervalBeats: 2, brushStreamIdleIntervalBeats: 2,
brushStreamActiveIntervalBeats: 1, brushStreamActiveIntervalBeats: 1,
brushStreamIntenseIntervalBeats: 0.5, brushStreamIntenseIntervalBeats: 0.75,
brushMotifMaxSteps: 8, brushMotifMaxSteps: 8,
brushMotifCanonDelaySeconds: 0.055, brushMotifCanonDelaySeconds: 0.055,
padDurationBarScale: 0.46, padDurationBarScale: 0.82,
}; };
export const styleVoices: [ export const styleVoices: [

View file

@ -196,7 +196,8 @@ export class GenerativePianoEngine {
if ( if (
this.isWaitingForGestureAccent && this.isWaitingForGestureAccent &&
now - this.lastGestureAccentAt >= generativePianoTuning.gestureAccentMinIntervalSeconds now - this.lastGestureAccentAt >=
generativePianoTuning.gestureAccentMinIntervalSeconds
) { ) {
this.recordTouchDown({ this.recordTouchDown({
vibe, vibe,
@ -554,7 +555,9 @@ export class GenerativePianoEngine {
const chordIntervals = getChordIntervals(chord, false); const chordIntervals = getChordIntervals(chord, false);
const degrees = this.rotate( const degrees = this.rotate(
pool.scaleDegrees, pool.scaleDegrees,
Math.round(strength * generativePianoTuning.gestureAccent.rotationStrengthMultiplier) Math.round(
strength * generativePianoTuning.gestureAccent.rotationStrengthMultiplier
)
); );
const midi = this.chooseMidi( const midi = this.chooseMidi(
@ -705,7 +708,9 @@ export class GenerativePianoEngine {
); );
layer.motifOffsets.push(this.getMotifOffset(strength)); layer.motifOffsets.push(this.getMotifOffset(strength));
if (layer.motifOffsets.length > generativePianoTuning.brushMotifMaxSteps) { if (layer.motifOffsets.length > generativePianoTuning.brushMotifMaxSteps) {
layer.motifOffsets = layer.motifOffsets.slice(-generativePianoTuning.brushMotifMaxSteps); layer.motifOffsets = layer.motifOffsets.slice(
-generativePianoTuning.brushMotifMaxSteps
);
} }
} }
@ -789,7 +794,9 @@ export class GenerativePianoEngine {
const chordIntervals = getChordIntervals(chord, false); const chordIntervals = getChordIntervals(chord, false);
const rootMidi = profile.rootMidi + chord.rootOffset; const rootMidi = profile.rootMidi + chord.rootOffset;
const useChordTone = const useChordTone =
this.brushStreamNoteIndex % generativePianoTuning.brushStream.chordToneEverySteps === 0; this.brushStreamNoteIndex %
generativePianoTuning.brushStream.chordToneEverySteps ===
0;
const source = useChordTone const source = useChordTone
? { ? {
baseMidi: rootMidi, baseMidi: rootMidi,
@ -897,7 +904,8 @@ export class GenerativePianoEngine {
layer.energy * layer.energy *
this.getBrushPhraseFade(layer, startTime) * this.getBrushPhraseFade(layer, startTime) *
(generativePianoTuning.brushPhrase.layerIntensityBase + (generativePianoTuning.brushPhrase.layerIntensityBase +
layer.maniaAmount * generativePianoTuning.brushPhrase.layerIntensityManiaWeight), layer.maniaAmount *
generativePianoTuning.brushPhrase.layerIntensityManiaWeight),
})); }));
const dominant = layerStates.reduce<{ const dominant = layerStates.reduce<{
layer: BrushPhraseLayer; layer: BrushPhraseLayer;
@ -1073,7 +1081,8 @@ export class GenerativePianoEngine {
} }
return ( return (
barIndex % generativePianoTuning.supportBarSpacing === generativePianoTuning.supportBarOffset barIndex % generativePianoTuning.supportBarSpacing ===
generativePianoTuning.supportBarOffset
); );
} }
@ -1136,7 +1145,8 @@ export class GenerativePianoEngine {
): number { ): number {
const midiLift = const midiLift =
clamp01( clamp01(
(midi - generativePianoTuning.lowpass.midiBase) / generativePianoTuning.lowpass.midiRange (midi - generativePianoTuning.lowpass.midiBase) /
generativePianoTuning.lowpass.midiRange
) * generativePianoTuning.lowpass.midiLiftHz; ) * generativePianoTuning.lowpass.midiLiftHz;
return clamp( return clamp(
this.config.piano.lowpassHz * this.config.piano.lowpassHz *

View file

@ -7,8 +7,6 @@ import { getLoadedPianoSamples, loadPianoSamples } from './piano-samples';
export const PIANO_SCHEDULE_AHEAD_SECONDS = 0.002; export const PIANO_SCHEDULE_AHEAD_SECONDS = 0.002;
type PianoLoadState = 'idle' | 'loading' | 'loaded';
interface ActivePianoVoice { interface ActivePianoVoice {
gain: GainNode; gain: GainNode;
source: AudioScheduledSourceNode; source: AudioScheduledSourceNode;
@ -27,7 +25,6 @@ const pianoSamplerTuning = {
}; };
export class PianoSampler { export class PianoSampler {
private loadState: PianoLoadState = 'idle';
private samples: Array<LoadedPianoSample> = []; private samples: Array<LoadedPianoSample> = [];
private activeVoices: Array<ActivePianoVoice> = []; private activeVoices: Array<ActivePianoVoice> = [];
@ -37,27 +34,19 @@ export class PianoSampler {
) {} ) {}
public load(context: BaseAudioContext): Promise<void> { public load(context: BaseAudioContext): Promise<void> {
if (this.loadState === 'loaded') { if (this.samples.length > 0) {
return Promise.resolve(); return Promise.resolve();
} }
const loadedSamples = getLoadedPianoSamples(); const loadedSamples = getLoadedPianoSamples();
if (loadedSamples) { if (loadedSamples) {
this.setSamples(loadedSamples); this.setSamples(loadedSamples);
this.loadState = 'loaded';
return Promise.resolve(); return Promise.resolve();
} }
this.loadState = 'loading'; return loadPianoSamples(context).then((samples) => {
return loadPianoSamples(context) this.setSamples(samples);
.then((samples) => { });
this.setSamples(samples);
this.loadState = 'loaded';
})
.catch((error) => {
this.loadState = 'idle';
throw error;
});
} }
public play({ public play({
@ -154,7 +143,6 @@ export class PianoSampler {
} }
public reset(): void { public reset(): void {
this.loadState = 'idle';
this.samples = []; this.samples = [];
this.activeVoices = []; this.activeVoices = [];
} }

View file

@ -5,6 +5,11 @@ import type { GardenAppConfig } from './config/types';
import { defaultVibeId, vibePresets } from './config/vibe-presets'; import { defaultVibeId, vibePresets } from './config/vibe-presets';
import { APP_STORAGE_KEYS, DEFAULT_AUDIO_VOLUME } from './consts'; import { APP_STORAGE_KEYS, DEFAULT_AUDIO_VOLUME } from './consts';
export {
normalizeNumberControlValue,
normalizeRuntimeSettings,
} from './config/normalize-runtime-settings';
export type { export type {
GardenAppConfig, GardenAppConfig,
GardenRuntimeSettings, GardenRuntimeSettings,
@ -107,8 +112,6 @@ export const appConfig = {
stroke: { stroke: {
densityMultiplier: 110, densityMultiplier: 110,
maxAgentCount: 2_400, maxAgentCount: 2_400,
minAgentCount: 140,
minSegmentLengthPx: 1,
}, },
}, },
storage: { storage: {

View file

@ -19,7 +19,7 @@ const computeDefaultInternalRenderAreaMegapixels = (): number => {
const dpr = Math.min(Math.max(rawDpr, 1), DEFAULT_DEVICE_PIXEL_RATIO_CAP); const dpr = Math.min(Math.max(rawDpr, 1), DEFAULT_DEVICE_PIXEL_RATIO_CAP);
const cssWidth = typeof window !== 'undefined' ? window.innerWidth : 1920; const cssWidth = typeof window !== 'undefined' ? window.innerWidth : 1920;
const cssHeight = typeof window !== 'undefined' ? window.innerHeight : 1080; const cssHeight = typeof window !== 'undefined' ? window.innerHeight : 1080;
const cssMegapixels = Math.max(cssWidth, 1) * Math.max(cssHeight, 1) / 1_000_000; const cssMegapixels = (Math.max(cssWidth, 1) * Math.max(cssHeight, 1)) / 1_000_000;
return Math.min( return Math.min(
INTERNAL_RENDER_AREA_BOUNDS.max, INTERNAL_RENDER_AREA_BOUNDS.max,
Math.max(INTERNAL_RENDER_AREA_BOUNDS.min, dpr * dpr * cssMegapixels) Math.max(INTERNAL_RENDER_AREA_BOUNDS.min, dpr * dpr * cssMegapixels)

View file

@ -0,0 +1,46 @@
import type {
GardenAppConfig,
GardenRuntimeSettings,
NumberControlConfig,
} from './types';
type RuntimeSettingControls = GardenAppConfig['runtimeSettings']['controls'];
export const normalizeNumberControlValue = (
value: number,
config: NumberControlConfig
): number => {
if (config.options) {
const optionValues = Object.values(config.options);
if (optionValues.includes(value)) {
return value;
}
return optionValues.includes(0) ? 0 : (optionValues[0] ?? config.min ?? 0);
}
const min = config.min ?? Number.NEGATIVE_INFINITY;
const max = config.max ?? Number.POSITIVE_INFINITY;
const fallbackValue = config.min ?? 0;
const finiteValue = Number.isFinite(value) ? value : fallbackValue;
const clampedValue = Math.min(max, Math.max(min, finiteValue));
return config.integer ? Math.round(clampedValue) : clampedValue;
};
export const normalizeRuntimeSettings = (
settings: GardenRuntimeSettings,
controls: RuntimeSettingControls
): GardenRuntimeSettings => {
const normalized = { ...settings };
(
Object.entries(controls) as Array<
[keyof GardenRuntimeSettings, NumberControlConfig | undefined]
>
).forEach(([key, config]) => {
if (config) {
normalized[key] = normalizeNumberControlValue(normalized[key], config);
}
});
return normalized;
};

View file

@ -6,15 +6,15 @@ const formatRadiansAsDegrees = (value: number): string =>
`${Math.round((value * 180) / Math.PI)} deg`; `${Math.round((value * 180) / Math.PI)} deg`;
export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = { export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = {
color1ToColor1: colorInteractionControl('Primary Follows Primary'), color1ToColor1: colorInteractionControl('Color 1 Follows Color 1'),
color1ToColor2: colorInteractionControl('Primary Follows Secondary'), color1ToColor2: colorInteractionControl('Color 1 Follows Color 2'),
color1ToColor3: colorInteractionControl('Primary Follows Accent'), color1ToColor3: colorInteractionControl('Color 1 Follows Color 3'),
color2ToColor1: colorInteractionControl('Secondary Follows Primary'), color2ToColor1: colorInteractionControl('Color 2 Follows Color 1'),
color2ToColor2: colorInteractionControl('Secondary Follows Secondary'), color2ToColor2: colorInteractionControl('Color 2 Follows Color 2'),
color2ToColor3: colorInteractionControl('Secondary Follows Accent'), color2ToColor3: colorInteractionControl('Color 2 Follows Color 3'),
color3ToColor1: colorInteractionControl('Accent Follows Primary'), color3ToColor1: colorInteractionControl('Color 3 Follows Color 1'),
color3ToColor2: colorInteractionControl('Accent Follows Secondary'), color3ToColor2: colorInteractionControl('Color 3 Follows Color 2'),
color3ToColor3: colorInteractionControl('Accent Follows Accent'), color3ToColor3: colorInteractionControl('Color 3 Follows Color 3'),
brushSize: { brushSize: {
folder: 'Brush', folder: 'Brush',
@ -25,7 +25,7 @@ export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = {
}, },
spawnPerPixel: { spawnPerPixel: {
folder: 'Brush', folder: 'Brush',
label: 'Agent Density', label: 'Density',
min: 0.01, min: 0.01,
max: 1, max: 1,
step: 0.001, step: 0.001,
@ -39,28 +39,28 @@ export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = {
step: 0.01, step: 0.01,
}, },
sensorOffsetDistance: { sensorOffsetDistance: {
folder: 'Agents', folder: 'Movement',
label: 'Sensor Reach', label: 'Sensor Reach',
min: 0, min: 0,
max: 200, max: 200,
step: 1, step: 1,
}, },
moveSpeed: { moveSpeed: {
folder: 'Agents', folder: 'Movement',
label: 'Travel Speed', label: 'Travel Speed',
min: 10, min: 10,
max: 500, max: 500,
step: 1, step: 1,
}, },
turnSpeed: { turnSpeed: {
folder: 'Agents', folder: 'Movement',
label: 'Turning Speed', label: 'Turning Speed',
min: 1, min: 1,
max: 200, max: 200,
step: 1, step: 1,
}, },
forwardRotationScale: { forwardRotationScale: {
folder: 'Agents', folder: 'Movement',
format: formatPercent, format: formatPercent,
label: 'Forward Focus', label: 'Forward Focus',
min: 0, min: 0,
@ -68,21 +68,21 @@ export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = {
step: 0.01, step: 0.01,
}, },
turnWhenLost: { turnWhenLost: {
folder: 'Agents', folder: 'Movement',
label: 'Wander Turn', label: 'Wander Turn',
min: 0, min: 0,
max: 6.28, max: 6.28,
step: 0.01, step: 0.01,
}, },
individualTrailWeight: { individualTrailWeight: {
folder: 'Agents', folder: 'Movement',
label: 'Trail Strength', label: 'Trail Strength',
min: 0, min: 0,
max: 1, max: 1,
step: 0.001, step: 0.001,
}, },
decayRateTrails: { decayRateTrails: {
folder: 'Agents', folder: 'Movement',
label: 'Trail Fade', label: 'Trail Fade',
min: 800, min: 800,
max: 1000, max: 1000,
@ -107,7 +107,7 @@ export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = {
maxAgentCount: { maxAgentCount: {
folder: 'Performance', folder: 'Performance',
integer: true, integer: true,
label: 'Agent Limit', label: 'Population Limit',
min: 0, min: 0,
step: 10_000, step: 10_000,
}, },

View file

@ -22,6 +22,7 @@ export interface NumberControlConfig {
export type GardenRuntimeSettings = { export type GardenRuntimeSettings = {
adaptiveCapInitial: number; adaptiveCapInitial: number;
adaptiveCapMin: number; adaptiveCapMin: number;
backgroundGrainStrength: number;
brushCurveResolution: number; brushCurveResolution: number;
brushCurveMinBrushRadius: number; brushCurveMinBrushRadius: number;
brushCurveMinSegmentSpacing: number; brushCurveMinSegmentSpacing: number;
@ -70,12 +71,14 @@ type GardenDefaultSettings = Omit<
>; >;
export enum VibeId { export enum VibeId {
CandyRain = 'candy-rain', AuroraMycelium = 'aurora-mycelium',
SunlitMoss = 'sunlit-moss', EmberCircuit = 'ember-circuit',
CoralTide = 'coral-tide', VelvetObservatory = 'velvet-observatory',
MoonOrchid = 'moon-orchid', LichenSignal = 'lichen-signal',
PeachNeon = 'peach-neon', UltravioletSiren = 'ultraviolet-siren',
FrostBloom = 'frost-bloom', TidepoolLantern = 'tidepool-lantern',
PaperLanternFog = 'paper-lantern-fog',
ChromePollen = 'chrome-pollen',
} }
export interface VibePreset { export interface VibePreset {
@ -181,8 +184,6 @@ export interface GardenAppConfig {
stroke: { stroke: {
densityMultiplier: number; densityMultiplier: number;
maxAgentCount: number; maxAgentCount: number;
minAgentCount: number;
minSegmentLengthPx: number;
}; };
}; };
storage: { storage: {

View file

@ -1,166 +1,255 @@
import type { GardenAudioVibeSettings } from '../audio/garden-audio-config'; import { defaultGardenAudioVibeSettings } from '../audio/garden-audio-config';
import { VibeId, type VibePreset } from './types'; import { VibeId, type VibePreset } from './types';
const defaultAudioSettings = { export const defaultVibeId = VibeId.AuroraMycelium;
idleIntensity: 0.08,
bpm: 74,
rampUpIntensity: 0.85,
rampUpTime: 0.08,
noteLength: 0.42,
notePitchOffset: 0,
} satisfies Omit<GardenAudioVibeSettings, 'brightness'>;
export const defaultVibeId = VibeId.CandyRain;
export const vibePresets: Array<VibePreset> = [ export const vibePresets: Array<VibePreset> = [
{ {
id: VibeId.CandyRain, id: VibeId.AuroraMycelium,
name: 'Candy Rain', name: 'Aurora Mycelium',
colors: [ colors: [
[255, 93, 162], [78, 255, 176],
[54, 215, 208], [154, 99, 255],
[255, 216, 77], [169, 238, 255],
], ],
backgroundColor: [16, 21, 31], backgroundColor: [6, 13, 22],
settings: { settings: {
backgroundGrainStrength: 0.018, backgroundGrainStrength: 0.016,
brushSize: 14, brushSize: 20,
clarity: 0.62, clarity: 0.52,
decayRateTrails: 965, decayRateTrails: 988,
individualTrailWeight: 0.07, individualTrailWeight: 0.085,
moveSpeed: 82, moveSpeed: 54,
sensorOffsetDistance: 38, sensorOffsetDistance: 72,
spawnPerPixel: 0.22, spawnPerPixel: 0.13,
turnSpeed: 58, turnSpeed: 35,
}, },
audio: { audio: {
...defaultAudioSettings, ...defaultGardenAudioVibeSettings,
brightness: 1.04, idleIntensity: 0.12,
bpm: 60,
rampUpIntensity: 0.7,
rampUpTime: 0.14,
noteLength: 0.86,
notePitchOffset: -2,
brightness: 0.84,
}, },
}, },
{ {
id: VibeId.SunlitMoss, id: VibeId.EmberCircuit,
name: 'Sunlit Moss', name: 'Ember Circuit',
colors: [ colors: [
[131, 212, 131], [255, 95, 38],
[246, 215, 107], [255, 43, 132],
[94, 193, 161], [43, 219, 255],
], ],
backgroundColor: [23, 32, 22], backgroundColor: [17, 10, 8],
settings: { settings: {
backgroundGrainStrength: 0.014, backgroundGrainStrength: 0.03,
brushSize: 16, brushSize: 8,
clarity: 0.68, clarity: 0.82,
decayRateTrails: 975, decayRateTrails: 918,
individualTrailWeight: 0.06, individualTrailWeight: 0.04,
moveSpeed: 70, moveSpeed: 150,
sensorOffsetDistance: 46, sensorOffsetDistance: 24,
spawnPerPixel: 0.18, spawnPerPixel: 0.31,
turnSpeed: 44, turnSpeed: 130,
}, },
audio: { audio: {
...defaultAudioSettings, ...defaultGardenAudioVibeSettings,
brightness: 0.92, idleIntensity: 0.03,
bpm: 124,
rampUpIntensity: 1.35,
rampUpTime: 0.04,
noteLength: 0.18,
notePitchOffset: 7,
brightness: 1.34,
}, },
}, },
{ {
id: VibeId.CoralTide, id: VibeId.VelvetObservatory,
name: 'Coral Tide', name: 'Velvet Observatory',
colors: [ colors: [
[255, 127, 110], [72, 98, 255],
[64, 184, 255], [255, 89, 176],
[244, 240, 166], [235, 236, 255],
], ],
backgroundColor: [15, 24, 34], backgroundColor: [7, 8, 20],
settings: { settings: {
backgroundGrainStrength: 0.022, backgroundGrainStrength: 0.01,
brushSize: 13, brushSize: 24,
clarity: 0.58, clarity: 0.45,
decayRateTrails: 955, decayRateTrails: 992,
individualTrailWeight: 0.055, individualTrailWeight: 0.095,
moveSpeed: 90, moveSpeed: 45,
sensorOffsetDistance: 35, sensorOffsetDistance: 86,
spawnPerPixel: 0.25, spawnPerPixel: 0.1,
turnSpeed: 62, turnSpeed: 24,
}, },
audio: { audio: {
...defaultAudioSettings, ...defaultGardenAudioVibeSettings,
brightness: 1, idleIntensity: 0.14,
bpm: 56,
rampUpIntensity: 0.6,
rampUpTime: 0.16,
noteLength: 1.15,
notePitchOffset: -5,
brightness: 0.72,
}, },
}, },
{ {
id: VibeId.MoonOrchid, id: VibeId.LichenSignal,
name: 'Moon Orchid', name: 'Lichen Signal',
colors: [ colors: [
[201, 147, 255], [174, 205, 91],
[125, 216, 255], [71, 162, 126],
[240, 244, 255], [229, 117, 71],
], ],
backgroundColor: [20, 18, 29], backgroundColor: [18, 24, 17],
settings: { settings: {
backgroundGrainStrength: 0.018, backgroundGrainStrength: 0.028,
brushSize: 12, brushSize: 17,
clarity: 0.64, clarity: 0.66,
decayRateTrails: 968, decayRateTrails: 974,
individualTrailWeight: 0.065, individualTrailWeight: 0.065,
moveSpeed: 76, moveSpeed: 68,
sensorOffsetDistance: 42, sensorOffsetDistance: 52,
spawnPerPixel: 0.2, spawnPerPixel: 0.19,
turnSpeed: 52, turnSpeed: 38,
}, },
audio: { audio: {
...defaultAudioSettings, ...defaultGardenAudioVibeSettings,
brightness: 0.9, idleIntensity: 0.1,
bpm: 68,
rampUpIntensity: 0.8,
rampUpTime: 0.1,
noteLength: 0.62,
notePitchOffset: -3,
brightness: 0.82,
}, },
}, },
{ {
id: VibeId.PeachNeon, id: VibeId.UltravioletSiren,
name: 'Peach Neon', name: 'Ultraviolet Siren',
colors: [ colors: [
[255, 155, 115], [184, 75, 255],
[91, 240, 169], [0, 224, 255],
[110, 168, 255], [214, 255, 72],
], ],
backgroundColor: [25, 23, 22], backgroundColor: [13, 9, 31],
settings: { settings: {
backgroundGrainStrength: 0.024, backgroundGrainStrength: 0.02,
brushSize: 15, brushSize: 11,
clarity: 0.55, clarity: 0.72,
decayRateTrails: 948, decayRateTrails: 946,
individualTrailWeight: 0.05, individualTrailWeight: 0.052,
moveSpeed: 96, moveSpeed: 118,
sensorOffsetDistance: 32, sensorOffsetDistance: 30,
spawnPerPixel: 0.24, spawnPerPixel: 0.28,
turnSpeed: 70, turnSpeed: 96,
}, },
audio: { audio: {
...defaultAudioSettings, ...defaultGardenAudioVibeSettings,
brightness: 1.08, idleIntensity: 0.04,
bpm: 112,
rampUpIntensity: 1.2,
rampUpTime: 0.05,
noteLength: 0.25,
notePitchOffset: 5,
brightness: 1.22,
}, },
}, },
{ {
id: VibeId.FrostBloom, id: VibeId.TidepoolLantern,
name: 'Frost Bloom', name: 'Tidepool Lantern',
colors: [ colors: [
[180, 247, 255], [30, 219, 194],
[158, 200, 255], [61, 118, 255],
[255, 184, 210], [255, 191, 91],
], ],
backgroundColor: [16, 24, 32], backgroundColor: [5, 20, 28],
settings: {
backgroundGrainStrength: 0.018,
brushSize: 15,
clarity: 0.6,
decayRateTrails: 963,
individualTrailWeight: 0.058,
moveSpeed: 88,
sensorOffsetDistance: 44,
spawnPerPixel: 0.22,
turnSpeed: 60,
},
audio: {
...defaultGardenAudioVibeSettings,
idleIntensity: 0.08,
bpm: 82,
rampUpIntensity: 0.95,
rampUpTime: 0.08,
noteLength: 0.48,
notePitchOffset: 0,
brightness: 0.98,
},
},
{
id: VibeId.PaperLanternFog,
name: 'Paper Lantern Fog',
colors: [
[255, 174, 104],
[242, 102, 107],
[132, 211, 185],
],
backgroundColor: [31, 23, 20],
settings: {
backgroundGrainStrength: 0.036,
brushSize: 22,
clarity: 0.5,
decayRateTrails: 984,
individualTrailWeight: 0.08,
moveSpeed: 56,
sensorOffsetDistance: 64,
spawnPerPixel: 0.14,
turnSpeed: 32,
},
audio: {
...defaultGardenAudioVibeSettings,
idleIntensity: 0.13,
bpm: 64,
rampUpIntensity: 0.72,
rampUpTime: 0.12,
noteLength: 0.9,
notePitchOffset: -4,
brightness: 0.76,
},
},
{
id: VibeId.ChromePollen,
name: 'Chrome Pollen',
colors: [
[235, 255, 238],
[255, 214, 48],
[77, 240, 157],
],
backgroundColor: [9, 13, 12],
settings: { settings: {
backgroundGrainStrength: 0.012, backgroundGrainStrength: 0.012,
brushSize: 18, brushSize: 10,
clarity: 0.7, clarity: 0.9,
decayRateTrails: 982, decayRateTrails: 935,
individualTrailWeight: 0.075, individualTrailWeight: 0.045,
moveSpeed: 62, moveSpeed: 104,
sensorOffsetDistance: 52, sensorOffsetDistance: 36,
spawnPerPixel: 0.16, spawnPerPixel: 0.24,
turnSpeed: 40, turnSpeed: 78,
}, },
audio: { audio: {
...defaultAudioSettings, ...defaultGardenAudioVibeSettings,
brightness: 0.88, idleIntensity: 0.05,
bpm: 96,
rampUpIntensity: 1.05,
rampUpTime: 0.07,
noteLength: 0.3,
notePitchOffset: 3,
brightness: 1.18,
}, },
}, },
]; ];

View file

@ -1,9 +1,6 @@
export const ENABLED_FLAG_VALUE = '1'; export const ENABLED_FLAG_VALUE = '1';
export const DISABLED_FLAG_VALUE = '0'; export const DISABLED_FLAG_VALUE = '0';
export const UNIT_INTERVAL_INPUT_MIN = '0';
export const UNIT_INTERVAL_INPUT_MAX = '1';
export const DEFAULT_AUDIO_VOLUME = 0.5; export const DEFAULT_AUDIO_VOLUME = 0.5;
export const APP_STORAGE_KEYS = { export const APP_STORAGE_KEYS = {

View file

@ -0,0 +1,166 @@
import { vec2 } from 'gl-matrix';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { appConfig } from '../config';
import { type AgentGenerationPipeline } from '../pipelines/agents/agent-generation/agent-generation-pipeline';
import { AGENT_FLOAT_COUNT } from '../pipelines/agents/agent-limits';
import { settings } from '../settings';
import { AgentPopulation } from './agent-population';
import { type FramePerformance } from './frame-performance';
const originalSettings = {
brushSize: settings.brushSize,
maxAgentCount: settings.maxAgentCount,
selectedColorIndex: settings.selectedColorIndex,
spawnPerPixel: settings.spawnPerPixel,
strokeAngleJitterRadians: settings.strokeAngleJitterRadians,
};
class RecordingAgentGenerationPipeline {
public readonly writtenAgentCounts: Array<number> = [];
public readonly writtenAgentOffsets: Array<number> = [];
public readonly writtenBatches: Array<Float32Array> = [];
public readonly maxSupportedAgentCount = 1_000_000;
public maxAgentCount = 1_000_000;
private compactResolver: ((compactedAgentCount: number) => void) | null = null;
public ensureMaxAgentCount(requestedMaxAgentCount: number): number {
this.maxAgentCount = Math.max(this.maxAgentCount, requestedMaxAgentCount);
return this.maxAgentCount;
}
public writeAgents(agentOffset: number, data: Float32Array): void {
this.writtenAgentOffsets.push(agentOffset);
this.writtenAgentCounts.push(data.length / AGENT_FLOAT_COUNT);
this.writtenBatches.push(data.slice());
}
public compactAgents(): Promise<number> {
return new Promise((resolve) => {
this.compactResolver = resolve;
});
}
public finishCompaction(compactedAgentCount: number): void {
this.compactResolver?.(compactedAgentCount);
this.compactResolver = null;
}
}
const framePerformance = {
adaptiveCapDecreaseAgents: 0,
adaptiveCapInitial: 1_000_000,
adaptiveCapMin: 0,
hasAdaptiveCapHeadroom: true,
} as FramePerformance;
const createPopulation = (): {
pipeline: RecordingAgentGenerationPipeline;
population: AgentPopulation;
} => {
const pipeline = new RecordingAgentGenerationPipeline();
const population = new AgentPopulation(
pipeline as unknown as AgentGenerationPipeline,
0,
() => 1,
framePerformance
);
population.beginStroke();
return { pipeline, population };
};
const setSpawnRate = (agentsPerPixel: number): void => {
settings.spawnPerPixel = agentsPerPixel / appConfig.simulation.stroke.densityMultiplier;
};
describe('AgentPopulation stroke spawning', () => {
beforeEach(() => {
settings.brushSize = 0;
settings.maxAgentCount = 1_000_000;
settings.selectedColorIndex = 0;
settings.strokeAngleJitterRadians = 0;
setSpawnRate(1);
});
afterEach(() => {
Object.assign(settings, originalSettings);
});
it('spawns the same count for the same stroke length regardless of segmentation', () => {
const segmented = createPopulation();
for (let x = 0; x < 10; x++) {
segmented.population.spawnStrokeAgents(
vec2.fromValues(x, 0),
vec2.fromValues(x + 1, 0)
);
}
const singleSegment = createPopulation();
singleSegment.population.spawnStrokeAgents(
vec2.fromValues(0, 0),
vec2.fromValues(10, 0)
);
expect(segmented.population.activeAgentCount).toBe(10);
expect(singleSegment.population.activeAgentCount).toBe(10);
});
it('carries fractional spawn budget within a stroke', () => {
setSpawnRate(0.5);
const { population } = createPopulation();
population.spawnStrokeAgents(vec2.fromValues(0, 0), vec2.fromValues(1, 0));
expect(population.activeAgentCount).toBe(0);
population.spawnStrokeAgents(vec2.fromValues(1, 0), vec2.fromValues(2, 0));
expect(population.activeAgentCount).toBe(1);
population.spawnStrokeAgents(vec2.fromValues(2, 0), vec2.fromValues(3, 0));
expect(population.activeAgentCount).toBe(1);
population.spawnStrokeAgents(vec2.fromValues(3, 0), vec2.fromValues(4, 0));
expect(population.activeAgentCount).toBe(2);
});
it('chunks long stroke writes without clipping length-linear spawn counts', () => {
const { pipeline, population } = createPopulation();
const batchCapacity = appConfig.simulation.stroke.maxAgentCount;
const expectedAgentCount = batchCapacity + 10;
population.spawnStrokeAgents(
vec2.fromValues(0, 0),
vec2.fromValues(expectedAgentCount, 0)
);
expect(population.activeAgentCount).toBe(expectedAgentCount);
expect(pipeline.writtenAgentCounts).toEqual([batchCapacity, 10]);
});
it('spawns agents in the movement direction', () => {
const { pipeline, population } = createPopulation();
population.spawnStrokeAgents(vec2.fromValues(0, 0), vec2.fromValues(3, 0));
expect(population.activeAgentCount).toBe(3);
expect(pipeline.writtenBatches[0][2]).toBe(0);
});
it('queues stroke writes while async compaction is in flight', async () => {
const { pipeline, population } = createPopulation();
population.spawnStrokeAgents(vec2.fromValues(0, 0), vec2.fromValues(10, 0));
population.requestCompactionAfterErase();
population.compactAfterErase(false);
population.spawnStrokeAgents(vec2.fromValues(10, 0), vec2.fromValues(15, 0));
expect(population.activeAgentCount).toBe(10);
expect(pipeline.writtenAgentCounts).toEqual([10]);
pipeline.finishCompaction(6);
await population.waitForCompaction();
expect(population.activeAgentCount).toBe(11);
expect(pipeline.writtenAgentOffsets).toEqual([0, 6]);
expect(pipeline.writtenAgentCounts).toEqual([10, 5]);
});
});

Some files were not shown because too many files have changed in this diff Show more