@holtjs/stage 0.15.0 → 0.17.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 +22 -0
- package/dist/ecs.d.ts +18 -0
- package/dist/ecs.js +174 -0
- package/dist/{game-Ce35GTH4.d.ts → game-BrYrde7y.d.ts} +157 -1
- package/dist/{game-CFxS641c.js → game-ChUlbQwx.js} +1 -1
- package/dist/headless.d.ts +151 -4
- package/dist/headless.js +335 -12
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -4
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +468 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/particles.d.ts +75 -0
- package/dist/particles.js +127 -1
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-q4vdE3kA.js → renderer-webgpu-B4AvHUEt.js} +48 -7
- package/dist/renderer-webgpu.d.ts +2 -2
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +1 -1
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/dist/world.d.ts +1 -1
- package/package.json +2 -2
- package/skills/stage/references/subpaths.md +12 -10
package/dist/kernel.js
CHANGED
|
@@ -654,4 +654,471 @@ function createInputReplay(log, id = "stage.input-replay") {
|
|
|
654
654
|
};
|
|
655
655
|
return replay;
|
|
656
656
|
}
|
|
657
|
-
|
|
657
|
+
function fnv1aBytes(buf) {
|
|
658
|
+
let h = 0x811c9dc5;
|
|
659
|
+
for (let i = 0; i < buf.length; i++) {
|
|
660
|
+
h ^= buf[i];
|
|
661
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
662
|
+
}
|
|
663
|
+
return h >>> 0;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Deterministic ring-buffered rollback netcode (GGPO-style prediction + authoritative correction)
|
|
667
|
+
* and interactive Time-Travel debugger with zero steady-state heap allocations.
|
|
668
|
+
*/
|
|
669
|
+
var RollbackSession = class RollbackSession {
|
|
670
|
+
windowFrames;
|
|
671
|
+
curFrame;
|
|
672
|
+
minRecordedFrame;
|
|
673
|
+
codec;
|
|
674
|
+
stepFn;
|
|
675
|
+
inputEq;
|
|
676
|
+
ringFrames;
|
|
677
|
+
ringBufs;
|
|
678
|
+
ringLens;
|
|
679
|
+
ringChecksums;
|
|
680
|
+
ringInputs;
|
|
681
|
+
rollbacks = 0;
|
|
682
|
+
resimFrames = 0;
|
|
683
|
+
maxDepth = 0;
|
|
684
|
+
constructor(options) {
|
|
685
|
+
this.windowFrames = Math.max(2, Math.floor(options.windowFrames ?? 120));
|
|
686
|
+
this.curFrame = Math.max(0, Math.floor(options.initialFrame ?? 0));
|
|
687
|
+
this.minRecordedFrame = this.curFrame;
|
|
688
|
+
this.codec = options.codec;
|
|
689
|
+
this.stepFn = options.step;
|
|
690
|
+
this.inputEq = options.inputEquals ?? Object.is;
|
|
691
|
+
this.ringFrames = new Int32Array(this.windowFrames).fill(-1);
|
|
692
|
+
this.ringBufs = new Array(this.windowFrames);
|
|
693
|
+
this.ringLens = new Uint32Array(this.windowFrames);
|
|
694
|
+
this.ringChecksums = new Uint32Array(this.windowFrames);
|
|
695
|
+
this.ringInputs = new Array(this.windowFrames);
|
|
696
|
+
}
|
|
697
|
+
/** Create a `RollbackSession` bound directly to a `SoaWorld` (`world.snapshot` / `world.restore` / `world.checksum`). */
|
|
698
|
+
static fromSoaWorld(world, step, options = {}) {
|
|
699
|
+
return new RollbackSession({
|
|
700
|
+
...options,
|
|
701
|
+
codec: {
|
|
702
|
+
save: (into) => world.snapshot(into),
|
|
703
|
+
load: (snap) => world.restore(snap),
|
|
704
|
+
checksum: world.checksum ? () => world.checksum() : void 0
|
|
705
|
+
},
|
|
706
|
+
step
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
get currentFrame() {
|
|
710
|
+
return this.curFrame;
|
|
711
|
+
}
|
|
712
|
+
get oldestFrame() {
|
|
713
|
+
return Math.max(this.minRecordedFrame, this.curFrame - this.windowFrames);
|
|
714
|
+
}
|
|
715
|
+
captureAtSlot(slot, frame) {
|
|
716
|
+
let capBuf = this.ringBufs[slot];
|
|
717
|
+
const snap = this.codec.save(capBuf);
|
|
718
|
+
if (!capBuf || snap.buffer !== capBuf.buffer || capBuf.byteLength < snap.byteLength) {
|
|
719
|
+
const nextCap = Math.max(256, snap.byteLength * 2);
|
|
720
|
+
capBuf = new Uint8Array(nextCap);
|
|
721
|
+
capBuf.set(snap, 0);
|
|
722
|
+
this.ringBufs[slot] = capBuf;
|
|
723
|
+
}
|
|
724
|
+
this.ringLens[slot] = snap.byteLength;
|
|
725
|
+
this.ringChecksums[slot] = this.codec.checksum ? this.codec.checksum() >>> 0 : fnv1aBytes(snap);
|
|
726
|
+
this.ringFrames[slot] = frame;
|
|
727
|
+
}
|
|
728
|
+
/** Save pre-step state for `currentFrame`, execute `step(currentFrame, input)`, and advance `currentFrame`. */
|
|
729
|
+
advance(input) {
|
|
730
|
+
const f = this.curFrame;
|
|
731
|
+
const slot = f % this.windowFrames;
|
|
732
|
+
this.captureAtSlot(slot, f);
|
|
733
|
+
this.ringInputs[slot] = input;
|
|
734
|
+
this.stepFn(f, input);
|
|
735
|
+
this.curFrame = f + 1;
|
|
736
|
+
return this.curFrame;
|
|
737
|
+
}
|
|
738
|
+
/** Read the input applied at historical `frame` (within `[oldestFrame .. currentFrame - 1]`). */
|
|
739
|
+
inputAt(frame) {
|
|
740
|
+
if (frame < this.oldestFrame || frame >= this.curFrame) return void 0;
|
|
741
|
+
const slot = frame % this.windowFrames;
|
|
742
|
+
return this.ringFrames[slot] === frame ? this.ringInputs[slot] : void 0;
|
|
743
|
+
}
|
|
744
|
+
/** Compute current live state checksum. */
|
|
745
|
+
currentChecksum() {
|
|
746
|
+
if (this.codec.checksum) return this.codec.checksum() >>> 0;
|
|
747
|
+
return fnv1aBytes(this.codec.save());
|
|
748
|
+
}
|
|
749
|
+
/** Compute checksum of the pre-step snapshot stored at historical `frame` (`null` if evicted). */
|
|
750
|
+
checksumAt(frame) {
|
|
751
|
+
if (frame === this.curFrame) return this.currentChecksum();
|
|
752
|
+
if (frame < this.oldestFrame || frame > this.curFrame) return null;
|
|
753
|
+
const slot = frame % this.windowFrames;
|
|
754
|
+
if (this.ringFrames[slot] !== frame) return null;
|
|
755
|
+
return this.ringChecksums[slot];
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Time-Travel rewind: restore live simulation state back to `targetFrame` (`oldestFrame <= targetFrame <= currentFrame`),
|
|
759
|
+
* resetting `currentFrame = targetFrame` so subsequent `advance()` calls branch into a new timeline cleanly.
|
|
760
|
+
*/
|
|
761
|
+
rewindTo(targetFrame) {
|
|
762
|
+
const tf = Math.floor(targetFrame);
|
|
763
|
+
if (tf === this.curFrame) return;
|
|
764
|
+
if (tf < this.oldestFrame || tf > this.curFrame) throw new RangeError(`RollbackSession.rewindTo: frame ${tf} outside retained window [${this.oldestFrame}..${this.curFrame}]`);
|
|
765
|
+
const slot = tf % this.windowFrames;
|
|
766
|
+
const buf = this.ringBufs[slot];
|
|
767
|
+
if (this.ringFrames[slot] !== tf || !buf) throw new Error(`RollbackSession.rewindTo: missing snapshot for frame ${tf}`);
|
|
768
|
+
this.codec.load(buf.subarray(0, this.ringLens[slot]));
|
|
769
|
+
for (let f = tf + 1; f < this.curFrame; f++) this.ringFrames[f % this.windowFrames] = -1;
|
|
770
|
+
this.curFrame = tf;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Apply an authoritative remote/replay input for `targetFrame`.
|
|
774
|
+
* If it matches the predicted input already simulated at `targetFrame`, returns immediately (`rolledBack: false`).
|
|
775
|
+
* Otherwise restores `targetFrame`'s snapshot, updates the input at `targetFrame`, and re-simulates `[targetFrame .. currentFrame - 1]`.
|
|
776
|
+
*/
|
|
777
|
+
applyAuthoritativeInput(targetFrame, actualInput, equals) {
|
|
778
|
+
const tf = Math.floor(targetFrame);
|
|
779
|
+
if (tf < this.oldestFrame || tf >= this.curFrame) throw new RangeError(`RollbackSession.applyAuthoritativeInput: frame ${tf} outside active window [${this.oldestFrame}..${this.curFrame - 1}]`);
|
|
780
|
+
const slot = tf % this.windowFrames;
|
|
781
|
+
const buf = this.ringBufs[slot];
|
|
782
|
+
if (this.ringFrames[slot] !== tf || !buf) throw new Error(`RollbackSession.applyAuthoritativeInput: missing snapshot at frame ${tf}`);
|
|
783
|
+
if ((equals ?? this.inputEq)(this.ringInputs[slot], actualInput)) return {
|
|
784
|
+
rolledBack: false,
|
|
785
|
+
targetFrame: tf,
|
|
786
|
+
framesResimulated: 0,
|
|
787
|
+
checksum: this.currentChecksum()
|
|
788
|
+
};
|
|
789
|
+
const endFrame = this.curFrame;
|
|
790
|
+
const depth = endFrame - tf;
|
|
791
|
+
this.codec.load(buf.subarray(0, this.ringLens[slot]));
|
|
792
|
+
this.ringInputs[slot] = actualInput;
|
|
793
|
+
for (let f = tf; f < endFrame; f++) {
|
|
794
|
+
const fSlot = f % this.windowFrames;
|
|
795
|
+
if (f > tf) this.captureAtSlot(fSlot, f);
|
|
796
|
+
this.stepFn(f, this.ringInputs[fSlot]);
|
|
797
|
+
}
|
|
798
|
+
this.rollbacks++;
|
|
799
|
+
this.resimFrames += depth;
|
|
800
|
+
if (depth > this.maxDepth) this.maxDepth = depth;
|
|
801
|
+
return {
|
|
802
|
+
rolledBack: true,
|
|
803
|
+
targetFrame: tf,
|
|
804
|
+
framesResimulated: depth,
|
|
805
|
+
checksum: this.currentChecksum()
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
stats() {
|
|
809
|
+
return {
|
|
810
|
+
currentFrame: this.curFrame,
|
|
811
|
+
oldestFrame: this.oldestFrame,
|
|
812
|
+
windowFrames: this.windowFrames,
|
|
813
|
+
rollbackCount: this.rollbacks,
|
|
814
|
+
resimulatedFrames: this.resimFrames,
|
|
815
|
+
maxRollbackDepth: this.maxDepth
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
function createRollbackSession(options) {
|
|
820
|
+
return new RollbackSession(options);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* In-engine virtual camera choreography & spotlight framing plugin (`StagePlugin`) for product demos,
|
|
824
|
+
* scientific visualizations, and game cutscenes. Resolves targets either by world coordinates `{ x, y }`
|
|
825
|
+
* or live `trackId` across scene display nodes and `UiRoot` elements.
|
|
826
|
+
*/
|
|
827
|
+
function createCameraDirector(options = {}) {
|
|
828
|
+
const id = options.id ?? "stage.camera-director";
|
|
829
|
+
let hostKernel = null;
|
|
830
|
+
const cuts = [];
|
|
831
|
+
const pans = [];
|
|
832
|
+
let followState = null;
|
|
833
|
+
let spotState = null;
|
|
834
|
+
let spotGfx = null;
|
|
835
|
+
let spotScene = null;
|
|
836
|
+
const resolveRect = (scene, spec) => {
|
|
837
|
+
const cam = scene.cameras.main;
|
|
838
|
+
const z = cam.zoom || 1;
|
|
839
|
+
if (typeof spec !== "string") {
|
|
840
|
+
const w = spec.w ?? 48;
|
|
841
|
+
const h = spec.h ?? 48;
|
|
842
|
+
const pt = cam.worldToScreen(spec.x, spec.y);
|
|
843
|
+
return {
|
|
844
|
+
wx: spec.x,
|
|
845
|
+
wy: spec.y,
|
|
846
|
+
sx: pt.x - w * z * .5,
|
|
847
|
+
sy: pt.y - h * z * .5,
|
|
848
|
+
sw: w * z,
|
|
849
|
+
sh: h * z
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
let foundNode = null;
|
|
853
|
+
let foundWx = 0;
|
|
854
|
+
let foundWy = 0;
|
|
855
|
+
const walk = (list, px, py) => {
|
|
856
|
+
for (let i = 0; i < list.length; i++) {
|
|
857
|
+
const o = list[i];
|
|
858
|
+
if (!o || !o.active) continue;
|
|
859
|
+
const wx = px + (o.x || 0);
|
|
860
|
+
const wy = py + (o.y || 0);
|
|
861
|
+
if (o.trackId === spec) {
|
|
862
|
+
foundNode = o;
|
|
863
|
+
foundWx = wx;
|
|
864
|
+
foundWy = wy;
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
if (o.type === "Container" && Array.isArray(o.list)) {
|
|
868
|
+
if (walk(o.list, wx, wy)) return true;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return false;
|
|
872
|
+
};
|
|
873
|
+
if (walk(scene.children.list, 0, 0) && foundNode) {
|
|
874
|
+
const dw = Math.max(8, Math.abs(foundNode.displayWidth || foundNode.width || 32));
|
|
875
|
+
const dh = Math.max(8, Math.abs(foundNode.displayHeight || foundNode.height || 32));
|
|
876
|
+
const ox = (foundNode.displayOriginX ?? 0) * Math.abs(foundNode.scaleX ?? 1);
|
|
877
|
+
const oy = (foundNode.displayOriginY ?? 0) * Math.abs(foundNode.scaleY ?? 1);
|
|
878
|
+
const left = foundWx - ox;
|
|
879
|
+
const top = foundWy - oy;
|
|
880
|
+
const cx = left + dw * .5;
|
|
881
|
+
const cy = top + dh * .5;
|
|
882
|
+
const sfx = foundNode.scrollFactorX ?? 1;
|
|
883
|
+
const sfy = foundNode.scrollFactorY ?? 1;
|
|
884
|
+
if (sfx === 0 && sfy === 0) {
|
|
885
|
+
const worldPt = cam.screenToWorld(cx, cy);
|
|
886
|
+
return {
|
|
887
|
+
wx: worldPt.x,
|
|
888
|
+
wy: worldPt.y,
|
|
889
|
+
sx: left,
|
|
890
|
+
sy: top,
|
|
891
|
+
sw: dw,
|
|
892
|
+
sh: dh
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
const scrTl = cam.worldToScreen(left, top);
|
|
896
|
+
return {
|
|
897
|
+
wx: cx,
|
|
898
|
+
wy: cy,
|
|
899
|
+
sx: scrTl.x,
|
|
900
|
+
sy: scrTl.y,
|
|
901
|
+
sw: dw * z,
|
|
902
|
+
sh: dh * z
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
const dg = buildSceneDigest(scene, options.digestOptions);
|
|
906
|
+
for (let i = 0; i < dg.nodes.length; i++) {
|
|
907
|
+
const n = dg.nodes[i];
|
|
908
|
+
if (n.trackId === spec) {
|
|
909
|
+
const [bx, by, bw, bh] = n.bounds;
|
|
910
|
+
const cx = bx + bw * .5;
|
|
911
|
+
const cy = by + bh * .5;
|
|
912
|
+
const tl = cam.worldToScreen(bx, by);
|
|
913
|
+
return {
|
|
914
|
+
wx: cx,
|
|
915
|
+
wy: cy,
|
|
916
|
+
sx: tl.x,
|
|
917
|
+
sy: tl.y,
|
|
918
|
+
sw: Math.max(8, bw * z),
|
|
919
|
+
sh: Math.max(8, bh * z)
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return null;
|
|
924
|
+
};
|
|
925
|
+
const applyInstantCut = (scene, target, zoom) => {
|
|
926
|
+
const cam = scene.cameras.main;
|
|
927
|
+
if (zoom !== void 0 && zoom > 0) cam.setZoom(zoom);
|
|
928
|
+
const rect = resolveRect(scene, target);
|
|
929
|
+
if (rect) cam.centerOn(rect.wx, rect.wy);
|
|
930
|
+
};
|
|
931
|
+
const director = {
|
|
932
|
+
id,
|
|
933
|
+
setup(kernel) {
|
|
934
|
+
hostKernel = kernel;
|
|
935
|
+
return () => {
|
|
936
|
+
hostKernel = null;
|
|
937
|
+
};
|
|
938
|
+
},
|
|
939
|
+
update(scene, _timeMs, deltaMs) {
|
|
940
|
+
const simTimeMs = scene.game.clock.simTimeMs;
|
|
941
|
+
const cam = scene.cameras.main;
|
|
942
|
+
for (let i = 0; i < cuts.length; i++) {
|
|
943
|
+
const c = cuts[i];
|
|
944
|
+
if (!c.fired && simTimeMs >= c.atMs) {
|
|
945
|
+
c.fired = true;
|
|
946
|
+
followState = null;
|
|
947
|
+
applyInstantCut(scene, c.target, c.zoom);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
for (let i = 0; i < pans.length; i++) {
|
|
951
|
+
const p = pans[i];
|
|
952
|
+
if (p.finished) continue;
|
|
953
|
+
const startAt = p.startMs ?? simTimeMs;
|
|
954
|
+
if (p.startMs === null) p.startMs = startAt;
|
|
955
|
+
if (simTimeMs < startAt) continue;
|
|
956
|
+
if (!p.started) {
|
|
957
|
+
p.started = true;
|
|
958
|
+
followState = null;
|
|
959
|
+
cam.syncMetrics();
|
|
960
|
+
p.fromX = cam.worldView.x + cam.worldView.width * .5;
|
|
961
|
+
p.fromY = cam.worldView.y + cam.worldView.height * .5;
|
|
962
|
+
p.fromZoom = cam.zoom || 1;
|
|
963
|
+
}
|
|
964
|
+
const rect = resolveRect(scene, p.target);
|
|
965
|
+
const toX = rect ? rect.wx : p.fromX;
|
|
966
|
+
const toY = rect ? rect.wy : p.fromY;
|
|
967
|
+
const toZ = p.toZoom !== void 0 && p.toZoom > 0 ? p.toZoom : p.fromZoom;
|
|
968
|
+
const rawT = p.durationMs <= 0 ? 1 : Math.min(1, (simTimeMs - startAt) / p.durationMs);
|
|
969
|
+
const e = p.easing(rawT);
|
|
970
|
+
cam.setZoom(p.fromZoom + (toZ - p.fromZoom) * e);
|
|
971
|
+
cam.centerOn(p.fromX + (toX - p.fromX) * e, p.fromY + (toY - p.fromY) * e);
|
|
972
|
+
if (rawT >= 1) p.finished = true;
|
|
973
|
+
}
|
|
974
|
+
if (followState) {
|
|
975
|
+
const rect = resolveRect(scene, followState.target);
|
|
976
|
+
if (rect) {
|
|
977
|
+
if (followState.zoom !== void 0 && followState.zoom > 0) {
|
|
978
|
+
const zAlpha = 1 - Math.pow(1 - followState.lerp, Math.max(1, deltaMs / 16.6667));
|
|
979
|
+
cam.setZoom(cam.zoom + (followState.zoom - cam.zoom) * zAlpha);
|
|
980
|
+
}
|
|
981
|
+
cam.syncMetrics();
|
|
982
|
+
const curX = cam.worldView.x + cam.worldView.width * .5;
|
|
983
|
+
const curY = cam.worldView.y + cam.worldView.height * .5;
|
|
984
|
+
const alpha = 1 - Math.pow(1 - followState.lerp, Math.max(1, deltaMs / 16.6667));
|
|
985
|
+
cam.centerOn(curX + (rect.wx - curX) * alpha, curY + (rect.wy - curY) * alpha);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const activeSpot = spotState && (spotState.startMs === null || simTimeMs >= spotState.startMs) && (spotState.endMs === null || simTimeMs < spotState.endMs) ? spotState : null;
|
|
989
|
+
if (!activeSpot) {
|
|
990
|
+
if (spotGfx && spotGfx.active) {
|
|
991
|
+
spotGfx.clear();
|
|
992
|
+
spotGfx.setVisible(false);
|
|
993
|
+
}
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
const rect = resolveRect(scene, activeSpot.target);
|
|
997
|
+
if (!rect) return;
|
|
998
|
+
if (!spotGfx || spotScene !== scene || !spotGfx.active) {
|
|
999
|
+
spotScene = scene;
|
|
1000
|
+
spotGfx = scene.add.graphics();
|
|
1001
|
+
spotGfx.setDepth(999999e3);
|
|
1002
|
+
spotGfx.setScrollFactor(0, 0);
|
|
1003
|
+
spotGfx.trackId = "stage.camera-spotlight";
|
|
1004
|
+
spotGfx.role = "presentation";
|
|
1005
|
+
}
|
|
1006
|
+
spotGfx.setVisible(true);
|
|
1007
|
+
spotGfx.clear();
|
|
1008
|
+
const vw = cam.width;
|
|
1009
|
+
const vh = cam.height;
|
|
1010
|
+
const pad = activeSpot.padding;
|
|
1011
|
+
const hx = Math.max(0, Math.round(rect.sx - pad));
|
|
1012
|
+
const hy = Math.max(0, Math.round(rect.sy - pad));
|
|
1013
|
+
const hr = Math.min(vw, Math.round(rect.sx + rect.sw + pad));
|
|
1014
|
+
const hb = Math.min(vh, Math.round(rect.sy + rect.sh + pad));
|
|
1015
|
+
const hw = Math.max(0, hr - hx);
|
|
1016
|
+
const hh = Math.max(0, hb - hy);
|
|
1017
|
+
spotGfx.fillStyle(activeSpot.dimColor, activeSpot.dimAlpha);
|
|
1018
|
+
if (hy > 0) spotGfx.fillRect(0, 0, vw, hy);
|
|
1019
|
+
if (hb < vh) spotGfx.fillRect(0, hb, vw, vh - hb);
|
|
1020
|
+
if (hx > 0 && hh > 0) spotGfx.fillRect(0, hy, hx, hh);
|
|
1021
|
+
if (hr < vw && hh > 0) spotGfx.fillRect(hr, hy, vw - hr, hh);
|
|
1022
|
+
if (activeSpot.borderWidth > 0 && hw > 0 && hh > 0) {
|
|
1023
|
+
spotGfx.lineStyle(activeSpot.borderWidth, activeSpot.borderColor, .95);
|
|
1024
|
+
spotGfx.strokeRect(hx, hy, hw, hh);
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
digest() {
|
|
1028
|
+
const cam = (hostKernel?.game.scene.scenes[0])?.cameras.main;
|
|
1029
|
+
return {
|
|
1030
|
+
zoom: cam ? +cam.zoom.toFixed(3) : 1,
|
|
1031
|
+
scrollX: cam ? Math.round(cam.scrollX) : 0,
|
|
1032
|
+
scrollY: cam ? Math.round(cam.scrollY) : 0,
|
|
1033
|
+
following: Boolean(followState),
|
|
1034
|
+
spotlight: Boolean(spotState)
|
|
1035
|
+
};
|
|
1036
|
+
},
|
|
1037
|
+
dispose() {
|
|
1038
|
+
spotGfx?.destroy();
|
|
1039
|
+
spotGfx = null;
|
|
1040
|
+
spotScene = null;
|
|
1041
|
+
hostKernel = null;
|
|
1042
|
+
},
|
|
1043
|
+
cutTo(target, cutOpts = {}) {
|
|
1044
|
+
if (cutOpts.atMs !== void 0) cuts.push({
|
|
1045
|
+
target,
|
|
1046
|
+
atMs: Math.max(0, cutOpts.atMs),
|
|
1047
|
+
zoom: cutOpts.zoom,
|
|
1048
|
+
fired: false
|
|
1049
|
+
});
|
|
1050
|
+
else {
|
|
1051
|
+
followState = null;
|
|
1052
|
+
const sc = hostKernel?.game.scene.scenes[0];
|
|
1053
|
+
if (sc) applyInstantCut(sc, target, cutOpts.zoom);
|
|
1054
|
+
}
|
|
1055
|
+
return director;
|
|
1056
|
+
},
|
|
1057
|
+
panTo(target, panOpts = {}) {
|
|
1058
|
+
pans.push({
|
|
1059
|
+
target,
|
|
1060
|
+
startMs: panOpts.atMs !== void 0 ? Math.max(0, panOpts.atMs) : null,
|
|
1061
|
+
durationMs: Math.max(0, panOpts.durationMs ?? 450),
|
|
1062
|
+
toZoom: panOpts.zoom,
|
|
1063
|
+
easing: panOpts.easing ?? Easings.inOutCubic,
|
|
1064
|
+
started: false,
|
|
1065
|
+
finished: false,
|
|
1066
|
+
fromX: 0,
|
|
1067
|
+
fromY: 0,
|
|
1068
|
+
fromZoom: 1
|
|
1069
|
+
});
|
|
1070
|
+
return director;
|
|
1071
|
+
},
|
|
1072
|
+
follow(target, followOpts = {}) {
|
|
1073
|
+
followState = {
|
|
1074
|
+
target,
|
|
1075
|
+
lerp: Math.max(.01, Math.min(1, followOpts.lerp ?? .18)),
|
|
1076
|
+
zoom: followOpts.zoom
|
|
1077
|
+
};
|
|
1078
|
+
return director;
|
|
1079
|
+
},
|
|
1080
|
+
stopFollow() {
|
|
1081
|
+
followState = null;
|
|
1082
|
+
return director;
|
|
1083
|
+
},
|
|
1084
|
+
spotlight(target, spotOpts = {}) {
|
|
1085
|
+
const startMs = spotOpts.atMs !== void 0 ? Math.max(0, spotOpts.atMs) : null;
|
|
1086
|
+
const dur = spotOpts.durationMs && spotOpts.durationMs > 0 ? spotOpts.durationMs : null;
|
|
1087
|
+
const curNow = hostKernel?.game.clock.simTimeMs ?? 0;
|
|
1088
|
+
spotState = {
|
|
1089
|
+
target,
|
|
1090
|
+
padding: Math.max(0, spotOpts.padding ?? 14),
|
|
1091
|
+
dimColor: spotOpts.dimColor ?? 527122,
|
|
1092
|
+
dimAlpha: Math.max(0, Math.min(1, spotOpts.dimAlpha ?? .68)),
|
|
1093
|
+
borderColor: spotOpts.borderColor ?? 0xb6ef48,
|
|
1094
|
+
borderWidth: Math.max(0, spotOpts.borderWidth ?? 2.5),
|
|
1095
|
+
startMs,
|
|
1096
|
+
endMs: dur !== null ? (startMs ?? curNow) + dur : null
|
|
1097
|
+
};
|
|
1098
|
+
return director;
|
|
1099
|
+
},
|
|
1100
|
+
clearSpotlight() {
|
|
1101
|
+
spotState = null;
|
|
1102
|
+
if (spotGfx && spotGfx.active) {
|
|
1103
|
+
spotGfx.clear();
|
|
1104
|
+
spotGfx.setVisible(false);
|
|
1105
|
+
}
|
|
1106
|
+
return director;
|
|
1107
|
+
},
|
|
1108
|
+
reset() {
|
|
1109
|
+
cuts.length = 0;
|
|
1110
|
+
pans.length = 0;
|
|
1111
|
+
followState = null;
|
|
1112
|
+
director.clearSpotlight();
|
|
1113
|
+
const sc = hostKernel?.game.scene.scenes[0];
|
|
1114
|
+
if (sc) {
|
|
1115
|
+
const cam = sc.cameras.main;
|
|
1116
|
+
cam.setZoom(1);
|
|
1117
|
+
cam.setScroll(0, 0);
|
|
1118
|
+
}
|
|
1119
|
+
return director;
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
return director;
|
|
1123
|
+
}
|
|
1124
|
+
export { ActionMap, RollbackSession, ScriptScheduler, StageKernel, createCameraDirector, createInputRecorder, createInputReplay, createInputTimeline, createRollbackSession };
|
package/dist/lighting.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { An as Container, Kn as ImageObject, Ln as DisplayObject, Nn as CustomPassObject, Tn as StageRenderTarget, rr as SceneHostLike } from "./game-BrYrde7y.js";
|
|
2
2
|
export type DayPhase = 'day' | 'dusk' | 'night';
|
|
3
3
|
export interface DayNightConfig {
|
|
4
4
|
dayLengthMs?: number;
|
package/dist/particles.d.ts
CHANGED
|
@@ -216,4 +216,79 @@ export declare class JuiceController {
|
|
|
216
216
|
* Returns effective world particle delta in seconds (`0` while held in hitstop).
|
|
217
217
|
*/
|
|
218
218
|
tick(frameMs: number, nowMs: number, paused?: boolean): number;
|
|
219
|
+
}
|
|
220
|
+
export interface LocomotionFeelOptions {
|
|
221
|
+
/** Spring stiffness driving squash/stretch recovery back to `1.0` (`default = 260`). */
|
|
222
|
+
readonly stiffness?: number;
|
|
223
|
+
/** Damping ratio (`< 1` bouncy, `1` critically damped; `default = 0.62` for lively rubbery settle). */
|
|
224
|
+
readonly dampingRatio?: number;
|
|
225
|
+
/** Maximum lean angle in radians at full reference horizontal speed (`default = 0.12` rad ~ 7 deg). */
|
|
226
|
+
readonly maxLeanRad?: number;
|
|
227
|
+
/** Reference movement speed in world px/s for full lean & stride bob (`default = 180`). */
|
|
228
|
+
readonly referenceSpeed?: number;
|
|
229
|
+
/** Automatic squash impulse injected when reversing movement direction sharply (`default = -0.18`). */
|
|
230
|
+
readonly turnSquash?: number;
|
|
231
|
+
/** Automatic squash factor per px/s of downward landing velocity (`default = 0.0014`). */
|
|
232
|
+
readonly landSquashScale?: number;
|
|
233
|
+
/** Optional vertical stride hop amplitude in pixels while moving on the ground (`default = 0`). */
|
|
234
|
+
readonly strideBobPx?: number;
|
|
235
|
+
/** Stride hop frequency in Hz (`default = 7.5`). */
|
|
236
|
+
readonly strideFreqHz?: number;
|
|
237
|
+
}
|
|
238
|
+
export interface LocomotionFeelInput {
|
|
239
|
+
readonly vx: number;
|
|
240
|
+
readonly vy: number;
|
|
241
|
+
/** Optional height above ground (`>= 0`); triggers automatic landing squash when touching down to `0`. */
|
|
242
|
+
readonly wz?: number;
|
|
243
|
+
}
|
|
244
|
+
export interface LocomotionFeelSample {
|
|
245
|
+
/** Volume-preserving horizontal scale multiplier (`scaleX = 1 / scaleY`). */
|
|
246
|
+
scaleX: number;
|
|
247
|
+
/** Volume-preserving vertical scale multiplier. */
|
|
248
|
+
scaleY: number;
|
|
249
|
+
/** Velocity-driven lean angle in radians. */
|
|
250
|
+
rotation: number;
|
|
251
|
+
/** Vertical stride-hop offset in pixels (`<= 0`). */
|
|
252
|
+
offsetY: number;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Procedural character secondary-motion controller providing volume-preserving (`scaleX * scaleY = 1`)
|
|
256
|
+
* spring squash-and-stretch, sharp-turn anticipation squash, landing thud, stride bob, and velocity lean
|
|
257
|
+
* for any `SpriteObject`, `ImageObject`, or `Container` without baking extra animation frames.
|
|
258
|
+
*/
|
|
259
|
+
export declare class LocomotionFeel {
|
|
260
|
+
private stretch;
|
|
261
|
+
private stretchVel;
|
|
262
|
+
private lean;
|
|
263
|
+
private stridePhase;
|
|
264
|
+
private prevDirX;
|
|
265
|
+
private prevDirY;
|
|
266
|
+
private hadPrevDir;
|
|
267
|
+
private prevWz;
|
|
268
|
+
private prevVz;
|
|
269
|
+
private readonly stiffness;
|
|
270
|
+
private readonly damping;
|
|
271
|
+
private readonly maxLean;
|
|
272
|
+
private readonly refSpeed;
|
|
273
|
+
private readonly turnSquash;
|
|
274
|
+
private readonly landScale;
|
|
275
|
+
private readonly bobPx;
|
|
276
|
+
private readonly bobFreq;
|
|
277
|
+
private readonly out;
|
|
278
|
+
constructor(opts?: LocomotionFeelOptions);
|
|
279
|
+
/**
|
|
280
|
+
* Inject an instantaneous squash (`amount < 0`, wide & short) or stretch (`amount > 0`, tall & narrow)
|
|
281
|
+
* impulse — e.g. `-0.28` on melee hit/landing, `+0.25` on dash/jump launch.
|
|
282
|
+
*/
|
|
283
|
+
impulse(amount: number): this;
|
|
284
|
+
reset(): this;
|
|
285
|
+
/** Advance procedural squash/stretch, turn anticipation, landing thud, and lean by `dtSec` seconds. */
|
|
286
|
+
step(dtSec: number, input: LocomotionFeelInput): LocomotionFeelSample;
|
|
287
|
+
get current(): LocomotionFeelSample;
|
|
288
|
+
/** Apply current `scaleX`, `scaleY`, and `rotation` multipliers onto a Stage `DisplayObject`. */
|
|
289
|
+
applyTo(target: {
|
|
290
|
+
scaleX: number;
|
|
291
|
+
scaleY: number;
|
|
292
|
+
rotation: number;
|
|
293
|
+
}, baseScaleX?: number, baseScaleY?: number): LocomotionFeelSample;
|
|
219
294
|
}
|
package/dist/particles.js
CHANGED
|
@@ -475,4 +475,130 @@ var JuiceController = class {
|
|
|
475
475
|
return this.stop > 0 ? 0 : safeMs / 1e3;
|
|
476
476
|
}
|
|
477
477
|
};
|
|
478
|
-
|
|
478
|
+
/**
|
|
479
|
+
* Procedural character secondary-motion controller providing volume-preserving (`scaleX * scaleY = 1`)
|
|
480
|
+
* spring squash-and-stretch, sharp-turn anticipation squash, landing thud, stride bob, and velocity lean
|
|
481
|
+
* for any `SpriteObject`, `ImageObject`, or `Container` without baking extra animation frames.
|
|
482
|
+
*/
|
|
483
|
+
var LocomotionFeel = class {
|
|
484
|
+
stretch = 0;
|
|
485
|
+
stretchVel = 0;
|
|
486
|
+
lean = 0;
|
|
487
|
+
stridePhase = 0;
|
|
488
|
+
prevDirX = 0;
|
|
489
|
+
prevDirY = 0;
|
|
490
|
+
hadPrevDir = false;
|
|
491
|
+
prevWz = 0;
|
|
492
|
+
prevVz = 0;
|
|
493
|
+
stiffness;
|
|
494
|
+
damping;
|
|
495
|
+
maxLean;
|
|
496
|
+
refSpeed;
|
|
497
|
+
turnSquash;
|
|
498
|
+
landScale;
|
|
499
|
+
bobPx;
|
|
500
|
+
bobFreq;
|
|
501
|
+
out = {
|
|
502
|
+
scaleX: 1,
|
|
503
|
+
scaleY: 1,
|
|
504
|
+
rotation: 0,
|
|
505
|
+
offsetY: 0
|
|
506
|
+
};
|
|
507
|
+
constructor(opts = {}) {
|
|
508
|
+
this.stiffness = Math.max(10, opts.stiffness ?? 260);
|
|
509
|
+
const zeta = Math.max(.1, Math.min(2, opts.dampingRatio ?? .62));
|
|
510
|
+
this.damping = 2 * zeta * Math.sqrt(this.stiffness);
|
|
511
|
+
this.maxLean = Math.max(0, opts.maxLeanRad ?? .12);
|
|
512
|
+
this.refSpeed = Math.max(1, opts.referenceSpeed ?? 180);
|
|
513
|
+
this.turnSquash = opts.turnSquash ?? -.18;
|
|
514
|
+
this.landScale = Math.max(0, opts.landSquashScale ?? .0014);
|
|
515
|
+
this.bobPx = Math.max(0, opts.strideBobPx ?? 0);
|
|
516
|
+
this.bobFreq = Math.max(.5, opts.strideFreqHz ?? 7.5);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Inject an instantaneous squash (`amount < 0`, wide & short) or stretch (`amount > 0`, tall & narrow)
|
|
520
|
+
* impulse — e.g. `-0.28` on melee hit/landing, `+0.25` on dash/jump launch.
|
|
521
|
+
*/
|
|
522
|
+
impulse(amount) {
|
|
523
|
+
this.stretch = Math.max(-.55, Math.min(.55, this.stretch + amount));
|
|
524
|
+
return this;
|
|
525
|
+
}
|
|
526
|
+
reset() {
|
|
527
|
+
this.stretch = 0;
|
|
528
|
+
this.stretchVel = 0;
|
|
529
|
+
this.lean = 0;
|
|
530
|
+
this.stridePhase = 0;
|
|
531
|
+
this.hadPrevDir = false;
|
|
532
|
+
this.prevWz = 0;
|
|
533
|
+
this.prevVz = 0;
|
|
534
|
+
this.out.scaleX = 1;
|
|
535
|
+
this.out.scaleY = 1;
|
|
536
|
+
this.out.rotation = 0;
|
|
537
|
+
this.out.offsetY = 0;
|
|
538
|
+
return this;
|
|
539
|
+
}
|
|
540
|
+
/** Advance procedural squash/stretch, turn anticipation, landing thud, and lean by `dtSec` seconds. */
|
|
541
|
+
step(dtSec, input) {
|
|
542
|
+
const dt = Math.min(.1, Math.max(0, dtSec));
|
|
543
|
+
if (dt <= 0) return this.out;
|
|
544
|
+
const { vx, vy } = input;
|
|
545
|
+
const wz = Math.max(0, input.wz ?? 0);
|
|
546
|
+
const speed = Math.hypot(vx, vy);
|
|
547
|
+
if (speed > this.refSpeed * .2) {
|
|
548
|
+
const dx = vx / speed;
|
|
549
|
+
const dy = vy / speed;
|
|
550
|
+
if (this.hadPrevDir) {
|
|
551
|
+
const dot = dx * this.prevDirX + dy * this.prevDirY;
|
|
552
|
+
if (dot < -.25 && this.turnSquash !== 0) this.impulse(this.turnSquash * Math.min(1, (-dot - .25) / .75));
|
|
553
|
+
}
|
|
554
|
+
this.prevDirX = dx;
|
|
555
|
+
this.prevDirY = dy;
|
|
556
|
+
this.hadPrevDir = true;
|
|
557
|
+
} else if (speed < this.refSpeed * .05) this.hadPrevDir = false;
|
|
558
|
+
const vz = (wz - this.prevWz) / dt;
|
|
559
|
+
if (this.prevWz > .5 && wz <= .01) {
|
|
560
|
+
const impactSpeed = Math.max(40, -Math.min(vz, this.prevVz));
|
|
561
|
+
this.impulse(-Math.min(.42, impactSpeed * this.landScale));
|
|
562
|
+
}
|
|
563
|
+
this.prevWz = wz;
|
|
564
|
+
this.prevVz = vz;
|
|
565
|
+
const subSteps = 2;
|
|
566
|
+
const h = dt / subSteps;
|
|
567
|
+
for (let s = 0; s < subSteps; s++) {
|
|
568
|
+
const acc = -this.stiffness * this.stretch - this.damping * this.stretchVel;
|
|
569
|
+
this.stretchVel += acc * h;
|
|
570
|
+
this.stretch += this.stretchVel * h;
|
|
571
|
+
}
|
|
572
|
+
if (Math.abs(this.stretch) < 1e-4 && Math.abs(this.stretchVel) < 1e-4) {
|
|
573
|
+
this.stretch = 0;
|
|
574
|
+
this.stretchVel = 0;
|
|
575
|
+
}
|
|
576
|
+
const targetLean = Math.max(-1, Math.min(1, vx / this.refSpeed)) * this.maxLean;
|
|
577
|
+
const leanAlpha = 1 - Math.exp(-16 * dt);
|
|
578
|
+
this.lean += (targetLean - this.lean) * leanAlpha;
|
|
579
|
+
let offsetY = 0;
|
|
580
|
+
if (this.bobPx > 0 && wz <= .05 && speed > this.refSpeed * .1) {
|
|
581
|
+
const speedNorm = Math.min(1.25, speed / this.refSpeed);
|
|
582
|
+
this.stridePhase = (this.stridePhase + dt * this.bobFreq * speedNorm * Math.PI * 2) % (Math.PI * 2);
|
|
583
|
+
offsetY = -Math.abs(Math.sin(this.stridePhase)) * this.bobPx * speedNorm;
|
|
584
|
+
} else this.stridePhase = 0;
|
|
585
|
+
const clamped = Math.max(-.55, Math.min(.55, this.stretch));
|
|
586
|
+
const sy = Math.exp(clamped);
|
|
587
|
+
this.out.scaleX = 1 / sy;
|
|
588
|
+
this.out.scaleY = sy;
|
|
589
|
+
this.out.rotation = Math.abs(this.lean) < 1e-4 ? 0 : this.lean;
|
|
590
|
+
this.out.offsetY = offsetY;
|
|
591
|
+
return this.out;
|
|
592
|
+
}
|
|
593
|
+
get current() {
|
|
594
|
+
return this.out;
|
|
595
|
+
}
|
|
596
|
+
/** Apply current `scaleX`, `scaleY`, and `rotation` multipliers onto a Stage `DisplayObject`. */
|
|
597
|
+
applyTo(target, baseScaleX = 1, baseScaleY = 1) {
|
|
598
|
+
target.scaleX = baseScaleX * this.out.scaleX;
|
|
599
|
+
target.scaleY = baseScaleY * this.out.scaleY;
|
|
600
|
+
target.rotation = this.out.rotation;
|
|
601
|
+
return this.out;
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
export { AmbientEmitterPool, FADE_EASE, FADE_FLICKER, FADE_LINEAR, FADE_PUNCH, FADE_SINE, FLAG_SIZE_POP, JuiceController, LocomotionFeel, PARTICLE_BUBBLE, PARTICLE_RECT, PARTICLE_SPARKLE, PARTICLE_WAKE, ParticlePool, drawParticlePool };
|
package/dist/projection.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { An as Container, Ln as DisplayObject, rr as SceneHostLike } from "./game-BrYrde7y.js";
|
|
2
2
|
export interface Camera25DConfig {
|
|
3
3
|
viewportWidth: number;
|
|
4
4
|
viewportHeight: number;
|