@holtjs/stage 0.0.0-stage → 0.3.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 +62 -0
- package/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +172 -2
- package/dist/audio.d.ts +159 -0
- package/dist/audio.js +781 -0
- package/dist/ecs.d.ts +172 -0
- package/dist/ecs.js +537 -0
- package/dist/flex.d.ts +113 -0
- package/dist/flex.js +426 -0
- package/dist/game-BHDcwovp.js +6725 -0
- package/dist/game-NqFMKsuL.d.ts +1205 -0
- package/dist/headless.d.ts +147 -0
- package/dist/headless.js +327 -0
- package/dist/hit.d.ts +63 -0
- package/dist/hit.js +185 -0
- package/dist/index.d.ts +307 -0
- package/dist/index.js +45 -0
- package/dist/joystick.d.ts +233 -0
- package/dist/joystick.js +763 -0
- package/dist/nav.d.ts +119 -0
- package/dist/nav.js +342 -0
- package/dist/particles.d.ts +219 -0
- package/dist/particles.js +478 -0
- package/dist/spatial.d.ts +70 -0
- package/dist/spatial.js +165 -0
- package/dist/surfaces.d.ts +209 -0
- package/dist/surfaces.js +567 -0
- package/dist/trace.d.ts +143 -0
- package/dist/trace.js +246 -0
- package/dist/tween-D3Ztppuz.d.ts +91 -0
- package/dist/tween.d.ts +2 -0
- package/dist/tween.js +312 -0
- package/dist/types-ChGhuDNX.js +165 -0
- package/llms.txt +40 -0
- package/package.json +107 -4
- package/skills/stage/SKILL.md +282 -0
- package/skills/stage/references/subpaths.md +74 -0
package/dist/ecs.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { SpatialHashGrid } from "./spatial.js";
|
|
2
|
+
/** Supported TypedArray scalar column kinds for SoA components. */
|
|
3
|
+
export type ComponentFieldType = 'f32' | 'f64' | 'i32' | 'u32' | 'i16' | 'u16' | 'i8' | 'u8';
|
|
4
|
+
/** Map from scalar kind token to its concrete TypedArray constructor output. */
|
|
5
|
+
export interface ComponentArrayMap {
|
|
6
|
+
f32: Float32Array;
|
|
7
|
+
f64: Float64Array;
|
|
8
|
+
i32: Int32Array;
|
|
9
|
+
u32: Uint32Array;
|
|
10
|
+
i16: Int16Array;
|
|
11
|
+
u16: Uint16Array;
|
|
12
|
+
i8: Int8Array;
|
|
13
|
+
u8: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
/** Schema dictionary describing a component's flat numeric fields. */
|
|
16
|
+
export type ComponentSchema = Record<string, ComponentFieldType>;
|
|
17
|
+
/** Resolved SoA column object returned by `world.store(def)`. */
|
|
18
|
+
export type ComponentColumns<S extends ComponentSchema> = { [K in keyof S]: ComponentArrayMap[S[K]]; };
|
|
19
|
+
/** Optional initial values object passed to `world.add(entity, def, init)`. */
|
|
20
|
+
export type ComponentInit<S extends ComponentSchema> = { [K in keyof S]?: number; };
|
|
21
|
+
/** Immutable component definition created by `defineComponent()`. */
|
|
22
|
+
export interface ComponentDef<S extends ComponentSchema = ComponentSchema> {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly schema: Readonly<S>;
|
|
25
|
+
readonly fields: readonly (keyof S & string)[];
|
|
26
|
+
}
|
|
27
|
+
/** Opaque generational entity handle (20-bit handle index + 11-bit generation in a positive 31-bit SMI). */
|
|
28
|
+
export type EntityId = number;
|
|
29
|
+
/** Painter's-order slice of depth-sorted slots guaranteed strictly between surrounding 2.5D blockers. */
|
|
30
|
+
export interface DepthBand {
|
|
31
|
+
/** Inclusive start index into the sorted slots buffer. */
|
|
32
|
+
start: number;
|
|
33
|
+
/** Exclusive end index into the sorted slots buffer. */
|
|
34
|
+
end: number;
|
|
35
|
+
/** Depth value guaranteed strictly between adjacent static blocker depths. */
|
|
36
|
+
depth: number;
|
|
37
|
+
}
|
|
38
|
+
/** Options for rebuilding the world's uniform spatial hash grid over dense slots. */
|
|
39
|
+
export interface EcsSpatialOptions {
|
|
40
|
+
originX: number;
|
|
41
|
+
originY: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
cellSize: number;
|
|
45
|
+
}
|
|
46
|
+
/** PII-free snapshot of SoaWorld runtime telemetry (compatible with Stage2D tracing). */
|
|
47
|
+
export interface SoaWorldStats {
|
|
48
|
+
entities: number;
|
|
49
|
+
capacity: number;
|
|
50
|
+
components: number;
|
|
51
|
+
spatialCells: number;
|
|
52
|
+
}
|
|
53
|
+
/** Extract the stable internal handle index (0..1,048,575) from an `EntityId`. */
|
|
54
|
+
export declare function entityIndex(entity: EntityId): number;
|
|
55
|
+
/** Extract the 11-bit generation counter from an `EntityId`. */
|
|
56
|
+
export declare function entityGeneration(entity: EntityId): number;
|
|
57
|
+
/**
|
|
58
|
+
* Define a typed Structure-of-Arrays component schema.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* const Position = defineComponent('Position', { x: 'f32', y: 'f32' });
|
|
62
|
+
* const Velocity = defineComponent('Velocity', { vx: 'f32', vy: 'f32' });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function defineComponent<const S extends ComponentSchema>(name: string, schema: S): ComponentDef<S>;
|
|
66
|
+
/**
|
|
67
|
+
* Dense-packed, zero-GC Structure-of-Arrays (SoA) ECS world.
|
|
68
|
+
*
|
|
69
|
+
* Live entities occupy contiguous dense slots `0 .. world.count - 1` so simulation loops,
|
|
70
|
+
* frustum culling, spatial indexing, and GPU instanced buffer uploads iterate straight over
|
|
71
|
+
* flat `TypedArray`s with zero per-frame allocations and zero dead-slot branches.
|
|
72
|
+
*/
|
|
73
|
+
export declare class SoaWorld {
|
|
74
|
+
/** Number of currently live entities (dense slots `0 .. count - 1`). */
|
|
75
|
+
count: number;
|
|
76
|
+
/** Allocated dense slot capacity (always a power of two). */
|
|
77
|
+
capacity: number;
|
|
78
|
+
/** Per-dense-slot 32-bit component membership bitmask (`masks[slot]`). */
|
|
79
|
+
masks: Uint32Array;
|
|
80
|
+
/** Dense slot -> live `EntityId` handle (`entities[slot]`). */
|
|
81
|
+
entities: Uint32Array;
|
|
82
|
+
private handleCapacity;
|
|
83
|
+
private nextHandle;
|
|
84
|
+
private freeCount;
|
|
85
|
+
private freeHandles;
|
|
86
|
+
private handleToSlot;
|
|
87
|
+
private handleGen;
|
|
88
|
+
private stores;
|
|
89
|
+
private defToStore;
|
|
90
|
+
/** Optional uniform CSR spatial hash grid synced over dense slots `0 .. count - 1`. */
|
|
91
|
+
grid: SpatialHashGrid | null;
|
|
92
|
+
private gridOriginX;
|
|
93
|
+
private gridOriginY;
|
|
94
|
+
private gridWidth;
|
|
95
|
+
private gridHeight;
|
|
96
|
+
private gridCellSize;
|
|
97
|
+
private gridMaxItems;
|
|
98
|
+
constructor(initialCapacity?: number);
|
|
99
|
+
/** Register a component definition and return its live SoA TypedArray column view. */
|
|
100
|
+
register<S extends ComponentSchema>(def: ComponentDef<S>): ComponentColumns<S>;
|
|
101
|
+
/** Access the SoA TypedArray column view for `def` (auto-registers if not yet registered). */
|
|
102
|
+
store<S extends ComponentSchema>(def: ComponentDef<S>): ComponentColumns<S>;
|
|
103
|
+
/** Bitmask bit for a single component definition (auto-registers if needed). */
|
|
104
|
+
bitOf(def: ComponentDef<any>): number;
|
|
105
|
+
/** Combined 32-bit component query bitmask for one or more component definitions. */
|
|
106
|
+
maskOf(...defs: readonly ComponentDef<any>[]): number;
|
|
107
|
+
/** Ensure dense slot capacity can hold at least `needed` live entities. */
|
|
108
|
+
ensureCapacity(needed: number): void;
|
|
109
|
+
private ensureHandleCapacity;
|
|
110
|
+
/** Spawn a new entity at dense slot `world.count` (O(1), zero GC). */
|
|
111
|
+
spawn(): EntityId;
|
|
112
|
+
/** Returns true iff `entity` is currently alive (matches generation and live slot). */
|
|
113
|
+
alive(entity: EntityId): boolean;
|
|
114
|
+
/** Return the current dense slot index (`0 .. count - 1`) for `entity`, or `-1` if dead. */
|
|
115
|
+
slotOf(entity: EntityId): number;
|
|
116
|
+
/** Return the live `EntityId` stored at dense `slot`. */
|
|
117
|
+
entityAt(slot: number): EntityId;
|
|
118
|
+
/**
|
|
119
|
+
* Despawn `entity` in O(1) via dense swap-remove.
|
|
120
|
+
* Note: the entity previously at `count - 1` moves into `slotOf(entity)`, keeping
|
|
121
|
+
* dense arrays `0 .. count - 1` gap-free for hot iteration and GPU uploads.
|
|
122
|
+
*/
|
|
123
|
+
despawn(entity: EntityId): boolean;
|
|
124
|
+
/** Attach component `def` to `entity` (optionally setting initial field values). Returns dense slot or `-1`. */
|
|
125
|
+
add<S extends ComponentSchema>(entity: EntityId, def: ComponentDef<S>, init?: ComponentInit<S>): number;
|
|
126
|
+
/** Detach component `def` from `entity`. */
|
|
127
|
+
remove(entity: EntityId, def: ComponentDef<any>): boolean;
|
|
128
|
+
/** Returns true iff `entity` is alive and currently holds component `def`. */
|
|
129
|
+
has(entity: EntityId, def: ComponentDef<any>): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Populate `outSlots` with dense slot indices matching `includeMask` (and excluding `excludeMask`).
|
|
132
|
+
* Returns the number of matching slots written (zero allocations).
|
|
133
|
+
*/
|
|
134
|
+
query(includeMask: number, outSlots: Int32Array, excludeMask?: number): number;
|
|
135
|
+
/** Zero-GC callback iteration over dense slots matching `includeMask` (and excluding `excludeMask`). */
|
|
136
|
+
forEach(includeMask: number, fn: (slot: number, entity: EntityId) => void, excludeMask?: number): void;
|
|
137
|
+
/**
|
|
138
|
+
* Rebuild the uniform CSR `SpatialHashGrid` over dense slots `0 .. count - 1` using position columns.
|
|
139
|
+
* Reuses grid buffers across frames unless map bounds or capacity grow.
|
|
140
|
+
*/
|
|
141
|
+
syncSpatial(xCol: Float32Array | Float64Array, yCol: Float32Array | Float64Array, opts: EcsSpatialOptions): SpatialHashGrid;
|
|
142
|
+
/** Query dense slots within Euclidean `radius` of `(cx, cy)` using the synced spatial grid. */
|
|
143
|
+
queryRadius(cx: number, cy: number, radius: number, xCol: Float32Array | Float64Array, yCol: Float32Array | Float64Array, outSlots: Int32Array, includeMask?: number): number;
|
|
144
|
+
/** Query dense slots inside `[minX, maxX] x [minY, maxY]` using the synced spatial grid. */
|
|
145
|
+
queryRect(minX: number, minY: number, maxX: number, maxY: number, xCol: Float32Array | Float64Array, yCol: Float32Array | Float64Array, outSlots: Int32Array, includeMask?: number): number;
|
|
146
|
+
/** Despawn all live entities while keeping allocated TypedArray capacity and registered components. */
|
|
147
|
+
clear(): void;
|
|
148
|
+
/** PII-free runtime statistics snapshot. */
|
|
149
|
+
stats(): SoaWorldStats;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* In-place zero-GC insertion/Ciura-gap Shell sort of `slots[0..count - 1]` ordered ascending by
|
|
153
|
+
* `depthCol[slot]`, with optional secondary tie-break ascending by `tieCol[slot]` (e.g. primary
|
|
154
|
+
* texture or material ID to minimize GPU batch switches on equal-depth rows).
|
|
155
|
+
*/
|
|
156
|
+
export declare function sortSlotsByDepth(slots: Int32Array, count: number, depthCol: ArrayLike<number>, tieCol?: ArrayLike<number>): void;
|
|
157
|
+
/**
|
|
158
|
+
* Cull entities within `[minX, maxX] x [minY, maxY]` (optionally filtered by `requiredMask`)
|
|
159
|
+
* into `outSlots` and sort them ascending by `depthCol[slot]` with zero allocations.
|
|
160
|
+
*/
|
|
161
|
+
export declare function cullAndSortSlots(count: number, xCol: ArrayLike<number>, yCol: ArrayLike<number>, depthCol: ArrayLike<number>, minX: number, minY: number, maxX: number, maxY: number, outSlots: Int32Array, maskCol?: Uint32Array, requiredMask?: number, tieCol?: ArrayLike<number>): number;
|
|
162
|
+
/**
|
|
163
|
+
* Partition depth-sorted entity slots (`sortedSlots[0..sortedCount - 1]`) into minimal
|
|
164
|
+
* painter's-order `DepthBand` spans strictly interleaved between static 2.5D blockers
|
|
165
|
+
* (`blockerDepths[0..blockerCount - 1]`, sorted ascending).
|
|
166
|
+
*
|
|
167
|
+
* Ideal for hardware-instanced 2.5D rendering: emits only as many instanced passes as there
|
|
168
|
+
* are distinct blocker intervals occupied by visible entities, while clamping open-edge bands
|
|
169
|
+
* to actual entity depths so un-blocked sprites preserve exact painter's order. Reuses objects
|
|
170
|
+
* in `outBands`.
|
|
171
|
+
*/
|
|
172
|
+
export declare function partitionDepthBands(sortedSlots: Int32Array, sortedCount: number, depthCol: ArrayLike<number>, blockerDepths: ArrayLike<number>, blockerCount: number, outBands: DepthBand[]): number;
|