@next2d/texture-packer 3.15.1 → 3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/texture-packer",
3
- "version": "3.15.1",
3
+ "version": "3.17.0",
4
4
  "description": "Next2D Texture Packer Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -1,14 +1,24 @@
1
- import { Node } from "../../Node";
1
+ import type { Node } from "../../Node";
2
2
  /**
3
3
  * @description ノード解放ロジック
4
4
  * Node release logic
5
5
  *
6
+ * 子ノードは必ず親ノードの矩形の中にある (NodeInsertService が親の矩形を 2 つに分ける) ので、
7
+ * 解放する矩形を含まない枝には、一致するノードは無い。その枝はたどらずに戻る。
8
+ * これを省くと、解放 1 回ごとに木の全ノードをたどることになり、画面の切り替えで多数の
9
+ * キャッシュをまとめて解放するときに、ノード数 × 解放数の時間がかかる。
10
+ *
11
+ * Child nodes always lie inside their parent's rectangle (NodeInsertService splits the
12
+ * parent's rectangle in two), so a branch that does not contain the rectangle being
13
+ * released cannot hold a matching node and is skipped. Without this, every release walks
14
+ * the whole tree, which costs nodes x releases when many caches are released at once.
15
+ *
6
16
  * @param {Node} node
7
17
  * @param {number} x
8
18
  * @param {number} y
9
19
  * @param {number} width
10
20
  * @param {number} height
11
- * @return {void}
21
+ * @return {boolean}
12
22
  * @method
13
23
  * @protected
14
24
  */
@@ -2,39 +2,54 @@
2
2
  * @description ノード解放ロジック
3
3
  * Node release logic
4
4
  *
5
+ * 子ノードは必ず親ノードの矩形の中にある (NodeInsertService が親の矩形を 2 つに分ける) ので、
6
+ * 解放する矩形を含まない枝には、一致するノードは無い。その枝はたどらずに戻る。
7
+ * これを省くと、解放 1 回ごとに木の全ノードをたどることになり、画面の切り替えで多数の
8
+ * キャッシュをまとめて解放するときに、ノード数 × 解放数の時間がかかる。
9
+ *
10
+ * Child nodes always lie inside their parent's rectangle (NodeInsertService splits the
11
+ * parent's rectangle in two), so a branch that does not contain the rectangle being
12
+ * released cannot hold a matching node and is skipped. Without this, every release walks
13
+ * the whole tree, which costs nodes x releases when many caches are released at once.
14
+ *
5
15
  * @param {Node} node
6
16
  * @param {number} x
7
17
  * @param {number} y
8
18
  * @param {number} width
9
19
  * @param {number} height
10
- * @return {void}
20
+ * @return {boolean}
11
21
  * @method
12
22
  * @protected
13
23
  */
