@pirireis/webglobeplugins 0.15.20-alpha → 0.15.22-alpha
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/Math/arc.js +1 -2
- package/Math/circle-cdf-points.js +1 -170
- package/Math/circle.js +0 -25
- package/Math/vec3.js +1 -1
- package/altitude-locator/plugin.js +1 -1
- package/package.json +1 -1
- package/point-tracks/plugin.js +1 -2
- package/programs/line-on-globe/lines-color-instanced-flat.js +0 -1
- package/programs/point-on-globe/element-globe-surface-glow.js +0 -1
- package/programs/totems/camerauniformblock.js +7 -0
- package/range-tools-on-terrain/bearing-line/plugin.js +0 -1
- package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +4 -9
- package/range-tools-on-terrain/circle-line-chain/plugin.js +5 -3
- package/semiplugins/lightweight/line-plugin.js +35 -40
- package/semiplugins/shape-on-terrain/padding-1-degree.js +94 -44
- package/util/account/single-attribute-buffer-management/buffer-manager.js +1 -1
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +121 -70
- package/util/account/single-attribute-buffer-management/buffer-orchestrator1.js +159 -0
- package/util/account/single-attribute-buffer-management/object-store.js +1 -1
- package/Math/arc-generate-points copy.js +0 -366
- package/Math/globe-util/horizon-plane.js +0 -112
- package/altitude-locator/draw-subset-obj.js +0 -16
- package/semiplugins/shape-on-terrain/derived/padding-plugin.js +0 -101
- package/util/account/single-attribute-buffer-management/buffer-orchestrator copy.js +0 -161
- package/util/account/single-attribute-buffer-management/chunked-buffer-manager.js +0 -75
- package/util/account/single-attribute-buffer-management/chunked-buffer-orchestrator.js +0 -195
|
@@ -24,15 +24,14 @@ export class Padding1DegreePlugin {
|
|
|
24
24
|
bufferOrchestrator;
|
|
25
25
|
bufferManagersMap;
|
|
26
26
|
lineProgram = null;
|
|
27
|
-
_opacityLODCoef = 1;
|
|
28
|
-
_pluginOpacity = 1; // this is used to set the opacity of the plugin
|
|
29
27
|
_innerPaddingRatio = 0.9; //
|
|
30
28
|
_float32Array = null; // this is used to forward the data to the buffer manager
|
|
31
29
|
_uboHandler = null; // this is used to forward the data to the shader program
|
|
32
30
|
_bufferNames = ["position2d", "position3d"];
|
|
33
31
|
_vao = null; // this is used to store the VAO for the plugin
|
|
34
32
|
_freed = false; // this is used to check if the plugin is freed or not
|
|
35
|
-
|
|
33
|
+
_userOpacity = 1;
|
|
34
|
+
_adaptiveOpacityMultiplier = 1;
|
|
36
35
|
_dataMap = new Map();
|
|
37
36
|
_options = {
|
|
38
37
|
bufferType: "STATIC_DRAW",
|
|
@@ -86,7 +85,7 @@ export class Padding1DegreePlugin {
|
|
|
86
85
|
this.bufferOrchestrator.deleteBulk(keys, this.bufferManagersMap);
|
|
87
86
|
this.globe?.DrawRender();
|
|
88
87
|
}
|
|
89
|
-
setPluginOpacity(opacity) {
|
|
88
|
+
setPluginOpacity(opacity, drawRender = false) {
|
|
90
89
|
if (this._freed) {
|
|
91
90
|
console.warn("Plugin is freed, cannot set opacity");
|
|
92
91
|
return;
|
|
@@ -96,9 +95,10 @@ export class Padding1DegreePlugin {
|
|
|
96
95
|
return;
|
|
97
96
|
}
|
|
98
97
|
opacityCheck(opacity);
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
this._userOpacity = opacity;
|
|
99
|
+
if (drawRender) {
|
|
100
|
+
this.globe.DrawRender();
|
|
101
|
+
}
|
|
102
102
|
}
|
|
103
103
|
setDefaultColor(color) {
|
|
104
104
|
if (this._freed) {
|
|
@@ -143,19 +143,19 @@ export class Padding1DegreePlugin {
|
|
|
143
143
|
this._float32Array.fill(NaN); // reset the float32Array
|
|
144
144
|
}
|
|
145
145
|
for (let i = 0; i < 360; i++) {
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
146
|
+
const outerCoords = paddingInput.outerCoords[i];
|
|
147
|
+
const innerCoords = paddingInput.innerCoords[i];
|
|
148
|
+
if (outerCoords === null || innerCoords === null) {
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
151
|
-
let coords = globe.api_GetMercator2DPoint(
|
|
151
|
+
let coords = globe.api_GetMercator2DPoint(outerCoords[0], outerCoords[1]);
|
|
152
152
|
// fill the second coordinate with 0
|
|
153
153
|
this._float32Array[i * 6] = coords[0];
|
|
154
154
|
this._float32Array[i * 6 + 1] = coords[1];
|
|
155
|
-
let
|
|
155
|
+
let coordsInner = globe.api_GetMercator2DPoint(innerCoords[0], innerCoords[1]);
|
|
156
156
|
// fill the second coordinate with 0
|
|
157
|
-
this._float32Array[i * 6 + 2] =
|
|
158
|
-
this._float32Array[i * 6 + 3] =
|
|
157
|
+
this._float32Array[i * 6 + 2] = coordsInner[0];
|
|
158
|
+
this._float32Array[i * 6 + 3] = coordsInner[1];
|
|
159
159
|
}
|
|
160
160
|
return this._float32Array.subarray(0, 360 * 2 * 3);
|
|
161
161
|
}
|
|
@@ -174,22 +174,22 @@ export class Padding1DegreePlugin {
|
|
|
174
174
|
}
|
|
175
175
|
const _float32Array = this._float32Array;
|
|
176
176
|
for (let i = 0; i < 360; i++) {
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
if (
|
|
177
|
+
const outerCoords = paddingInput.outerCoords[i];
|
|
178
|
+
const innerCoords = paddingInput.innerCoords[i];
|
|
179
|
+
if (outerCoords === null || innerCoords === null) {
|
|
180
180
|
continue;
|
|
181
181
|
}
|
|
182
182
|
const height = paddingInput.heightFromGroundIn3D ?? this._options.defaultHeightFromGroundIn3D;
|
|
183
|
-
let coords = globe.api_GetCartesian3DPoint(
|
|
183
|
+
let coords = globe.api_GetCartesian3DPoint(outerCoords[0], outerCoords[1], height, this._options.isMSL);
|
|
184
184
|
// fill the second coordinate with 0
|
|
185
185
|
_float32Array[i * 9] = coords[0];
|
|
186
186
|
_float32Array[i * 9 + 1] = coords[1];
|
|
187
187
|
_float32Array[i * 9 + 2] = coords[2];
|
|
188
|
-
let
|
|
188
|
+
let coordsInner = globe.api_GetCartesian3DPoint(innerCoords[0], innerCoords[1], height, this._options.isMSL);
|
|
189
189
|
// fill the second coordinate with 0
|
|
190
|
-
_float32Array[i * 9 + 3] =
|
|
191
|
-
_float32Array[i * 9 + 4] =
|
|
192
|
-
_float32Array[i * 9 + 5] =
|
|
190
|
+
_float32Array[i * 9 + 3] = coordsInner[0];
|
|
191
|
+
_float32Array[i * 9 + 4] = coordsInner[1];
|
|
192
|
+
_float32Array[i * 9 + 5] = coordsInner[2];
|
|
193
193
|
}
|
|
194
194
|
return _float32Array.subarray(0, 360 * 3 * 3);
|
|
195
195
|
}
|
|
@@ -215,11 +215,11 @@ export class Padding1DegreePlugin {
|
|
|
215
215
|
this._float32Array[i * 12] = color[0];
|
|
216
216
|
this._float32Array[i * 12 + 1] = color[1];
|
|
217
217
|
this._float32Array[i * 12 + 2] = color[2];
|
|
218
|
-
this._float32Array[i * 12 + 3] = color[3]
|
|
218
|
+
this._float32Array[i * 12 + 3] = color[3];
|
|
219
219
|
this._float32Array[i * 12 + 4] = color[0];
|
|
220
220
|
this._float32Array[i * 12 + 5] = color[1];
|
|
221
221
|
this._float32Array[i * 12 + 6] = color[2];
|
|
222
|
-
this._float32Array[i * 12 + 7] = 0; //color[3]
|
|
222
|
+
this._float32Array[i * 12 + 7] = 0; //color[3] ;
|
|
223
223
|
}
|
|
224
224
|
return this._float32Array.subarray(0, 360 * 4 * 3);
|
|
225
225
|
}
|
|
@@ -233,11 +233,11 @@ export class Padding1DegreePlugin {
|
|
|
233
233
|
this._float32Array[i * 12] = color[0];
|
|
234
234
|
this._float32Array[i * 12 + 1] = color[1];
|
|
235
235
|
this._float32Array[i * 12 + 2] = color[2];
|
|
236
|
-
this._float32Array[i * 12 + 3] = color[3]
|
|
236
|
+
this._float32Array[i * 12 + 3] = color[3];
|
|
237
237
|
this._float32Array[i * 12 + 4] = color[0];
|
|
238
238
|
this._float32Array[i * 12 + 5] = color[1];
|
|
239
239
|
this._float32Array[i * 12 + 6] = color[2];
|
|
240
|
-
this._float32Array[i * 12 + 7] = 0; // color[3]
|
|
240
|
+
this._float32Array[i * 12 + 7] = 0; // color[3] ;
|
|
241
241
|
i++;
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -272,6 +272,9 @@ export class Padding1DegreePlugin {
|
|
|
272
272
|
console.warn("Globe or LineProgram or VAO is not initialized, cannot draw");
|
|
273
273
|
return;
|
|
274
274
|
}
|
|
275
|
+
if (this.globe.api_IsScreenMoving()) {
|
|
276
|
+
this.__build();
|
|
277
|
+
}
|
|
275
278
|
const gl = this.globe.gl;
|
|
276
279
|
const drawOptions = {
|
|
277
280
|
drawRange: {
|
|
@@ -280,7 +283,7 @@ export class Padding1DegreePlugin {
|
|
|
280
283
|
},
|
|
281
284
|
};
|
|
282
285
|
gl.disable(gl.DEPTH_TEST);
|
|
283
|
-
this.lineProgram.draw(this._vao, drawOptions, this.
|
|
286
|
+
this.lineProgram.draw(this._vao, drawOptions, this._userOpacity * this._adaptiveOpacityMultiplier, this._uboHandler);
|
|
284
287
|
gl.enable(gl.DEPTH_TEST);
|
|
285
288
|
}
|
|
286
289
|
free() {
|
|
@@ -310,17 +313,64 @@ export class Padding1DegreePlugin {
|
|
|
310
313
|
this._innerPaddingRatio = 1 - Math.pow(0.7, lod);
|
|
311
314
|
}
|
|
312
315
|
_buildPaddings(level) {
|
|
316
|
+
if (level === "input") {
|
|
317
|
+
// Build input paddings
|
|
318
|
+
}
|
|
319
|
+
else if (level === "innerCircle") {
|
|
320
|
+
// Build inner circle paddings
|
|
321
|
+
this.__innerCircle();
|
|
322
|
+
this.__elevation();
|
|
323
|
+
}
|
|
324
|
+
else if (level === "elevation") {
|
|
325
|
+
// Build elevation paddings
|
|
326
|
+
this.__elevation();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
__innerCircle() {
|
|
330
|
+
// Implement inner circle padding logic
|
|
331
|
+
console.log("innerCircle Level Update");
|
|
332
|
+
const datas = this._dataMap;
|
|
333
|
+
for (const [key, value] of datas) {
|
|
334
|
+
// Implement inner circle padding logic using key and value
|
|
335
|
+
const { innerCoords } = preAdapter(this.globe, value, this._innerPaddingRatio, value.outerCoords);
|
|
336
|
+
value.innerCoords = innerCoords;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
__elevation() {
|
|
340
|
+
this._updateAdaptiveOpacityMultiplier();
|
|
341
|
+
const bufferToUpdate = this.globe?.api_GetCurrentGeometry() === 1 ? "position2d" : "position3d";
|
|
342
|
+
console.log(bufferToUpdate);
|
|
343
|
+
const datas = this._dataMap;
|
|
344
|
+
const wrapper = [null];
|
|
345
|
+
this._float32Array = new Float32Array(360 * 4 * 4); // largest float32Array
|
|
346
|
+
for (const [key, value] of datas) {
|
|
347
|
+
wrapper[0] = value;
|
|
348
|
+
this.bufferOrchestrator.updateBulk(wrapper, this.bufferManagersMap, [bufferToUpdate]);
|
|
349
|
+
}
|
|
350
|
+
this._float32Array = null; // reset the float32Array
|
|
351
|
+
}
|
|
352
|
+
__build() {
|
|
353
|
+
const globeChanges = this.lineProgram?.cameraBlockTotem.getGlobeChanges();
|
|
354
|
+
if (globeChanges.lodChanged) {
|
|
355
|
+
console.log("lod changed");
|
|
356
|
+
}
|
|
357
|
+
if (globeChanges.lodChanged) {
|
|
358
|
+
this.__updateLODRelatedParameters();
|
|
359
|
+
this._buildPaddings("innerCircle");
|
|
360
|
+
}
|
|
361
|
+
else if (globeChanges.lookChanged || globeChanges.geometryChanged) {
|
|
362
|
+
this._buildPaddings("elevation");
|
|
363
|
+
}
|
|
313
364
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// if cam change, recalculate 3d positions
|
|
365
|
+
_updateAdaptiveOpacityMultiplier() {
|
|
366
|
+
const currentLod = this.globe?.api_GetCurrentLODWithDecimal();
|
|
367
|
+
this._adaptiveOpacityMultiplier = Math.max(1 - (2.9 / currentLod), 0.1);
|
|
318
368
|
}
|
|
319
369
|
}
|
|
320
|
-
function preAdapter(globe, paddingInput, paddingRatio,
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
|
|
370
|
+
function preAdapter(globe, paddingInput, paddingRatio, outerCoords) {
|
|
371
|
+
const innerCoords = new Array(360);
|
|
372
|
+
if (outerCoords === null) {
|
|
373
|
+
outerCoords = new Array(360);
|
|
324
374
|
for (let i = 0; i < 360; i++) {
|
|
325
375
|
const { long, lat } = globe.Math.FindPointByPolar(paddingInput.center[0], // center long
|
|
326
376
|
paddingInput.center[1], // center lat
|
|
@@ -333,25 +383,25 @@ function preAdapter(globe, paddingInput, paddingRatio, startCoords) {
|
|
|
333
383
|
const longDifference = Math.abs(long - endLong);
|
|
334
384
|
const latDifference = Math.abs(lat - endLat);
|
|
335
385
|
if (longDifference > 45) {
|
|
336
|
-
|
|
337
|
-
|
|
386
|
+
outerCoords[i] = null;
|
|
387
|
+
innerCoords[i] = null;
|
|
338
388
|
continue;
|
|
339
389
|
}
|
|
340
390
|
// Assign the calculated coordinates
|
|
341
|
-
|
|
342
|
-
|
|
391
|
+
outerCoords[i] = [long, lat];
|
|
392
|
+
innerCoords[i] = [endLong, endLat];
|
|
343
393
|
}
|
|
344
394
|
}
|
|
345
395
|
else {
|
|
346
|
-
// Handle case when
|
|
396
|
+
// Handle case when outerCoords is provided
|
|
347
397
|
for (let i = 0; i < 360; i++) {
|
|
348
|
-
if (
|
|
349
|
-
|
|
398
|
+
if (outerCoords[i] === null) {
|
|
399
|
+
innerCoords[i] = null;
|
|
350
400
|
continue;
|
|
351
401
|
}
|
|
352
402
|
const { long: endLong, lat: endLat } = globe.Math.FindPointByPolar(paddingInput.center[0], paddingInput.center[1], paddingInput.outerRadius * paddingRatio, i);
|
|
353
|
-
|
|
403
|
+
innerCoords[i] = [endLong, endLat];
|
|
354
404
|
}
|
|
355
405
|
}
|
|
356
|
-
return {
|
|
406
|
+
return { outerCoords, innerCoords };
|
|
357
407
|
}
|
|
@@ -60,7 +60,7 @@ export class BufferManager {
|
|
|
60
60
|
}
|
|
61
61
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
insertBlock(items, offset, adapter, Constructor = Float32Array) {
|
|
64
64
|
const { gl, buffer, itemSize } = this;
|
|
65
65
|
const cpuBuffer = new Constructor(itemSize * items.length);
|
|
66
66
|
for (let i = 0; i < items.length; i++) {
|
|
@@ -19,6 +19,92 @@ export class BufferOrchestrator {
|
|
|
19
19
|
this.tombstoneOffsets = [];
|
|
20
20
|
this._length = 0;
|
|
21
21
|
}
|
|
22
|
+
// ...existing code...
|
|
23
|
+
// TODO: CLEAN THIS
|
|
24
|
+
// insertBulk2(items: any[], bufferManagersMap: BufferManagersMap, bufferKeys: string[] | null = null) {
|
|
25
|
+
// this.ensureSpace(items.length, bufferManagersMap);
|
|
26
|
+
// const { offsetMap } = this;
|
|
27
|
+
// // For block insert (truly new, consecutive offsets)
|
|
28
|
+
// const blockItems: any[] = [];
|
|
29
|
+
// let blockStart: number | null = null;
|
|
30
|
+
// let lastBlockOffset: number | null = null;
|
|
31
|
+
// // For single insert (existing or tombstone-assigned)
|
|
32
|
+
// const singleItems: any[] = [];
|
|
33
|
+
// const singleOffsets: number[] = [];
|
|
34
|
+
// for (const item of items) {
|
|
35
|
+
// let offset = offsetMap.get(item.key);
|
|
36
|
+
// if (offset !== undefined) {
|
|
37
|
+
// // Already present, update in place
|
|
38
|
+
// singleItems.push(item);
|
|
39
|
+
// singleOffsets.push(offset);
|
|
40
|
+
// } else {
|
|
41
|
+
// // Assign offset (tombstone or new)
|
|
42
|
+
// if (this.tombstoneOffsets.length > 0) {
|
|
43
|
+
// offset = this.tombstoneOffsets.pop() as number;
|
|
44
|
+
// offsetMap.set(item.key, offset);
|
|
45
|
+
// singleItems.push(item);
|
|
46
|
+
// singleOffsets.push(offset);
|
|
47
|
+
// } else {
|
|
48
|
+
// offset = this._length++;
|
|
49
|
+
// if (offset >= this._capacity) throw new Error("The Size Should Be Increased!!");
|
|
50
|
+
// offsetMap.set(item.key, offset);
|
|
51
|
+
// // Check for consecutive block
|
|
52
|
+
// if (blockStart === null) {
|
|
53
|
+
// blockStart = offset;
|
|
54
|
+
// lastBlockOffset = offset;
|
|
55
|
+
// blockItems.push(item);
|
|
56
|
+
// } else if (lastBlockOffset !== null && offset === lastBlockOffset + 1) {
|
|
57
|
+
// lastBlockOffset = offset;
|
|
58
|
+
// blockItems.push(item);
|
|
59
|
+
// } else {
|
|
60
|
+
// // Not consecutive, flush current block
|
|
61
|
+
// if (blockItems.length > 0) {
|
|
62
|
+
// this._insertBlock(blockItems, blockStart, bufferManagersMap, bufferKeys);
|
|
63
|
+
// blockItems.length = 0;
|
|
64
|
+
// }
|
|
65
|
+
// blockStart = offset;
|
|
66
|
+
// lastBlockOffset = offset;
|
|
67
|
+
// blockItems.push(item);
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
72
|
+
// // Flush any remaining block
|
|
73
|
+
// if (blockItems.length > 0 && blockStart !== null) {
|
|
74
|
+
// this._insertBlock(blockItems, blockStart, bufferManagersMap, bufferKeys);
|
|
75
|
+
// }
|
|
76
|
+
// // Insert singles
|
|
77
|
+
// if (singleItems.length > 0) {
|
|
78
|
+
// if (bufferKeys) {
|
|
79
|
+
// for (const key of bufferKeys) {
|
|
80
|
+
// const bufferManagerComp = bufferManagersMap.get(key);
|
|
81
|
+
// if (!bufferManagerComp) throw new Error("insertBulk bufferKey does not exist");
|
|
82
|
+
// const { bufferManager, adaptor } = bufferManagerComp;
|
|
83
|
+
// bufferManager.insertBulk(singleItems.map(adaptor), singleOffsets);
|
|
84
|
+
// }
|
|
85
|
+
// } else {
|
|
86
|
+
// for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
87
|
+
// bufferManager.insertBulk(singleItems.map(adaptor), singleOffsets);
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
// // Helper for block insert
|
|
93
|
+
// private _insertBlock(blockItems: any[], blockStart: number, bufferManagersMap: BufferManagersMap, bufferKeys: string[] | null) {
|
|
94
|
+
// if (bufferKeys) {
|
|
95
|
+
// for (const key of bufferKeys) {
|
|
96
|
+
// const bufferManagerComp = bufferManagersMap.get(key);
|
|
97
|
+
// if (!bufferManagerComp) throw new Error("insertBulk bufferKey does not exist");
|
|
98
|
+
// const { bufferManager, adaptor } = bufferManagerComp;
|
|
99
|
+
// bufferManager.insertBlock(blockItems, blockStart, adaptor, Float32Array);
|
|
100
|
+
// }
|
|
101
|
+
// } else {
|
|
102
|
+
// for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
103
|
+
// bufferManager.insertBlock(blockItems, blockStart, adaptor, Float32Array);
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// ...existing code...
|
|
22
108
|
// want to add stack load to this method
|
|
23
109
|
// if offsetMap.has(item.key) === false get next offset, add the item to stack
|
|
24
110
|
// create a single big float32array and fill it with the items
|
|
@@ -27,10 +113,18 @@ export class BufferOrchestrator {
|
|
|
27
113
|
this.ensureSpace(items.length, bufferManagersMap);
|
|
28
114
|
const { offsetMap } = this;
|
|
29
115
|
let offsetStart = null;
|
|
30
|
-
const
|
|
116
|
+
const offsets = [];
|
|
117
|
+
const blockLoad = [];
|
|
31
118
|
for (const item of items) {
|
|
32
119
|
let o = offsetMap.get(item.key);
|
|
120
|
+
if (o === undefined && this.tombstoneOffsets.length > 0) {
|
|
121
|
+
// If there is a tombstone, use it
|
|
122
|
+
o = this.tombstoneOffsets.pop();
|
|
123
|
+
offsetMap.set(item.key, o);
|
|
124
|
+
}
|
|
33
125
|
if (o !== undefined) {
|
|
126
|
+
// Already exist or there is a random empty space in earlear part of memory.
|
|
127
|
+
// insert for single slots
|
|
34
128
|
if (bufferKeys) {
|
|
35
129
|
for (const key of bufferKeys) {
|
|
36
130
|
const bufferManagerComp = bufferManagersMap.get(key);
|
|
@@ -45,88 +139,42 @@ export class BufferOrchestrator {
|
|
|
45
139
|
bufferManager.insertBulk([adaptor(item)], [o]);
|
|
46
140
|
}
|
|
47
141
|
}
|
|
48
|
-
continue;
|
|
49
142
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
143
|
+
else {
|
|
144
|
+
// offset comes from increment function
|
|
145
|
+
// this part stacks data to be load a a single big block.
|
|
146
|
+
const offset = this.nextOffset();
|
|
147
|
+
if (offset === undefined) {
|
|
148
|
+
throw new Error("The Size Should Be Increased!!");
|
|
149
|
+
}
|
|
150
|
+
offsets.push(offset);
|
|
151
|
+
offsetMap.set(item.key, offset);
|
|
152
|
+
blockLoad.push(item);
|
|
153
|
+
if (offsetStart === null) {
|
|
154
|
+
offsetStart = offset;
|
|
155
|
+
}
|
|
55
156
|
}
|
|
56
157
|
}
|
|
57
158
|
if (offsetStart === null)
|
|
58
159
|
return;
|
|
160
|
+
for (let i = 0; i < offsets.length - 1; i++) {
|
|
161
|
+
if (offsets[i] - offsets[i + 1] !== -1) {
|
|
162
|
+
// TODO: DELETE THIS
|
|
163
|
+
throw new Error("consecutive is not consecutive");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
59
166
|
if (bufferKeys) {
|
|
60
167
|
for (const key of bufferKeys) {
|
|
61
168
|
const bufferManagerComp = bufferManagersMap.get(key);
|
|
62
169
|
if (bufferManagerComp === undefined)
|
|
63
170
|
throw new Error("insertBulk bufferKey does not exist");
|
|
64
171
|
const { bufferManager, adaptor } = bufferManagerComp;
|
|
65
|
-
bufferManager.
|
|
172
|
+
bufferManager.insertBlock(blockLoad, offsetStart, adaptor, Float32Array);
|
|
66
173
|
}
|
|
67
174
|
}
|
|
68
175
|
else {
|
|
69
176
|
for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
70
|
-
bufferManager.
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
insertBulk2(items, bufferManagersMap, bufferKeys = null) {
|
|
75
|
-
this.ensureSpace(items.length, bufferManagersMap);
|
|
76
|
-
const { offsetMap } = this;
|
|
77
|
-
// Pre-allocate arrays only if needed
|
|
78
|
-
const newItemsCount = items.reduce((acc, item) => acc + (offsetMap.has(item.key) ? 0 : 1), 0);
|
|
79
|
-
if (newItemsCount === 0)
|
|
80
|
-
return;
|
|
81
|
-
// Only allocate if there are new items
|
|
82
|
-
const newItems = new Array(newItemsCount);
|
|
83
|
-
const newOffsets = new Array(newItemsCount);
|
|
84
|
-
let idx = 0;
|
|
85
|
-
for (const item of items) {
|
|
86
|
-
let o = offsetMap.get(item.key);
|
|
87
|
-
if (o !== undefined) {
|
|
88
|
-
// Update existing
|
|
89
|
-
if (bufferKeys) {
|
|
90
|
-
for (const key of bufferKeys) {
|
|
91
|
-
const bufferManagerComp = bufferManagersMap.get(key);
|
|
92
|
-
if (!bufferManagerComp)
|
|
93
|
-
throw new Error("insertBulk bufferKey does not exist");
|
|
94
|
-
const { bufferManager, adaptor } = bufferManagerComp;
|
|
95
|
-
bufferManager.insertBulk([adaptor(item)], [o]);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
100
|
-
bufferManager.insertBulk([adaptor(item)], [o]);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
// New item
|
|
106
|
-
const offset = this.nextOffset();
|
|
107
|
-
offsetMap.set(item.key, offset);
|
|
108
|
-
newItems[idx] = item;
|
|
109
|
-
newOffsets[idx] = offset;
|
|
110
|
-
idx++;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (idx > 0) {
|
|
114
|
-
// Only slice the arrays to the actual number of new items
|
|
115
|
-
const itemsToInsert = newItems.slice(0, idx);
|
|
116
|
-
const offsetsToInsert = newOffsets.slice(0, idx);
|
|
117
|
-
if (bufferKeys) {
|
|
118
|
-
for (const key of bufferKeys) {
|
|
119
|
-
const bufferManagerComp = bufferManagersMap.get(key);
|
|
120
|
-
if (!bufferManagerComp)
|
|
121
|
-
throw new Error("insertBulk bufferKey does not exist");
|
|
122
|
-
const { bufferManager, adaptor } = bufferManagerComp;
|
|
123
|
-
bufferManager.insertConsecutiveBulk(itemsToInsert, offsetsToInsert[0], adaptor, Float32Array);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
128
|
-
bufferManager.insertConsecutiveBulk(itemsToInsert, offsetsToInsert[0], adaptor, Float32Array);
|
|
129
|
-
}
|
|
177
|
+
bufferManager.insertBlock(blockLoad, offsetStart, adaptor, Float32Array);
|
|
130
178
|
}
|
|
131
179
|
}
|
|
132
180
|
}
|
|
@@ -175,15 +223,18 @@ export class BufferOrchestrator {
|
|
|
175
223
|
getOffset(key) {
|
|
176
224
|
return this.offsetMap.get(key);
|
|
177
225
|
}
|
|
178
|
-
|
|
226
|
+
nextTombstone() {
|
|
179
227
|
if (this.tombstoneOffsets.length > 0) {
|
|
180
228
|
const offset = this.tombstoneOffsets.pop();
|
|
181
229
|
return offset;
|
|
182
230
|
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
nextOffset() {
|
|
183
234
|
if (this._length < this._capacity) {
|
|
184
235
|
return this._length++;
|
|
185
236
|
}
|
|
186
|
-
return
|
|
237
|
+
return undefined;
|
|
187
238
|
}
|
|
188
239
|
ensureSpace(itemsLength, bufferManagersMap) {
|
|
189
240
|
if (itemsLength <= this.emptySpace)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { BufferOrchestrator as BufferOrchestratorI, BufferManagersMap, BufferManager } from "./types";
|
|
3
|
+
// const EXTRA_SIZE = 10;
|
|
4
|
+
// export class BufferOrchestrator implements BufferOrchestratorI {
|
|
5
|
+
// _capacity: number;
|
|
6
|
+
// offsetMap: Map<string, number>;
|
|
7
|
+
// tombstoneOffsets: number[];
|
|
8
|
+
// _length: number;
|
|
9
|
+
// constructor({ capacity = 10 } = {}) {
|
|
10
|
+
// this._capacity = capacity;
|
|
11
|
+
// this.offsetMap = new Map();
|
|
12
|
+
// this.tombstoneOffsets = [];
|
|
13
|
+
// this._length = 0;
|
|
14
|
+
// }
|
|
15
|
+
// resetWithCapacity(bufferManagersMap: BufferManagersMap, capacity: number | null = null) {
|
|
16
|
+
// this._capacity = capacity !== null ? capacity : this._capacity;
|
|
17
|
+
// for (const [key, { bufferManager }] of bufferManagersMap) {
|
|
18
|
+
// bufferManager.resetWithCapacity(this._capacity);
|
|
19
|
+
// }
|
|
20
|
+
// this.offsetMap.clear();
|
|
21
|
+
// this.tombstoneOffsets = [];
|
|
22
|
+
// this._length = 0;
|
|
23
|
+
// }
|
|
24
|
+
// insertBulk(items: any[], bufferManagersMap: BufferManagersMap, bufferKeys: string[] | null = null) {
|
|
25
|
+
// this.ensureSpace(items.length, bufferManagersMap);
|
|
26
|
+
// const { offsetMap } = this;
|
|
27
|
+
// const offsets = [];
|
|
28
|
+
// for (const item of items) {
|
|
29
|
+
// let o = offsetMap.get(item.key);
|
|
30
|
+
// const offset = o !== undefined ? o : this.nextOffset() as number;
|
|
31
|
+
// if (offset === undefined) {
|
|
32
|
+
// throw new Error("The Size Should Be Increased!!")
|
|
33
|
+
// }
|
|
34
|
+
// offsetMap.set(item.key, offset);
|
|
35
|
+
// offsets.push(offset);
|
|
36
|
+
// }
|
|
37
|
+
// if (bufferKeys) {
|
|
38
|
+
// for (const key of bufferKeys) {
|
|
39
|
+
// const bufferManagerComp = bufferManagersMap.get(key);
|
|
40
|
+
// if (bufferManagerComp === undefined) throw new Error("insertBulk bufferKey does not exist");
|
|
41
|
+
// const { bufferManager, adaptor } = bufferManagerComp;
|
|
42
|
+
// bufferManager.insertBulk(items.map(adaptor), offsets);
|
|
43
|
+
// }
|
|
44
|
+
// } else {
|
|
45
|
+
// for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
46
|
+
// bufferManager.insertBulk(items.map(adaptor), offsets);
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
50
|
+
// // does not assign offset to the new items.
|
|
51
|
+
// updateBulk(items: any[], bufferManagersMap: BufferManagersMap, bufferKeys: string[] | null = null) {
|
|
52
|
+
// const { offsetMap } = this;
|
|
53
|
+
// const offsets = [];
|
|
54
|
+
// for (const item of items) {
|
|
55
|
+
// const offset = offsetMap.get(item.key);
|
|
56
|
+
// if (offset !== undefined) {
|
|
57
|
+
// offsets.push(offset);
|
|
58
|
+
// } else {
|
|
59
|
+
// throw new Error("updateBulk item Key does not exist");
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
// if (bufferKeys) {
|
|
63
|
+
// for (const key of bufferKeys) {
|
|
64
|
+
// const bufferManagerComp = bufferManagersMap.get(key);
|
|
65
|
+
// if (bufferManagerComp === undefined) throw new Error("updateBulk bufferKey does not exist");
|
|
66
|
+
// const { bufferManager, adaptor } = bufferManagerComp;
|
|
67
|
+
// bufferManager.insertBulk(items.map(adaptor), offsets);
|
|
68
|
+
// }
|
|
69
|
+
// } else {
|
|
70
|
+
// for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
|
|
71
|
+
// bufferManager.insertBulk(items.map(adaptor), offsets);
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
74
|
+
// }
|
|
75
|
+
// deleteBulk(keys: string[], bufferManagersMap: BufferManagersMap) {
|
|
76
|
+
// const offsets = [];
|
|
77
|
+
// for (const key of keys) {
|
|
78
|
+
// const offset = this.getOffset(key);
|
|
79
|
+
// if (offset !== undefined) {
|
|
80
|
+
// offsets.push(offset);
|
|
81
|
+
// this.offsetMap.delete(key);
|
|
82
|
+
// this.tombstoneOffsets.push(offset);
|
|
83
|
+
// }
|
|
84
|
+
// }
|
|
85
|
+
// for (const [key, { bufferManager }] of bufferManagersMap) {
|
|
86
|
+
// bufferManager.deleteBulk(offsets);
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// getOffset(key: string) {
|
|
90
|
+
// return this.offsetMap.get(key);
|
|
91
|
+
// }
|
|
92
|
+
// nextOffset(): number | undefined {
|
|
93
|
+
// if (this.tombstoneOffsets.length > 0) {
|
|
94
|
+
// const offset = this.tombstoneOffsets.pop() as number;
|
|
95
|
+
// return offset;
|
|
96
|
+
// }
|
|
97
|
+
// if (this._length < this._capacity) {
|
|
98
|
+
// return this._length++;
|
|
99
|
+
// }
|
|
100
|
+
// return undefined;
|
|
101
|
+
// }
|
|
102
|
+
// ensureSpace(itemsLength: number, bufferManagersMap: BufferManagersMap) {
|
|
103
|
+
// if (itemsLength <= this.emptySpace) return;
|
|
104
|
+
// const newCapacity = this.length + itemsLength;
|
|
105
|
+
// for (const [key, { bufferManager }] of bufferManagersMap) {
|
|
106
|
+
// bufferManager.extendBuffer(this.length, newCapacity);
|
|
107
|
+
// }
|
|
108
|
+
// this._capacity = newCapacity;
|
|
109
|
+
// }
|
|
110
|
+
// defrag(bufferManagers: BufferManagersMap, bufferKeys: string[]) { // TODO defrag and leave some empty space
|
|
111
|
+
// const offsetMap = this.offsetMap;
|
|
112
|
+
// const newCapacity = offsetMap.size + EXTRA_SIZE;
|
|
113
|
+
// if (bufferKeys) {
|
|
114
|
+
// for (const key of bufferKeys) {
|
|
115
|
+
// const offset = offsetMap.get(key);
|
|
116
|
+
// if (offset !== undefined) {
|
|
117
|
+
// for (const [key, { bufferManager }] of bufferManagers) {
|
|
118
|
+
// bufferManager.defrag([offset], this.length, newCapacity);
|
|
119
|
+
// }
|
|
120
|
+
// }
|
|
121
|
+
// }
|
|
122
|
+
// } else {
|
|
123
|
+
// for (const [key, { bufferManager }] of bufferManagers) {
|
|
124
|
+
// bufferManager.defrag(offsetMap.values(), this.length, newCapacity);
|
|
125
|
+
// }
|
|
126
|
+
// }
|
|
127
|
+
// this._defrag();
|
|
128
|
+
// this._length = offsetMap.size;
|
|
129
|
+
// this._capacity = newCapacity;
|
|
130
|
+
// this.tombstoneOffsets = [];
|
|
131
|
+
// }
|
|
132
|
+
// /**
|
|
133
|
+
// * Flushes metadata and sets length to 0 without actualize change on buffers
|
|
134
|
+
// * This method created for cases in which data is loaded on each frame
|
|
135
|
+
// */
|
|
136
|
+
// flush({ capacity = 10 } = {}) {
|
|
137
|
+
// this._length = 0;
|
|
138
|
+
// this._capacity = capacity;
|
|
139
|
+
// this.tombstoneOffsets = []
|
|
140
|
+
// this.offsetMap.clear();
|
|
141
|
+
// }
|
|
142
|
+
// _defrag() {
|
|
143
|
+
// const newOffsetMap = new Map();
|
|
144
|
+
// let newOffset = 0;
|
|
145
|
+
// for (const [key, offset] of this.offsetMap) {
|
|
146
|
+
// newOffsetMap.set(key, newOffset++);
|
|
147
|
+
// }
|
|
148
|
+
// this.offsetMap = newOffsetMap
|
|
149
|
+
// }
|
|
150
|
+
// get length() {
|
|
151
|
+
// return this._length;
|
|
152
|
+
// }
|
|
153
|
+
// get emptySpace() {
|
|
154
|
+
// return this._capacity - this.offsetMap.size;
|
|
155
|
+
// }
|
|
156
|
+
// get capacity() {
|
|
157
|
+
// return this._capacity;
|
|
158
|
+
// }
|
|
159
|
+
// }
|