@holtjs/stage 0.6.0 → 0.7.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 +14 -0
- package/dist/anims-CS0rfUIz.d.ts +389 -0
- package/dist/anims.d.ts +2 -0
- package/dist/anims.js +436 -0
- package/dist/{game-Blm49zGH.d.ts → game-3L9wS-Bv.d.ts} +112 -202
- package/dist/{game-Ds-cn2YI.js → game-BnSWR44q.js} +179 -5
- package/dist/headless.d.ts +5 -1
- package/dist/headless.js +18 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -3
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-DJVQHR70.js → renderer-webgpu-alSDj9RR.js} +410 -29
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +2 -1
- package/dist/tilemap.d.ts +14 -3
- package/dist/tilemap.js +84 -10
- package/dist/trace.d.ts +1 -1
- package/dist/trace.js +7 -1
- package/package.json +5 -1
- package/skills/stage/SKILL.md +23 -7
- package/skills/stage/references/subpaths.md +11 -7
|
@@ -637,16 +637,42 @@ var ImageObject = class extends DisplayObject {
|
|
|
637
637
|
cropW = 0;
|
|
638
638
|
cropH = 0;
|
|
639
639
|
customRenderNodes = {};
|
|
640
|
-
constructor(scene, x, y, key, frame) {
|
|
641
|
-
super(scene,
|
|
640
|
+
constructor(scene, x, y, key, frame, nodeType = "Image") {
|
|
641
|
+
super(scene, nodeType);
|
|
642
642
|
this.x = x;
|
|
643
643
|
this.y = y;
|
|
644
644
|
this.texture = scene.textures.get(key);
|
|
645
645
|
this.frame = this.texture.get(frame);
|
|
646
646
|
this.width = this.frame.width;
|
|
647
647
|
this.height = this.frame.height;
|
|
648
|
-
this.
|
|
649
|
-
|
|
648
|
+
this._syncFrameOrigin();
|
|
649
|
+
}
|
|
650
|
+
get displayOriginX() {
|
|
651
|
+
if (!this.customOrigin && this.frame?.customPivot) return this.frame.pixelPivotX;
|
|
652
|
+
return super.displayOriginX;
|
|
653
|
+
}
|
|
654
|
+
get displayOriginY() {
|
|
655
|
+
if (!this.customOrigin && this.frame?.customPivot) return this.frame.pixelPivotY;
|
|
656
|
+
return super.displayOriginY;
|
|
657
|
+
}
|
|
658
|
+
_syncFrameOrigin() {
|
|
659
|
+
if (!this.customOrigin) {
|
|
660
|
+
if (this.frame.customPivot) {
|
|
661
|
+
this._displayOriginX = this.frame.pixelPivotX;
|
|
662
|
+
this._displayOriginY = this.frame.pixelPivotY;
|
|
663
|
+
this.originX = this.width > 0 ? this._displayOriginX / this.width : .5;
|
|
664
|
+
this.originY = this.height > 0 ? this._displayOriginY / this.height : .5;
|
|
665
|
+
} else {
|
|
666
|
+
this._displayOriginX = this.width * this.originX;
|
|
667
|
+
this._displayOriginY = this.height * this.originY;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
/** Clear any manual `setOrigin()` override so per-frame baked pivots (`ax/ay` or `pivotX/pivotY`) drive alignment automatically. */
|
|
672
|
+
useFramePivot() {
|
|
673
|
+
this.customOrigin = false;
|
|
674
|
+
this._syncFrameOrigin();
|
|
675
|
+
return this;
|
|
650
676
|
}
|
|
651
677
|
setTexture(key, frame) {
|
|
652
678
|
this.texture = this.scene.textures.get(key);
|
|
@@ -656,12 +682,66 @@ var ImageObject = class extends DisplayObject {
|
|
|
656
682
|
this.frame = this.texture.get(frame);
|
|
657
683
|
this.width = this.frame.width;
|
|
658
684
|
this.height = this.frame.height;
|
|
659
|
-
|
|
660
|
-
this._displayOriginX = this.width * this.originX;
|
|
661
|
-
this._displayOriginY = this.height * this.originY;
|
|
662
|
-
}
|
|
685
|
+
this._syncFrameOrigin();
|
|
663
686
|
return this;
|
|
664
687
|
}
|
|
688
|
+
/**
|
|
689
|
+
* Compute the exact transformed coordinates of a named per-frame pixel socket (e.g. `'hand'`, `'head'`, `'emissive'`)
|
|
690
|
+
* accounting for trimmed `displayOrigin`, `flipX`/`flipY`, `scaleX`/`scaleY`, `rotation`, and ancestor `Container`s.
|
|
691
|
+
*/
|
|
692
|
+
getAnchor(name, space = "parent", out = {
|
|
693
|
+
x: 0,
|
|
694
|
+
y: 0
|
|
695
|
+
}) {
|
|
696
|
+
const raw = this.frame?.getAnchor(name);
|
|
697
|
+
if (!raw) return null;
|
|
698
|
+
const ox = this._displayOriginX;
|
|
699
|
+
const oy = this._displayOriginY;
|
|
700
|
+
const pivotMirrored = this.frame.customPivot && !this.customOrigin && !this.isCropped;
|
|
701
|
+
const lx = this.flipX ? pivotMirrored ? ox - raw[0] : this.width - ox - raw[0] : raw[0] - ox;
|
|
702
|
+
const ly = this.flipY ? pivotMirrored ? oy - raw[1] : this.height - oy - raw[1] : raw[1] - oy;
|
|
703
|
+
if (space === "local") {
|
|
704
|
+
out.x = lx;
|
|
705
|
+
out.y = ly;
|
|
706
|
+
return out;
|
|
707
|
+
}
|
|
708
|
+
const sx = lx * this.scaleX;
|
|
709
|
+
const sy = ly * this.scaleY;
|
|
710
|
+
let px;
|
|
711
|
+
let py;
|
|
712
|
+
if (this.rotation === 0) {
|
|
713
|
+
px = this.x + sx;
|
|
714
|
+
py = this.y + sy;
|
|
715
|
+
} else {
|
|
716
|
+
const c = Math.cos(this.rotation);
|
|
717
|
+
const s = Math.sin(this.rotation);
|
|
718
|
+
px = this.x + sx * c - sy * s;
|
|
719
|
+
py = this.y + sx * s + sy * c;
|
|
720
|
+
}
|
|
721
|
+
if (space === "parent" || !this.parentContainer) {
|
|
722
|
+
out.x = px;
|
|
723
|
+
out.y = py;
|
|
724
|
+
return out;
|
|
725
|
+
}
|
|
726
|
+
let cur = this.parentContainer;
|
|
727
|
+
while (cur) {
|
|
728
|
+
const csx = px * cur.scaleX;
|
|
729
|
+
const csy = py * cur.scaleY;
|
|
730
|
+
if (cur.rotation === 0) {
|
|
731
|
+
px = cur.x + csx;
|
|
732
|
+
py = cur.y + csy;
|
|
733
|
+
} else {
|
|
734
|
+
const cc = Math.cos(cur.rotation);
|
|
735
|
+
const cs = Math.sin(cur.rotation);
|
|
736
|
+
px = cur.x + csx * cc - csy * cs;
|
|
737
|
+
py = cur.y + csx * cs + csy * cc;
|
|
738
|
+
}
|
|
739
|
+
cur = cur.parentContainer;
|
|
740
|
+
}
|
|
741
|
+
out.x = px;
|
|
742
|
+
out.y = py;
|
|
743
|
+
return out;
|
|
744
|
+
}
|
|
665
745
|
setTint(color) {
|
|
666
746
|
this.tint = color & HEX_MASK;
|
|
667
747
|
this.isTinted = true;
|
|
@@ -695,6 +775,226 @@ var ImageObject = class extends DisplayObject {
|
|
|
695
775
|
return this;
|
|
696
776
|
}
|
|
697
777
|
};
|
|
778
|
+
/**
|
|
779
|
+
* First-class animated 2D / 2.5D sprite (`scene.add.sprite(x, y, key, frame)`).
|
|
780
|
+
* - Automatically aligns per-frame trimmed pivots (`ax/ay`) & transforms named sockets (`getAnchor('hand')`)
|
|
781
|
+
* - Deterministic simulation-stepped clip playback (`play`, `playDirectional`, `stop`, `pause`, `resume`)
|
|
782
|
+
* - Phase-preserving 4/8-directional locomotion (`playDirectional`) aligned with `Camera25D` & `@holtjs/craft`
|
|
783
|
+
* - Exact frame-crossing event callbacks (`onAnimEvent` for `footstep`, `hit`, etc.)
|
|
784
|
+
*/
|
|
785
|
+
var SpriteObject = class extends ImageObject {
|
|
786
|
+
_anim = null;
|
|
787
|
+
_frameIdx = 0;
|
|
788
|
+
_frameElapsedMs = 0;
|
|
789
|
+
_forward = true;
|
|
790
|
+
_repeatsLeft = 0;
|
|
791
|
+
_playing = false;
|
|
792
|
+
_paused = false;
|
|
793
|
+
_timeScale = 1;
|
|
794
|
+
_activeDirBase = null;
|
|
795
|
+
_activeDirIndex = -1;
|
|
796
|
+
_animListeners = /* @__PURE__ */ new Set();
|
|
797
|
+
constructor(scene, x, y, key, frame) {
|
|
798
|
+
super(scene, x, y, key, frame, "Sprite");
|
|
799
|
+
}
|
|
800
|
+
get currentAnim() {
|
|
801
|
+
return this._anim;
|
|
802
|
+
}
|
|
803
|
+
get currentAnimKey() {
|
|
804
|
+
return this._anim?.key ?? null;
|
|
805
|
+
}
|
|
806
|
+
get currentFrameIndex() {
|
|
807
|
+
return this._frameIdx;
|
|
808
|
+
}
|
|
809
|
+
get currentDirection() {
|
|
810
|
+
return this._activeDirIndex;
|
|
811
|
+
}
|
|
812
|
+
get isPlaying() {
|
|
813
|
+
return this._playing && !this._paused;
|
|
814
|
+
}
|
|
815
|
+
get timeScale() {
|
|
816
|
+
return this._timeScale;
|
|
817
|
+
}
|
|
818
|
+
setTimeScale(scale) {
|
|
819
|
+
this._timeScale = Number.isFinite(scale) ? Math.max(0, scale) : 1;
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
onAnimEvent(fn) {
|
|
823
|
+
this._animListeners.add(fn);
|
|
824
|
+
return () => {
|
|
825
|
+
this._animListeners.delete(fn);
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
/** Normalized progress `[0..1)` through the current forward pass of the active animation. */
|
|
829
|
+
get cycleProgress() {
|
|
830
|
+
const anim = this._anim;
|
|
831
|
+
if (!anim || anim.totalDurationMs <= 0 || anim.frames.length === 0) return 0;
|
|
832
|
+
const cf = anim.frames[this._frameIdx];
|
|
833
|
+
if (!cf) return 0;
|
|
834
|
+
return Math.max(0, Math.min(.999999, (cf.offsetMs + this._frameElapsedMs) / anim.totalDurationMs));
|
|
835
|
+
}
|
|
836
|
+
/** Play a registered animation clip by key (or `StageAnimation` object). Fails fast if `key` does not exist! */
|
|
837
|
+
play(keyOrAnim, opts) {
|
|
838
|
+
const options = typeof opts === "boolean" ? { ignoreIfPlaying: opts } : opts ?? {};
|
|
839
|
+
const nextAnim = this.scene.anims.resolveOrThrow(keyOrAnim);
|
|
840
|
+
if (options.timeScale !== void 0) this.setTimeScale(options.timeScale);
|
|
841
|
+
if (options.ignoreIfPlaying && this._playing && this._anim === nextAnim) return this;
|
|
842
|
+
const prevPhase = options.preservePhase && this._anim ? this.cycleProgress : null;
|
|
843
|
+
this._activeDirBase = null;
|
|
844
|
+
this._anim = nextAnim;
|
|
845
|
+
this._playing = true;
|
|
846
|
+
this._paused = false;
|
|
847
|
+
this._forward = true;
|
|
848
|
+
this._repeatsLeft = options.repeat !== void 0 ? options.repeat : nextAnim.repeat;
|
|
849
|
+
if (prevPhase !== null && nextAnim.frames.length > 0) {
|
|
850
|
+
const targetMs = prevPhase * nextAnim.totalDurationMs;
|
|
851
|
+
let idx = 0;
|
|
852
|
+
while (idx + 1 < nextAnim.frames.length && nextAnim.frames[idx + 1].offsetMs <= targetMs) idx++;
|
|
853
|
+
this._frameIdx = idx;
|
|
854
|
+
this._frameElapsedMs = Math.max(0, targetMs - nextAnim.frames[idx].offsetMs);
|
|
855
|
+
this._applyAnimFrame(idx, false);
|
|
856
|
+
} else {
|
|
857
|
+
const startIdx = Math.max(0, Math.min(nextAnim.frames.length - 1, Math.floor(options.startFrame ?? 0)));
|
|
858
|
+
this._frameIdx = startIdx;
|
|
859
|
+
this._frameElapsedMs = 0;
|
|
860
|
+
this._applyAnimFrame(startIdx, true);
|
|
861
|
+
}
|
|
862
|
+
this.scene._registerAnimatedSprite(this);
|
|
863
|
+
return this;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Play a 4- or 8-directional animation group (e.g. `'survivor/walk'` or `'zombie/attack'`) quantized by
|
|
867
|
+
* world movement angle `headingRad = Math.atan2(vy, vx)` and optional `Camera25D.yaw`!
|
|
868
|
+
*
|
|
869
|
+
* Automatically preserves stride phase when turning between directions of the same clip (`walk/d0 -> walk/d1`)
|
|
870
|
+
* so characters never freeze on frame 0 or stutter mid-step!
|
|
871
|
+
*/
|
|
872
|
+
playDirectional(baseKey, headingRad, opts = {}) {
|
|
873
|
+
const grp = this.scene.anims.resolveDirectionalOrThrow(baseKey);
|
|
874
|
+
const dirs = Math.max(1, grp.directions);
|
|
875
|
+
const step = Math.PI * 2 / dirs;
|
|
876
|
+
const camYaw = opts.cameraYaw ?? 0;
|
|
877
|
+
const atlasYaw = opts.atlasYaw ?? grp.atlasYaw;
|
|
878
|
+
const effective = (Number.isFinite(headingRad) ? headingRad : 0) - camYaw + atlasYaw;
|
|
879
|
+
const dirIdx = (Math.round(effective / step) % dirs + dirs) % dirs;
|
|
880
|
+
const targetAnim = grp.dirClips[dirIdx] ?? grp.dirClips[0];
|
|
881
|
+
const sameBase = this._playing && this._activeDirBase === grp.baseKey;
|
|
882
|
+
this._activeDirIndex = dirIdx;
|
|
883
|
+
if (sameBase && this._anim === targetAnim) {
|
|
884
|
+
if (opts.timeScale !== void 0) this.setTimeScale(opts.timeScale);
|
|
885
|
+
this._activeDirBase = grp.baseKey;
|
|
886
|
+
return this;
|
|
887
|
+
}
|
|
888
|
+
this.play(targetAnim, {
|
|
889
|
+
ignoreIfPlaying: false,
|
|
890
|
+
preservePhase: sameBase ? opts.preservePhase !== false : Boolean(opts.preservePhase),
|
|
891
|
+
timeScale: opts.timeScale,
|
|
892
|
+
repeat: opts.repeat
|
|
893
|
+
});
|
|
894
|
+
this._activeDirBase = grp.baseKey;
|
|
895
|
+
return this;
|
|
896
|
+
}
|
|
897
|
+
pause() {
|
|
898
|
+
this._paused = true;
|
|
899
|
+
return this;
|
|
900
|
+
}
|
|
901
|
+
resume() {
|
|
902
|
+
this._paused = false;
|
|
903
|
+
return this;
|
|
904
|
+
}
|
|
905
|
+
stop() {
|
|
906
|
+
this._playing = false;
|
|
907
|
+
this._paused = false;
|
|
908
|
+
this._activeDirBase = null;
|
|
909
|
+
this.scene._unregisterAnimatedSprite(this);
|
|
910
|
+
return this;
|
|
911
|
+
}
|
|
912
|
+
/** Internal deterministic simulation step invoked by `Scene._stepAnimations(dt)`. */
|
|
913
|
+
_stepAnim(deltaMs) {
|
|
914
|
+
if (!this._playing || this._paused || !this._anim) return;
|
|
915
|
+
const scaled = deltaMs * this._timeScale;
|
|
916
|
+
if (scaled <= 0) return;
|
|
917
|
+
const anim = this._anim;
|
|
918
|
+
const frames = anim.frames;
|
|
919
|
+
const n = frames.length;
|
|
920
|
+
if (n === 0) return;
|
|
921
|
+
this._frameElapsedMs += scaled;
|
|
922
|
+
let safety = 0;
|
|
923
|
+
while (this._playing && this._anim === anim && safety++ < 64) {
|
|
924
|
+
const cur = frames[this._frameIdx];
|
|
925
|
+
const dur = Math.max(.001, cur.durationMs);
|
|
926
|
+
if (this._frameElapsedMs < dur) break;
|
|
927
|
+
this._frameElapsedMs -= dur;
|
|
928
|
+
if (n === 1) {
|
|
929
|
+
if (this._repeatsLeft === 0) {
|
|
930
|
+
this._finishAnim(anim);
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (this._repeatsLeft > 0) this._repeatsLeft--;
|
|
934
|
+
this._applyAnimFrame(0, true);
|
|
935
|
+
this.emit("animrepeat", anim.key, this);
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
if (this._forward) {
|
|
939
|
+
if (this._frameIdx + 1 < n) {
|
|
940
|
+
this._frameIdx++;
|
|
941
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
942
|
+
} else if (anim.yoyo) {
|
|
943
|
+
this._forward = false;
|
|
944
|
+
this._frameIdx = n - 2;
|
|
945
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
946
|
+
} else if (this._repeatsLeft === 0) {
|
|
947
|
+
this._finishAnim(anim);
|
|
948
|
+
return;
|
|
949
|
+
} else {
|
|
950
|
+
if (this._repeatsLeft > 0) this._repeatsLeft--;
|
|
951
|
+
this._frameIdx = 0;
|
|
952
|
+
this._applyAnimFrame(0, true);
|
|
953
|
+
this.emit("animrepeat", anim.key, this);
|
|
954
|
+
}
|
|
955
|
+
} else if (this._frameIdx - 1 >= 0) {
|
|
956
|
+
this._frameIdx--;
|
|
957
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
958
|
+
} else if (this._repeatsLeft === 0) {
|
|
959
|
+
this._finishAnim(anim);
|
|
960
|
+
return;
|
|
961
|
+
} else {
|
|
962
|
+
if (this._repeatsLeft > 0) this._repeatsLeft--;
|
|
963
|
+
this._forward = true;
|
|
964
|
+
this._frameIdx = Math.min(1, n - 1);
|
|
965
|
+
this._applyAnimFrame(this._frameIdx, true);
|
|
966
|
+
this.emit("animrepeat", anim.key, this);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
_applyAnimFrame(index, fireEvents) {
|
|
971
|
+
const anim = this._anim;
|
|
972
|
+
if (!anim) return;
|
|
973
|
+
const cf = anim.frames[index];
|
|
974
|
+
if (!cf) return;
|
|
975
|
+
if (this.texture.key !== cf.textureKey) this.setTexture(cf.textureKey, cf.frameName);
|
|
976
|
+
else this.setFrame(cf.frameName);
|
|
977
|
+
if (fireEvents && cf.events.length > 0) for (let i = 0; i < cf.events.length; i++) {
|
|
978
|
+
const ev = cf.events[i];
|
|
979
|
+
for (const fn of this._animListeners) fn(ev, anim.key, index, cf.frameName);
|
|
980
|
+
this.emit("animevent", ev, anim.key, index, cf.frameName);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
_finishAnim(anim) {
|
|
984
|
+
this._frameElapsedMs = 0;
|
|
985
|
+
this._playing = false;
|
|
986
|
+
this._activeDirBase = null;
|
|
987
|
+
this.scene._unregisterAnimatedSprite(this);
|
|
988
|
+
this.emit("animcomplete", anim.key, this);
|
|
989
|
+
}
|
|
990
|
+
destroy(fromScene) {
|
|
991
|
+
this.scene._unregisterAnimatedSprite(this);
|
|
992
|
+
this._animListeners.clear();
|
|
993
|
+
this._anim = null;
|
|
994
|
+
this._playing = false;
|
|
995
|
+
super.destroy(fromScene);
|
|
996
|
+
}
|
|
997
|
+
};
|
|
698
998
|
var NineSliceObject = class extends DisplayObject {
|
|
699
999
|
texture;
|
|
700
1000
|
frame;
|
|
@@ -1866,11 +2166,14 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
1866
2166
|
tintCtx = null;
|
|
1867
2167
|
tintCache = /* @__PURE__ */ new Map();
|
|
1868
2168
|
maskWorldMat = createMatrix2D();
|
|
2169
|
+
rootScrollMat = createMatrix2D();
|
|
2170
|
+
matPool = Array.from({ length: 16 }, () => createMatrix2D());
|
|
1869
2171
|
pathCache = /* @__PURE__ */ new Map();
|
|
1870
2172
|
curDrawCalls = 0;
|
|
1871
2173
|
curFlushes = 0;
|
|
1872
2174
|
curQuads = 0;
|
|
1873
2175
|
curTris = 0;
|
|
2176
|
+
curCulled = 0;
|
|
1874
2177
|
curSdfPanels = 0;
|
|
1875
2178
|
curMsdfIcons = 0;
|
|
1876
2179
|
lastStats = {
|
|
@@ -1969,7 +2272,39 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
1969
2272
|
tg.restore();
|
|
1970
2273
|
return tc;
|
|
1971
2274
|
}
|
|
1972
|
-
|
|
2275
|
+
isOffscreen(m, x0, y0, x1, y1) {
|
|
2276
|
+
const a = m.a, b = m.b, c = m.c, d = m.d, tx = m.tx, ty = m.ty;
|
|
2277
|
+
const px0 = a * x0 + c * y0 + tx, py0 = b * x0 + d * y0 + ty;
|
|
2278
|
+
const px1 = a * x1 + c * y0 + tx, py1 = b * x1 + d * y0 + ty;
|
|
2279
|
+
const px2 = a * x1 + c * y1 + tx, py2 = b * x1 + d * y1 + ty;
|
|
2280
|
+
const px3 = a * x0 + c * y1 + tx, py3 = b * x0 + d * y1 + ty;
|
|
2281
|
+
if (px0 < 0 && px1 < 0 && px2 < 0 && px3 < 0) return true;
|
|
2282
|
+
if (py0 < 0 && py1 < 0 && py2 < 0 && py3 < 0) return true;
|
|
2283
|
+
const w = this.width, h = this.height;
|
|
2284
|
+
if (px0 > w && px1 > w && px2 > w && px3 > w) return true;
|
|
2285
|
+
if (py0 > h && py1 > h && py2 > h && py3 > h) return true;
|
|
2286
|
+
return false;
|
|
2287
|
+
}
|
|
2288
|
+
mulMat(parent, x, y, sx, sy, rot, out) {
|
|
2289
|
+
const pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
|
|
2290
|
+
out.tx = pa * x + pc * y + parent.tx;
|
|
2291
|
+
out.ty = pb * x + pd * y + parent.ty;
|
|
2292
|
+
if (rot === 0) {
|
|
2293
|
+
out.a = pa * sx;
|
|
2294
|
+
out.b = pb * sx;
|
|
2295
|
+
out.c = pc * sy;
|
|
2296
|
+
out.d = pd * sy;
|
|
2297
|
+
} else {
|
|
2298
|
+
const cos = Math.cos(rot), sin = Math.sin(rot);
|
|
2299
|
+
const la = cos * sx, lb = sin * sx, lc = -sin * sy, ld = cos * sy;
|
|
2300
|
+
out.a = pa * la + pc * lb;
|
|
2301
|
+
out.b = pb * la + pd * lb;
|
|
2302
|
+
out.c = pa * lc + pc * ld;
|
|
2303
|
+
out.d = pb * lc + pd * ld;
|
|
2304
|
+
}
|
|
2305
|
+
return out;
|
|
2306
|
+
}
|
|
2307
|
+
renderImage(img, ctx, m) {
|
|
1973
2308
|
const frame = img.frame;
|
|
1974
2309
|
if (!frame || frame.width <= 0 || frame.height <= 0) return;
|
|
1975
2310
|
const srcImg = frame.source.image;
|
|
@@ -1992,7 +2327,6 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
1992
2327
|
dh = rh;
|
|
1993
2328
|
}
|
|
1994
2329
|
if (img.pixelAA) {
|
|
1995
|
-
const m = ctx.getTransform();
|
|
1996
2330
|
const dispW = Math.hypot(m.a * dw, m.b * dw);
|
|
1997
2331
|
const dispH = Math.hypot(m.c * dh, m.d * dh);
|
|
1998
2332
|
const sxRatio = dispW / Math.max(1, sw);
|
|
@@ -2000,7 +2334,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2000
2334
|
ctx.imageSmoothingEnabled = !(sxRatio >= .98 && syRatio >= .98 && Math.abs(sxRatio - Math.round(sxRatio)) <= .02 && Math.abs(syRatio - Math.round(syRatio)) <= .02);
|
|
2001
2335
|
} else ctx.imageSmoothingEnabled = frame.source.filterMode !== FilterMode.NEAREST;
|
|
2002
2336
|
if (img.flipX || img.flipY) {
|
|
2003
|
-
ctx.translate(img.flipX ? dx * 2 + dw : 0, img.flipY ? dy * 2 + dh : 0);
|
|
2337
|
+
if (!(frame.customPivot && !img.customOrigin && !img.isCropped)) ctx.translate(img.flipX ? dx * 2 + dw : 0, img.flipY ? dy * 2 + dh : 0);
|
|
2004
2338
|
ctx.scale(img.flipX ? -1 : 1, img.flipY ? -1 : 1);
|
|
2005
2339
|
}
|
|
2006
2340
|
if (img.isTinted && (img.tint !== 0xffffff || img.tintMode === TintModes.FILL)) {
|
|
@@ -2809,7 +3143,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2809
3143
|
src.dirty = true;
|
|
2810
3144
|
}
|
|
2811
3145
|
}
|
|
2812
|
-
renderBlitter(blitter, ctx) {
|
|
3146
|
+
renderBlitter(blitter, ctx, m) {
|
|
2813
3147
|
const list = blitter.children.list;
|
|
2814
3148
|
const baseAlpha = ctx.globalAlpha;
|
|
2815
3149
|
let vis = 0;
|
|
@@ -2817,6 +3151,10 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2817
3151
|
const bob = list[i];
|
|
2818
3152
|
if (!bob.visible || bob.alpha <= 0) continue;
|
|
2819
3153
|
const frame = bob.frame;
|
|
3154
|
+
if (this.isOffscreen(m, bob.x, bob.y, bob.x + frame.width, bob.y + frame.height)) {
|
|
3155
|
+
this.curCulled++;
|
|
3156
|
+
continue;
|
|
3157
|
+
}
|
|
2820
3158
|
ctx.imageSmoothingEnabled = frame.source.filterMode !== FilterMode.NEAREST;
|
|
2821
3159
|
ctx.globalAlpha = baseAlpha * bob.alpha;
|
|
2822
3160
|
ctx.drawImage(frame.source.image, frame.cutX, frame.cutY, frame.cutWidth, frame.cutHeight, bob.x, bob.y, frame.width, frame.height);
|
|
@@ -2829,23 +3167,57 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2829
3167
|
this.curTris += vis * 2;
|
|
2830
3168
|
}
|
|
2831
3169
|
}
|
|
2832
|
-
renderNode(obj, camera, ctx,
|
|
3170
|
+
renderNode(obj, camera, ctx, parentMat, depth) {
|
|
2833
3171
|
if (!obj.visible || obj.alpha <= 0) return;
|
|
2834
|
-
|
|
2835
|
-
if (
|
|
2836
|
-
if (obj.scrollFactorX === 1 && obj.scrollFactorY === 1)
|
|
2837
|
-
|
|
2838
|
-
ctx.setTransform(cm.a, cm.b, cm.c, cm.d, cm.tx, cm.ty);
|
|
2839
|
-
} else {
|
|
3172
|
+
let baseMat;
|
|
3173
|
+
if (parentMat === null) {
|
|
3174
|
+
if (obj.scrollFactorX === 1 && obj.scrollFactorY === 1) baseMat = camera.matrixCombined;
|
|
3175
|
+
else {
|
|
2840
3176
|
const z = camera.zoom || 1;
|
|
2841
3177
|
const ox = camera.width * camera.originX;
|
|
2842
3178
|
const oy = camera.height * camera.originY;
|
|
2843
3179
|
const sx = camera.roundPixels ? Math.round(camera.scrollX) : camera.scrollX;
|
|
2844
3180
|
const sy = camera.roundPixels ? Math.round(camera.scrollY) : camera.scrollY;
|
|
2845
|
-
|
|
3181
|
+
const rm = this.rootScrollMat;
|
|
3182
|
+
rm.a = z;
|
|
3183
|
+
rm.b = 0;
|
|
3184
|
+
rm.c = 0;
|
|
3185
|
+
rm.d = z;
|
|
3186
|
+
rm.tx = (-sx * obj.scrollFactorX - ox) * z + ox + camera.x;
|
|
3187
|
+
rm.ty = (-sy * obj.scrollFactorY - oy) * z + oy + camera.y;
|
|
3188
|
+
baseMat = rm;
|
|
3189
|
+
}
|
|
3190
|
+
} else baseMat = parentMat;
|
|
3191
|
+
while (depth >= this.matPool.length) this.matPool.push(createMatrix2D());
|
|
3192
|
+
const m = this.mulMat(baseMat, obj.x, obj.y, obj.scaleX, obj.scaleY, obj.rotation, this.matPool[depth]);
|
|
3193
|
+
const t = obj.type;
|
|
3194
|
+
if (t === "Image" || t === "Sprite" || t === "NineSlice" || t === "TileSprite" || t === "Rectangle" || t === "Panel") {
|
|
3195
|
+
const ox = obj.displayOriginX;
|
|
3196
|
+
const oy = obj.displayOriginY;
|
|
3197
|
+
const w = obj.width;
|
|
3198
|
+
const h = obj.height;
|
|
3199
|
+
let x0 = -ox, y0 = -oy, x1 = w - ox, y1 = h - oy;
|
|
3200
|
+
if (t === "Image" || t === "Sprite") {
|
|
3201
|
+
const img = obj;
|
|
3202
|
+
if (img.frame?.customPivot && !img.customOrigin && !img.isCropped) {
|
|
3203
|
+
if (img.flipX) {
|
|
3204
|
+
x0 = ox - w;
|
|
3205
|
+
x1 = ox;
|
|
3206
|
+
}
|
|
3207
|
+
if (img.flipY) {
|
|
3208
|
+
y0 = oy - h;
|
|
3209
|
+
y1 = oy;
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
if (this.isOffscreen(m, x0, y0, x1, y1)) {
|
|
3214
|
+
this.curCulled++;
|
|
3215
|
+
return;
|
|
2846
3216
|
}
|
|
2847
3217
|
}
|
|
2848
|
-
|
|
3218
|
+
ctx.save();
|
|
3219
|
+
if (parentMat === null) ctx.setTransform(baseMat.a, baseMat.b, baseMat.c, baseMat.d, baseMat.tx, baseMat.ty);
|
|
3220
|
+
if (t === "Container") {
|
|
2849
3221
|
const mask = obj.clipMask;
|
|
2850
3222
|
if (mask && mask.active && mask.graphics?.maskRect) {
|
|
2851
3223
|
const mr = mask.graphics.maskRect;
|
|
@@ -2874,9 +3246,10 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2874
3246
|
if (obj.x !== 0 || obj.y !== 0) ctx.translate(obj.x, obj.y);
|
|
2875
3247
|
if (obj.rotation !== 0) ctx.rotate(obj.rotation);
|
|
2876
3248
|
if (obj.scaleX !== 1 || obj.scaleY !== 1) ctx.scale(obj.scaleX, obj.scaleY);
|
|
2877
|
-
switch (
|
|
3249
|
+
switch (t) {
|
|
2878
3250
|
case "Image":
|
|
2879
|
-
|
|
3251
|
+
case "Sprite":
|
|
3252
|
+
this.renderImage(obj, ctx, m);
|
|
2880
3253
|
break;
|
|
2881
3254
|
case "NineSlice":
|
|
2882
3255
|
this.renderNineSlice(obj, ctx);
|
|
@@ -2900,7 +3273,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2900
3273
|
this.renderGraphics(obj, ctx);
|
|
2901
3274
|
break;
|
|
2902
3275
|
case "Blitter":
|
|
2903
|
-
this.renderBlitter(obj, ctx);
|
|
3276
|
+
this.renderBlitter(obj, ctx, m);
|
|
2904
3277
|
break;
|
|
2905
3278
|
case "InstancedBatch":
|
|
2906
3279
|
this.renderInstancedBatch(obj, ctx);
|
|
@@ -2910,7 +3283,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2910
3283
|
break;
|
|
2911
3284
|
case "Container": {
|
|
2912
3285
|
const list = obj.sortedChildren();
|
|
2913
|
-
for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, ctx,
|
|
3286
|
+
for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, ctx, m, depth + 1);
|
|
2914
3287
|
break;
|
|
2915
3288
|
}
|
|
2916
3289
|
}
|
|
@@ -2921,6 +3294,7 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2921
3294
|
this.curFlushes = 0;
|
|
2922
3295
|
this.curQuads = 0;
|
|
2923
3296
|
this.curTris = 0;
|
|
3297
|
+
this.curCulled = 0;
|
|
2924
3298
|
this.curSdfPanels = 0;
|
|
2925
3299
|
this.curMsdfIcons = 0;
|
|
2926
3300
|
camera.syncMetrics();
|
|
@@ -2936,11 +3310,12 @@ var Renderer2D = class Renderer2D extends EventEmitter {
|
|
|
2936
3310
|
}
|
|
2937
3311
|
ctx.globalAlpha = camera.alpha;
|
|
2938
3312
|
const list = displayList.sorted();
|
|
2939
|
-
for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, ctx,
|
|
3313
|
+
for (let i = 0; i < list.length; i++) this.renderNode(list[i], camera, ctx, null, 0);
|
|
2940
3314
|
this.lastStats.drawCalls = this.curDrawCalls;
|
|
2941
3315
|
this.lastStats.flushes = this.curFlushes;
|
|
2942
3316
|
this.lastStats.quads = this.curQuads;
|
|
2943
3317
|
this.lastStats.tris = this.curTris;
|
|
3318
|
+
this.lastStats.culled = this.curCulled;
|
|
2944
3319
|
this.lastStats.sdfPanels = this.curSdfPanels;
|
|
2945
3320
|
this.lastStats.sdfDraws = this.curSdfPanels > 0 ? 1 : 0;
|
|
2946
3321
|
this.lastStats.msdfIcons = this.curMsdfIcons;
|
|
@@ -3937,18 +4312,24 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
3937
4312
|
m = multiplyMat(baseMat, obj.x, obj.y, obj.scaleX, obj.scaleY, obj.rotation, this.matPool[depth]);
|
|
3938
4313
|
}
|
|
3939
4314
|
switch (obj.type) {
|
|
3940
|
-
case "Image":
|
|
4315
|
+
case "Image":
|
|
4316
|
+
case "Sprite": {
|
|
3941
4317
|
const img = obj;
|
|
3942
4318
|
const fr = img.frame;
|
|
3943
4319
|
if (!fr || fr.width <= 0 || fr.height <= 0) break;
|
|
3944
4320
|
const bg = this.ensureSourceBindGroup(fr.source);
|
|
3945
4321
|
if (!bg) break;
|
|
3946
4322
|
const ox = img.displayOriginX, oy = img.displayOriginY;
|
|
4323
|
+
const pivotMirrored = fr.customPivot && !img.customOrigin && !img.isCropped;
|
|
4324
|
+
const x0 = pivotMirrored && img.flipX ? ox - img.width : -ox;
|
|
4325
|
+
const y0 = pivotMirrored && img.flipY ? oy - img.height : -oy;
|
|
4326
|
+
const x1 = pivotMirrored && img.flipX ? ox : img.width - ox;
|
|
4327
|
+
const y1 = pivotMirrored && img.flipY ? oy : img.height - oy;
|
|
3947
4328
|
const u0 = img.flipX ? fr.u1 : fr.u0, u1 = img.flipX ? fr.u0 : fr.u1;
|
|
3948
4329
|
const v0 = img.flipY ? fr.v1 : fr.v0, v1 = img.flipY ? fr.v0 : fr.v1;
|
|
3949
4330
|
const rgb = img.isTinted ? img.tint : WHITE_RGB;
|
|
3950
4331
|
const mode = img.isTinted && img.tintMode === TintModes.FILL ? 1 : 0;
|
|
3951
|
-
this.pushQuad(m,
|
|
4332
|
+
this.pushQuad(m, x0, y0, x1, y1, u0, v0, u1, v1, packColorAbgr(rgb, effAlpha), mode, img.blendMode, bg);
|
|
3952
4333
|
break;
|
|
3953
4334
|
}
|
|
3954
4335
|
case "Rectangle": {
|
|
@@ -4253,4 +4634,4 @@ var RendererWebGpu = class extends EventEmitter {
|
|
|
4253
4634
|
} catch {}
|
|
4254
4635
|
}
|
|
4255
4636
|
};
|
|
4256
|
-
export {
|
|
4637
|
+
export { SpriteObject as _, Container as a, Camera as b, DisplayObject as c, InstancedBatchObject as d, MsdfIconObject as f, ShapeBatchObject as g, RectangleObject as h, BlitterObject as i, Graphics as l, PanelObject as m, requestWebGpuDevice as n, CustomPassObject as o, NineSliceObject as p, Renderer2D as r, DisplayList as s, RendererWebGpu as t, ImageObject as u, TextObject as v, TileSpriteObject as y };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as WebGpuBootstrapResult, Q as RequestWebGpuOptions, X as RendererWebGpu, Z as RendererWebGpuOptions, et as WebGpuCanvasContextLike, nt as requestWebGpuDevice, tt as WebGpuDeviceLike } from "./game-
|
|
1
|
+
import { $ as WebGpuBootstrapResult, Q as RequestWebGpuOptions, X as RendererWebGpu, Z as RendererWebGpuOptions, et as WebGpuCanvasContextLike, nt as requestWebGpuDevice, tt as WebGpuDeviceLike } from "./game-3L9wS-Bv.js";
|
|
2
2
|
export { RendererWebGpu, RendererWebGpuOptions, RequestWebGpuOptions, WebGpuBootstrapResult, WebGpuCanvasContextLike, WebGpuDeviceLike, requestWebGpuDevice };
|
package/dist/renderer-webgpu.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-
|
|
1
|
+
export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-alSDj9RR.js";
|
package/dist/rig2d.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { w as BlendMode } from "./anims-CS0rfUIz.js";
|
|
2
|
+
import { Nt as SceneHostLike, St as ImageObject, dt as Container, xt as Graphics } from "./game-3L9wS-Bv.js";
|
|
2
3
|
export type RigCurveKind = 'linear' | 'step' | 'smoothstep' | 'outBack';
|
|
3
4
|
export interface RigBoneDef {
|
|
4
5
|
name: string;
|
package/dist/tilemap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Nt as SceneHostLike, dt as Container, lt as BlitterObject } from "./game-3L9wS-Bv.js";
|
|
2
2
|
/** Pack signed 16-bit chunk coordinates `[-32768..32767]` into a single 32-bit integer Map key (zero string allocation). */
|
|
3
3
|
export declare function packChunkKey(cx: number, cy: number): number;
|
|
4
4
|
export declare function unpackChunkX(key: number): number;
|
|
@@ -142,17 +142,28 @@ export interface MountedChunkedTilemap {
|
|
|
142
142
|
readonly blitters: ReadonlyArray<BlitterObject>;
|
|
143
143
|
/** Update visible chunks around `(viewLeft, viewTop, viewWidth, viewHeight)` in world pixels (O(visibleChunks)). */
|
|
144
144
|
syncViewport(viewLeft: number, viewTop: number, viewWidth: number, viewHeight: number): void;
|
|
145
|
+
/** Convenience alias accepting `Camera25D.getGroundViewportBounds()` (`{ left, top, width, height }`) directly. */
|
|
146
|
+
update(bounds: {
|
|
147
|
+
left: number;
|
|
148
|
+
top: number;
|
|
149
|
+
width: number;
|
|
150
|
+
height: number;
|
|
151
|
+
}): void;
|
|
145
152
|
readonly activeChunkCount: number;
|
|
146
153
|
readonly activeBobCount: number;
|
|
147
154
|
destroy(): void;
|
|
148
155
|
}
|
|
149
156
|
/**
|
|
150
|
-
* Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene
|
|
151
|
-
*
|
|
157
|
+
* Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene`.
|
|
158
|
+
* - On WebGL2 / WebGPU: batches into 1 GPU `BlitterObject` draw call per Dual-Grid layer.
|
|
159
|
+
* - On Canvas2D / pure-Node `createHeadlessStage`: automatically pre-composites all Dual-Grid layers of each
|
|
160
|
+
* `16×16` chunk onto a cached offscreen chunk canvas keyed by `chunk.version` (collapsing ~4,500 per-frame
|
|
161
|
+
* rotated tile `drawImage` calls down to ~12 chunk blits — >10× faster 60 FPS headless video rendering!).
|
|
152
162
|
*/
|
|
153
163
|
export declare function mountChunkedTilemap(scene: SceneHostLike, map: ChunkedTilemap, atlas: BakedDualGridAtlas, opts?: {
|
|
154
164
|
baseColor?: number;
|
|
155
165
|
depth?: number;
|
|
156
166
|
marginChunks?: number;
|
|
157
167
|
trackId?: string;
|
|
168
|
+
chunkCache?: boolean;
|
|
158
169
|
}): MountedChunkedTilemap;
|