@holtjs/stage 0.4.1 → 0.5.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.
- package/CHANGELOG.md +12 -0
- package/README.md +140 -119
- package/dist/lighting.d.ts +129 -0
- package/dist/lighting.js +527 -0
- package/dist/projection.d.ts +131 -0
- package/dist/projection.js +262 -0
- package/dist/rig2d.d.ts +317 -0
- package/dist/rig2d.js +871 -0
- package/dist/tilemap.d.ts +158 -0
- package/dist/tilemap.js +583 -0
- package/dist/world.d.ts +183 -0
- package/dist/world.js +400 -0
- package/llms.txt +26 -17
- package/package.json +21 -1
- package/skills/stage/SKILL.md +140 -157
- package/skills/stage/references/subpaths.md +62 -54
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,18 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.5.0] - 2026-12-04
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- **5 First-Party 2.5D Survival Sandbox Engine Subpaths** (`sideEffects: false`, zero runtime dependencies):
|
|
13
|
+
- **`@holtjs/stage/rig2d`** (`src/rig2d.ts`): 2D cutout/slot skeletal hierarchy (`defineRig2DSkeleton`, `Rig2DInstance`), O(1) slot/skin attachment swapping (`setAttachment`, `applySkin`) without resetting animation phase, two-layer animation mixer (`base` locomotion + bone-masked `overlay` action clips such as upper-body chopping while walking), keyframe events (`onEvent`), `mountRig2D()` scene adapter, and procedural `bakeCutoutAtlas()` spritesheet generator.
|
|
14
|
+
- **`@holtjs/stage/tilemap`** (`src/tilemap.ts`): Sparse integer-keyed `ChunkedTilemap` (`±1,000,000` tile coordinates) with cross-chunk border dirty propagation, Oskar Stålberg 16-tile **Dual-Grid Autotiler** (`computeDualGridMask`, `bakeDualGridTileset`), 47-tile Blob autotiler (`computeBlob47Index`), deterministic island biome noise generator (`createIslandBiomeGenerator`), nav obstacle extraction (`extractWalkableRect`), and viewport-streaming `mountChunkedTilemap()`.
|
|
15
|
+
- **`@holtjs/stage/projection`** (`src/projection.ts`): Rotatable oblique 2.5D camera (`Camera25D` with exact inverse `worldToScreen` ↔ `screenToGround` across full 360° `yaw` spins and smooth damped `Q/E` rotation) and `mountStage25D()` (3-stage nested ground-plane projection + upright cylindrical depth-sorted billboards + oblique sun shadow vector).
|
|
16
|
+
- **`@holtjs/stage/lighting`** (`src/lighting.ts`): `DayNightCycle` (`day`/`dusk`/`night` ambient tint, sun direction & shadow scale), 3×3 Sobel height-to-normal-map baker (`computeNormalMapPixels`, `bakeNormalMapCanvas`), `Lighting2DSystem` (`MULTIPLY` offscreen lightmap FBO + flickering point torches), and WebGL2 `createNormalLitSpritePass()` per-pixel directional + point normal-mapped sprite shader pass.
|
|
17
|
+
- **`@holtjs/stage/world`** (`src/world.ts`): `ItemRegistry`, `InventoryContainer` (with `freshness01` spoilage -> `'rot'`), `RecipeRegistry`, `WorkstationInstance` & `WorkstationScheduler` (fuel auto-refuel + deterministic offline `stepAll(deltaMs)` catch-up), and compact `WorldDeltaSave` (`captureWorldDelta`, `applyWorldDelta`, `encodeWorldDeltaBytes` / `decodeWorldDeltaBytes` `HWLD` binary codec).
|
|
18
|
+
- **12-Second 60 FPS Multi-Cut Survival Trailer Example (`examples/nightfall-trailer.mjs`)**: runnable via `pnpm run example:nightfall`, combining `StageKernel` + `createInputTimeline({ showCursor: true })` + all 5 new survival subpaths + 44.1 kHz stereo procedural foley & music score into a deterministic 1280×720 60 FPS MP4 + 6-panel storyboard PNG.
|
|
19
|
+
- **Expanded WebGPU, `StageKernel` & Survival Sandbox Documentation**: comprehensive reference & recipes across `README.md`, `docs/architecture.md`, `skills/stage/SKILL.md`, `skills/stage/references/subpaths.md`, and `llms.txt`.
|
|
20
|
+
|
|
9
21
|
## [0.4.1] - 2026-12-03
|
|
10
22
|
|
|
11
23
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,49 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Stage (`@holtjs/stage`)
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@holtjs/stage)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
[](package.json)
|
|
6
|
-
[](scripts/size.mjs)
|
|
7
7
|
|
|
8
|
-
A zero-dependency, tracing-first WebGL2 / Canvas2D 2D game
|
|
8
|
+
A zero-dependency, tracing-first **WebGPU / WebGL2 / Canvas2D** 2D & 2.5D game, UI, and 60 FPS programmable video engine written in strict TypeScript — covering GPU SDF panels, `StageKernel` plugins & unified `InputTimeline` automation, Flex/Wrap layout, damped springs, `SurfaceTree` barriers, zero-GC SoA ECS, FlowField/A* navigation, procedural foley audio, 2D cutout skeletal rigs, Dual-Grid chunked tilemaps, rotatable 2.5D camera projection, 2D normal-map lighting, and world delta saves.
|
|
9
9
|
|
|
10
|
+
- **Official Docs & Playground**: https://holt.js.org
|
|
10
11
|
- **npm**: https://www.npmjs.com/package/@holtjs/stage
|
|
11
12
|
- **Repository**: https://github.com/botiverse-play/stage
|
|
12
13
|
- **Architecture Docs**: [docs/architecture.md](docs/architecture.md)
|
|
13
14
|
- **AI Agent Kit**: [AGENTS.md](AGENTS.md) · [skills/stage/SKILL.md](skills/stage/SKILL.md) · [llms.txt](llms.txt)
|
|
14
15
|
- **Changelog & Community**: [CHANGELOG.md](CHANGELOG.md) · [CONTRIBUTING.md](CONTRIBUTING.md) · [SECURITY.md](SECURITY.md)
|
|
15
16
|
|
|
16
|
-
Extracted from production use inside interactive 2D multiplayer worlds and canvas-native UI suites where bundle size, deterministic timing, crisp HiDPI rendering, and production observability matter.
|
|
17
|
-
|
|
18
17
|
## Highlights
|
|
19
18
|
|
|
20
|
-
- **Zero runtime dependencies**: Pure ESM TypeScript (
|
|
21
|
-
- **WebGL2
|
|
22
|
-
-
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
- `
|
|
32
|
-
- `
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
- `
|
|
36
|
-
- `VirtualJoystick` — multi-touch finger-isolated (`pointer.id`) virtual joystick (`fixed` / `floating` with optional `follow`) + pure vector/deadzone/8-way D-pad math.
|
|
37
|
-
- `createSurfaceTree()` — Godot-inspired unified visual stacking = input barrier tree (`SURFACE_BAND`, `modal`/`fullscreen` barriers, scoped occlusion, `ui.cancel` / `onKey` / `Tab` focus dispatch, and monotonic DOM `z-index` solver).
|
|
38
|
-
- **First-Party Tree-Shakeable 2D Game Engine Primitives** (`sideEffects: false`, zero extra bytes if unused):
|
|
39
|
-
- **Spatial Hash Grid** (`@holtjs/stage/spatial`): zero-GC CSR uniform spatial hash for O(N) broadphase queries and crowd separation.
|
|
40
|
-
- **Deterministic 2D Hit & Push-Out** (`@holtjs/stage/hit`): IEEE-754 swept circles, melee arc sweeps, segments/capsules, AABB/circle obstacle resolution, and frame-rate-independent knockback.
|
|
41
|
-
- **Navigation** (`@holtjs/stage/nav`): multi-target `FlowFieldGrid`, bounded 8-neighbor A* with greedy LOS string-pulling (`findGridPath`), and local steering.
|
|
42
|
-
- **Particles & Hit-Feel Juice** (`@holtjs/stage/particles`): zero-GC `ParticlePool`, continuous `AmbientEmitterPool`, and hitstop + squared-trauma screen shake (`JuiceController`).
|
|
43
|
-
- **Procedural Audio & Foley** (`@holtjs/stage/audio`): pure-TS organic foley synthesis (`renderFoley`), spatial stereo panning (`spatialMix`), sfxr voice synth, and PCM16 WAV export.
|
|
44
|
-
- **Zero-GC SoA ECS** (`@holtjs/stage/ecs`): dense-packed `TypedArray` `SoaWorld` with generational entity handles, bitmask queries, `SpatialHashGrid` sync, frustum culling, Ciura-gap Shell depth sort, and 2.5D `DepthBand` partitioning.
|
|
45
|
-
- **Tracing-First Observability (`buildSceneDigest`)**:
|
|
46
|
-
- Privacy-safe structural scene snapshot (`clock`, `viewport`, `renderer`, `lifecycle`, `tweens`, `overlays`, `surfaces`, `sandbox`, and sanitized `trackId`/`role`/`alt`/`surface` nodes). Never scrapes arbitrary `TextObject.text` or user input.
|
|
19
|
+
- **Zero runtime dependencies & 20 tree-shakeable subpaths**: Pure ESM TypeScript (`sideEffects: false`); individual subpaths range from **1.1 kB to 7.4 kB gzipped**.
|
|
20
|
+
- **WebGPU + WebGL2 + Isomorphic Canvas2D + Node 60 FPS Headless**:
|
|
21
|
+
- **Native WebGPU (`@holtjs/stage/webgpu`)**: Zero-dependency `RendererWebGpu` + `requestWebGpuDevice()` with WGSL quad/polygon batching and WGSL analytical rounded/stepped-pixel SDF `PanelObject` pipelines across `NORMAL`, `ADD`, `MULTIPLY`, and `SCREEN` blends.
|
|
22
|
+
- **WebGL2 Primary (`RendererGl`)**: 1-sampler zero-branch shader + 8-unit multi-texture uber-batcher, `InstancedBatchObject` (`drawElementsInstanced`), offscreen `StageRenderTarget` FBOs, GPU SDF panels, Sharp-Bilinear Pixel-AA, MTSDF vector icons, and state-isolated `CustomPassObject`.
|
|
23
|
+
- **Isomorphic Canvas2D & Pure-Node 60 FPS Video (`@holtjs/stage/headless`)**: Identical scene graph runs in headless Node via `@napi-rs/canvas` (`createHeadlessStage`, `fastForward`, `renderStoryboard`, `createAudioTimeline` stereo WAV + `ffmpeg` MP4).
|
|
24
|
+
- **Godot-First `StageKernel` & Semantic `InputTimeline` (`@holtjs/stage/kernel`)**:
|
|
25
|
+
- Unified `StagePlugin` lifecycle (`setup`, `prestep`, `update`, `postrender`, LIFO `dispose`, auto-reported in `SceneDigest.plugins`).
|
|
26
|
+
- `ActionMap` (`bind`, `isDown`, `justPressed`, `axis`) + `InputProvider` bus shared by hardware mouse/keyboard, `createInputTimeline({ showCursor: true })` (click directly by `trackId`!), and `createInputRecorder` / `createInputReplay`.
|
|
27
|
+
- **2.5D Survival Sandbox Engine Pillars (*Don't Starve* / *Graveyard Keeper*-ready)**:
|
|
28
|
+
- **`@holtjs/stage/rig2d`** (`5.7 kB` gz): 2D cutout/slot skeletal hierarchy, O(1) tool/hat/armor attachment & skin swapping without phase glitches, 2-layer base + bone-masked overlay mixer (chop while walking), keyframe events, and procedural `bakeCutoutAtlas()`.
|
|
29
|
+
- **`@holtjs/stage/tilemap`** (`3.5 kB` gz): Sparse `ChunkedTilemap` (`±1,000,000` coords), cross-chunk dirty propagation, Oskar Stålberg **16-tile Dual-Grid** & **47-tile Blob** autotilers, island biome generator, and viewport-streaming `mountChunkedTilemap()`.
|
|
30
|
+
- **`@holtjs/stage/projection`** (`1.6 kB` gz): Rotatable oblique `Camera25D` (`worldToScreen` ↔ `screenToGround` exact inverse across 360° `yaw` spins + smooth `Q/E` rotation) and `mountStage25D()` upright cylindrical depth-sorted billboards.
|
|
31
|
+
- **`@holtjs/stage/lighting`** (`4.1 kB` gz): `DayNightCycle`, Sobel 3×3 `bakeNormalMapCanvas()`, `Lighting2DSystem` (`MULTIPLY` offscreen lightmap FBO + flickering torches), and WebGL2 `createNormalLitSpritePass()`.
|
|
32
|
+
- **`@holtjs/stage/world`** (`2.8 kB` gz): `ItemRegistry`, `InventoryContainer` (with `freshness01` spoilage), `RecipeRegistry`, `WorkstationScheduler` (offline tick catch-up), and compact `HWLD` binary `WorldDeltaSave`.
|
|
33
|
+
- **Zero-GC Simulation, UI & Tracing (`buildSceneDigest`)**:
|
|
34
|
+
- `SoaWorld` ECS, CSR `SpatialHashGrid`, `FlowFieldGrid` + A*, swept-circle/arc `hit` + knockback, `ParticlePool` + `JuiceController`, procedural WebAudio `renderFoley`, `computeFlexLayout`, damped springs, `SurfaceTree` barriers, and zero-PII `buildSceneDigest()`.
|
|
47
35
|
|
|
48
36
|
## Install
|
|
49
37
|
|
|
@@ -51,103 +39,146 @@ Extracted from production use inside interactive 2D multiplayer worlds and canva
|
|
|
51
39
|
pnpm add @holtjs/stage
|
|
52
40
|
```
|
|
53
41
|
|
|
54
|
-
## Subpath Exports
|
|
55
|
-
|
|
56
|
-
| Import Path | Description | DOM Required? |
|
|
57
|
-
|
|
58
|
-
| `@holtjs/stage` | Full engine barrel (`
|
|
59
|
-
| `@holtjs/stage/
|
|
60
|
-
| `@holtjs/stage/
|
|
61
|
-
| `@holtjs/stage/
|
|
62
|
-
| `@holtjs/stage/
|
|
63
|
-
| `@holtjs/stage/
|
|
64
|
-
| `@holtjs/stage/
|
|
65
|
-
| `@holtjs/stage/
|
|
66
|
-
| `@holtjs/stage/
|
|
67
|
-
| `@holtjs/stage/
|
|
68
|
-
| `@holtjs/stage/
|
|
69
|
-
| `@holtjs/stage/
|
|
70
|
-
| `@holtjs/stage/
|
|
71
|
-
|
|
72
|
-
|
|
42
|
+
## 20 Subpath Exports
|
|
43
|
+
|
|
44
|
+
| Import Path | Gzip | Description | DOM Required? |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| `@holtjs/stage` | `57.3 kB` | Full engine barrel (`Stage`, `Game`, `Scene`, renderers, `InstancedBatch`, `Panel`, `StageKernel`, layout, tweens, tracing, surfaces) | Browser (`Game`/renderers) |
|
|
47
|
+
| `@holtjs/stage/webgpu` | `7.4 kB` | Native WebGPU WGSL batch & analytical SDF `PanelObject` renderer (`RendererWebGpu`, `requestWebGpuDevice`) | Browser WebGPU |
|
|
48
|
+
| `@holtjs/stage/kernel` | `4.8 kB` | `StageKernel`, `StagePlugin`, `ActionMap`, `createInputTimeline` (`trackId` clicks + cursor), recorder/replay | No |
|
|
49
|
+
| `@holtjs/stage/headless` | `38.6 kB` | Zero-browser 60 FPS `createHeadlessStage`, `fastForward`, `renderStoryboard`, `createAudioTimeline` WAV mixer | No (`@napi-rs/canvas`) |
|
|
50
|
+
| `@holtjs/stage/rig2d` | `5.7 kB` | 2D cutout skeletal rig (`defineRig2DSkeleton`, `Rig2DInstance`, `mountRig2D`, `bakeCutoutAtlas`), O(1) slot swap & 2-layer mixer | No |
|
|
51
|
+
| `@holtjs/stage/tilemap` | `3.5 kB` | Sparse `ChunkedTilemap`, 16-tile Dual-Grid & 47-tile Blob autotilers, biome generator, `mountChunkedTilemap` | No |
|
|
52
|
+
| `@holtjs/stage/projection` | `1.6 kB` | Rotatable 2.5D `Camera25D` (`worldToScreen` ↔ `screenToGround`) + `mountStage25D` upright cylindrical billboards | No |
|
|
53
|
+
| `@holtjs/stage/lighting` | `4.1 kB` | `DayNightCycle`, 3×3 Sobel normal-map baker, `Lighting2DSystem` (`MULTIPLY` lightmap), WebGL2 normal-lit sprite pass | No |
|
|
54
|
+
| `@holtjs/stage/world` | `2.8 kB` | `ItemRegistry`, `InventoryContainer` (spoilage), `RecipeRegistry`, `WorkstationScheduler`, `HWLD` binary `WorldDeltaSave` | No |
|
|
55
|
+
| `@holtjs/stage/flex` | `2.3 kB` | Pure 1D Flex & Wrap layout solvers (`computeFlexLayout`, `computeWrapLayout`, `resolvePadding`) | No |
|
|
56
|
+
| `@holtjs/stage/tween` | `1.4 kB` | Deterministic `TweenManager`, `Easings`, and damped springs | No |
|
|
57
|
+
| `@holtjs/stage/joystick` | `4.4 kB` | `VirtualJoystick` + pure vector/origin/8-way D-pad math helpers | Pure helpers: No |
|
|
58
|
+
| `@holtjs/stage/surfaces` | `2.2 kB` | Godot-inspired `SurfaceTree` input barrier & DOM `z-index` router | No |
|
|
59
|
+
| `@holtjs/stage/trace` | `1.9 kB` | Privacy-safe `buildSceneDigest()` and `sanitizeTrackToken()` | No |
|
|
60
|
+
| `@holtjs/stage/spatial` | `1.2 kB` | Zero-GC CSR `SpatialHashGrid` for broadphase queries & crowd separation | No |
|
|
61
|
+
| `@holtjs/stage/hit` | `1.1 kB` | Deterministic swept-circle, arc, segment, capsule, AABB hit & knockback math | No |
|
|
62
|
+
| `@holtjs/stage/nav` | `2.3 kB` | Multi-target `FlowFieldGrid`, A* + LOS string-pulling (`findGridPath`), steering | No |
|
|
63
|
+
| `@holtjs/stage/particles` | `3.0 kB` | Zero-GC `ParticlePool`, `AmbientEmitterPool`, and `JuiceController` (hitstop/shake) | No |
|
|
64
|
+
| `@holtjs/stage/audio` | `4.0 kB` | Procedural foley DSP (`renderFoley`), `spatialMix`, sfxr voices, PCM16 WAV export | No |
|
|
65
|
+
| `@holtjs/stage/ecs` | `3.5 kB` | Dense-packed zero-GC `SoaWorld` ECS, spatial sync, depth sort & 2.5D `DepthBand`s | No |
|
|
66
|
+
|
|
67
|
+
## Quick Starts
|
|
68
|
+
|
|
69
|
+
### 1. WebGPU-First Bootstrap with Automatic WebGL2 / Canvas2D Fallback
|
|
73
70
|
|
|
74
71
|
```ts
|
|
75
|
-
import {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class DemoScene extends Scene {
|
|
85
|
-
create() {
|
|
86
|
-
const layout = computeFlexLayout(
|
|
87
|
-
{ dir: 'row', w: 480, h: 120, gap: 12, padding: 16, align: 'center' },
|
|
88
|
-
[
|
|
89
|
-
{ w: 140, h: 80 },
|
|
90
|
-
{ w: 0, h: 80, grow: 1 },
|
|
91
|
-
],
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const card = this.add.panel(layout.rects[0].x, layout.rects[0].y, layout.rects[0].w, layout.rects[0].h, {
|
|
95
|
-
fillColor: 0xfff8e7,
|
|
96
|
-
borderColor: 0x2c241d,
|
|
97
|
-
borderWidth: 2,
|
|
98
|
-
radius: 14,
|
|
99
|
-
});
|
|
100
|
-
card.trackId = 'demo.card';
|
|
101
|
-
card.role = 'panel';
|
|
102
|
-
|
|
103
|
-
// Deterministic spring animation bound to the node's lifetime
|
|
104
|
-
this.tweens.spring({
|
|
105
|
-
from: card.y + 12,
|
|
106
|
-
to: card.y,
|
|
107
|
-
stiffness: 240,
|
|
108
|
-
damping: 20,
|
|
109
|
-
owner: card,
|
|
110
|
-
onUpdate: (y) => { card.y = y; },
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Privacy-safe structural trace snapshot
|
|
114
|
-
console.log(buildSceneDigest(this, { traceId: 'demo-trace-01' }));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
72
|
+
import { AUTO, Game, Scene, Scale, WEBGPU } from '@holtjs/stage';
|
|
73
|
+
import { requestWebGpuDevice } from '@holtjs/stage/webgpu';
|
|
74
|
+
|
|
75
|
+
const canvas = document.createElement('canvas');
|
|
76
|
+
document.getElementById('app')!.appendChild(canvas);
|
|
77
|
+
|
|
78
|
+
// Probes navigator.gpu cleanly; returns null when WebGPU is unavailable
|
|
79
|
+
const gpu = await requestWebGpuDevice(canvas, { powerPreference: 'high-performance' });
|
|
117
80
|
|
|
118
81
|
new Game({
|
|
119
|
-
type: AUTO,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
82
|
+
type: gpu ? WEBGPU : AUTO,
|
|
83
|
+
canvas,
|
|
84
|
+
webgpu: gpu ?? undefined,
|
|
85
|
+
width: 960,
|
|
86
|
+
height: 540,
|
|
87
|
+
backgroundColor: '#131722',
|
|
124
88
|
scale: { mode: Scale.NONE },
|
|
125
|
-
scene: [
|
|
89
|
+
scene: [MyScene],
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 2. `StageKernel` Actions & Semantic `InputTimeline` (`@holtjs/stage/kernel`)
|
|
94
|
+
|
|
95
|
+
Drive the exact same scene from physical keyboard/mouse, automated tests, or cinematic trailers — clicking UI elements directly by `trackId` via `buildSceneDigest()`:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { createInputTimeline } from '@holtjs/stage/kernel';
|
|
99
|
+
|
|
100
|
+
// Bind semantic actions once on game.kernel.actions
|
|
101
|
+
game.kernel.actions
|
|
102
|
+
.bind('rotateCCW', ['KeyQ'])
|
|
103
|
+
.bind('rotateCW', ['KeyE'])
|
|
104
|
+
.bind('interact', ['Space', 'KeyF']);
|
|
105
|
+
|
|
106
|
+
// Script deterministic player input with a rendered virtual cursor & click ripples
|
|
107
|
+
const timeline = createInputTimeline({ showCursor: true, cursorColor: 0xffe066 });
|
|
108
|
+
timeline
|
|
109
|
+
.moveTo(640, 360, 0, 200)
|
|
110
|
+
.click('craft.torch', 600, { moveDurationMs: 280 }) // resolves bounds of node with trackId === 'craft.torch'
|
|
111
|
+
.pressKey('KeyE', 1200, 750); // smoothly orbits 2.5D camera via ActionMap
|
|
112
|
+
|
|
113
|
+
game.kernel.use(timeline);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 3. 2.5D Survival Sandbox (`rig2d` + `tilemap` + `projection` + `lighting` + `world`)
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { defineRig2DSkeleton, Rig2DInstance, mountRig2D } from '@holtjs/stage/rig2d';
|
|
120
|
+
import {
|
|
121
|
+
ChunkedTilemap, SurvivalBiomes, bakeDualGridTileset, createIslandBiomeGenerator, mountChunkedTilemap,
|
|
122
|
+
} from '@holtjs/stage/tilemap';
|
|
123
|
+
import { Camera25D, mountStage25D } from '@holtjs/stage/projection';
|
|
124
|
+
import { DayNightCycle, Lighting2DSystem } from '@holtjs/stage/lighting';
|
|
125
|
+
import { captureWorldDelta, encodeWorldDeltaBytes } from '@holtjs/stage/world';
|
|
126
|
+
|
|
127
|
+
const map = new ChunkedTilemap({
|
|
128
|
+
chunkSize: 16,
|
|
129
|
+
tileSize: 36,
|
|
130
|
+
generator: createIslandBiomeGenerator({ seed: 42, islandRadiusTiles: 24 }),
|
|
126
131
|
});
|
|
132
|
+
const dgAtlas = bakeDualGridTileset('island_dg', 36, [
|
|
133
|
+
{ id: 'beach', fillColor: 0xe6c88c, edgeColor: 0xfef3c7, matches: (t) => t >= SurvivalBiomes.BEACH },
|
|
134
|
+
{ id: 'meadow', fillColor: 0x5c8d3e, edgeColor: 0x3f6212, matches: (t) => t >= SurvivalBiomes.MEADOW },
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
const cam25 = new Camera25D({ viewportWidth: 1280, viewportHeight: 720, pitch: 0.84, zoom: 1.4 });
|
|
138
|
+
const stage25 = mountStage25D(scene, cam25, { depth: 10 });
|
|
139
|
+
const terrain = mountChunkedTilemap(scene, map, dgAtlas);
|
|
140
|
+
terrain.container.removeFromDisplayList();
|
|
141
|
+
stage25.groundWorld.add(terrain.container);
|
|
142
|
+
|
|
143
|
+
const heroRig = new Rig2DInstance(survivorSkeleton);
|
|
144
|
+
heroRig.play('walk');
|
|
145
|
+
heroRig.setAttachment('tool', 'axe_iron'); // O(1) slot swap without resetting walk cycle
|
|
146
|
+
heroRig.playOverlay('chop', { maskBones: ['arm_r', 'hand_r'] }); // upper-body chop while walking!
|
|
147
|
+
const heroView = mountRig2D(scene, heroRig, { depth: 20, trackId: 'actor.survivor' });
|
|
148
|
+
stage25.registerBillboard(heroView.container, 0, 0);
|
|
149
|
+
|
|
150
|
+
const cycle = new DayNightCycle({ dayLengthMs: 480_000 });
|
|
151
|
+
const lights = new Lighting2DSystem(scene, { width: 1280, height: 720, depth: 500 });
|
|
152
|
+
lights.addLight({ id: 'campfire', x: 0, y: 0, z: 18, radius: 240, color: 0xffa94d, intensity: 1, flicker: 0.18 });
|
|
153
|
+
|
|
154
|
+
// Save modified tiles + inventories + workstations in a compact binary HWLD delta
|
|
155
|
+
const saveBytes = encodeWorldDeltaBytes(captureWorldDelta({ seed: 42, simTimeMs: 120_000, tilemap: map }));
|
|
127
156
|
```
|
|
128
157
|
|
|
129
158
|
## AI Agent Support (`AGENTS.md`, Skills & `llms.txt`)
|
|
130
159
|
|
|
131
|
-
|
|
160
|
+
`@holtjs/stage` ships a full AI Agent Kit directly inside the npm tarball (`node_modules/@holtjs/stage/skills/stage/`):
|
|
132
161
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
- **
|
|
138
|
-
- **
|
|
162
|
+
```bash
|
|
163
|
+
npx skills add botiverse-play/stage
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- **Agent Skill**: [skills/stage/SKILL.md](skills/stage/SKILL.md) + [references/subpaths.md](skills/stage/references/subpaths.md)
|
|
167
|
+
- **Repository Agent Guide**: [AGENTS.md](AGENTS.md) & [skills/stage-contributor/SKILL.md](skills/stage-contributor/SKILL.md)
|
|
168
|
+
- **Machine-Readable Index**: [llms.txt](llms.txt)
|
|
139
169
|
|
|
140
170
|
## Runnable Examples
|
|
141
171
|
|
|
142
172
|
| Example | What it demonstrates | How to run |
|
|
143
173
|
|---|---|---|
|
|
174
|
+
| [examples/nightfall-trailer.mjs](examples/nightfall-trailer.mjs) | **12s 60 FPS 2.5D Survival Trailer** (`StageKernel` + `InputTimeline` + `rig2d` + Dual-Grid `tilemap` + rotatable `Camera25D` + `DayNightCycle`/`Lighting2DSystem` + `world` + stereo score) | `pnpm run pack && pnpm run example:nightfall` |
|
|
175
|
+
| [examples/headless-video.mjs](examples/headless-video.mjs) | Zero-browser 1280x720 60 FPS storyboard PNG + stereo WAV + H.264 MP4 video pipeline | `pnpm run pack && pnpm run example:video` |
|
|
176
|
+
| [examples/headless-sim.mjs](examples/headless-sim.mjs) | Zero-DOM Node 24 authoritative tick (`SoaWorld` + `FlowFieldGrid` + `sweptCircleHit` + `partitionDepthBands`) | `pnpm run pack && pnpm run example:headless` |
|
|
144
177
|
| [examples/showcase.html](examples/showcase.html) | Full 2-tab interactive Showcase (`2D Game Engine Lab` + `UI & SurfaceTree`) | `pnpm run build:pages && npx serve dist-pages` |
|
|
145
178
|
| [examples/minimal-game.html](examples/minimal-game.html) | ~120-line 2D arena (`SoaWorld` + `FlowFieldGrid` + `SpatialHashGrid` + `hit` + `ParticlePool` + `JuiceController`) | Open `/examples/minimal-game.html` from `dist-pages` |
|
|
146
179
|
| [examples/minimal-ui.html](examples/minimal-ui.html) | ~120-line GPU SDF UI (`computeFlexLayout` + `pixelStep` + damped springs + `SurfaceTree` Escape modal + `buildSceneDigest`) | Open `/examples/minimal-ui.html` from `dist-pages` |
|
|
147
|
-
| [examples/headless-sim.mjs](examples/headless-sim.mjs) | Zero-DOM Node 24 authoritative tick (`SoaWorld` + `FlowFieldGrid` + `sweptCircleHit` + `partitionDepthBands`) | `pnpm run pack && pnpm run example:headless` |
|
|
148
|
-
| [examples/headless-video.mjs](examples/headless-video.mjs) | Zero-browser 1280x720 60 FPS storyboard PNG + stereo WAV + H.264 MP4 video pipeline | `pnpm run pack && pnpm run example:video` |
|
|
149
180
|
|
|
150
|
-
## Development &
|
|
181
|
+
## Development & Verification
|
|
151
182
|
|
|
152
183
|
```bash
|
|
153
184
|
pnpm install
|
|
@@ -158,16 +189,6 @@ pnpm run build:pages
|
|
|
158
189
|
pnpm run size
|
|
159
190
|
```
|
|
160
191
|
|
|
161
|
-
Preview the 2-tab interactive Showcase (`2D Game Engine Lab` + `UI & SurfaceTree`) locally with `pnpm run build:pages && npx serve dist-pages`. Static hosting is pre-configured for **AWS Amplify** (`amplify.yml` + `customHttp.yml`) and **GitHub Pages** (`.github/workflows/pages.yml`).
|
|
162
|
-
|
|
163
|
-
See [docs/architecture.md](docs/architecture.md) for deep technical details on GPU batching invariants, coordinate/DPR contracts, cascading disposal, `SurfaceTree`, and tracing-first observability, and [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request.
|
|
164
|
-
|
|
165
|
-
## Community & Security
|
|
166
|
-
|
|
167
|
-
- Contributions welcome — see [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
|
|
168
|
-
- Release history — see [CHANGELOG.md](CHANGELOG.md).
|
|
169
|
-
- Security reports — see [SECURITY.md](SECURITY.md) (please do not open public issues for vulnerabilities).
|
|
170
|
-
|
|
171
192
|
## License
|
|
172
193
|
|
|
173
194
|
Apache License 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { bt as ImageObject, jt as SceneHostLike, pt as CustomPassObject } from "./game-GdPaQUqH.js";
|
|
2
|
+
export type DayPhase = 'day' | 'dusk' | 'night';
|
|
3
|
+
export interface DayNightConfig {
|
|
4
|
+
dayLengthMs?: number;
|
|
5
|
+
dayRatio?: number;
|
|
6
|
+
duskRatio?: number;
|
|
7
|
+
initialTime01?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface DayNightState {
|
|
10
|
+
time01: number;
|
|
11
|
+
dayCount: number;
|
|
12
|
+
phase: DayPhase;
|
|
13
|
+
ambientRgb: number;
|
|
14
|
+
/** 0.0 at bright noon -> up to ~0.92 in pitch-black night. */
|
|
15
|
+
darkness: number;
|
|
16
|
+
sunAzimuthRad: number;
|
|
17
|
+
sunElevationRad: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function lerpRgb(rgbA: number, rgbB: number, t: number): number;
|
|
20
|
+
/** Deterministic *Don't Starve* / *Graveyard Keeper* Day -> Dusk -> Night clock controller. */
|
|
21
|
+
export declare class DayNightCycle {
|
|
22
|
+
readonly dayLengthMs: number;
|
|
23
|
+
readonly dayRatio: number;
|
|
24
|
+
readonly duskRatio: number;
|
|
25
|
+
time01: number;
|
|
26
|
+
dayCount: number;
|
|
27
|
+
constructor(cfg?: DayNightConfig);
|
|
28
|
+
step(deltaMs: number): DayNightState;
|
|
29
|
+
setTime01(t: number): DayNightState;
|
|
30
|
+
sample(out?: DayNightState): DayNightState;
|
|
31
|
+
}
|
|
32
|
+
export interface NormalMapBakeOptions {
|
|
33
|
+
/** Bevel strength along alpha silhouette & luminance height (`default = 2.4`). */
|
|
34
|
+
strength?: number;
|
|
35
|
+
/** Weight of RGB luminance relative to alpha silhouette (`0 = pure silhouette dome`, `default = 0.35`). */
|
|
36
|
+
luminanceWeight?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Compute a tangent-space RGBA normal map (`R = nx*0.5+0.5`, `G = ny*0.5+0.5`, `B = nz*0.5+0.5`, `A = sourceAlpha`)
|
|
40
|
+
* from raw `Uint8ClampedArray` RGBA pixels using a 3x3 Sobel height gradient.
|
|
41
|
+
* Pure zero-DOM function usable in Node, Workers, and browsers!
|
|
42
|
+
*/
|
|
43
|
+
export declare function computeNormalMapPixels(rgba: Uint8ClampedArray | Uint8Array, width: number, height: number, opts?: NormalMapBakeOptions): Uint8ClampedArray;
|
|
44
|
+
/** Bake a tangent-space normal map `HTMLCanvasElement` directly from any 2D sprite/cutout atlas canvas! */
|
|
45
|
+
export declare function bakeNormalMapCanvas(sourceCanvas: HTMLCanvasElement, createCanvasFn?: (w: number, h: number) => HTMLCanvasElement, opts?: NormalMapBakeOptions): HTMLCanvasElement;
|
|
46
|
+
export interface PointLight2D {
|
|
47
|
+
id: string;
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
/** Height of light above the 2D sprite plane in pixels (`default = 36`, controls normal-map grazing angle). */
|
|
51
|
+
z: number;
|
|
52
|
+
radius: number;
|
|
53
|
+
color: number;
|
|
54
|
+
intensity: number;
|
|
55
|
+
/** Torch flame organic flicker amplitude in `[0, 0.5]` (`default = 0`). */
|
|
56
|
+
flicker?: number;
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Evaluate exact 2D normal-mapped Lambertian + specular lighting at pixel `(px, py)` for unit-testing & CPU reference parity.
|
|
61
|
+
*/
|
|
62
|
+
export declare function evaluateNormalLitPixel(baseRgb: number, normalX: number, normalY: number, normalZ: number, px: number, py: number, ambientRgb: number, lights: ReadonlyArray<PointLight2D>): number;
|
|
63
|
+
export interface Lighting2DSystemOptions {
|
|
64
|
+
key?: string;
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
/** Downscale factor for the offscreen lightmap FBO (`2` = half-res soft butter-smooth light falloff at 1/4 fillrate!). */
|
|
68
|
+
resolutionScale?: number;
|
|
69
|
+
depth?: number;
|
|
70
|
+
cycle?: DayNightCycle;
|
|
71
|
+
}
|
|
72
|
+
export declare class Lighting2DSystem {
|
|
73
|
+
readonly scene: SceneHostLike;
|
|
74
|
+
readonly cycle: DayNightCycle;
|
|
75
|
+
readonly overlayImage: ImageObject;
|
|
76
|
+
private renderTarget;
|
|
77
|
+
private readonly lightGraphics;
|
|
78
|
+
private readonly lights;
|
|
79
|
+
private resScale;
|
|
80
|
+
private viewportW;
|
|
81
|
+
private viewportH;
|
|
82
|
+
private elapsedSec;
|
|
83
|
+
private manualAmbientRgb;
|
|
84
|
+
constructor(scene: SceneHostLike, opts: Lighting2DSystemOptions);
|
|
85
|
+
addLight(light: PointLight2D): PointLight2D;
|
|
86
|
+
getLight(id: string): PointLight2D | undefined;
|
|
87
|
+
removeLight(id: string): boolean;
|
|
88
|
+
get lightCount(): number;
|
|
89
|
+
setAmbientOverride(rgb: number | null): void;
|
|
90
|
+
resize(width: number, height: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Step the day/night cycle + torch flicker and render the `MULTIPLY` lightmap FBO!
|
|
93
|
+
* Pass `projectToScreen` when using `Camera25D`; otherwise defaults to `scene.cameras.main.worldToScreen`.
|
|
94
|
+
*/
|
|
95
|
+
update(deltaMs: number, projectToScreen?: (wx: number, wy: number, wz: number, out: {
|
|
96
|
+
x: number;
|
|
97
|
+
y: number;
|
|
98
|
+
scale: number;
|
|
99
|
+
}) => void): DayNightState;
|
|
100
|
+
destroy(): void;
|
|
101
|
+
}
|
|
102
|
+
export interface NormalLitQuad {
|
|
103
|
+
x: number;
|
|
104
|
+
y: number;
|
|
105
|
+
width: number;
|
|
106
|
+
height: number;
|
|
107
|
+
u0?: number;
|
|
108
|
+
v0?: number;
|
|
109
|
+
u1?: number;
|
|
110
|
+
v1?: number;
|
|
111
|
+
originX?: number;
|
|
112
|
+
originY?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a state-isolated WebGL2 `CustomPass` that renders normal-mapped 2D props/characters with per-pixel
|
|
116
|
+
* 3D tangent-space point lighting (`uDiffuse` + `uNormal`), gracefully no-oping on Canvas2D!
|
|
117
|
+
*/
|
|
118
|
+
export declare function createNormalLitSpritePass(scene: SceneHostLike, diffuseKey: string, normalKey: string, getQuadsAndLights: () => {
|
|
119
|
+
ambientRgb: number;
|
|
120
|
+
quads: ReadonlyArray<NormalLitQuad>;
|
|
121
|
+
lights: ReadonlyArray<{
|
|
122
|
+
screenX: number;
|
|
123
|
+
screenY: number;
|
|
124
|
+
z: number;
|
|
125
|
+
radius: number;
|
|
126
|
+
color: number;
|
|
127
|
+
intensity: number;
|
|
128
|
+
}>;
|
|
129
|
+
}): CustomPassObject;
|