@daneren2005/shared-memory-objects 1.5.0 → 1.5.2
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.d.ts +7 -2
- package/dist/allocated-memory.js +10 -3
- package/dist/allocated-memory.js.map +1 -1
- package/dist/cached-item-list.d.ts +1 -1
- package/dist/lock/read-write-lock.d.ts +1 -0
- package/dist/lock/read-write-lock.js +6 -3
- package/dist/lock/read-write-lock.js.map +1 -1
- package/dist/memory-buffer.d.ts +11 -5
- package/dist/memory-buffer.js +70 -74
- package/dist/memory-buffer.js.map +1 -1
- package/dist/memory-heap.d.ts +1 -0
- package/dist/memory-heap.js +28 -25
- package/dist/memory-heap.js.map +1 -1
- package/dist/shared-list.d.ts +5 -1
- package/dist/shared-list.js +91 -47
- package/dist/shared-list.js.map +1 -1
- package/dist/shared-map.js +4 -1
- package/dist/shared-map.js.map +1 -1
- package/dist/shared-pool.js +4 -1
- package/dist/shared-pool.js.map +1 -1
- package/dist/shared-stack.js +11 -2
- package/dist/shared-stack.js.map +1 -1
- package/dist/shared-vector.js +4 -1
- package/dist/shared-vector.js.map +1 -1
- package/dist/spatial/shared-spatial-map.js +134 -134
- package/package.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { getPointer as e, loadRawPointer as t, storeRawPointer as n } from "../utils/pointer.js";
|
|
2
2
|
import r from "../allocated-memory.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
3
|
+
import { readLock as i, readUnlock as a, writeLock as o, writeUnlock as s } from "../lock/read-write-lock.js";
|
|
4
|
+
import { ARRAY_TYPE as c, getArrayTypeCode as l, getByteMultipler as u, makeArrayView as d } from "../utils/array-type.js";
|
|
5
|
+
import { lock as f, unlock as p } from "../lock/simple-lock.js";
|
|
6
|
+
import m from "../shared-map.js";
|
|
7
|
+
import h from "../shared-stack.js";
|
|
8
|
+
import g from "../shared-pool.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
11
|
//#region src/spatial/shared-spatial-map.ts
|
|
12
|
-
var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 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 = 73856093, se = 19349663, ce = 50, le = 256, Z = 1, Q = 2, ue = 1e6, de = 4, fe = Float32Array, pe = class
|
|
12
|
+
var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 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 = 73856093, se = 19349663, ce = 50, le = 256, Z = 1, Q = 2, ue = 1e6, de = 4, fe = Float32Array, pe = class l {
|
|
13
13
|
static ALLOCATE_COUNT = 11;
|
|
14
14
|
memory;
|
|
15
15
|
firstBlock;
|
|
@@ -60,46 +60,46 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
60
60
|
get type() {
|
|
61
61
|
return this.coordType;
|
|
62
62
|
}
|
|
63
|
-
constructor(
|
|
64
|
-
if (this.memory =
|
|
63
|
+
constructor(i, a) {
|
|
64
|
+
if (this.memory = i, a && "firstBlock" in a) this.firstBlock = new r(i, a.firstBlock), this.coordType = this.firstBlock.data[T], this.bucketPointers = new h(i, { firstBlock: e(t(this.firstBlock.data, b), i.positionBits) }), this.entityPool = new g(i, { firstBlock: e(t(this.firstBlock.data, x), i.positionBits) }), this.slotPool = new g(i, { firstBlock: e(t(this.firstBlock.data, S), i.positionBits) }), this.idMap = new m(i, { firstBlock: e(t(this.firstBlock.data, C), i.positionBits) }), this.bucketCount = Atomics.load(this.firstBlock.data, w), this.maxBucketCount = this.firstBlock.data[ne], this.nullIndex = ge(this.coordType);
|
|
65
65
|
else {
|
|
66
|
-
let e =
|
|
67
|
-
this.bucketCount = Math.min(1073741824, Math.max(1, Math.floor(
|
|
68
|
-
let t =
|
|
69
|
-
if (this.maxBucketCount = Math.min(1073741824, Math.max(this.bucketCount, Math.floor(
|
|
70
|
-
let
|
|
66
|
+
let e = a?.gridSize ?? ce;
|
|
67
|
+
this.bucketCount = Math.min(1073741824, Math.max(1, Math.floor(a?.buckets ?? le)));
|
|
68
|
+
let t = a?.maxEntities ?? ue, r = a?.maxSlots ?? t * de;
|
|
69
|
+
if (this.maxBucketCount = Math.min(1073741824, Math.max(this.bucketCount, Math.floor(a?.maxBuckets ?? _e(r * 2)))), this.coordType = me(a?.type), this.nullIndex = ge(this.coordType), this.coordType === c.float32 && (t > X || r > X)) throw Error(`Float32 SharedSpatialMap supports at most ${X} entities and slots; pass type: Float64Array for more`);
|
|
70
|
+
let o = {
|
|
71
71
|
type: he(this.coordType),
|
|
72
72
|
dataLength: Y,
|
|
73
73
|
maxLength: t,
|
|
74
|
-
maxChunkSize: te(t, Y,
|
|
75
|
-
},
|
|
74
|
+
maxChunkSize: te(t, Y, u(this.coordType), i.maxAllocationLength)
|
|
75
|
+
}, s = {
|
|
76
76
|
type: he(this.coordType),
|
|
77
77
|
dataLength: B,
|
|
78
78
|
maxLength: r,
|
|
79
|
-
maxChunkSize: te(r, B,
|
|
80
|
-
},
|
|
81
|
-
this.firstBlock =
|
|
79
|
+
maxChunkSize: te(r, B, u(this.coordType), i.maxAllocationLength)
|
|
80
|
+
}, d = g.getAllocateCount(i, o), f = g.getAllocateCount(i, s), p = m.ALLOCATE_COUNT, _ = l.ALLOCATE_COUNT;
|
|
81
|
+
this.firstBlock = i.allocUI32(_ + d + f + p), this.firstBlock.data[w] = this.bucketCount, this.firstBlock.data[T] = this.coordType, this.firstBlock.data[ne] = this.maxBucketCount;
|
|
82
82
|
let v = this.getConfigView();
|
|
83
|
-
v[0] = e, this.bucketPointers = new
|
|
84
|
-
let y = this.firstBlock.getSubAllocation(_,
|
|
85
|
-
this.entityPool = new
|
|
83
|
+
v[0] = e, this.bucketPointers = new h(i), n(this.firstBlock.data, b, this.bucketPointers.pointer), this.appendBucketSegments(this.bucketCount);
|
|
84
|
+
let y = this.firstBlock.getSubAllocation(_, d);
|
|
85
|
+
this.entityPool = new g(i, {
|
|
86
86
|
firstBlock: y,
|
|
87
|
-
...
|
|
87
|
+
...o
|
|
88
88
|
}), n(this.firstBlock.data, x, y.pointer);
|
|
89
|
-
let E = this.firstBlock.getSubAllocation(_ +
|
|
90
|
-
this.slotPool = new
|
|
89
|
+
let E = this.firstBlock.getSubAllocation(_ + d, f);
|
|
90
|
+
this.slotPool = new g(i, {
|
|
91
91
|
firstBlock: E,
|
|
92
|
-
...
|
|
92
|
+
...s
|
|
93
93
|
}), n(this.firstBlock.data, S, E.pointer);
|
|
94
|
-
let D = this.firstBlock.getSubAllocation(_ +
|
|
95
|
-
this.idMap = new
|
|
94
|
+
let D = this.firstBlock.getSubAllocation(_ + d + f, p);
|
|
95
|
+
this.idMap = new m(i, {
|
|
96
96
|
firstBlock: D,
|
|
97
|
-
capacity: ee(t,
|
|
97
|
+
capacity: ee(t, i.maxAllocationLength)
|
|
98
98
|
}), n(this.firstBlock.data, C, D.pointer);
|
|
99
99
|
}
|
|
100
100
|
this.bucketMask = $(this.bucketCount), this.tableLock = new Int32Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + D * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
101
|
-
let
|
|
102
|
-
this.cellSize =
|
|
101
|
+
let o = this.getConfigView();
|
|
102
|
+
this.cellSize = o[0];
|
|
103
103
|
}
|
|
104
104
|
get pointer() {
|
|
105
105
|
return this.firstBlock.pointer;
|
|
@@ -109,41 +109,41 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
109
109
|
for (let n of this.bucketPointers) t += new r(this.memory, e(n, this.memory.positionBits)).usedMemory;
|
|
110
110
|
return t;
|
|
111
111
|
}
|
|
112
|
-
insert(e, t, n, r = 0,
|
|
113
|
-
|
|
112
|
+
insert(e, t, n, r = 0, o = 0) {
|
|
113
|
+
i(this.tableLock);
|
|
114
114
|
try {
|
|
115
|
-
this.syncBucketCount(), this.insertLocked(e, t, n, r,
|
|
115
|
+
this.syncBucketCount(), this.insertLocked(e, t, n, r, o);
|
|
116
116
|
} finally {
|
|
117
|
-
|
|
117
|
+
a(this.tableLock);
|
|
118
118
|
}
|
|
119
119
|
this.growBucketsIfNeeded();
|
|
120
120
|
}
|
|
121
121
|
bulkInsert(e) {
|
|
122
122
|
let t = /* @__PURE__ */ new Map();
|
|
123
123
|
for (let n of e) t.set(n.id, n);
|
|
124
|
-
let n = Array.from(t.values()), r = this.idMap.getAll(n.map((e) => e.id)),
|
|
124
|
+
let n = Array.from(t.values()), r = this.idMap.getAll(n.map((e) => e.id)), o = [], s = 0, c = 0;
|
|
125
125
|
for (let e = 0; e < n.length; e++) if (r[e] === void 0) {
|
|
126
126
|
let t = n[e];
|
|
127
|
-
|
|
127
|
+
c++, s += (this.colOf(t.x + (t.width ?? 0)) - this.colOf(t.x) + 1) * (this.rowOf(t.y + (t.height ?? 0)) - this.rowOf(t.y) + 1);
|
|
128
128
|
}
|
|
129
|
-
this.ensureBucketCapacity(this.slotPool.length +
|
|
130
|
-
let
|
|
131
|
-
|
|
129
|
+
this.ensureBucketCapacity(this.slotPool.length + s);
|
|
130
|
+
let l = this.entityPool.reserveContiguous(c), u = this.slotPool.reserveContiguous(s);
|
|
131
|
+
i(this.tableLock);
|
|
132
132
|
try {
|
|
133
133
|
this.syncBucketCount();
|
|
134
134
|
for (let e = 0; e < n.length; e++) {
|
|
135
|
-
let t = n[e],
|
|
135
|
+
let t = n[e], i = t.width ?? 0, a = t.height ?? 0;
|
|
136
136
|
if (r[e] !== void 0) {
|
|
137
|
-
this.updateLocked(t.id, t.x, t.y,
|
|
137
|
+
this.updateLocked(t.id, t.x, t.y, i, a);
|
|
138
138
|
continue;
|
|
139
139
|
}
|
|
140
|
-
let
|
|
141
|
-
m[h + V] =
|
|
142
|
-
for (let e =
|
|
140
|
+
let s = this.colOf(t.x), c = this.rowOf(t.y), d = this.colOf(t.x + i), f = this.rowOf(t.y + a), p = l++, m = this.entityPool.blockFor(p), h = this.entityPool.blockOffset(p);
|
|
141
|
+
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] = i, m[h + J] = a, o.push([t.id, p]);
|
|
142
|
+
for (let e = c; e <= f; e++) for (let n = s; n <= d; n++) this.linkReservedBucket(n, e, u++, t.id, p, s, c);
|
|
143
143
|
}
|
|
144
|
-
this.idMap.setAll(
|
|
144
|
+
this.idMap.setAll(o);
|
|
145
145
|
} finally {
|
|
146
|
-
|
|
146
|
+
a(this.tableLock);
|
|
147
147
|
}
|
|
148
148
|
this.growBucketsForBulk();
|
|
149
149
|
}
|
|
@@ -157,20 +157,20 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
157
157
|
let u = this.entityPool.push(l);
|
|
158
158
|
this.idMap.set(e, u), this.linkRange(e, u, a, o, s, c);
|
|
159
159
|
}
|
|
160
|
-
update(e, t, n, r = 0,
|
|
161
|
-
let
|
|
162
|
-
if (
|
|
163
|
-
let e = this.entityPool.blockFor(
|
|
164
|
-
if (
|
|
165
|
-
e[
|
|
160
|
+
update(e, t, n, r = 0, o = 0) {
|
|
161
|
+
let s = this.idMap.get(e);
|
|
162
|
+
if (s !== void 0) {
|
|
163
|
+
let e = this.entityPool.blockFor(s), i = this.entityPool.blockOffset(s), a = this.colOf(t), c = this.rowOf(n), l = this.colOf(t + r), u = this.rowOf(n + o);
|
|
164
|
+
if (a === e[i + V] && c === e[i + H] && l === e[i + U] && u === e[i + W]) {
|
|
165
|
+
e[i + G] = t, e[i + K] = n, e[i + q] = r, e[i + J] = o;
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
i(this.tableLock);
|
|
170
170
|
try {
|
|
171
|
-
this.syncBucketCount(), this.updateLocked(e, t, n, r,
|
|
171
|
+
this.syncBucketCount(), this.updateLocked(e, t, n, r, o);
|
|
172
172
|
} finally {
|
|
173
|
-
|
|
173
|
+
a(this.tableLock);
|
|
174
174
|
}
|
|
175
175
|
this.growBucketsIfNeeded();
|
|
176
176
|
}
|
|
@@ -188,11 +188,11 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
188
188
|
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;
|
|
189
189
|
}
|
|
190
190
|
remove(e) {
|
|
191
|
-
|
|
191
|
+
i(this.tableLock);
|
|
192
192
|
try {
|
|
193
193
|
return this.syncBucketCount(), this.removeLocked(e);
|
|
194
194
|
} finally {
|
|
195
|
-
|
|
195
|
+
a(this.tableLock);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
removeLocked(e) {
|
|
@@ -208,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 =
|
|
|
208
208
|
let a = [];
|
|
209
209
|
return this.searchInto(a, e, t, n, r, i), a;
|
|
210
210
|
}
|
|
211
|
-
searchInto(e, t, n, r,
|
|
212
|
-
|
|
211
|
+
searchInto(e, t, n, r, o, s) {
|
|
212
|
+
i(this.tableLock);
|
|
213
213
|
try {
|
|
214
|
-
return this.syncBucketCount(), this.searchIntoLocked(e, t, n, r,
|
|
214
|
+
return this.syncBucketCount(), this.searchIntoLocked(e, t, n, r, o, s);
|
|
215
215
|
} finally {
|
|
216
|
-
|
|
216
|
+
a(this.tableLock);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
searchIntoLocked(e, t, n, r, i, a) {
|
|
@@ -232,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 =
|
|
|
232
232
|
}
|
|
233
233
|
return e;
|
|
234
234
|
}
|
|
235
|
-
neighbors(e, t, n, r,
|
|
236
|
-
|
|
235
|
+
neighbors(e, t, n, r, o) {
|
|
236
|
+
i(this.tableLock);
|
|
237
237
|
try {
|
|
238
|
-
return this.syncBucketCount(), this.neighborsLocked(e, t, n, r,
|
|
238
|
+
return this.syncBucketCount(), this.neighborsLocked(e, t, n, r, o);
|
|
239
239
|
} finally {
|
|
240
|
-
|
|
240
|
+
a(this.tableLock);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
neighborsLocked(e, t, n, r, i) {
|
|
@@ -282,7 +282,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
282
282
|
return n === 1 ? d.id === void 0 ? [] : [d.id] : o.map((e) => e.id);
|
|
283
283
|
}
|
|
284
284
|
clear() {
|
|
285
|
-
|
|
285
|
+
o(this.tableLock);
|
|
286
286
|
try {
|
|
287
287
|
this.syncBucketCount();
|
|
288
288
|
for (let e = 0; e < this.bucketPointers.length; e++) {
|
|
@@ -295,7 +295,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
295
295
|
for (let [t] of this.idMap) e.push(t);
|
|
296
296
|
for (let t of e) this.idMap.delete(t);
|
|
297
297
|
} finally {
|
|
298
|
-
|
|
298
|
+
s(this.tableLock);
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
free() {
|
|
@@ -306,7 +306,7 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
306
306
|
return { firstBlock: this.firstBlock.getSharedMemory() };
|
|
307
307
|
}
|
|
308
308
|
getConfigView() {
|
|
309
|
-
return
|
|
309
|
+
return d(this.coordType, this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + E * Uint32Array.BYTES_PER_ELEMENT, 1);
|
|
310
310
|
}
|
|
311
311
|
colOf(e) {
|
|
312
312
|
return Math.floor(e / this.cellSize);
|
|
@@ -347,25 +347,25 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
347
347
|
growBucketsIfNeeded() {
|
|
348
348
|
let e = Atomics.load(this.firstBlock.data, w);
|
|
349
349
|
if (!(e >= this.maxBucketCount || this.slotPool.length * Q <= e * Z)) {
|
|
350
|
-
|
|
350
|
+
o(this.tableLock);
|
|
351
351
|
try {
|
|
352
352
|
if (this.syncBucketCount(), this.slotPool.length * Q <= this.bucketCount * Z) return;
|
|
353
353
|
let e = Math.min(this.bucketCount * 2, this.maxBucketCount);
|
|
354
354
|
if (e === this.bucketCount) return;
|
|
355
355
|
this.resizeBuckets(e);
|
|
356
356
|
} finally {
|
|
357
|
-
|
|
357
|
+
s(this.tableLock);
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
ensureBucketCapacity(e) {
|
|
362
362
|
let t = Math.ceil(e * Q / Z), n = Math.min(_e(t), this.maxBucketCount);
|
|
363
363
|
if (!(n <= Atomics.load(this.firstBlock.data, w))) {
|
|
364
|
-
|
|
364
|
+
o(this.tableLock);
|
|
365
365
|
try {
|
|
366
366
|
this.syncBucketCount(), n > this.bucketCount && this.resizeBuckets(n);
|
|
367
367
|
} finally {
|
|
368
|
-
|
|
368
|
+
s(this.tableLock);
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
}
|
|
@@ -396,18 +396,18 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
396
396
|
}
|
|
397
397
|
linkIntoBucket(e, t, n) {
|
|
398
398
|
n[P] = e, n[F] = t;
|
|
399
|
-
let r = this.slotPool, i = r.push(n), a = this.bucketOf(e, t), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j],
|
|
400
|
-
|
|
401
|
-
let
|
|
402
|
-
r.set(i, R, s[
|
|
399
|
+
let r = this.slotPool, i = r.push(n), a = this.bucketOf(e, t), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], c = this.bucketOffset(a), l = c + O;
|
|
400
|
+
f(o, l);
|
|
401
|
+
let u = c + k;
|
|
402
|
+
r.set(i, R, s[u]), s[u] = i, p(o, l);
|
|
403
403
|
}
|
|
404
404
|
linkReservedBucket(e, t, n, r, i, a, o) {
|
|
405
|
-
let s = this.slotPool,
|
|
406
|
-
|
|
407
|
-
let
|
|
408
|
-
|
|
405
|
+
let s = this.slotPool, c = s.blockFor(n), l = s.blockOffset(n);
|
|
406
|
+
c[l + N] = r, c[l + P] = e, c[l + F] = t, c[l + I] = a, c[l + L] = o, c[l + z] = i;
|
|
407
|
+
let u = this.bucketOf(e, t), d = this.getBucketSegment(u), m = this.bucketHeadSegments[u >>> j], h = this.bucketOffset(u), g = h + O;
|
|
408
|
+
f(d, g);
|
|
409
409
|
let _ = h + k;
|
|
410
|
-
|
|
410
|
+
c[l + R] = m[_], m[_] = n, p(d, g);
|
|
411
411
|
}
|
|
412
412
|
relinkRange(e, t, n, r, i, a, o, s, c, l) {
|
|
413
413
|
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;
|
|
@@ -427,18 +427,18 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
refreshAnchorInBucket(e, t, n, r, i, a) {
|
|
430
|
-
let o = this.nullIndex, s = this.getBucketSegment(e),
|
|
431
|
-
|
|
432
|
-
let
|
|
433
|
-
for (;
|
|
434
|
-
let e =
|
|
430
|
+
let o = this.nullIndex, s = this.getBucketSegment(e), c = this.bucketOffset(e), l = c + O;
|
|
431
|
+
f(s, l);
|
|
432
|
+
let u = this.slotPool, d = this.bucketHeadSegments[e >>> j][c + k];
|
|
433
|
+
for (; d !== o;) {
|
|
434
|
+
let e = u.blockFor(d), o = u.blockOffset(d);
|
|
435
435
|
if (e[o + N] === t && e[o + P] === n && e[o + F] === r) {
|
|
436
436
|
e[o + I] = i, e[o + L] = a;
|
|
437
437
|
break;
|
|
438
438
|
}
|
|
439
|
-
|
|
439
|
+
d = e[o + R];
|
|
440
440
|
}
|
|
441
|
-
|
|
441
|
+
p(s, l);
|
|
442
442
|
}
|
|
443
443
|
unlinkRange(e, t, n, r, i) {
|
|
444
444
|
let a = this.nullIndex, o = this.slotPool;
|
|
@@ -448,65 +448,65 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
collectBucket(e, t, n, r, i, a, o, s) {
|
|
451
|
-
let
|
|
452
|
-
|
|
453
|
-
let
|
|
454
|
-
for (;
|
|
455
|
-
let t = m.blockFor(
|
|
451
|
+
let c = this.nullIndex, l = r + k, u = r + O;
|
|
452
|
+
f(t, u);
|
|
453
|
+
let d = n[l], m = this.slotPool;
|
|
454
|
+
for (; d !== c;) {
|
|
455
|
+
let t = m.blockFor(d), n = m.blockOffset(d);
|
|
456
456
|
if (t[n + P] === i && t[n + F] === a) {
|
|
457
457
|
let r = t[n + I], c = t[n + L];
|
|
458
458
|
i === (r > o ? r : o) && a === (c > s ? c : s) && e.push(t[n + N]);
|
|
459
459
|
}
|
|
460
|
-
|
|
460
|
+
d = t[n + R];
|
|
461
461
|
}
|
|
462
|
-
|
|
462
|
+
p(t, u);
|
|
463
463
|
}
|
|
464
464
|
collectNeighborBucket(e, t, n) {
|
|
465
465
|
let r = this.bucketOf(t, n), i = this.getBucketSegment(r), a = this.bucketHeadSegments[r >>> j], o = this.bucketOffset(r), s = o + k;
|
|
466
466
|
if (a[s] === this.nullIndex) return;
|
|
467
|
-
let
|
|
468
|
-
|
|
469
|
-
let
|
|
470
|
-
for (;
|
|
471
|
-
let r = this.slotPool.blockFor(
|
|
472
|
-
r[i + P] === t && r[i + F] === n && e.push(r[i + N]),
|
|
467
|
+
let c = o + O;
|
|
468
|
+
f(i, c);
|
|
469
|
+
let l = a[s];
|
|
470
|
+
for (; l !== this.nullIndex;) {
|
|
471
|
+
let r = this.slotPool.blockFor(l), i = this.slotPool.blockOffset(l);
|
|
472
|
+
r[i + P] === t && r[i + F] === n && e.push(r[i + N]), l = r[i + R];
|
|
473
473
|
}
|
|
474
|
-
|
|
474
|
+
p(i, c);
|
|
475
475
|
}
|
|
476
476
|
collectNearestBucket(e, t, n, r, i) {
|
|
477
|
-
let a = this.bucketOf(t, n), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j],
|
|
478
|
-
if (s[
|
|
479
|
-
let
|
|
480
|
-
|
|
481
|
-
let
|
|
482
|
-
for (;
|
|
483
|
-
let a = this.slotPool.blockFor(
|
|
477
|
+
let a = this.bucketOf(t, n), o = this.getBucketSegment(a), s = this.bucketHeadSegments[a >>> j], c = this.bucketOffset(a), l = c + k;
|
|
478
|
+
if (s[l] === this.nullIndex) return;
|
|
479
|
+
let u = c + O;
|
|
480
|
+
f(o, u);
|
|
481
|
+
let d = s[l];
|
|
482
|
+
for (; d !== this.nullIndex;) {
|
|
483
|
+
let a = this.slotPool.blockFor(d), o = this.slotPool.blockOffset(d);
|
|
484
484
|
if (a[o + P] === t && a[o + F] === n) {
|
|
485
485
|
let t = a[o + z], n = this.entityPool.blockFor(t), s = this.entityPool.blockOffset(t), c = a[o + N], l = this.entityBlockDistanceSquared(n, s, r, i);
|
|
486
486
|
(l < e.distance || l === e.distance && (e.id === void 0 || c < e.id)) && (e.id = c, e.distance = l);
|
|
487
487
|
}
|
|
488
|
-
|
|
488
|
+
d = a[o + R];
|
|
489
489
|
}
|
|
490
|
-
|
|
490
|
+
p(o, u);
|
|
491
491
|
}
|
|
492
|
-
collectNeighborCandidates(e, t, n, r, i, a, o, s,
|
|
493
|
-
let
|
|
494
|
-
if (
|
|
492
|
+
collectNeighborCandidates(e, t, n, r, i, a, o, s, c) {
|
|
493
|
+
let l = this.bucketOf(t, n), u = this.getBucketSegment(l), d = this.bucketHeadSegments[l >>> j], m = this.bucketOffset(l), h = m + k;
|
|
494
|
+
if (d[h] === this.nullIndex) return;
|
|
495
495
|
let g = m + O;
|
|
496
|
-
|
|
497
|
-
let v =
|
|
496
|
+
f(u, g);
|
|
497
|
+
let v = d[h];
|
|
498
498
|
for (; v !== this.nullIndex;) {
|
|
499
|
-
let
|
|
500
|
-
if (
|
|
501
|
-
let d =
|
|
499
|
+
let l = this.slotPool.blockFor(v), u = this.slotPool.blockOffset(v);
|
|
500
|
+
if (l[u + P] === t && l[u + F] === n) {
|
|
501
|
+
let d = l[u + 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];
|
|
502
502
|
if (t === (r < m ? m : r > h ? h : r) && n === (i < g ? g : i > v ? v : i)) {
|
|
503
503
|
let t = this.entityBlockDistanceSquared(f, p, a, o);
|
|
504
|
-
t <=
|
|
504
|
+
t <= c && _(e, l[u + N], t, s);
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
v =
|
|
507
|
+
v = l[u + R];
|
|
508
508
|
}
|
|
509
|
-
|
|
509
|
+
p(u, g);
|
|
510
510
|
}
|
|
511
511
|
addEntityCandidate(e, t, n, r, i, a, o) {
|
|
512
512
|
let s = this.entityDistanceSquared(n, r, i);
|
|
@@ -521,27 +521,27 @@ var b = 0, x = 1, S = 2, C = 3, w = 4, T = 5, E = 6, D = 8, ne = 10, O = 0, k =
|
|
|
521
521
|
return y(n, r, i, a, i + e[t + q], a + e[t + J]);
|
|
522
522
|
}
|
|
523
523
|
unlinkFromBucket(e, t, n, r) {
|
|
524
|
-
let i = this.nullIndex, a = this.getBucketSegment(e), o = this.bucketHeadSegments[e >>> j], s = this.bucketOffset(e),
|
|
525
|
-
|
|
526
|
-
let
|
|
524
|
+
let i = this.nullIndex, a = this.getBucketSegment(e), o = this.bucketHeadSegments[e >>> j], s = this.bucketOffset(e), c = s + O;
|
|
525
|
+
f(a, c);
|
|
526
|
+
let l = s + k, u = this.slotPool, d = i, m = o[l];
|
|
527
527
|
for (; m !== i;) {
|
|
528
|
-
let e =
|
|
529
|
-
if (e[s + N] === t && e[s + P] === n && e[s + F] === r) return
|
|
530
|
-
|
|
528
|
+
let e = u.blockFor(m), s = u.blockOffset(m), f = e[s + R];
|
|
529
|
+
if (e[s + N] === t && e[s + P] === n && e[s + F] === r) return d === i ? o[l] = f : u.set(d, R, f), p(a, c), m;
|
|
530
|
+
d = m, m = f;
|
|
531
531
|
}
|
|
532
|
-
return
|
|
532
|
+
return p(a, c), i;
|
|
533
533
|
}
|
|
534
534
|
};
|
|
535
535
|
function me(e) {
|
|
536
|
-
let t =
|
|
537
|
-
if (t !==
|
|
536
|
+
let t = l(e ?? fe);
|
|
537
|
+
if (t !== c.float32 && t !== c.float64) throw Error("SharedSpatialMap must be Float32Array or Float64Array");
|
|
538
538
|
return t;
|
|
539
539
|
}
|
|
540
540
|
function he(e) {
|
|
541
|
-
return
|
|
541
|
+
return u(e) === 2 ? Float64Array : Float32Array;
|
|
542
542
|
}
|
|
543
543
|
function ge(e) {
|
|
544
|
-
return e ===
|
|
544
|
+
return e === c.float32 ? ie : ae;
|
|
545
545
|
}
|
|
546
546
|
function $(e) {
|
|
547
547
|
return e & e - 1 ? -1 : e - 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daneren2005/shared-memory-objects",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"author": "daneren2005@gmail.com",
|
|
5
5
|
"description": "Creating objects with a SharedArrayBuffer",
|
|
6
6
|
"homepage": "https://github.com/daneren2005/shared-memory-objects#readme",
|