14
24
  export const execute = (node, x, y, width, height) => {
15
- if (node.left?.dispose(x, y, width, height)) {
16
- if (!node.left.used && !node.right?.used) {
25
+ // このノードの矩形に含まれない矩形は、このノードにも子孫にも無い
26
+ if (x < node.x
27
+ || y < node.y
28
+ || x + width > node.x + node.w
29
+ || y + height > node.y + node.h) {
30
+ return false;
31
+ }
32
+ const left = node.left;
33
+ const right = node.right;
34
+ if (left && execute(left, x, y, width, height)) {
35
+ if (!left.used && !(right && right.used)) {
17
36
  // 子ノードをプールに返却
18
- if (node.left) {
19
- node.left.release();
20
- }
21
- if (node.right) {
22
- node.right.release();
37
+ left.release();
38
+ if (right) {
39
+ right.release();
23
40
  }
24
41
  node.left = node.right = null;
25
42
  node.used = false;
26
43
  }
27
44
  return true;
28
45
  }
29
- if (node.right?.dispose(x, y, width, height)) {
30
- if (!node.right.used && !node.left?.used) {
46
+ if (right && execute(right, x, y, width, height)) {
47
+ if (!right.used && !(left && left.used)) {
31
48
  // 子ノードをプールに返却
32
- if (node.left) {
33
- node.left.release();
34
- }
35
- if (node.right) {
36
- node.right.release();
49
+ if (left) {
50
+ left.release();
37
51
  }
52
+ right.release();
38
53
  node.left = node.right = null;
39
54
  node.used = false;
40
55
  }
@@ -10,13 +10,22 @@
10
10
  * @protected
11
11
  */
12
12
  export const execute = (node, width, height) => {
13
- if (node.used) {
14
- const newNode = node.left?.insert(width, height);
15
- return newNode ? newNode : node.right?.insert(width, height) || null;
16
- }
13
+ // 子ノードは必ずこのノードの矩形の中にあるので、このノードに入らない大きさは子孫にも入らない。
14
+ // 使用中のノードでも先に判定して、入らない枝をたどらない。
17
15
  if (width > node.w || height > node.h) {
18
16
  return null;
19
17
  }
18
+ if (node.used) {
19
+ const left = node.left;
20
+ if (left) {
21
+ const newNode = execute(left, width, height);
22
+ if (newNode) {
23
+ return newNode;
24
+ }
25
+ }
26
+ const right = node.right;
27
+ return right ? execute(right, width, height) : null;
28
+ }
20
29
  if (width === node.w && height === node.h) {
21
30
  node.used = true;
22
31
  return node;
package/src/Node.js CHANGED
@@ -25,110 +25,6 @@ export class Node {
25
25
  * @public
26
26
  */
27
27
  constructor(index, x, y, w, h) {
28
- /**
29
- * @description パッキングされたテクスチャの識別番号
30
- * Identification number of packed texture
31
- *
32
- * @type {number}
33
- * @public
34
- */
35
- Object.defineProperty(this, "index", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: void 0
40
- });
41
- /**
42
- * @description パッキングされたテクスチャのx座標
43
- * x coordinate of packed texture
44
- *
45
- * @type {number}
46
- * @public
47
- */
48
- Object.defineProperty(this, "x", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: void 0
53
- });
54
- /**
55
- * @description パッキングされたテクスチャのy座標
56
- * y coordinate of packed texture
57
- *
58
- * @type {number}
59
- * @public
60
- */
61
- Object.defineProperty(this, "y", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
67
- /**
68
- * @description パッキングされたテクスチャの幅
69
- * Width of packed texture
70
- *
71
- * @type {number}
72
- * @public
73
- */
74
- Object.defineProperty(this, "w", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: void 0
79
- });
80
- /**
81
- * @description パッキングされたテクスチャの高さ
82
- * Height of packed texture
83
- *
84
- * @type {number}
85
- * @public
86
- */
87
- Object.defineProperty(this, "h", {
88
- enumerable: true,
89
- configurable: true,
90
- writable: true,
91
- value: void 0
92
- });
93
- /**
94
- * @description 左のノード
95
- * Left node
96
- *
97
- * @type {Node}
98
- * @public
99
- */
100
- Object.defineProperty(this, "left", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- /**
107
- * @description 右のノード
108
- * Right node
109
- *
110
- * @type {Node}
111
- * @public
112
- */
113
- Object.defineProperty(this, "right", {
114
- enumerable: true,
115
- configurable: true,
116
- writable: true,
117
- value: void 0
118
- });
119
- /**
120
- * @description 使用済みフラグ
121
- * Used flag
122
- *
123
- * @type {boolean}
124
- * @public
125
- */
126
- Object.defineProperty(this, "used", {
127
- enumerable: true,
128
- configurable: true,
129
- writable: true,
130
- value: void 0
131
- });
132
28
  this.index = index;
133
29
  this.x = x;
134
30
  this.y = y;
@@ -15,19 +15,6 @@ export class TexturePacker {
15
15
  * @public
16
16
  */
17
17
  constructor(index, width, height) {
18
- /**
19
- * @description ルートノード
20
- * Root node
21
- *
22
- * @type {Node}
23
- * @private
24
- */
25
- Object.defineProperty(this, "_$root", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
18
  this._$root = new Node(index, 0, 0, width, height);
32
19
  }
33
20
  /**