1681-engine 0.6.2 → 0.6.5

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 CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this package are written here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
4
4
  and versions follow [Semantic Versioning](https://semver.org/); before 1.0 a minor version may break the API.
5
5
 
6
+ ## 0.6.5
7
+
8
+ ### Changed
9
+
10
+ - `Group.moveAbove` / `moveBelow` do nothing when the child is already directly above / below the other. Taking it out
11
+ and putting it back marked the render group's structure changed, so Pixi rebuilt its draw instructions that frame:
12
+ a game ordering a held weapon against its body every frame rebuilt them every frame.
13
+
14
+ ## 0.6.3
15
+
16
+ ### Changed
17
+
18
+ - `SharpText` lays a label's stand-in again only when its home moved, hid, faded or changed depth: `setFromMatrix`
19
+ (a decomposition with trigonometry that also marks the transform changed for Pixi) ran for every label every frame,
20
+ and a town's standing NPC names took ~9% of a frame on a CPU throttled 6x.
21
+
6
22
  ## 0.6.2
7
23
 
8
24
  ### Added
@@ -1,6 +1,6 @@
1
- import { Container as r } from "pixi.js";
2
- import { GameObject as i } from "./gameObject.js";
3
- class a extends i(r) {
1
+ import { Container as i } from "pixi.js";
2
+ import { GameObject as r } from "./gameObject.js";
3
+ class d extends r(i) {
4
4
  get list() {
5
5
  return this.children;
6
6
  }
@@ -14,15 +14,19 @@ class a extends i(r) {
14
14
  remove(t, e = !1) {
15
15
  return t.parent === this && this.removeChild(t), e && t.destroy({ children: !0, context: !0 }), this;
16
16
  }
17
- /** Puts `child` directly below `other` in the draw order. */
17
+ /**
18
+ * Puts `child` directly below `other` in the draw order. Already there, it does nothing: taking a child out and
19
+ * putting it back marks the render group's structure changed, and Pixi rebuilds its draw instructions for that
20
+ * frame — a held weapon ordered against its body every frame did it every frame.
21
+ */
18
22
  moveBelow(t, e) {
19
- return t.parent !== this || e.parent !== this || t === e ? this : (this.removeChild(t), this.addChildAt(t, this.getChildIndex(e)), this);
23
+ return t.parent !== this || e.parent !== this || t === e ? this : this.getChildIndex(t) === this.getChildIndex(e) - 1 ? this : (this.removeChild(t), this.addChildAt(t, this.getChildIndex(e)), this);
20
24
  }
21
- /** Puts `child` directly above `other` in the draw order. */
25
+ /** Puts `child` directly above `other` in the draw order; already there, it does nothing (see `moveBelow`). */
22
26
  moveAbove(t, e) {
23
- return t.parent !== this || e.parent !== this || t === e ? this : (this.removeChild(t), this.addChildAt(t, this.getChildIndex(e) + 1), this);
27
+ return t.parent !== this || e.parent !== this || t === e ? this : this.getChildIndex(t) === this.getChildIndex(e) + 1 ? this : (this.removeChild(t), this.addChildAt(t, this.getChildIndex(e) + 1), this);
24
28
  }
25
29
  }
26
30
  export {
27
- a as Group
31
+ d as Group
28
32
  };
@@ -1,46 +1,46 @@
1
- import { Container as n, Matrix as d } from "pixi.js";
2
- class c {
1
+ import { Container as p, Matrix as c } from "pixi.js";
2
+ class u {
3
3
  constructor(e) {
4
4
  this.world = e;
5
5
  }
6
6
  world;
7
- layer = new n({ sortableChildren: !0 });
7
+ layer = new p({ sortableChildren: !0 });
8
8
  labels = /* @__PURE__ */ new Set();
9
- m = new d();
9
+ m = new c();
10
10
  /** Labels tracked since the last sweep for destroyed ones: off, nothing else sweeps them. */
11
11
  sinceSweep = 0;
12
12
  track(e) {
13
- this.labels.add({ obj: e, home: null, wrap: null }), ++this.sinceSweep >= 256 && this.prune();
13
+ this.labels.add({ obj: e, home: null, wrap: null, last: null }), ++this.sinceSweep >= 256 && this.prune();
14
14
  }
15
15
  /** Lays the layer over the world (`origin`: where the world's origin lands on screen) and every label on its home. */
16
- sync(e, r) {
17
- this.layer.position.set(e.x, e.y), this.layer.scale.set(r);
16
+ sync(e, o) {
17
+ this.layer.position.set(e.x, e.y), this.layer.scale.set(o);
18
18
  for (const t of this.labels) {
19
- const s = t.obj;
20
- if (s.destroyed) {
19
+ const r = t.obj;
20
+ if (r.destroyed) {
21
21
  this.drop(t);
22
22
  continue;
23
23
  }
24
- s.parent && s.parent !== t.wrap && (t.home = s.parent, t.wrap ??= this.layer.addChild(new n()), t.wrap.addChild(s));
25
- const o = t.home, i = t.wrap;
26
- if (!(!o || !i)) {
27
- if (o.destroyed) {
28
- s.destroy(), this.drop(t);
24
+ r.parent && r.parent !== t.wrap && (t.home = r.parent, t.wrap ??= this.layer.addChild(new p()), t.wrap.addChild(r), t.last = null);
25
+ const s = t.home, a = t.wrap;
26
+ if (!(!s || !a)) {
27
+ if (s.destroyed) {
28
+ r.destroy(), this.drop(t);
29
29
  continue;
30
30
  }
31
- this.place(o, i, s);
31
+ this.place(t, s, a, r);
32
32
  }
33
33
  }
34
34
  }
35
35
  /** Every label back in its home (the grid switched off), the stand-ins gone. */
36
36
  release() {
37
37
  for (const e of this.labels) {
38
- const { obj: r, home: t, wrap: s } = e;
39
- if (r.destroyed) {
38
+ const { obj: o, home: t, wrap: r } = e;
39
+ if (o.destroyed) {
40
40
  this.drop(e);
41
41
  continue;
42
42
  }
43
- t && s && r.parent === s && (t.destroyed ? r.destroy() : t.addChild(r)), s?.destroy(), e.wrap = null, e.home = null;
43
+ t && r && o.parent === r && (t.destroyed ? o.destroy() : t.addChild(o)), r?.destroy(), e.wrap = null, e.home = null, e.last = null;
44
44
  }
45
45
  }
46
46
  /** Forgets labels the game destroyed while nothing synced (the grid off). */
@@ -51,22 +51,23 @@ class c {
51
51
  destroy() {
52
52
  this.release(), this.labels.clear(), this.layer.destroy({ children: !0 });
53
53
  }
54
- place(e, r, t) {
54
+ place(e, o, t, r) {
55
55
  const s = this.m.identity();
56
- let o = !0, i = 1, a = e;
57
- for (let l = e; l !== this.world; l = l.parent) {
58
- if (!l) {
59
- o = !1;
56
+ let a = !0, n = 1, h = o;
57
+ for (let i = o; i !== this.world; i = i.parent) {
58
+ if (!i) {
59
+ a = !1;
60
60
  break;
61
61
  }
62
- (!l.visible || !l.renderable) && (o = !1), i *= l.alpha, l.updateLocalTransform(), s.prepend(l.localTransform), a = l;
62
+ (!i.visible || !i.renderable) && (a = !1), n *= i.alpha, i.updateLocalTransform(), s.prepend(i.localTransform), h = i;
63
63
  }
64
- r.visible = o, o && (r.setFromMatrix(s), r.alpha = i, r.zIndex = e === this.world ? t.zIndex : a.zIndex);
64
+ const d = o === this.world ? r.zIndex : h.zIndex, l = e.last ??= new Float64Array(9).fill(NaN);
65
+ a === (l[8] === 1) && (!a || l[0] === s.a && l[1] === s.b && l[2] === s.c && l[3] === s.d && l[4] === s.tx && l[5] === s.ty && l[6] === n && l[7] === d) || (l[8] = a ? 1 : 0, t.visible = a, a && (l[0] = s.a, l[1] = s.b, l[2] = s.c, l[3] = s.d, l[4] = s.tx, l[5] = s.ty, l[6] = n, l[7] = d, t.setFromMatrix(s), t.alpha = n, t.zIndex = d));
65
66
  }
66
67
  drop(e) {
67
68
  e.wrap?.destroy(), this.labels.delete(e);
68
69
  }
69
70
  }
70
71
  export {
71
- c as SharpText
72
+ u as SharpText
72
73
  };
@@ -6,9 +6,13 @@ export declare class Group extends Group_base {
6
6
  add(child: PixiContainer | PixiContainer[]): this;
7
7
  addAt(child: PixiContainer, index: number): this;
8
8
  remove(child: PixiContainer, destroy?: boolean): this;
9
- /** Puts `child` directly below `other` in the draw order. */
9
+ /**
10
+ * Puts `child` directly below `other` in the draw order. Already there, it does nothing: taking a child out and
11
+ * putting it back marks the render group's structure changed, and Pixi rebuilds its draw instructions for that
12
+ * frame — a held weapon ordered against its body every frame did it every frame.
13
+ */
10
14
  moveBelow(child: PixiContainer, other: PixiContainer): this;
11
- /** Puts `child` directly above `other` in the draw order. */
15
+ /** Puts `child` directly above `other` in the draw order; already there, it does nothing (see `moveBelow`). */
12
16
  moveAbove(child: PixiContainer, other: PixiContainer): this;
13
17
  }
14
18
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Group.d.ts","sourceRoot":"","sources":["../../../src/core/Group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;;AAGrE,yFAAyF;AACzF,qBAAa,KAAM,SAAQ,UAAqB;IAC9C,IAAI,IAAI,IAAI,aAAa,EAAE,CAE1B;IAED,GAAG,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,GAAG,IAAI;IAKjD,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAKhD,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,UAAQ,GAAG,IAAI;IAMnD,6DAA6D;IAC7D,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;IAO3D,6DAA6D;IAC7D,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;CAM5D"}
1
+ {"version":3,"file":"Group.d.ts","sourceRoot":"","sources":["../../../src/core/Group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;;AAGrE,yFAAyF;AACzF,qBAAa,KAAM,SAAQ,UAAqB;IAC9C,IAAI,IAAI,IAAI,aAAa,EAAE,CAE1B;IAED,GAAG,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,GAAG,IAAI;IAKjD,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAKhD,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,UAAQ,GAAG,IAAI;IAMnD;;;;OAIG;IACH,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;IAQ3D,+GAA+G;IAC/G,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;CAO5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"SharpText.d.ts","sourceRoot":"","sources":["../../../src/core/Sharp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AAC,EAAE,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IA6B1D,gFAAgF;IAChF,OAAO,IAAI,IAAI;IAkBf,6EAA6E;IAC7E,KAAK,IAAI,IAAI;IAKb,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,KAAK;IAqCb,OAAO,CAAC,IAAI;CAIb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "1681-engine",
3
- "version": "0.6.2",
3
+ "version": "0.6.5",
4
4
  "description": "A 2D game engine on PixiJS 8 for any art style: scenes and a fast ECS, a fixed-step loop, asset loading, Tiled maps, sprite animation, input actions, camera follow, audio and deterministic, server-replayable movement, plus Dither, an optional pixel-art module (pixel-perfect effects, dithered lighting).",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",