@daneren2005/shared-memory-objects 1.6.2 → 1.6.3
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/dist/allocated-memory.js +1 -2
- package/dist/cached-item-list.js +1 -2
- package/dist/constant-string.js +13 -14
- package/dist/local-pool.js +5 -6
- package/dist/lock/read-write-lock.js +0 -1
- package/dist/lock/simple-lock.js +0 -1
- package/dist/memory-buffer.js +1 -2
- package/dist/memory-heap.js +24 -25
- package/dist/serialize-object.js +4 -5
- package/dist/shared-list.js +43 -44
- package/dist/shared-map.js +74 -75
- package/dist/shared-pointer-list.js +15 -16
- package/dist/shared-pool.d.ts +1 -0
- package/dist/shared-pool.js +36 -32
- package/dist/shared-pool.js.map +1 -1
- package/dist/shared-stack.js +33 -34
- package/dist/shared-string.js +19 -20
- package/dist/shared-vector.js +23 -24
- package/dist/spatial/shared-quadtree.js +81 -82
- package/dist/spatial/shared-quadtree.js.map +1 -1
- package/dist/spatial/shared-spatial-grid.js +104 -110
- package/dist/spatial/shared-spatial-grid.js.map +1 -1
- package/dist/spatial/shared-spatial-map.js +189 -190
- package/dist/spatial/shared-spatial-map.js.map +1 -1
- package/dist/spatial/spatial-entity.js +1 -2
- package/dist/spatial/spatial-neighbors.js +1 -2
- package/dist/utils/16-from-32-array.js +1 -2
- package/dist/utils/16-from-32-float.js +1 -2
- package/dist/utils/16-from-32-int.js +1 -2
- package/dist/utils/16-from-32-uint.js +1 -2
- package/dist/utils/16-from-64-array.js +1 -2
- package/dist/utils/16-from-64-float.js +1 -2
- package/dist/utils/16-from-64-int.js +1 -2
- package/dist/utils/16-from-64-uint.js +1 -2
- package/dist/utils/32-from-64-float.js +1 -2
- package/dist/utils/32-from-64-int.js +1 -2
- package/dist/utils/32-from-64-uint.js +1 -2
- package/dist/utils/array-type.js +1 -2
- package/dist/utils/atomic-math.js +1 -2
- package/dist/utils/float32-atomics.js +1 -2
- package/dist/utils/float64-atomics.js +1 -2
- package/dist/utils/hash.js +1 -2
- package/dist/utils/pointer.js +1 -2
- package/dist/utils/typedarray.js +1 -2
- package/package.json +11 -11
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { lock as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import g from "../
|
|
1
|
+
import e from "../allocated-memory.js";
|
|
2
|
+
import t from "../shared-pool.js";
|
|
3
|
+
import n from "../shared-map.js";
|
|
4
|
+
import r from "../shared-stack.js";
|
|
5
|
+
import { lock as i, unlock as a } from "../lock/simple-lock.js";
|
|
6
|
+
import { readLock as o, readUnlock as s, writeLock as c, writeUnlock as l } from "../lock/read-write-lock.js";
|
|
7
|
+
import { getPointer as u, loadRawPointer as d, storeRawPointer as f } from "../utils/pointer.js";
|
|
8
|
+
import { ARRAY_TYPE as p, getArrayTypeCode as m, getByteMultipler as h, makeArrayView as g } from "../utils/array-type.js";
|
|
9
9
|
import { addCandidate as _, candidateLimit as v, distanceSquaredToRect as y } from "./spatial-neighbors.js";
|
|
10
10
|
import { getSpatialMapCapacity as ee, getSpatialPoolChunkSize as te } from "./spatial-entity.js";
|
|
11
|
-
|
|
12
|
-
var
|
|
11
|
+
// src/spatial/shared-spatial-map.ts
|
|
12
|
+
var ne = 0, b = 1, x = 2, S = 3, C = 4, w = 5, T = 6, E = 8, D = 10, O = 0, k = 1, A = 2, j = 8, M = 256, re = 255, N = 0, P = 1, F = 2, I = 3, L = 4, R = 5, z = 6, B = 7, V = 0, H = 1, U = 2, W = 3, G = 4, K = 5, q = 6, J = 7, Y = 8, X = 16777216, ie = X, ae = 4294967295, oe = 4294967296, se = 73856093, ce = 19349663, le = 50, ue = 256, Z = 1, Q = 2, de = 1e6, fe = 4, pe = Float32Array, me = class m {
|
|
13
13
|
static ALLOCATE_COUNT = 11;
|
|
14
14
|
memory;
|
|
15
15
|
firstBlock;
|
|
@@ -53,7 +53,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
53
53
|
return this.cellSize;
|
|
54
54
|
}
|
|
55
55
|
get buckets() {
|
|
56
|
-
return Atomics.load(this.firstBlock.data,
|
|
56
|
+
return Atomics.load(this.firstBlock.data, C);
|
|
57
57
|
}
|
|
58
58
|
get maxBuckets() {
|
|
59
59
|
return this.maxBucketCount;
|
|
@@ -62,43 +62,43 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
62
62
|
return this.coordType;
|
|
63
63
|
}
|
|
64
64
|
constructor(i, a) {
|
|
65
|
-
if (this.memory = i, a && "firstBlock" in a) this.firstBlock = new
|
|
65
|
+
if (this.memory = i, a && "firstBlock" in a) this.firstBlock = new e(i, a.firstBlock), this.coordType = this.firstBlock.data[w], this.bucketPointers = new r(i, { firstBlock: u(d(this.firstBlock.data, ne), i.positionBits) }), this.entityPool = new t(i, { firstBlock: u(d(this.firstBlock.data, b), i.positionBits) }), this.slotPool = new t(i, { firstBlock: u(d(this.firstBlock.data, x), i.positionBits) }), this.idMap = new n(i, { firstBlock: u(d(this.firstBlock.data, S), i.positionBits) }), this.bucketCount = Atomics.load(this.firstBlock.data, C), this.maxBucketCount = this.firstBlock.data[D], this.nullIndex = _e(this.coordType);
|
|
66
66
|
else {
|
|
67
67
|
let e = a?.gridSize ?? le;
|
|
68
68
|
this.bucketCount = Math.min(1073741824, Math.max(1, Math.floor(a?.buckets ?? ue)));
|
|
69
|
-
let
|
|
70
|
-
if (this.maxBucketCount = Math.min(1073741824, Math.max(this.bucketCount, Math.floor(a?.maxBuckets ?? ve(
|
|
71
|
-
let
|
|
69
|
+
let o = a?.maxEntities ?? de, s = a?.maxSlots ?? o * fe;
|
|
70
|
+
if (this.maxBucketCount = Math.min(1073741824, Math.max(this.bucketCount, Math.floor(a?.maxBuckets ?? ve(s * 2)))), this.coordType = he(a?.type), this.nullIndex = _e(this.coordType), this.coordType === p.float32 && (o > X || s > X)) throw Error(`Float32 SharedSpatialMap supports at most ${X} entities and slots; pass type: Float64Array for more`);
|
|
71
|
+
let c = {
|
|
72
72
|
type: ge(this.coordType),
|
|
73
73
|
dataLength: Y,
|
|
74
|
-
maxLength:
|
|
75
|
-
maxChunkSize: te(
|
|
76
|
-
},
|
|
74
|
+
maxLength: o,
|
|
75
|
+
maxChunkSize: te(o, Y, h(this.coordType), i.maxAllocationLength)
|
|
76
|
+
}, l = {
|
|
77
77
|
type: ge(this.coordType),
|
|
78
78
|
dataLength: B,
|
|
79
|
-
maxLength:
|
|
80
|
-
maxChunkSize: te(
|
|
81
|
-
},
|
|
82
|
-
this.firstBlock = i.allocUI32(_ +
|
|
79
|
+
maxLength: s,
|
|
80
|
+
maxChunkSize: te(s, B, h(this.coordType), i.maxAllocationLength)
|
|
81
|
+
}, u = t.getAllocateCount(i, c), d = t.getAllocateCount(i, l), g = n.ALLOCATE_COUNT, _ = m.ALLOCATE_COUNT;
|
|
82
|
+
this.firstBlock = i.allocUI32(_ + u + d + g), this.firstBlock.data[C] = this.bucketCount, this.firstBlock.data[w] = this.coordType, this.firstBlock.data[D] = this.maxBucketCount;
|
|
83
83
|
let v = this.getConfigView();
|
|
84
|
-
v[0] = e, this.bucketPointers = new
|
|
85
|
-
let y = this.firstBlock.getSubAllocation(_,
|
|
86
|
-
this.entityPool = new
|
|
84
|
+
v[0] = e, this.bucketPointers = new r(i), f(this.firstBlock.data, ne, this.bucketPointers.pointer), this.appendBucketSegments(this.bucketCount);
|
|
85
|
+
let y = this.firstBlock.getSubAllocation(_, u);
|
|
86
|
+
this.entityPool = new t(i, {
|
|
87
87
|
firstBlock: y,
|
|
88
|
-
...
|
|
89
|
-
}),
|
|
90
|
-
let
|
|
91
|
-
this.slotPool = new
|
|
88
|
+
...c
|
|
89
|
+
}), f(this.firstBlock.data, b, y.pointer);
|
|
90
|
+
let T = this.firstBlock.getSubAllocation(_ + u, d);
|
|
91
|
+
this.slotPool = new t(i, {
|
|
92
|
+
firstBlock: T,
|
|
93
|
+
...l
|
|
94
|
+
}), f(this.firstBlock.data, x, T.pointer);
|
|
95
|
+
let E = this.firstBlock.getSubAllocation(_ + u + d, g);
|
|
96
|
+
this.idMap = new n(i, {
|
|
92
97
|
firstBlock: E,
|
|
93
|
-
|
|
94
|
-
}),
|
|
95
|
-
let D = this.firstBlock.getSubAllocation(_ + d + f, p);
|
|
96
|
-
this.idMap = new m(i, {
|
|
97
|
-
firstBlock: D,
|
|
98
|
-
capacity: ee(t, i.maxAllocationLength)
|
|
99
|
-
}), n(this.firstBlock.data, C, D.pointer);
|
|
98
|
+
capacity: ee(o, i.maxAllocationLength)
|
|
99
|
+
}), f(this.firstBlock.data, S, E.pointer);
|
|
100
100
|
}
|
|
101
|
-
this.idLimit = this.coordType ===
|
|
101
|
+
this.idLimit = this.coordType === p.float32 ? X : oe, this.bucketMask = $(this.bucketCount), this.tableLock = new Int32Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + E * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
102
102
|
let o = this.getConfigView();
|
|
103
103
|
this.cellSize = o[0];
|
|
104
104
|
}
|
|
@@ -107,49 +107,49 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
107
107
|
}
|
|
108
108
|
get usedMemory() {
|
|
109
109
|
let t = this.firstBlock.usedMemory + this.bucketPointers.usedMemory + this.entityPool.usedMemory + this.slotPool.usedMemory + this.idMap.usedMemory;
|
|
110
|
-
for (let n of this.bucketPointers) t += new
|
|
110
|
+
for (let n of this.bucketPointers) t += new e(this.memory, u(n, this.memory.positionBits)).usedMemory;
|
|
111
111
|
return t;
|
|
112
112
|
}
|
|
113
|
-
insert(e, t, n, r = 0,
|
|
114
|
-
|
|
113
|
+
insert(e, t, n, r = 0, i = 0) {
|
|
114
|
+
o(this.tableLock);
|
|
115
115
|
try {
|
|
116
|
-
this.syncBucketCount(), this.insertLocked(e, t, n, r,
|
|
116
|
+
this.syncBucketCount(), this.insertLocked(e, t, n, r, i);
|
|
117
117
|
} finally {
|
|
118
|
-
|
|
118
|
+
s(this.tableLock);
|
|
119
119
|
}
|
|
120
120
|
this.growBucketsIfNeeded();
|
|
121
121
|
}
|
|
122
122
|
bulkInsert(e) {
|
|
123
123
|
let t = /* @__PURE__ */ new Map();
|
|
124
124
|
for (let n of e) this.assertValidId(n.id), t.set(n.id, n);
|
|
125
|
-
let n = Array.from(t.values()), r = this.idMap.getAll(n.map((e) => e.id)),
|
|
125
|
+
let n = Array.from(t.values()), r = this.idMap.getAll(n.map((e) => e.id)), i = [], a = 0, c = 0;
|
|
126
126
|
for (let e = 0; e < n.length; e++) if (r[e] === void 0) {
|
|
127
127
|
let t = n[e];
|
|
128
|
-
c++,
|
|
128
|
+
c++, a += (this.colOf(t.x + (t.width ?? 0)) - this.colOf(t.x) + 1) * (this.rowOf(t.y + (t.height ?? 0)) - this.rowOf(t.y) + 1);
|
|
129
129
|
}
|
|
130
|
-
this.ensureBucketCapacity(this.slotPool.length +
|
|
131
|
-
let l = this.entityPool.reserveContiguous(c), u = this.slotPool.reserveContiguous(
|
|
132
|
-
|
|
130
|
+
this.ensureBucketCapacity(this.slotPool.length + a);
|
|
131
|
+
let l = this.entityPool.reserveContiguous(c), u = this.slotPool.reserveContiguous(a);
|
|
132
|
+
o(this.tableLock);
|
|
133
133
|
try {
|
|
134
134
|
this.syncBucketCount();
|
|
135
135
|
for (let e = 0; e < n.length; e++) {
|
|
136
|
-
let t = n[e],
|
|
136
|
+
let t = n[e], a = t.width ?? 0, o = t.height ?? 0;
|
|
137
137
|
if (r[e] !== void 0) {
|
|
138
|
-
this.updateLocked(t.id, t.x, t.y,
|
|
138
|
+
this.updateLocked(t.id, t.x, t.y, a, o);
|
|
139
139
|
continue;
|
|
140
140
|
}
|
|
141
|
-
let s = this.colOf(t.x), c = this.rowOf(t.y), d = this.colOf(t.x +
|
|
142
|
-
m[h + V] = s, m[h + H] = c, m[h + U] = d, m[h + W] = f, m[h + G] = t.x, m[h + K] = t.y, m[h + q] =
|
|
141
|
+
let s = this.colOf(t.x), c = this.rowOf(t.y), d = this.colOf(t.x + a), f = this.rowOf(t.y + o), p = l++, m = this.entityPool.blockFor(p), h = this.entityPool.blockOffset(p);
|
|
142
|
+
m[h + V] = s, m[h + H] = c, m[h + U] = d, m[h + W] = f, m[h + G] = t.x, m[h + K] = t.y, m[h + q] = a, m[h + J] = o, i.push([t.id, p]);
|
|
143
143
|
for (let e = c; e <= f; e++) for (let n = s; n <= d; n++) this.linkReservedBucket(n, e, u++, t.id, p, s, c);
|
|
144
144
|
}
|
|
145
|
-
this.idMap.setAll(
|
|
145
|
+
this.idMap.setAll(i);
|
|
146
146
|
} finally {
|
|
147
|
-
|
|
147
|
+
s(this.tableLock);
|
|
148
148
|
}
|
|
149
149
|
this.growBucketsForBulk();
|
|
150
150
|
}
|
|
151
151
|
assertValidId(e) {
|
|
152
|
-
if (!Number.isInteger(e) || e < 0 || e >= this.idLimit) throw Error(`SharedSpatialMap id ${e} must be an integer in [0, ${this.idLimit})` + (this.coordType ===
|
|
152
|
+
if (!Number.isInteger(e) || e < 0 || e >= this.idLimit) throw Error(`SharedSpatialMap id ${e} must be an integer in [0, ${this.idLimit})` + (this.coordType === p.float32 ? "; pass type: Float64Array for ids up to 2^32 - 1" : ""));
|
|
153
153
|
}
|
|
154
154
|
insertLocked(e, t, n, r, i) {
|
|
155
155
|
if (this.assertValidId(e), this.idMap.get(e) !== void 0) {
|
|
@@ -161,20 +161,20 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
161
161
|
let u = this.entityPool.push(l);
|
|
162
162
|
this.idMap.set(e, u), this.linkRange(e, u, a, o, s, c);
|
|
163
163
|
}
|
|
164
|
-
update(e, t, n, r = 0,
|
|
165
|
-
let
|
|
166
|
-
if (
|
|
167
|
-
let e = this.entityPool.blockFor(
|
|
168
|
-
if (
|
|
169
|
-
e[
|
|
164
|
+
update(e, t, n, r = 0, i = 0) {
|
|
165
|
+
let a = this.idMap.get(e);
|
|
166
|
+
if (a !== void 0) {
|
|
167
|
+
let e = this.entityPool.blockFor(a), o = this.entityPool.blockOffset(a), s = this.colOf(t), c = this.rowOf(n), l = this.colOf(t + r), u = this.rowOf(n + i);
|
|
168
|
+
if (s === e[o + V] && c === e[o + H] && l === e[o + U] && u === e[o + W]) {
|
|
169
|
+
e[o + G] = t, e[o + K] = n, e[o + q] = r, e[o + J] = i;
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
|
|
173
|
+
o(this.tableLock);
|
|
174
174
|
try {
|
|
175
|
-
this.syncBucketCount(), this.updateLocked(e, t, n, r,
|
|
175
|
+
this.syncBucketCount(), this.updateLocked(e, t, n, r, i);
|
|
176
176
|
} finally {
|
|
177
|
-
|
|
177
|
+
s(this.tableLock);
|
|
178
178
|
}
|
|
179
179
|
this.growBucketsIfNeeded();
|
|
180
180
|
}
|
|
@@ -185,18 +185,14 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
let o = this.entityPool.blockFor(a), s = this.entityPool.blockOffset(a), c = o[s + V], l = o[s + H], u = o[s + U], d = o[s + W], f = this.colOf(t), p = this.rowOf(n), m = this.colOf(t + r), h = this.rowOf(n + i);
|
|
188
|
-
|
|
189
|
-
o[s + G] = t, o[s + K] = n, o[s + q] = r, o[s + J] = i;
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
this.relinkRange(e, a, f, p, m, h, c, l, u, d), o[s + V] = f, o[s + H] = p, o[s + U] = m, o[s + W] = h, o[s + G] = t, o[s + K] = n, o[s + q] = r, o[s + J] = i;
|
|
188
|
+
f === c && p === l && m === u && h === d ? (o[s + G] = t, o[s + K] = n, o[s + q] = r, o[s + J] = i) : (this.relinkRange(e, a, f, p, m, h, c, l, u, d), o[s + V] = f, o[s + H] = p, o[s + U] = m, o[s + W] = h, o[s + G] = t, o[s + K] = n, o[s + q] = r, o[s + J] = i);
|
|
193
189
|
}
|
|
194
190
|
remove(e) {
|
|
195
|
-
|
|
191
|
+
o(this.tableLock);
|
|
196
192
|
try {
|
|
197
193
|
return this.syncBucketCount(), this.removeLocked(e);
|
|
198
194
|
} finally {
|
|
199
|
-
|
|
195
|
+
s(this.tableLock);
|
|
200
196
|
}
|
|
201
197
|
}
|
|
202
198
|
removeLocked(e) {
|
|
@@ -212,12 +208,12 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
212
208
|
let a = [];
|
|
213
209
|
return this.searchInto(a, e, t, n, r, i), a;
|
|
214
210
|
}
|
|
215
|
-
searchInto(e, t, n, r,
|
|
216
|
-
|
|
211
|
+
searchInto(e, t, n, r, i, a) {
|
|
212
|
+
o(this.tableLock);
|
|
217
213
|
try {
|
|
218
|
-
return this.syncBucketCount(), this.searchIntoLocked(e, t, n, r,
|
|
214
|
+
return this.syncBucketCount(), this.searchIntoLocked(e, t, n, r, i, a);
|
|
219
215
|
} finally {
|
|
220
|
-
|
|
216
|
+
s(this.tableLock);
|
|
221
217
|
}
|
|
222
218
|
}
|
|
223
219
|
searchIntoLocked(e, t, n, r, i, a) {
|
|
@@ -236,12 +232,12 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
236
232
|
}
|
|
237
233
|
return e;
|
|
238
234
|
}
|
|
239
|
-
neighbors(e, t, n, r,
|
|
240
|
-
|
|
235
|
+
neighbors(e, t, n, r, i) {
|
|
236
|
+
o(this.tableLock);
|
|
241
237
|
try {
|
|
242
|
-
return this.syncBucketCount(), this.neighborsLocked(e, t, n, r,
|
|
238
|
+
return this.syncBucketCount(), this.neighborsLocked(e, t, n, r, i);
|
|
243
239
|
} finally {
|
|
244
|
-
|
|
240
|
+
s(this.tableLock);
|
|
245
241
|
}
|
|
246
242
|
}
|
|
247
243
|
neighborsLocked(e, t, n, r, i) {
|
|
@@ -255,20 +251,19 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
255
251
|
id: void 0,
|
|
256
252
|
distance: a
|
|
257
253
|
}, f = (r, f) => {
|
|
258
|
-
if (i === void 0)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
} else this.addEntityCandidate(o, r, s, e, t, n, a);
|
|
254
|
+
if (i === void 0) n === 1 ? this.collectNearestBucket(d, r, f, e, t) : this.collectNeighborCandidates(o, r, f, l, u, e, t, n, a);
|
|
255
|
+
else {
|
|
256
|
+
s.length = 0, this.collectNeighborBucket(s, r, f);
|
|
257
|
+
for (let r of s) {
|
|
258
|
+
if (c?.has(r)) continue;
|
|
259
|
+
c?.add(r);
|
|
260
|
+
let s = this.idMap.get(r);
|
|
261
|
+
if (s !== void 0 && (i === void 0 || i(r))) {
|
|
262
|
+
if (n === 1) {
|
|
263
|
+
let n = this.entityDistanceSquared(s, e, t);
|
|
264
|
+
(n < d.distance || n === d.distance && (d.id === void 0 || r < d.id)) && (d.id = r, d.distance = n);
|
|
265
|
+
} else this.addEntityCandidate(o, r, s, e, t, n, a);
|
|
266
|
+
}
|
|
272
267
|
}
|
|
273
268
|
}
|
|
274
269
|
};
|
|
@@ -286,7 +281,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
286
281
|
return n === 1 ? d.id === void 0 ? [] : [d.id] : o.map((e) => e.id);
|
|
287
282
|
}
|
|
288
283
|
clear() {
|
|
289
|
-
|
|
284
|
+
c(this.tableLock);
|
|
290
285
|
try {
|
|
291
286
|
this.syncBucketCount();
|
|
292
287
|
for (let e = 0; e < this.bucketPointers.length; e++) {
|
|
@@ -299,18 +294,18 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
299
294
|
for (let [t] of this.idMap) e.push(t);
|
|
300
295
|
for (let t of e) this.idMap.delete(t);
|
|
301
296
|
} finally {
|
|
302
|
-
|
|
297
|
+
l(this.tableLock);
|
|
303
298
|
}
|
|
304
299
|
}
|
|
305
300
|
free() {
|
|
306
|
-
for (let t of this.bucketPointers) new
|
|
301
|
+
for (let t of this.bucketPointers) new e(this.memory, u(t, this.memory.positionBits)).free();
|
|
307
302
|
this.bucketPointers.free(), this.entityPool.free(), this.slotPool.free(), this.idMap.free(), this.firstBlock.free();
|
|
308
303
|
}
|
|
309
304
|
getSharedMemory() {
|
|
310
305
|
return { firstBlock: this.firstBlock.getSharedMemory() };
|
|
311
306
|
}
|
|
312
307
|
getConfigView() {
|
|
313
|
-
return
|
|
308
|
+
return g(this.coordType, this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + T * Uint32Array.BYTES_PER_ELEMENT, 1);
|
|
314
309
|
}
|
|
315
310
|
colOf(e) {
|
|
316
311
|
return Math.floor(e / this.cellSize);
|
|
@@ -331,10 +326,10 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
331
326
|
return (e & re) * A;
|
|
332
327
|
}
|
|
333
328
|
getBucketSegment(t) {
|
|
334
|
-
let n = t >>> j,
|
|
335
|
-
if (
|
|
336
|
-
let
|
|
337
|
-
return this.bucketHeadSegments[n] = new Uint32Array(
|
|
329
|
+
let n = t >>> j, r = this.bucketSegments[n];
|
|
330
|
+
if (r !== void 0) return r;
|
|
331
|
+
let i = this.bucketPointers.at(n), a = new e(this.memory, u(i, this.memory.positionBits)), o = new Int32Array(a.data.buffer, a.bufferByteOffset, M * A);
|
|
332
|
+
return this.bucketHeadSegments[n] = new Uint32Array(a.data.buffer, a.bufferByteOffset, M * A), this.bucketSegments[n] = o, o;
|
|
338
333
|
}
|
|
339
334
|
appendBucketSegments(e) {
|
|
340
335
|
let t = Math.ceil(e / M);
|
|
@@ -345,31 +340,31 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
345
340
|
}
|
|
346
341
|
}
|
|
347
342
|
syncBucketCount() {
|
|
348
|
-
let e = Atomics.load(this.firstBlock.data,
|
|
343
|
+
let e = Atomics.load(this.firstBlock.data, C);
|
|
349
344
|
e !== this.bucketCount && (this.bucketCount = e, this.bucketMask = $(e));
|
|
350
345
|
}
|
|
351
346
|
growBucketsIfNeeded() {
|
|
352
|
-
let e = Atomics.load(this.firstBlock.data,
|
|
347
|
+
let e = Atomics.load(this.firstBlock.data, C);
|
|
353
348
|
if (!(e >= this.maxBucketCount || this.slotPool.length * Q <= e * Z)) {
|
|
354
|
-
|
|
349
|
+
c(this.tableLock);
|
|
355
350
|
try {
|
|
356
351
|
if (this.syncBucketCount(), this.slotPool.length * Q <= this.bucketCount * Z) return;
|
|
357
352
|
let e = Math.min(this.bucketCount * 2, this.maxBucketCount);
|
|
358
353
|
if (e === this.bucketCount) return;
|
|
359
354
|
this.resizeBuckets(e);
|
|
360
355
|
} finally {
|
|
361
|
-
|
|
356
|
+
l(this.tableLock);
|
|
362
357
|
}
|
|
363
358
|
}
|
|
364
359
|
}
|
|
365
360
|
ensureBucketCapacity(e) {
|
|
366
361
|
let t = Math.ceil(e * Q / Z), n = Math.min(ve(t), this.maxBucketCount);
|
|
367
|
-
if (!(n <= Atomics.load(this.firstBlock.data,
|
|
368
|
-
|
|
362
|
+
if (!(n <= Atomics.load(this.firstBlock.data, C))) {
|
|
363
|
+
c(this.tableLock);
|
|
369
364
|
try {
|
|
370
365
|
this.syncBucketCount(), n > this.bucketCount && this.resizeBuckets(n);
|
|
371
366
|
} finally {
|
|
372
|
-
|
|
367
|
+
l(this.tableLock);
|
|
373
368
|
}
|
|
374
369
|
}
|
|
375
370
|
}
|
|
@@ -381,16 +376,21 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
381
376
|
for (let e = k; e < t.length; e += A) t[e] = this.nullIndex;
|
|
382
377
|
}
|
|
383
378
|
this.bucketCount = e, this.bucketMask = $(e);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
379
|
+
let t = this.slotPool, n = t.getRecycledMask(), r = n.length, i = t.maxChunkSize;
|
|
380
|
+
for (let e = 0; e < r; e += i) {
|
|
381
|
+
let a = t.blockFor(e), o = Math.min(e + i, r);
|
|
382
|
+
for (let t = e; t < o; t++) {
|
|
383
|
+
if (n[t] === 1) continue;
|
|
384
|
+
let r = (t - e) * B, i = this.bucketOf(a[r + P], a[r + F]), o = this.bucketHeadSegments[i >>> j], s = this.bucketOffset(i) + k;
|
|
385
|
+
a[r + R] = o[s], o[s] = t;
|
|
386
|
+
}
|
|
387
387
|
}
|
|
388
|
-
Atomics.store(this.firstBlock.data,
|
|
388
|
+
Atomics.store(this.firstBlock.data, C, e);
|
|
389
389
|
}
|
|
390
390
|
growBucketsForBulk() {
|
|
391
391
|
for (;;) {
|
|
392
|
-
let e = Atomics.load(this.firstBlock.data,
|
|
393
|
-
if (this.growBucketsIfNeeded(), Atomics.load(this.firstBlock.data,
|
|
392
|
+
let e = Atomics.load(this.firstBlock.data, C);
|
|
393
|
+
if (this.growBucketsIfNeeded(), Atomics.load(this.firstBlock.data, C) === e) return;
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
linkRange(e, t, n, r, i, a) {
|
|
@@ -400,18 +400,18 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
400
400
|
}
|
|
401
401
|
linkIntoBucket(e, t, n) {
|
|
402
402
|
n[P] = e, n[F] = t;
|
|
403
|
-
let r = this.slotPool,
|
|
404
|
-
|
|
405
|
-
let
|
|
406
|
-
r.set(
|
|
407
|
-
}
|
|
408
|
-
linkReservedBucket(e, t, n, r,
|
|
409
|
-
let
|
|
410
|
-
|
|
411
|
-
let
|
|
412
|
-
|
|
403
|
+
let r = this.slotPool, o = r.push(n), s = this.bucketOf(e, t), c = this.getBucketSegment(s), l = this.bucketHeadSegments[s >>> j], u = this.bucketOffset(s), d = u + O;
|
|
404
|
+
i(c, d);
|
|
405
|
+
let f = u + k;
|
|
406
|
+
r.set(o, R, l[f]), l[f] = o, a(c, d);
|
|
407
|
+
}
|
|
408
|
+
linkReservedBucket(e, t, n, r, o, s, c) {
|
|
409
|
+
let l = this.slotPool, u = l.blockFor(n), d = l.blockOffset(n);
|
|
410
|
+
u[d + N] = r, u[d + P] = e, u[d + F] = t, u[d + I] = s, u[d + L] = c, u[d + z] = o;
|
|
411
|
+
let f = this.bucketOf(e, t), p = this.getBucketSegment(f), m = this.bucketHeadSegments[f >>> j], h = this.bucketOffset(f), g = h + O;
|
|
412
|
+
i(p, g);
|
|
413
413
|
let _ = h + k;
|
|
414
|
-
|
|
414
|
+
u[d + R] = m[_], m[_] = n, a(p, g);
|
|
415
415
|
}
|
|
416
416
|
relinkRange(e, t, n, r, i, a, o, s, c, l) {
|
|
417
417
|
let u = n > o ? n : o, d = i < c ? i : c, f = r > s ? r : s, p = a < l ? a : l, m = u <= d && f <= p, h = this.slotScratch;
|
|
@@ -430,19 +430,19 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
|
-
refreshAnchorInBucket(e, t, n, r,
|
|
434
|
-
let
|
|
435
|
-
|
|
436
|
-
let
|
|
437
|
-
for (;
|
|
438
|
-
let e =
|
|
439
|
-
if (e[
|
|
440
|
-
e[
|
|
433
|
+
refreshAnchorInBucket(e, t, n, r, o, s) {
|
|
434
|
+
let c = this.nullIndex, l = this.getBucketSegment(e), u = this.bucketOffset(e), d = u + O;
|
|
435
|
+
i(l, d);
|
|
436
|
+
let f = this.slotPool, p = this.bucketHeadSegments[e >>> j][u + k];
|
|
437
|
+
for (; p !== c;) {
|
|
438
|
+
let e = f.blockFor(p), i = f.blockOffset(p);
|
|
439
|
+
if (e[i + N] === t && e[i + P] === n && e[i + F] === r) {
|
|
440
|
+
e[i + I] = o, e[i + L] = s;
|
|
441
441
|
break;
|
|
442
442
|
}
|
|
443
|
-
|
|
443
|
+
p = e[i + R];
|
|
444
444
|
}
|
|
445
|
-
|
|
445
|
+
a(l, d);
|
|
446
446
|
}
|
|
447
447
|
unlinkRange(e, t, n, r, i) {
|
|
448
448
|
let a = this.nullIndex, o = this.slotPool;
|
|
@@ -451,66 +451,66 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
451
451
|
t !== a && o.deleteIndex(t);
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
|
-
collectBucket(e, t, n, r,
|
|
455
|
-
let
|
|
456
|
-
|
|
457
|
-
let
|
|
458
|
-
for (;
|
|
459
|
-
let t = m.blockFor(
|
|
460
|
-
if (t[n + P] ===
|
|
461
|
-
let r = t[n + I],
|
|
462
|
-
|
|
454
|
+
collectBucket(e, t, n, r, o, s, c, l) {
|
|
455
|
+
let u = this.nullIndex, d = r + k, f = r + O;
|
|
456
|
+
i(t, f);
|
|
457
|
+
let p = n[d], m = this.slotPool;
|
|
458
|
+
for (; p !== u;) {
|
|
459
|
+
let t = m.blockFor(p), n = m.blockOffset(p);
|
|
460
|
+
if (t[n + P] === o && t[n + F] === s) {
|
|
461
|
+
let r = t[n + I], i = t[n + L];
|
|
462
|
+
o === (r > c ? r : c) && s === (i > l ? i : l) && e.push(t[n + N]);
|
|
463
463
|
}
|
|
464
|
-
|
|
464
|
+
p = t[n + R];
|
|
465
465
|
}
|
|
466
|
-
|
|
466
|
+
a(t, f);
|
|
467
467
|
}
|
|
468
468
|
collectNeighborBucket(e, t, n) {
|
|
469
|
-
let r = this.bucketOf(t, n),
|
|
470
|
-
if (a[s] === this.nullIndex) return;
|
|
471
|
-
let c = o + O;
|
|
472
|
-
f(i, c);
|
|
473
|
-
let l = a[s];
|
|
474
|
-
for (; l !== this.nullIndex;) {
|
|
475
|
-
let r = this.slotPool.blockFor(l), i = this.slotPool.blockOffset(l);
|
|
476
|
-
r[i + P] === t && r[i + F] === n && e.push(r[i + N]), l = r[i + R];
|
|
477
|
-
}
|
|
478
|
-
p(i, c);
|
|
479
|
-
}
|
|
480
|
-
collectNearestBucket(e, t, n, r, i) {
|
|
481
|
-
let a = this.bucketOf(t, n), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], c = this.bucketOffset(a), l = c + k;
|
|
469
|
+
let r = this.bucketOf(t, n), o = this.getBucketSegment(r), s = this.bucketHeadSegments[r >>> j], c = this.bucketOffset(r), l = c + k;
|
|
482
470
|
if (s[l] === this.nullIndex) return;
|
|
483
471
|
let u = c + O;
|
|
484
|
-
|
|
472
|
+
i(o, u);
|
|
485
473
|
let d = s[l];
|
|
486
474
|
for (; d !== this.nullIndex;) {
|
|
487
|
-
let
|
|
488
|
-
|
|
489
|
-
|
|
475
|
+
let r = this.slotPool.blockFor(d), i = this.slotPool.blockOffset(d);
|
|
476
|
+
r[i + P] === t && r[i + F] === n && e.push(r[i + N]), d = r[i + R];
|
|
477
|
+
}
|
|
478
|
+
a(o, u);
|
|
479
|
+
}
|
|
480
|
+
collectNearestBucket(e, t, n, r, o) {
|
|
481
|
+
let s = this.bucketOf(t, n), c = this.getBucketSegment(s), l = this.bucketHeadSegments[s >>> j], u = this.bucketOffset(s), d = u + k;
|
|
482
|
+
if (l[d] === this.nullIndex) return;
|
|
483
|
+
let f = u + O;
|
|
484
|
+
i(c, f);
|
|
485
|
+
let p = l[d];
|
|
486
|
+
for (; p !== this.nullIndex;) {
|
|
487
|
+
let i = this.slotPool.blockFor(p), a = this.slotPool.blockOffset(p);
|
|
488
|
+
if (i[a + P] === t && i[a + F] === n) {
|
|
489
|
+
let t = i[a + z], n = this.entityPool.blockFor(t), s = this.entityPool.blockOffset(t), c = i[a + N], l = this.entityBlockDistanceSquared(n, s, r, o);
|
|
490
490
|
(l < e.distance || l === e.distance && (e.id === void 0 || c < e.id)) && (e.id = c, e.distance = l);
|
|
491
491
|
}
|
|
492
|
-
|
|
492
|
+
p = i[a + R];
|
|
493
493
|
}
|
|
494
|
-
|
|
494
|
+
a(c, f);
|
|
495
495
|
}
|
|
496
|
-
collectNeighborCandidates(e, t, n, r,
|
|
497
|
-
let
|
|
498
|
-
if (
|
|
496
|
+
collectNeighborCandidates(e, t, n, r, o, s, c, l, u) {
|
|
497
|
+
let d = this.bucketOf(t, n), f = this.getBucketSegment(d), p = this.bucketHeadSegments[d >>> j], m = this.bucketOffset(d), h = m + k;
|
|
498
|
+
if (p[h] === this.nullIndex) return;
|
|
499
499
|
let g = m + O;
|
|
500
|
-
f
|
|
501
|
-
let v =
|
|
500
|
+
i(f, g);
|
|
501
|
+
let v = p[h];
|
|
502
502
|
for (; v !== this.nullIndex;) {
|
|
503
|
-
let
|
|
504
|
-
if (
|
|
505
|
-
let d =
|
|
506
|
-
if (t === (r < m ? m : r > h ? h : r) && n === (
|
|
507
|
-
let t = this.entityBlockDistanceSquared(f, p,
|
|
508
|
-
t <=
|
|
503
|
+
let i = this.slotPool.blockFor(v), a = this.slotPool.blockOffset(v);
|
|
504
|
+
if (i[a + P] === t && i[a + F] === n) {
|
|
505
|
+
let d = i[a + z], f = this.entityPool.blockFor(d), p = this.entityPool.blockOffset(d), m = f[p + V], h = f[p + U], g = f[p + H], v = f[p + W];
|
|
506
|
+
if (t === (r < m ? m : r > h ? h : r) && n === (o < g ? g : o > v ? v : o)) {
|
|
507
|
+
let t = this.entityBlockDistanceSquared(f, p, s, c);
|
|
508
|
+
t <= u && _(e, i[a + N], t, l);
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
|
-
v =
|
|
511
|
+
v = i[a + R];
|
|
512
512
|
}
|
|
513
|
-
|
|
513
|
+
a(f, g);
|
|
514
514
|
}
|
|
515
515
|
addEntityCandidate(e, t, n, r, i, a, o) {
|
|
516
516
|
let s = this.entityDistanceSquared(n, r, i);
|
|
@@ -525,27 +525,27 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
525
525
|
return y(n, r, i, a, i + e[t + q], a + e[t + J]);
|
|
526
526
|
}
|
|
527
527
|
unlinkFromBucket(e, t, n, r) {
|
|
528
|
-
let
|
|
529
|
-
|
|
530
|
-
let
|
|
531
|
-
for (; m !==
|
|
532
|
-
let e =
|
|
533
|
-
if (e[
|
|
534
|
-
|
|
528
|
+
let o = this.nullIndex, s = this.getBucketSegment(e), c = this.bucketHeadSegments[e >>> j], l = this.bucketOffset(e), u = l + O;
|
|
529
|
+
i(s, u);
|
|
530
|
+
let d = l + k, f = this.slotPool, p = o, m = c[d];
|
|
531
|
+
for (; m !== o;) {
|
|
532
|
+
let e = f.blockFor(m), i = f.blockOffset(m), l = e[i + R];
|
|
533
|
+
if (e[i + N] === t && e[i + P] === n && e[i + F] === r) return p === o ? c[d] = l : f.set(p, R, l), a(s, u), m;
|
|
534
|
+
p = m, m = l;
|
|
535
535
|
}
|
|
536
|
-
return
|
|
536
|
+
return a(s, u), o;
|
|
537
537
|
}
|
|
538
538
|
};
|
|
539
539
|
function he(e) {
|
|
540
|
-
let t =
|
|
541
|
-
if (t !==
|
|
540
|
+
let t = m(e ?? pe);
|
|
541
|
+
if (t !== p.float32 && t !== p.float64) throw Error("SharedSpatialMap must be Float32Array or Float64Array");
|
|
542
542
|
return t;
|
|
543
543
|
}
|
|
544
544
|
function ge(e) {
|
|
545
|
-
return
|
|
545
|
+
return h(e) === 2 ? Float64Array : Float32Array;
|
|
546
546
|
}
|
|
547
547
|
function _e(e) {
|
|
548
|
-
return e ===
|
|
548
|
+
return e === p.float32 ? ie : ae;
|
|
549
549
|
}
|
|
550
550
|
function $(e) {
|
|
551
551
|
return e & e - 1 ? -1 : e - 1;
|
|
@@ -553,7 +553,6 @@ function $(e) {
|
|
|
553
553
|
function ve(e) {
|
|
554
554
|
return 2 ** Math.ceil(Math.log2(Math.max(1, e)));
|
|
555
555
|
}
|
|
556
|
-
//#endregion
|
|
557
556
|
export { me as default };
|
|
558
557
|
|
|
559
558
|
//# sourceMappingURL=shared-spatial-map.js.map
|