create-threenative 0.2.7 → 0.2.8
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.
- package/README.md +3 -1
- package/agent-docs/references/capability-reference.md +177 -7
- package/capabilities.json +247 -4
- package/dist/index.js +6 -1
- package/dist/threenative.js +3 -2
- package/package.json +4 -4
- package/templates/action-rpg/package.json +1 -1
- package/templates/minimal/package.json +1 -1
- package/templates/platformer/package.json +1 -1
- package/templates/puzzle/package.json +1 -1
- package/templates/racing/package.json +1 -1
- package/templates/rain/.codex/config.toml +19 -0
- package/templates/rain/.cursor/mcp.json +32 -0
- package/templates/rain/.gemini/settings.json +32 -0
- package/templates/rain/.mcp.json +32 -0
- package/templates/rain/.vscode/mcp.json +36 -0
- package/templates/rain/.zed/settings.json +36 -0
- package/templates/rain/AGENTS.md +96 -0
- package/templates/rain/CLAUDE.md +98 -0
- package/templates/rain/assets/rain-loop.wav +0 -0
- package/templates/rain/assets/thunder.wav +0 -0
- package/templates/rain/assets/wind-loop.wav +0 -0
- package/templates/rain/index.html +18 -0
- package/templates/rain/kit.json +7 -0
- package/templates/rain/native-playtests/boot.playtest.json +13 -0
- package/templates/rain/native-playtests/lightning.playtest.json +173 -0
- package/templates/rain/opencode.json +41 -0
- package/templates/rain/package.json +56 -0
- package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
- package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
- package/templates/rain/playtests/automation.playtest.json +133 -0
- package/templates/rain/playtests/cinematic.playtest.json +59 -0
- package/templates/rain/playtests/flash.playtest.json +27 -0
- package/templates/rain/playtests/fly.playtest.json +54 -0
- package/templates/rain/playtests/lightning.playtest.json +220 -0
- package/templates/rain/playtests/loading.playtest.json +57 -0
- package/templates/rain/playtests/paused.playtest.json +59 -0
- package/templates/rain/playtests/performance.playtest.json +22 -0
- package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
- package/templates/rain/playtests/simulation.playtest.json +20 -0
- package/templates/rain/playtests/storm.playtest.json +150 -0
- package/templates/rain/playtests/survives.playtest.json +58 -0
- package/templates/rain/playtests/tiers.playtest.json +179 -0
- package/templates/rain/playtests/weather.playtest.json +77 -0
- package/templates/rain/public/favicon.svg +5 -0
- package/templates/rain/src/audio/storm.ts +314 -0
- package/templates/rain/src/game.ts +114 -0
- package/templates/rain/src/main.ts +15 -0
- package/templates/rain/src/render/bloom-shader.ts +65 -0
- package/templates/rain/src/render/camera.ts +160 -0
- package/templates/rain/src/render/clouds-shader.ts +242 -0
- package/templates/rain/src/render/clouds.ts +142 -0
- package/templates/rain/src/render/lighting.ts +39 -0
- package/templates/rain/src/render/lightning.ts +360 -0
- package/templates/rain/src/render/loading.ts +327 -0
- package/templates/rain/src/render/materials.ts +19 -0
- package/templates/rain/src/render/noise-volume.ts +159 -0
- package/templates/rain/src/render/palette.ts +18 -0
- package/templates/rain/src/render/post-shader.ts +178 -0
- package/templates/rain/src/render/postprocessing.ts +226 -0
- package/templates/rain/src/render/quality.ts +135 -0
- package/templates/rain/src/render/rain.ts +299 -0
- package/templates/rain/src/render/sky.ts +28 -0
- package/templates/rain/src/render/world-shader.ts +680 -0
- package/templates/rain/src/render/world.ts +146 -0
- package/templates/rain/src/render/worldEnvironment.ts +809 -0
- package/templates/rain/src/scenes/Boot.ts +334 -0
- package/templates/rain/src/state.ts +257 -0
- package/templates/rain/src/style.css +1160 -0
- package/templates/rain/src/ui/App.tsx +29 -0
- package/templates/rain/src/ui/GameUi.tsx +187 -0
- package/templates/rain/src/ui/Hud.tsx +327 -0
- package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
- package/templates/rain/src/ui/Menu.tsx +370 -0
- package/templates/rain/src/ui/automation.ts +60 -0
- package/templates/rain/src/ui/main.tsx +7 -0
- package/templates/rain/src/ui/tempest.ts +149 -0
- package/templates/rain/tailwind.config.ts +2 -0
- package/templates/rain/threenative.config.ts +66 -0
- package/templates/rain/tools/generate-shaders.mjs +656 -0
- package/templates/rain/tools/make-storm-audio.mjs +387 -0
- package/templates/rain/tools/storm-dsp.mjs +177 -0
- package/templates/rain/tools/tempest-bloom.frag +10 -0
- package/templates/rain/tools/tempest-clouds.frag +86 -0
- package/templates/rain/tools/tempest-post.frag +47 -0
- package/templates/rain/tools/tempest-world.frag +210 -0
- package/templates/rain/tools/verify-noise-volume.mjs +61 -0
- package/templates/rain/tsconfig.json +17 -0
- package/templates/rain/vite.config.ts +37 -0
- package/templates/rts/package.json +1 -1
- package/templates/runner/package.json +1 -1
- package/templates/sailing/package.json +1 -1
- package/templates/shooter/package.json +1 -1
- package/templates/snow/.codex/config.toml +19 -0
- package/templates/snow/.cursor/mcp.json +32 -0
- package/templates/snow/.gemini/settings.json +32 -0
- package/templates/snow/.mcp.json +32 -0
- package/templates/snow/.vscode/mcp.json +36 -0
- package/templates/snow/.zed/settings.json +36 -0
- package/templates/snow/AGENTS.md +88 -0
- package/templates/snow/CLAUDE.md +90 -0
- package/templates/snow/README.md +26 -0
- package/templates/snow/assets/crunch.wav +0 -0
- package/templates/snow/assets/wind.wav +0 -0
- package/templates/snow/index.html +12 -0
- package/templates/snow/kit.json +7 -0
- package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
- package/templates/snow/native-playtests/survives.playtest.json +47 -0
- package/templates/snow/opencode.json +41 -0
- package/templates/snow/package.json +58 -0
- package/templates/snow/playtests/footsteps.playtest.json +95 -0
- package/templates/snow/playtests/performance.playtest.json +36 -0
- package/templates/snow/playtests/snow-physics.playtest.json +154 -0
- package/templates/snow/playtests/survives.playtest.json +56 -0
- package/templates/snow/playtests/touch-controls.playtest.json +71 -0
- package/templates/snow/playtests/weather.playtest.json +119 -0
- package/templates/snow/public/favicon.svg +5 -0
- package/templates/snow/src/audio.ts +58 -0
- package/templates/snow/src/commands.ts +8 -0
- package/templates/snow/src/entities/Explorer.ts +279 -0
- package/templates/snow/src/game.ts +69 -0
- package/templates/snow/src/main.ts +15 -0
- package/templates/snow/src/render/bootPrint.ts +50 -0
- package/templates/snow/src/render/camera.ts +84 -0
- package/templates/snow/src/render/explorer.ts +321 -0
- package/templates/snow/src/render/lighting.ts +50 -0
- package/templates/snow/src/render/loading.ts +325 -0
- package/templates/snow/src/render/materials.ts +36 -0
- package/templates/snow/src/render/palette.ts +17 -0
- package/templates/snow/src/render/postprocessing.ts +44 -0
- package/templates/snow/src/render/props.ts +42 -0
- package/templates/snow/src/render/quality.ts +135 -0
- package/templates/snow/src/render/scenery.ts +244 -0
- package/templates/snow/src/render/sky.ts +57 -0
- package/templates/snow/src/render/snowSurface.ts +259 -0
- package/templates/snow/src/render/touch-controls.ts +143 -0
- package/templates/snow/src/render/weather.ts +279 -0
- package/templates/snow/src/render/worldEnvironment.ts +809 -0
- package/templates/snow/src/scenes/Boot.ts +12 -0
- package/templates/snow/src/scenes/Snow.ts +635 -0
- package/templates/snow/src/state.ts +46 -0
- package/templates/snow/src/style.css +143 -0
- package/templates/snow/src/terrain.ts +64 -0
- package/templates/snow/src/ui/App.tsx +15 -0
- package/templates/snow/src/ui/Controls.tsx +322 -0
- package/templates/snow/src/ui/GameUi.tsx +354 -0
- package/templates/snow/src/ui/icons.tsx +54 -0
- package/templates/snow/src/ui/main.tsx +7 -0
- package/templates/snow/tailwind.config.ts +2 -0
- package/templates/snow/threenative.config.ts +51 -0
- package/templates/snow/tsconfig.json +17 -0
- package/templates/snow/vite.config.ts +37 -0
- package/templates/starter/package.json +1 -1
- package/templates/tower-defense/package.json +1 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rain-four-tiers-render-the-storm",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"target": "web",
|
|
5
|
+
"viewport": {
|
|
6
|
+
"width": 1440,
|
|
7
|
+
"height": 900
|
|
8
|
+
},
|
|
9
|
+
"warmupFrames": 30,
|
|
10
|
+
"artifacts": {
|
|
11
|
+
"screenshots": "before-after"
|
|
12
|
+
},
|
|
13
|
+
"steps": [
|
|
14
|
+
{
|
|
15
|
+
"kind": "wait",
|
|
16
|
+
"label": "high",
|
|
17
|
+
"waitTicks": 30,
|
|
18
|
+
"screenshot": "tier-high",
|
|
19
|
+
"release": true
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"kind": "click",
|
|
23
|
+
"at": {
|
|
24
|
+
"element": {
|
|
25
|
+
"id": "quality"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"waitTicks": 2,
|
|
29
|
+
"release": true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"kind": "input",
|
|
33
|
+
"press": "Escape",
|
|
34
|
+
"waitTicks": 2,
|
|
35
|
+
"release": true
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"kind": "input",
|
|
39
|
+
"press": "ArrowUp",
|
|
40
|
+
"waitTicks": 10,
|
|
41
|
+
"release": true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"kind": "wait",
|
|
45
|
+
"label": "balanced",
|
|
46
|
+
"waitTicks": 20,
|
|
47
|
+
"screenshot": "tier-balanced",
|
|
48
|
+
"release": true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"kind": "input",
|
|
52
|
+
"press": "ArrowUp",
|
|
53
|
+
"waitTicks": 10,
|
|
54
|
+
"release": true
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"kind": "wait",
|
|
58
|
+
"label": "performance",
|
|
59
|
+
"waitTicks": 20,
|
|
60
|
+
"screenshot": "tier-low",
|
|
61
|
+
"release": true
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"kind": "input",
|
|
65
|
+
"press": "ArrowDown",
|
|
66
|
+
"waitTicks": 2,
|
|
67
|
+
"release": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"kind": "input",
|
|
71
|
+
"press": "ArrowDown",
|
|
72
|
+
"waitTicks": 2,
|
|
73
|
+
"release": true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"kind": "input",
|
|
77
|
+
"press": "ArrowDown",
|
|
78
|
+
"waitTicks": 10,
|
|
79
|
+
"release": true
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"kind": "wait",
|
|
83
|
+
"label": "ultra",
|
|
84
|
+
"waitTicks": 20,
|
|
85
|
+
"screenshot": "tier-ultra",
|
|
86
|
+
"release": true
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"assert": {
|
|
90
|
+
"diagnostics": {
|
|
91
|
+
"noConsoleErrors": true,
|
|
92
|
+
"noNetworkErrors": true,
|
|
93
|
+
"noRuntimeDiagnostics": true,
|
|
94
|
+
"runtimeReady": true
|
|
95
|
+
},
|
|
96
|
+
"resources": [
|
|
97
|
+
{
|
|
98
|
+
"id": "state",
|
|
99
|
+
"path": "quality",
|
|
100
|
+
"atSteps": [
|
|
101
|
+
{
|
|
102
|
+
"equals": "high",
|
|
103
|
+
"label": "high"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"equals": "balanced",
|
|
107
|
+
"label": "balanced"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"equals": "performance",
|
|
111
|
+
"label": "performance"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"equals": "ultra",
|
|
115
|
+
"label": "ultra"
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
"equals": "ultra"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"id": "state",
|
|
122
|
+
"path": "cloudPass.steps",
|
|
123
|
+
"atSteps": [
|
|
124
|
+
{
|
|
125
|
+
"equals": 64,
|
|
126
|
+
"label": "high"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"equals": 48,
|
|
130
|
+
"label": "balanced"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"equals": 32,
|
|
134
|
+
"label": "performance"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"equals": 88,
|
|
138
|
+
"label": "ultra"
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"equals": 88
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"id": "state",
|
|
145
|
+
"path": "dropCount",
|
|
146
|
+
"atSteps": [
|
|
147
|
+
{
|
|
148
|
+
"equals": 9120,
|
|
149
|
+
"label": "high"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"equals": 9120,
|
|
153
|
+
"label": "balanced"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"equals": 4940,
|
|
157
|
+
"label": "performance"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"equals": 12160,
|
|
161
|
+
"label": "ultra"
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"equals": 12160
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
"visual": [
|
|
168
|
+
{
|
|
169
|
+
"region": {
|
|
170
|
+
"x": 0,
|
|
171
|
+
"y": 0,
|
|
172
|
+
"width": 1440,
|
|
173
|
+
"height": 900,
|
|
174
|
+
"minNonblankPixelRatio": 0.01
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rain-drizzle-control-changes-the-rendered-weather",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"target": "web",
|
|
5
|
+
"viewport": {
|
|
6
|
+
"width": 1280,
|
|
7
|
+
"height": 720
|
|
8
|
+
},
|
|
9
|
+
"warmupFrames": 60,
|
|
10
|
+
"artifacts": {
|
|
11
|
+
"screenshots": "both"
|
|
12
|
+
},
|
|
13
|
+
"steps": [
|
|
14
|
+
{
|
|
15
|
+
"kind": "click",
|
|
16
|
+
"at": {
|
|
17
|
+
"element": {
|
|
18
|
+
"id": "preset-drizzle"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"release": true
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"kind": "wait",
|
|
25
|
+
"waitTicks": 180,
|
|
26
|
+
"release": true
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"assert": {
|
|
30
|
+
"diagnostics": {
|
|
31
|
+
"noConsoleErrors": true,
|
|
32
|
+
"noNetworkErrors": true,
|
|
33
|
+
"noRuntimeDiagnostics": true,
|
|
34
|
+
"runtimeReady": true
|
|
35
|
+
},
|
|
36
|
+
"resources": [
|
|
37
|
+
{
|
|
38
|
+
"id": "state",
|
|
39
|
+
"path": "preset",
|
|
40
|
+
"equals": "drizzle"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "state",
|
|
44
|
+
"path": "target.rain",
|
|
45
|
+
"equals": 0.24
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": "state",
|
|
49
|
+
"path": "weather.rain",
|
|
50
|
+
"changed": true,
|
|
51
|
+
"lte": 0.32
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "state",
|
|
55
|
+
"path": "dropCount",
|
|
56
|
+
"changed": true,
|
|
57
|
+
"lte": 4000
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"visual": [
|
|
61
|
+
{
|
|
62
|
+
"frameDiff": {
|
|
63
|
+
"minChangedPixelRatio": 0.1
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"region": {
|
|
68
|
+
"x": 0,
|
|
69
|
+
"y": 0,
|
|
70
|
+
"width": 1280,
|
|
71
|
+
"height": 720,
|
|
72
|
+
"minNonblankPixelRatio": 0.01
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
|
2
|
+
<rect width="64" height="64" rx="14" fill="#061b2b"/>
|
|
3
|
+
<path d="M10 45h44M17 45l16-30 14 30M25 30h17" fill="none" stroke="#ffd27a" stroke-linecap="round" stroke-linejoin="round" stroke-width="5"/>
|
|
4
|
+
<path d="M12 51c8-4 16 4 24 0s16 4 16 0" fill="none" stroke="#6fe8ff" stroke-linecap="round" stroke-width="4"/>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// Generated for you. The storm's sound, as the reference study mixed it.
|
|
2
|
+
//
|
|
3
|
+
// The study synthesised all of this live: a Web Audio graph of noise buffers and biquads, built on
|
|
4
|
+
// the first click. This file plays three clips that `tools/make-storm-audio.mjs` baked from the same
|
|
5
|
+
// maths, through the engine's own `AudioBus`. Everything that used to be a node is a constant below,
|
|
6
|
+
// next to the line of the study it came from; nothing is re-tuned, and nothing here is a framework
|
|
7
|
+
// concept.
|
|
8
|
+
//
|
|
9
|
+
// What is the source's, exactly:
|
|
10
|
+
// rain hiss noise → highpass 1800 / lowpass 11000, gain = weather.rain * .20 over .25 s
|
|
11
|
+
// wind bed pink noise → bandpass 35..350, gain = .02 + weather.wind * .18 * LFO over .4 s
|
|
12
|
+
// thunder crack + rumble + 9 Hz tremolo, lowpass and gain set by how far it was struck
|
|
13
|
+
//
|
|
14
|
+
// One seam the source had and this file now asks the engine for: the `DynamicsCompressor` it ran
|
|
15
|
+
// in front of the master is declared by name below, on the engine's own `AudioBus`. A second,
|
|
16
|
+
// native-only seam is named at `thunderDistance`. What has been exercised is the maths and this
|
|
17
|
+
// wiring against the engine's real `AudioBus`, plus a headed WebGPU playtest of the registered
|
|
18
|
+
// entity; no native target has run the file.
|
|
19
|
+
|
|
20
|
+
import { AudioBus, type ICtx } from "@threenative/core";
|
|
21
|
+
import type { GameState } from "../state.js";
|
|
22
|
+
|
|
23
|
+
/** The name this is registered under, so a pause intent can reach it without a captured closure. */
|
|
24
|
+
export const STORM_AUDIO_ENTITY = "storm-audio";
|
|
25
|
+
|
|
26
|
+
/** Baked by `tools/make-storm-audio.mjs`, logical paths into `assets/`. */
|
|
27
|
+
const CLIPS = {
|
|
28
|
+
rain: "rain-loop.wav",
|
|
29
|
+
thunder: "thunder.wav",
|
|
30
|
+
wind: "wind-loop.wav",
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `this.master.gain.setTargetAtTime(.42, this.ctx.currentTime, .12)`.
|
|
35
|
+
*
|
|
36
|
+
* The source ran a `DynamicsCompressor` in front of this, to hold the three voices down when they
|
|
37
|
+
* summed; that response to a loud mix is `MASTER_COMPRESSOR` below, asked for on the bus rather
|
|
38
|
+
* than rebuilt out of gains. What this gain cannot do on its own is soften anything: a mix past
|
|
39
|
+
* `MASTER_GAIN` clips, and the compressor ahead of it is what keeps that from happening.
|
|
40
|
+
*/
|
|
41
|
+
const MASTER_GAIN = 0.42;
|
|
42
|
+
const MASTER_FADE = 0.12;
|
|
43
|
+
/** `mute()`'s `setTargetAtTime(0, currentTime, .06)`. */
|
|
44
|
+
const MUTE_FADE = 0.06;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The source's compressor, value by value: `new DynamicsCompressorNode(ctx, {
|
|
48
|
+
* threshold: -15, knee: 30, ratio: 5, attack: .003, release: .25 })`.
|
|
49
|
+
*
|
|
50
|
+
* `AudioBus` takes all five as one option and installs the node where every voice sums, ahead of
|
|
51
|
+
* the master gain — the same place the source had it. A runtime with no dynamics node reports
|
|
52
|
+
* `compressor` in `bus.unsupported` rather than playing on uncompressed and quiet about it.
|
|
53
|
+
*/
|
|
54
|
+
const MASTER_COMPRESSOR = {
|
|
55
|
+
attack: 0.003,
|
|
56
|
+
knee: 30,
|
|
57
|
+
ratio: 5,
|
|
58
|
+
release: 0.25,
|
|
59
|
+
threshold: -15,
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
/** `weather.rain * .20` — the source overwrote the loop node's own .09 with this every frame. */
|
|
63
|
+
const RAIN_GAIN = 0.2;
|
|
64
|
+
/** `.02 + weather.wind * .18 * (.78 + .22 * Math.sin(time * .37))`, term by term. */
|
|
65
|
+
const WIND_BASE = 0.02;
|
|
66
|
+
const WIND_GAIN = 0.18;
|
|
67
|
+
const WIND_LFO_RATE = 0.37;
|
|
68
|
+
const WIND_LFO_FLOOR = 0.78;
|
|
69
|
+
const WIND_LFO_DEPTH = 0.22;
|
|
70
|
+
/** The two time constants the source smoothed its own gain nodes with. */
|
|
71
|
+
const RAIN_TAU = 0.25;
|
|
72
|
+
const WIND_TAU = 0.4;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `thunder()`'s distance law: `clamp(4500 - distance * 5, 280, 4500)` and
|
|
76
|
+
* `clamp(1.05 - distance * .0009, .18, .95)`. The low-pass goes to the engine as `lowpassHz`, which
|
|
77
|
+
* is a real `BiquadFilterNode` on the web. The native host binds no `createBiquadFilter`, so it
|
|
78
|
+
* drops the option and the bus names it in `bus.unsupported` — on a phone a near strike is as
|
|
79
|
+
* bright as a far one. That is the one unsupported cue option observed in the installed native
|
|
80
|
+
* audio bindings; `detune` is the other, and this file does not use it.
|
|
81
|
+
*/
|
|
82
|
+
function thunderDistance(metres: number): { readonly lowpassHz: number; readonly volume: number } {
|
|
83
|
+
return {
|
|
84
|
+
lowpassHz: Math.max(280, Math.min(4500, 4500 - metres * 5)),
|
|
85
|
+
volume: Math.max(0.18, Math.min(0.95, 1.05 - metres * 0.0009)),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A strike, handed over by the scene at the moment it is struck and not before. */
|
|
90
|
+
export interface IStormStrike {
|
|
91
|
+
/** Absolute simulation time the thunder is due, which is what makes it survive a freeze. */
|
|
92
|
+
readonly at: number;
|
|
93
|
+
/** How far away it was struck, for the distance law above. */
|
|
94
|
+
readonly metres: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface IStormAudio {
|
|
98
|
+
/** Queues one strike. Strikes queue: a second one does not overwrite one still crossing the air. */
|
|
99
|
+
queueStrike(strike: IStormStrike): void;
|
|
100
|
+
/** The frame's truth. Call it once per frame, after the simulation has advanced. */
|
|
101
|
+
update(state: GameState): void;
|
|
102
|
+
/**
|
|
103
|
+
* An explicit hold, from the pause intent. Separate from `setHidden` because the two clear
|
|
104
|
+
* independently: the game's own pause outlives the tab it was pressed in.
|
|
105
|
+
*/
|
|
106
|
+
setSilenced(silenced: boolean): void;
|
|
107
|
+
/**
|
|
108
|
+
* A visibility hold, from the UI realm or the engine's lifecycle — the one place that knows
|
|
109
|
+
* whether the frame is still on screen. Neither this nor `setSilenced` is a substitute for the
|
|
110
|
+
* other, and the bus is released only when both are clear.
|
|
111
|
+
*/
|
|
112
|
+
setHidden(hidden: boolean): void;
|
|
113
|
+
dispose(): void;
|
|
114
|
+
/** What a playtest reads back. */
|
|
115
|
+
debug(): Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type LoopVoice = ReturnType<AudioBus["play"]>;
|
|
119
|
+
|
|
120
|
+
export function createStormAudio(ctx: ICtx<GameState>): IStormAudio {
|
|
121
|
+
const bus = new AudioBus({ camera: ctx.camera, compressor: MASTER_COMPRESSOR });
|
|
122
|
+
const clips: Partial<Record<keyof typeof CLIPS, AudioBuffer>> = {};
|
|
123
|
+
let loops: { readonly rain: LoopVoice; readonly wind: LoopVoice } | undefined;
|
|
124
|
+
/** Struck but not yet crossed the air, oldest first. */
|
|
125
|
+
let pending: IStormStrike[] = [];
|
|
126
|
+
/** Struck and sounding, in play order. */
|
|
127
|
+
const thunder: LoopVoice[] = [];
|
|
128
|
+
let wanted = false;
|
|
129
|
+
let muted = false;
|
|
130
|
+
let silenced = false;
|
|
131
|
+
let hidden = false;
|
|
132
|
+
/** What the bus is actually being told, so neither hold can latch the other. */
|
|
133
|
+
let held = false;
|
|
134
|
+
let master = -1;
|
|
135
|
+
let loadError: string | undefined;
|
|
136
|
+
let unlockError: string | undefined;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* `AudioBus.pause` holds each voice where it stands and `resume` gives it back from there, which
|
|
140
|
+
* is the honest reading of a paused simulation. The study suspended the whole `AudioContext`
|
|
141
|
+
* instead; the bus will not, because that would silence every other bus on it.
|
|
142
|
+
*
|
|
143
|
+
* The two holds are kept apart so neither can latch the other: a tab that goes visible again
|
|
144
|
+
* releases the sound, and a pause that was pressed still holds it afterwards.
|
|
145
|
+
*/
|
|
146
|
+
function applyHold(): void {
|
|
147
|
+
const hold = silenced || hidden;
|
|
148
|
+
if (hold === held) return;
|
|
149
|
+
held = hold;
|
|
150
|
+
if (hold) bus.pause();
|
|
151
|
+
else bus.resume();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Everything that is sounding but is not a bed, stopped and forgotten. */
|
|
155
|
+
function clearThunder(): void {
|
|
156
|
+
pending = [];
|
|
157
|
+
for (const voice of thunder) bus.stopVoice(voice);
|
|
158
|
+
thunder.length = 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The source's own smoothing: `gain.setTargetAtTime(target, t, .25)` for rain, `.4` for wind. */
|
|
162
|
+
function ramp(voice: LoopVoice, target: number, tau: number): void {
|
|
163
|
+
const param = voice.gain.gain;
|
|
164
|
+
if (typeof param.setTargetAtTime === "function")
|
|
165
|
+
param.setTargetAtTime(target, bus.listener.context.currentTime, tau);
|
|
166
|
+
else voice.setVolume(target);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Fires every strike the simulation clock has carried past its own delay, once each. */
|
|
170
|
+
function fireDue(now: number): void {
|
|
171
|
+
// A voice that ran out is back in the bus's pool; a stale handle here is only a wrong count.
|
|
172
|
+
for (let index = thunder.length - 1; index >= 0; index -= 1)
|
|
173
|
+
if (thunder[index]?.isPlaying !== true) thunder.splice(index, 1);
|
|
174
|
+
// A strike queued before its clip landed waits in the queue rather than throwing.
|
|
175
|
+
if (pending.length === 0 || clips.thunder === undefined) return;
|
|
176
|
+
const due = pending.filter((strike) => now >= strike.at);
|
|
177
|
+
if (due.length === 0) return;
|
|
178
|
+
pending = pending.filter((strike) => now < strike.at);
|
|
179
|
+
for (const strike of due)
|
|
180
|
+
thunder.push(
|
|
181
|
+
bus.play(clips.thunder as AudioBuffer, {
|
|
182
|
+
cue: "thunder",
|
|
183
|
+
...thunderDistance(strike.metres),
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Puts the two beds down. Their gains are written every frame from the eased weather. */
|
|
189
|
+
function startLoops(): void {
|
|
190
|
+
loops = {
|
|
191
|
+
rain: bus.play(clips.rain as AudioBuffer, { cue: "rain-loop", loop: true, volume: 0 }),
|
|
192
|
+
wind: bus.play(clips.wind as AudioBuffer, { cue: "wind-loop", loop: true, volume: 0 }),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The enable edge is the gesture, and the beds wait for it — and for the clips, which arrive
|
|
198
|
+
* after the first frame. Turning sound off has to take the beds down, not just forget that they
|
|
199
|
+
* were asked for: `AudioBus.stop` is the one call that ends every voice, and the strikes in the
|
|
200
|
+
* air go with them rather than piling up on the way back.
|
|
201
|
+
*/
|
|
202
|
+
function arm(state: GameState): void {
|
|
203
|
+
if (state.audioEnabled !== wanted) {
|
|
204
|
+
wanted = state.audioEnabled;
|
|
205
|
+
if (wanted) {
|
|
206
|
+
// `AudioBus` also unlocks on the first key or pointer event; doing it here as well is what
|
|
207
|
+
// lets the automation API raise sound with no gesture at all. A refused unlock is
|
|
208
|
+
// reported, never swallowed: a game whose sound silently never starts is worse.
|
|
209
|
+
void bus.unlock().catch((error: unknown) => {
|
|
210
|
+
unlockError = error instanceof Error ? error.message : String(error);
|
|
211
|
+
console.warn(`TN_RAIN_AUDIO_UNLOCK_FAILED ${unlockError}`);
|
|
212
|
+
});
|
|
213
|
+
} else {
|
|
214
|
+
bus.stop();
|
|
215
|
+
loops = undefined;
|
|
216
|
+
clearThunder();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (wanted && loops === undefined && clips.rain !== undefined && clips.wind !== undefined)
|
|
220
|
+
startLoops();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The master level and the two bed gains, from the frame's weather. */
|
|
224
|
+
function mix(state: GameState): void {
|
|
225
|
+
muted = state.muted;
|
|
226
|
+
const level = muted ? 0 : MASTER_GAIN;
|
|
227
|
+
if (level !== master) {
|
|
228
|
+
master = level;
|
|
229
|
+
bus.setVolume(level, muted ? MUTE_FADE : MASTER_FADE);
|
|
230
|
+
}
|
|
231
|
+
if (loops === undefined) return;
|
|
232
|
+
ramp(loops.rain, state.weather.rain * RAIN_GAIN, RAIN_TAU);
|
|
233
|
+
ramp(
|
|
234
|
+
loops.wind,
|
|
235
|
+
WIND_BASE +
|
|
236
|
+
state.weather.wind *
|
|
237
|
+
WIND_GAIN *
|
|
238
|
+
(WIND_LFO_FLOOR + WIND_LFO_DEPTH * Math.sin(state.elapsed * WIND_LFO_RATE)),
|
|
239
|
+
WIND_TAU,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
for (const key of Object.keys(CLIPS) as (keyof typeof CLIPS)[]) {
|
|
244
|
+
void ctx.assets
|
|
245
|
+
.audio(CLIPS[key])
|
|
246
|
+
.then((buffer) => {
|
|
247
|
+
clips[key] = buffer;
|
|
248
|
+
})
|
|
249
|
+
.catch((error: unknown) => {
|
|
250
|
+
// Sound is not the storm. A missing clip is reported once and leaves the rest audible.
|
|
251
|
+
loadError = `${key}: ${error instanceof Error ? error.message : String(error)}`;
|
|
252
|
+
console.warn(`TN_RAIN_AUDIO_MISSING ${loadError}`);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
queueStrike(strike) {
|
|
258
|
+
if (!Number.isFinite(strike.at) || !Number.isFinite(strike.metres) || strike.metres < 0)
|
|
259
|
+
throw new RangeError(
|
|
260
|
+
"a strike needs a finite simulation time and a non-negative distance.",
|
|
261
|
+
);
|
|
262
|
+
pending.push(strike);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
update(state) {
|
|
266
|
+
arm(state);
|
|
267
|
+
mix(state);
|
|
268
|
+
if (loops === undefined) return;
|
|
269
|
+
// Photosensitivity mode is the study's `setSafe`, which also called `clearThunder`.
|
|
270
|
+
if (state.safe) clearThunder();
|
|
271
|
+
else fireDue(state.elapsed);
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
setSilenced(next) {
|
|
275
|
+
silenced = next;
|
|
276
|
+
applyHold();
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
setHidden(next) {
|
|
280
|
+
hidden = next;
|
|
281
|
+
applyHold();
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
dispose() {
|
|
285
|
+
pending = [];
|
|
286
|
+
thunder.length = 0;
|
|
287
|
+
loops = undefined;
|
|
288
|
+
bus.dispose();
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
debug() {
|
|
292
|
+
return {
|
|
293
|
+
enabled: wanted,
|
|
294
|
+
muted,
|
|
295
|
+
silenced,
|
|
296
|
+
hidden,
|
|
297
|
+
held: held,
|
|
298
|
+
// The engine's own readings, not a mirror of what this file last asked for.
|
|
299
|
+
master: bus.volume,
|
|
300
|
+
paused: bus.paused,
|
|
301
|
+
compressor: bus.compressor !== undefined,
|
|
302
|
+
loaded: Object.keys(clips).length,
|
|
303
|
+
loadError: loadError ?? "none",
|
|
304
|
+
unlockError: unlockError ?? "none",
|
|
305
|
+
pendingThunder: pending.length,
|
|
306
|
+
thunderVoices: thunder.length,
|
|
307
|
+
voices: bus.voices,
|
|
308
|
+
queued: bus.queued,
|
|
309
|
+
pausedVoices: bus.pausedVoices,
|
|
310
|
+
unsupported: bus.unsupported,
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type IGame, defineGame } from "@threenative/core";
|
|
2
|
+
import { playtest } from "@threenative/core/playtest";
|
|
3
|
+
import { UI_READY_INTENT } from "@threenative/core/ui-layer";
|
|
4
|
+
import config from "../threenative.config.js";
|
|
5
|
+
import { type IStormAudio, STORM_AUDIO_ENTITY } from "./audio/storm.js";
|
|
6
|
+
import { Coast } from "./scenes/Boot.js";
|
|
7
|
+
import {
|
|
8
|
+
type GameState,
|
|
9
|
+
type PresetName,
|
|
10
|
+
type QualityName,
|
|
11
|
+
VISIBILITY_INTENT,
|
|
12
|
+
type WeatherKey,
|
|
13
|
+
intentPatch,
|
|
14
|
+
} from "./state.js";
|
|
15
|
+
|
|
16
|
+
const game = defineGame<GameState>({
|
|
17
|
+
input: {
|
|
18
|
+
ascend: { keys: ["KeyE"] },
|
|
19
|
+
boost: { keys: ["ShiftLeft", "ShiftRight"] },
|
|
20
|
+
descend: { keys: ["KeyQ"] },
|
|
21
|
+
// The drag's own motion, sampled at the tick. No click capture: the study looks by dragging,
|
|
22
|
+
// and a locked pointer would take the cursor away from the panel beside it.
|
|
23
|
+
look: { captureOnClick: false, pointerRelative: true },
|
|
24
|
+
move: {
|
|
25
|
+
down: ["ArrowDown", "KeyS"],
|
|
26
|
+
left: ["ArrowLeft", "KeyA"],
|
|
27
|
+
right: ["ArrowRight", "KeyD"],
|
|
28
|
+
up: ["ArrowUp", "KeyW"],
|
|
29
|
+
},
|
|
30
|
+
// The study's own shortcuts live here, in the game's input map, rather than in a browser
|
|
31
|
+
// keydown listener: on a native host the interface is a web view that never has keyboard
|
|
32
|
+
// focus, so a shortcut only the UI realm hears is a shortcut native players do not have.
|
|
33
|
+
// F (fullscreen) and P (save image) stay in the UI realm because both are browser APIs.
|
|
34
|
+
hideUi: { keys: ["KeyH"] },
|
|
35
|
+
pause: { keys: ["Space"] },
|
|
36
|
+
resetCamera: { keys: ["KeyR"] },
|
|
37
|
+
safe: { keys: ["KeyX"] },
|
|
38
|
+
sound: { keys: ["KeyM"] },
|
|
39
|
+
strike: { keys: ["KeyL"] },
|
|
40
|
+
},
|
|
41
|
+
plugins: [playtest()],
|
|
42
|
+
display: config.display,
|
|
43
|
+
render: config.renderer,
|
|
44
|
+
scenes: { coast: Coast },
|
|
45
|
+
seed: 607,
|
|
46
|
+
start: "coast",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export default game;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The intents the UI sends, and the payload each one carries. The UI slice owns nothing else:
|
|
53
|
+
* every control here is a named intent and a validated payload, and nothing else crosses.
|
|
54
|
+
*/
|
|
55
|
+
export type RainIntent =
|
|
56
|
+
| { readonly name: "closeHelp" }
|
|
57
|
+
| { readonly name: "help" }
|
|
58
|
+
| { readonly name: "hideUi" }
|
|
59
|
+
| { readonly name: "pause" }
|
|
60
|
+
| { readonly name: "resetCamera"; readonly payload?: never }
|
|
61
|
+
| { readonly name: "resume" }
|
|
62
|
+
| { readonly name: "setAudioEnabled"; readonly payload: boolean }
|
|
63
|
+
| { readonly name: "setAutoLightning"; readonly payload: boolean }
|
|
64
|
+
| { readonly name: "setCinematic"; readonly payload: boolean }
|
|
65
|
+
| { readonly name: "setDroplets"; readonly payload: boolean }
|
|
66
|
+
| { readonly name: "setFrozen"; readonly payload: boolean }
|
|
67
|
+
| { readonly name: "setMuted"; readonly payload: boolean }
|
|
68
|
+
| { readonly name: "setPreset"; readonly payload: PresetName }
|
|
69
|
+
| { readonly name: "setQuality"; readonly payload: QualityName }
|
|
70
|
+
| { readonly name: "setSafe"; readonly payload: boolean }
|
|
71
|
+
| { readonly name: "setWeather"; readonly payload: Partial<Record<WeatherKey, number>> }
|
|
72
|
+
| { readonly name: "showUi" }
|
|
73
|
+
| { readonly name: "step"; readonly payload: number }
|
|
74
|
+
| { readonly name: "strike"; readonly payload?: never }
|
|
75
|
+
| { readonly name: typeof VISIBILITY_INTENT; readonly payload: boolean };
|
|
76
|
+
|
|
77
|
+
game.ui.onIntent((intent, payload) => {
|
|
78
|
+
// The framework's own "my tree has rendered" signal, and the one control that is not a player's:
|
|
79
|
+
// it arrives on the same door but carries no weather, so it is answered before the validator
|
|
80
|
+
// ever sees it. `uiReady` mirrors `game.ui.connected` rather than being set optimistically, so a
|
|
81
|
+
// UI that never came up leaves the loading study up instead of hiding it over nothing.
|
|
82
|
+
if (intent === UI_READY_INTENT) {
|
|
83
|
+
game.state.set({ uiReady: game.ui.connected });
|
|
84
|
+
game.state.flush();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// The two audio holds, answered at the door: a hidden tab stops the loop, so nothing in `Boot.ts`
|
|
88
|
+
// runs to notice it, and the pause hold has to land on the same edge as the press. Neither is a
|
|
89
|
+
// weather intent and neither needs a state field of its own.
|
|
90
|
+
const storm = (): IStormAudio | undefined =>
|
|
91
|
+
game.ctx?.entities.get<IStormAudio>(STORM_AUDIO_ENTITY);
|
|
92
|
+
if (intent === "pause" || intent === "resume") storm()?.setSilenced(intent === "pause");
|
|
93
|
+
if (intent === VISIBILITY_INTENT) {
|
|
94
|
+
if (typeof payload !== "boolean") {
|
|
95
|
+
console.warn(`TN_RAIN_INTENT ${intent}: expected a boolean payload`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
storm()?.setHidden(payload);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let patch: Partial<GameState>;
|
|
102
|
+
try {
|
|
103
|
+
patch = intentPatch(intent, payload, game.state.getState().target);
|
|
104
|
+
} catch (why) {
|
|
105
|
+
// Reported and dropped rather than thrown: one malformed control must not take the gesture
|
|
106
|
+
// flow down with it, and the rejection is visible in the console where the next agent looks.
|
|
107
|
+
console.warn(`TN_RAIN_INTENT ${intent}: ${(why as Error).message}`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
game.state.set(patch);
|
|
111
|
+
// The frame loop flushes too, but a control must feel instant: a slider that waits for the next
|
|
112
|
+
// frame reads as a dropped drag.
|
|
113
|
+
game.state.flush();
|
|
114
|
+
});
|