@pirireis/webglobeplugins 0.9.3 → 0.9.4

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.
@@ -15,7 +15,17 @@ const _originSphere = /*@__PURE__*/ { center: vec3.create(0, 0, 0), radius: 1 }
15
15
  const _intersectionPoints: [Vec3, Vec3] = /*@__PURE__*/[vec3.create(), vec3.create()];
16
16
 
17
17
  // TODO: out must be [Arc, Arc] there is a case where split into three arcs, visible by points or arcs but middle is not visible
18
- export function arcSlice(out: Arc, inArc: Arc, juctionPlane: Plane): boolean {
18
+
19
+
20
+
21
+ /**
22
+ *
23
+ * @param out \
24
+ * @param inArc
25
+ * @param juctionPlane
26
+ * @returns number of arcs segments in the junction divided by the junction plane.
27
+ */
28
+ export function arcSlice(out: [Arc, Arc], inArc: Arc, juctionPlane: Plane): number {
19
29
 
20
30
  // arc coverPlane and junctionPlane intersection exist in the range of unit sphere
21
31
  const coverRadiusAngle = plane.getUnitSphereRadiusAngle(inArc.coverPlane);
@@ -24,15 +34,15 @@ export function arcSlice(out: Arc, inArc: Arc, juctionPlane: Plane): boolean {
24
34
  const angleBetween_Cover_Visible = Math.acos(vec3.dot(inArc.coverPlane.normal, juctionPlane.normal));
25
35
 
26
36
  if (coverRadiusAngle + visibleRadiusAngle < angleBetween_Cover_Visible - EPSILON) { // case A: out of range
27
- return false; // No intersection
37
+ return 0; // No intersection
28
38
  }
29
39
  // ------------------------------------
30
40
 
31
41
  // the case when the arc is completely covered by the juction plane
32
42
 
33
43
  if (visibleRadiusAngle + EPSILON >= angleBetween_Cover_Visible + coverRadiusAngle) { // case B: fully visible
34
- arc.copy(out, inArc);
35
- return true;
44
+ arc.copy(out[0], inArc);
45
+ return 1;
36
46
  }
37
47
  // plane-plane intersection line should be calculated for the rest of the calculations
38
48
 
@@ -44,7 +54,7 @@ export function arcSlice(out: Arc, inArc: Arc, juctionPlane: Plane): boolean {
44
54
  // case B Covers they face each other
45
55
  throw new Error("Unexpected case: planes are parallel, case A and B should Cover it");
46
56
  }
47
-
57
+ // --- read until here ---
48
58
 
49
59
  // calculate the intersection points
50
60
 
@@ -52,28 +62,41 @@ export function arcSlice(out: Arc, inArc: Arc, juctionPlane: Plane): boolean {
52
62
 
53
63
  if (!isSphereIntersection) {
54
64
  // other edge caes should be covered by now
55
- return false; // No intersection
65
+ return 0; // No intersection
56
66
  }
57
67
 
58
68
 
59
69
  const i0IsCovered = plane.distanceToPoint(inArc.coverPlane, _intersectionPoints[0]) > -EPSILON;
60
70
  const i1IsCovered = plane.distanceToPoint(inArc.coverPlane, _intersectionPoints[1]) > -EPSILON;
61
71
 
62
- if (i0IsCovered && i1IsCovered) {
63
- arc.set(out, _intersectionPoints[0], _intersectionPoints[1]);
64
- return true;
65
- }
66
72
 
67
73
  const p0IsVisible = plane.distanceToPoint(juctionPlane, inArc.p0) > -EPSILON;
68
74
  const p1IsVisible = plane.distanceToPoint(juctionPlane, inArc.p1) > -EPSILON;
69
75
 
70
- if (p0IsVisible && p1IsVisible) {
71
- arc.copy(out, inArc);
72
- return true;
76
+ if (!p0IsVisible && !p1IsVisible && !i0IsCovered && !i1IsCovered) {
77
+ return 0; // No intersection
73
78
  }
74
79
 
75
- if (!p0IsVisible && !p1IsVisible && !i0IsCovered && !i1IsCovered) {
76
- return false; // No intersection
80
+ if (i0IsCovered && i1IsCovered && p0IsVisible && p1IsVisible) {
81
+ // calculate which points are closer
82
+ const p0i0DistanceSquared = vec3.distanceSquared(inArc.p0, _intersectionPoints[0]);
83
+ const p0i1DistanceSquared = vec3.distanceSquared(inArc.p0, _intersectionPoints[1]);
84
+ const case0 = p0i0DistanceSquared < p0i1DistanceSquared;
85
+ arc.set(out[0], inArc.p0, case0 ? _intersectionPoints[0] : _intersectionPoints[1]);
86
+ arc.set(out[1], inArc.p1, !case0 ? _intersectionPoints[0] : _intersectionPoints[1]);
87
+ return 2;
88
+ }
89
+
90
+
91
+ if (i0IsCovered && i1IsCovered) {
92
+ arc.set(out[0], _intersectionPoints[0], _intersectionPoints[1]);
93
+ return 1;
94
+ }
95
+
96
+
97
+ if (p0IsVisible && p1IsVisible) {
98
+ arc.copy(out[0], inArc);
99
+ return 1;
77
100
  }
78
101
 
79
102
  if ((p0IsVisible || p1IsVisible) !== (i0IsCovered || i1IsCovered)) {
@@ -81,10 +104,11 @@ export function arcSlice(out: Arc, inArc: Arc, juctionPlane: Plane): boolean {
81
104
  }
82
105
 
83
106
  arc.set(
84
- out,
107
+ out[0],
85
108
  p0IsVisible ? inArc.p0 : inArc.p1,
86
109
  i0IsCovered ? _intersectionPoints[0] : _intersectionPoints[1]
87
110
  );
88
111
 
89
- return true;
90
- }
112
+ return 1;
113
+ }
114
+
@@ -56,7 +56,7 @@ export const quaternion = Object.freeze({
56
56
  const z = a[2] * b[3] + a[3] * b[2] + a[0] * b[1] - a[1] * b[0];
57
57
  const w = a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2];
58
58
  this.set(out, x, y, z, w);
59
- this.normalize(out);
59
+ this.normalize(out, out);
60
60
  },
61
61
 
62
62
  lengthSquared(a: Quaternion): number {
@@ -67,17 +67,14 @@ export const quaternion = Object.freeze({
67
67
  return Math.sqrt(this.lengthSquared(a));
68
68
  },
69
69
 
70
- normalize(out: Quaternion) {
71
- const len = Math.sqrt(this.lengthSquared(out));
70
+ normalize(out: Quaternion, input: Quaternion) {
71
+ const len = Math.sqrt(this.lengthSquared(input));
72
72
  if (len < EPSILON) {
73
73
  this.set(out, 0, 0, 0, 1);
74
74
  }
75
75
  else {
76
76
  const invLen = 1 / len;
77
- out[0] *= invLen;
78
- out[1] *= invLen;
79
- out[2] *= invLen;
80
- out[3] *= invLen;
77
+ this.set(out, input[0] * invLen, input[1] * invLen, input[2] * invLen, input[3] * invLen);
81
78
  }
82
79
  },
83
80
 
@@ -105,7 +102,7 @@ export const quaternion = Object.freeze({
105
102
  const z = from[2] * to[3] + from[3] * to[2] + from[0] * to[1] - from[1] * to[0];
106
103
  const w = from[3] * to[3] - from[0] * to[0] - from[1] * to[1] - from[2] * to[2];
107
104
  this.set(out, x, y, z, w);
108
- this.normalize(out);
105
+ this.normalize(out, out);
109
106
  },
110
107
 
111
108
  conjugate(out: Quaternion, a: Quaternion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -14,7 +14,7 @@ import "../../util/gl-util/buffer/attribute-loader";
14
14
  import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
15
15
  import "../../util/gl-util/uniform-block/types";
16
16
 
17
- import { drawArrays } from "../../util/gl-util/draw-options/methods.js";
17
+ import { drawArrays } from "../../util/gl-util/draw-options/methods";
18
18
  import "../../util/gl-util/draw-options/types";
19
19
 
20
20
 
@@ -138,7 +138,7 @@ class Logic implements ProgramInterface {
138
138
  this.gl = globe.gl;
139
139
 
140
140
  this.globe = globe;
141
- this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
141
+ this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource) as WebGLProgram;
142
142
  const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
143
143
  this.gl.useProgram(this.program);
144
144
  this._opacity.location = this.gl.getUniformLocation(this.program, "opacity");
@@ -16,7 +16,7 @@ const globeProgramCache = (function () {
16
16
 
17
17
  const cache = new Map();
18
18
 
19
- function getProgram(globe, ProgramClass) {
19
+ function getProgram(globe: any, ProgramClass: any) {
20
20
  if (!cache.has(globe)) { cache.set(globe, new Map()) };
21
21
  if (!cache.get(globe).has(ProgramClass)) {
22
22
  cache.get(globe).set(ProgramClass, {
@@ -31,7 +31,7 @@ const globeProgramCache = (function () {
31
31
  return cache.get(globe).get(ProgramClass).program;
32
32
  };
33
33
 
34
- function releaseProgram(globe, ProgramClass) {
34
+ function releaseProgram(globe: any, ProgramClass: any) {
35
35
  if (cache.has(globe) && cache.get(globe).has(ProgramClass)) {
36
36
  if (cache.get(globe).get(ProgramClass).count === 0) {
37
37
  throw new Error("The program counter is already 0, cannot release program");
@@ -56,7 +56,7 @@ const glProgramCache = (function () {
56
56
 
57
57
  const cache = new Map();
58
58
 
59
- function getProgram(gl, ProgramClass) {
59
+ function getProgram(gl: WebGL2RenderingContext | WebGLRenderingContext, ProgramClass: any) {
60
60
  if (!cache.has(gl)) { cache.set(gl, new Map()) };
61
61
  if (!cache.get(gl).has(ProgramClass)) {
62
62
  cache.get(gl).set(ProgramClass, {
@@ -69,7 +69,7 @@ const glProgramCache = (function () {
69
69
  return cache.get(gl).get(ProgramClass).program;
70
70
  };
71
71
 
72
- function releaseProgram(gl, ProgramClass) {
72
+ function releaseProgram(gl: WebGL2RenderingContext | WebGLRenderingContext, ProgramClass: any) {
73
73
  if (cache.has(gl) && cache.get(gl).has(ProgramClass)) {
74
74
  if (cache.get(gl).get(ProgramClass).count === 0) {
75
75
  throw new Error("The program counter is already 0, cannot release program");
@@ -94,7 +94,7 @@ const noRegisterGlobeProgramCache = (function () {
94
94
 
95
95
  const cache = new Map();
96
96
 
97
- function getProgram(globe, ProgramClass) {
97
+ function getProgram(globe: any, ProgramClass: any) {
98
98
  if (!cache.has(globe)) { cache.set(globe, new Map()) };
99
99
  if (!cache.get(globe).has(ProgramClass)) {
100
100
  cache.get(globe).set(ProgramClass, {
@@ -107,7 +107,7 @@ const noRegisterGlobeProgramCache = (function () {
107
107
  return cache.get(globe).get(ProgramClass).program;
108
108
  };
109
109
 
110
- function releaseProgram(globe, ProgramClass) {
110
+ function releaseProgram(globe: any, ProgramClass: any) {
111
111
  if (cache.has(globe) && cache.get(globe).has(ProgramClass)) {
112
112
  if (cache.get(globe).get(ProgramClass).count === 0) {
113
113
  throw new Error("The program counter is already 0, cannot release program");
@@ -0,0 +1,48 @@
1
+ export declare const CameraUniformBlockString: string;
2
+
3
+ export default class CameraUniformBlockTotem {
4
+ id: string;
5
+ description: string;
6
+ gl: WebGL2RenderingContext | null;
7
+ globe: any;
8
+ ubo: WebGLBuffer | null;
9
+ // _frustumPlanes: any; // Uncomment and type if used
10
+ _isMovedParams: {
11
+ lastLod: number | null;
12
+ isMoved: boolean;
13
+ };
14
+ traslateFloat32: Float32Array;
15
+ mapWHFloat32: Float32Array;
16
+
17
+ constructor();
18
+
19
+ init(globe: any, gl: WebGL2RenderingContext): void;
20
+ resize(): void;
21
+ setGeometry(): void;
22
+ draw3D(
23
+ projection: Float32Array,
24
+ modelView: Float32Array,
25
+ translate: { x: number; y: number; z: number }
26
+ ): void;
27
+ assignBindingPoint(program: WebGLProgram, bindingPoint: number): void;
28
+ getUBO(): WebGLBuffer | null;
29
+ getFrustumPlanes(): any; // Update type if needed
30
+ bind(bindingPoint: number): void;
31
+ unbind(bindingPoint: number): void;
32
+ isMoved(): boolean;
33
+ free(): void;
34
+ readBuffer(): {
35
+ view: Float32Array;
36
+ projection: Float32Array;
37
+ translate: Float32Array;
38
+ is3D: number;
39
+ mapWH: Float32Array;
40
+ screenWH: Float32Array;
41
+ z_level: number;
42
+ };
43
+ }
44
+
45
+ export declare const CameraUniformBlockTotemCache: Readonly<{
46
+ get: (globe: any) => any;
47
+ release: (globe: any) => void;
48
+ }>;
@@ -1,6 +1,6 @@
1
1
  import { createProgram } from "../../../util";
2
2
  import { UBO_BINDING_POINT, shaderUboSource } from "./ubo.js";
3
- import { glProgramCache } from "../../programcache.js";
3
+ import { glProgramCache } from "../../programcache";
4
4
  /**
5
5
  * [+] ubo
6
6
  */
@@ -1,4 +1,4 @@
1
- import { Plane, Line, Vec3, Quaternion } from '../../../Math/types';
1
+ import { Plane, Line, Vec3, Quaternion, Arc } from '../../../Math/types';
2
2
  import { plane } from '../../../Math/plane';
3
3
  import { line } from '../../../Math/line';
4
4
  import { arc } from '../../../Math/arc';
@@ -10,7 +10,10 @@ import { EPSILON } from '../../../Math/constants';
10
10
 
11
11
 
12
12
  const arcIn = arc.create(vec3.create(0, 0, 1), vec3.create(1, 0, 0));
13
- const arcOut = arc.create(vec3.create(0, 0, 1), vec3.create(1, 0, 0));
13
+ const arcOut: [Arc, Arc] = [
14
+ arc.create(vec3.create(0, 0, 1), vec3.create(1, 0, 0)),
15
+ arc.create(vec3.create(0, 0, 1), vec3.create(1, 0, 0))
16
+ ];
14
17
  const arcExpected = arc.create(vec3.create(0, 0, 1), vec3.create(1, 0, 0));
15
18
  const junctionPlane = plane.create(vec3.create(0, 0, 1), 0);
16
19
 
@@ -20,7 +23,8 @@ const r3 = Math.sqrt(3) / 3;
20
23
  beforeAll(() => {
21
24
  // Initialize any necessary data or state before running the tests
22
25
  arc.set(arcIn, vec3.create(0, 0, 1), vec3.create(1, 0, 0));
23
- arc.set(arcOut, vec3.create(0, 0, 1), vec3.create(1, 0, 0));
26
+ arc.set(arcOut[0], vec3.create(0, 0, 1), vec3.create(1, 0, 0));
27
+ arc.set(arcOut[1], vec3.create(0, 0, 1), vec3.create(1, 0, 0));
24
28
 
25
29
  plane.set(junctionPlane, vec3.create(0, 0, 1), 0);
26
30
 
@@ -42,7 +46,7 @@ test('arcSlice - Full intersection 1', () => {
42
46
  junctionPlane.distance = 0; // Set distance to ensure full intersection
43
47
  const result = arcSlice(arcOut, arcIn, junctionPlane);
44
48
  expect(result).toBe(true);
45
- const isEqual = arc.equals(arcOut, arcExpected);
49
+ const isEqual = arc.equals(arcOut[0], arcExpected);
46
50
  expect(isEqual).toBe(true);
47
51
  });
48
52
 
@@ -93,7 +97,7 @@ test("arcSlice - Planes are parallel", () => {
93
97
 
94
98
  const result2 = arcSlice(arcOut, arcIn, junctionPlane);
95
99
  expect(result2).toBe(true); // Expect no intersection
96
- const isEqual = arc.equals(arcOut, arcIn);
100
+ const isEqual = arc.equals(arcOut[0], arcIn);
97
101
  expect(isEqual).toBe(true); // Expect the output arc to be equal to the input arc
98
102
  });
99
103
 
@@ -113,7 +117,7 @@ test("arcSlice - Arc sliced in half", () => {
113
117
  const expectedPoint1 = vec3.create(0, r2, r2);
114
118
  const expectedPoint2 = vec3.create(0, 0, 1);
115
119
  arc.set(arcExpected, expectedPoint1, expectedPoint2);
116
- const isEqual = arc.equals(arcOut, arcExpected);
120
+ const isEqual = arc.equals(arcOut[0], arcExpected);
117
121
  expect(isEqual).toBe(true); // Expect the output arc to be equal to the expected arc
118
122
  });
119
123
 
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2018",
4
+ "module": "commonjs",
5
+ "outDir": "./dist",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "allowJs": true,
11
+ "declaration": false
12
+ },
13
+ "include": [
14
+ "**/*.ts", // Include all .ts files in the current directory and subdirectories
15
+ "**/*.js" // Include all .js files in the current directory and subdirectories
16
+ ],
17
+ "exclude": [
18
+ "node_modules",
19
+ "dist" // Exclude the output directory itself
20
+ ]
21
+ }
@@ -1,4 +1,4 @@
1
- import BufferOffsetManager from './bufferoffsetmanager.js';
1
+ import BufferOffsetManager from './bufferoffsetmanager';
2
2
 
3
3
  export { BufferOffsetManager };
4
4
 
@@ -18,7 +18,13 @@
18
18
  */
19
19
 
20
20
  export class BufferManager {
21
- constructor(gl, itemSize, { bufferType = "STATIC_DRAW", buffer = null, initialCapacity = null } = {}) {
21
+ gl: WebGL2RenderingContext;
22
+ buffer: WebGLBuffer;
23
+ itemSize: number;
24
+ bufferType: string;
25
+ isFreed: boolean = false;
26
+
27
+ constructor(gl: WebGL2RenderingContext, itemSize: number, { bufferType = "STATIC_DRAW", buffer = null, initialCapacity = null } = {}) {
22
28
  this.gl = gl;
23
29
  this.itemSize = itemSize;
24
30
  this.bufferType = bufferType;
@@ -26,14 +32,15 @@ export class BufferManager {
26
32
  if (initialCapacity !== null) this.resetWithCapacity(initialCapacity);
27
33
  }
28
34
 
29
- resetWithCapacity(capacity) {
35
+ resetWithCapacity(capacity: number) {
30
36
  const { gl, buffer, bufferType, itemSize } = this;
31
37
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
38
+ // @ts-ignore
32
39
  gl.bufferData(gl.ARRAY_BUFFER, capacity * itemSize * 4, gl[bufferType]);
33
40
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
34
41
  }
35
42
 
36
- deleteBulk(offsets) {
43
+ deleteBulk(offsets: number[]) {
37
44
  const { gl, buffer, itemSize } = this;
38
45
  const emptyBlock = new Float32Array(this.itemSize).fill(NaN)
39
46
  const offsetMultiplier = itemSize * 4;
@@ -47,7 +54,7 @@ export class BufferManager {
47
54
  }
48
55
 
49
56
 
50
- insertBulk(blocks, offsets) {
57
+ insertBulk(blocks: any[], offsets: number[]) {
51
58
  const { gl, buffer, itemSize } = this;
52
59
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
53
60
  const offsetMultiplier = itemSize * 4;
@@ -61,7 +68,7 @@ export class BufferManager {
61
68
 
62
69
 
63
70
  // TODO: this is broken
64
- defrag(offsetValues, occupiedCapacity, newCapacity) {
71
+ defrag(offsetValues: MapIterator<number> | number[], occupiedCapacity: number, newCapacity: number) {
65
72
  const { gl, buffer, bufferType, itemSize } = this;
66
73
 
67
74
  const newArray = new Float32Array(newCapacity * itemSize);
@@ -74,23 +81,25 @@ export class BufferManager {
74
81
  }
75
82
 
76
83
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
84
+ // @ts-ignore
77
85
  gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
78
86
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, newArray);
79
87
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
80
88
 
81
89
  }
82
90
 
83
- extendBuffer(occupiedCapacity, newCapacity) {
91
+ extendBuffer(occupiedCapacity: number, newCapacity: number) {
84
92
  const { gl, buffer, bufferType } = this;
85
93
  const itemSize = this.itemSize;
86
94
  const bufferData = this._getBufferData(occupiedCapacity);
87
95
  gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
96
+ // @ts-ignore
88
97
  gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
89
98
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
90
99
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
91
100
  }
92
101
 
93
- _getBufferData(occupiedCapacity) {
102
+ _getBufferData(occupiedCapacity: number): Float32Array {
94
103
  const { gl, buffer } = this;
95
104
  const size = occupiedCapacity * this.itemSize;
96
105
  const bufferData = new Float32Array(size);
@@ -103,8 +112,8 @@ export class BufferManager {
103
112
  free() {
104
113
  if (this.isFreed) return;
105
114
  this.gl.deleteBuffer(this.buffer);
106
- this.buffer = null;
107
- this.gl = null;
115
+ // this.buffer = null;
116
+ // this.gl = null;
108
117
  this.isFreed = true;
109
118
  }
110
119
  }
@@ -1,6 +1,12 @@
1
+ import { BufferOrchestrator as BufferOrchestratorI, BufferManagersMap, BufferManager } from "./types";
2
+
1
3
  const EXTRA_SIZE = 10;
2
4
 
3
- export class BufferOrchestrator {
5
+ export class BufferOrchestrator implements BufferOrchestratorI {
6
+ _capacity: number;
7
+ offsetMap: Map<string, number>;
8
+ tombstoneOffsets: number[];
9
+ _length: number;
4
10
 
5
11
  constructor({ capacity = 10 } = {}) {
6
12
  this._capacity = capacity;
@@ -10,7 +16,7 @@ export class BufferOrchestrator {
10
16
  }
11
17
 
12
18
 
13
- resetWithCapacity(bufferManagersMap, capacity = null) {
19
+ resetWithCapacity(bufferManagersMap: BufferManagersMap, capacity: number | null = null) {
14
20
  this._capacity = capacity !== null ? capacity : this._capacity;
15
21
  for (const [key, { bufferManager }] of bufferManagersMap) {
16
22
  bufferManager.resetWithCapacity(this._capacity);
@@ -20,13 +26,13 @@ export class BufferOrchestrator {
20
26
  this._length = 0;
21
27
  }
22
28
 
23
- insertBulk(items, bufferManagersMap) {
29
+ insertBulk(items: any[], bufferManagersMap: BufferManagersMap) {
24
30
  this.autoExtendBuffers(items.length, bufferManagersMap);
25
31
  const { offsetMap } = this;
26
32
  const offsets = [];
27
33
  for (const item of items) {
28
34
  let o = offsetMap.get(item.key);
29
- const offset = o !== undefined ? o : this.nextOffset();
35
+ const offset = o !== undefined ? o : this.nextOffset() as number;
30
36
  offsetMap.set(item.key, offset);
31
37
  offsets.push(offset);
32
38
  }
@@ -37,7 +43,7 @@ export class BufferOrchestrator {
37
43
 
38
44
 
39
45
  // does not assign offset to the new items.
40
- updateBulk(items, bufferManagersMap, bufferKeys) {
46
+ updateBulk(items: any[], bufferManagersMap: BufferManagersMap, bufferKeys: string[] | null = null) {
41
47
  const { offsetMap } = this;
42
48
  const offsets = [];
43
49
  for (const item of items) {
@@ -64,7 +70,7 @@ export class BufferOrchestrator {
64
70
  }
65
71
 
66
72
 
67
- deleteBulk(keys, bufferManagersMap) {
73
+ deleteBulk(keys: string[], bufferManagersMap: BufferManagersMap) {
68
74
  const offsets = [];
69
75
  for (const key of keys) {
70
76
  const offset = this.getOffset(key);
@@ -80,13 +86,13 @@ export class BufferOrchestrator {
80
86
  }
81
87
 
82
88
 
83
- getOffset(key) {
89
+ getOffset(key: string) {
84
90
  return this.offsetMap.get(key);
85
91
  }
86
92
 
87
- nextOffset() {
93
+ nextOffset(): number | boolean {
88
94
  if (this.tombstoneOffsets.length > 0) {
89
- const offset = this.tombstoneOffsets.pop();
95
+ const offset = this.tombstoneOffsets.pop() as number;
90
96
  return offset;
91
97
  }
92
98
  if (this._length < this._capacity) {
@@ -96,7 +102,7 @@ export class BufferOrchestrator {
96
102
  }
97
103
 
98
104
 
99
- autoExtendBuffers(itemsLength, bufferManagersMap) {
105
+ autoExtendBuffers(itemsLength: number, bufferManagersMap: BufferManagersMap) {
100
106
  if (itemsLength <= this.emptySpace) return;
101
107
  const newCapacity = this.length + itemsLength;
102
108
  for (const [key, { bufferManager }] of bufferManagersMap) {
@@ -106,7 +112,7 @@ export class BufferOrchestrator {
106
112
  }
107
113
 
108
114
 
109
- defrag(bufferManagers, bufferKeys) { // TODO defrag and leave some empty space
115
+ defrag(bufferManagers: BufferManagersMap, bufferKeys: string[]) { // TODO defrag and leave some empty space
110
116
  const offsetMap = this.offsetMap;
111
117
  const newCapacity = offsetMap.size + EXTRA_SIZE;
112
118
  if (bufferKeys) {
@@ -137,7 +143,7 @@ export class BufferOrchestrator {
137
143
  flush({ capacity = 10 } = {}) {
138
144
  this._length = 0;
139
145
  this._capacity = capacity;
140
- this.tombstoneOffSet = []
146
+ this.tombstoneOffsets = []
141
147
  this.offsetMap.clear();
142
148
  }
143
149
 
@@ -1,16 +1,19 @@
1
1
 
2
2
  export class ObjectStore {
3
+ _container;
4
+
5
+
3
6
  constructor({ initialCapcity = 10 } = {}) {
4
7
  this._container = this._createEmptyList(initialCapcity);
5
8
  }
6
9
 
7
10
 
8
- resetWithCapacity(capacity) {
11
+ resetWithCapacity(capacity: number) {
9
12
  this._container = this._createEmptyList(capacity);
10
13
  }
11
14
 
12
15
 
13
- deleteBulk(offsets) {
16
+ deleteBulk(offsets: number[]) {
14
17
  for (let i = 0; i < offsets.length; i++) {
15
18
  const offset = offsets[i];
16
19
  if (offset !== undefined) {
@@ -20,7 +23,7 @@ export class ObjectStore {
20
23
  }
21
24
 
22
25
 
23
- insertBulk(objects, offsets) {
26
+ insertBulk(objects: any[], offsets: number[]) {
24
27
  for (let i = 0; i < objects.length; i++) {
25
28
  const object = objects[i];
26
29
  const offset = offsets[i];
@@ -30,7 +33,7 @@ export class ObjectStore {
30
33
  }
31
34
  }
32
35
 
33
- defrag(offsetValues, occupiedCapacity, newCapacity) {
36
+ defrag(offsetValues: number[], occupiedCapacity: number, newCapacity: number) {
34
37
 
35
38
  const hold = this._createEmptyList(newCapacity);
36
39
  for (let i = 0; i < offsetValues.length; i++) {
@@ -42,16 +45,16 @@ export class ObjectStore {
42
45
  this._container = hold;
43
46
  }
44
47
 
45
- extendBuffer(occupiedCapacity, newCapacity) {
48
+ extendBuffer(occupiedCapacity: number, newCapacity: number) {
46
49
  const oldCapacity = this._container.length;
47
50
  this._container = this._container.concat(this._createEmptyList(newCapacity - oldCapacity));
48
51
  }
49
52
 
50
- _createEmptyList(size) {
53
+ _createEmptyList(size: number) {
51
54
  return new Array(size).fill(null);
52
55
  }
53
56
 
54
- get(index) {
57
+ get(index: number) {
55
58
  return this._container[index];
56
59
  }
57
60
 
@@ -0,0 +1,39 @@
1
+ type BufferManagersMap = Map<string, {
2
+ bufferManager: BufferManager;
3
+ adaptor: (item: any) => Float32Array;
4
+ }>;
5
+
6
+ interface BufferManager {
7
+ gl: WebGL2RenderingContext;
8
+ buffer: WebGLBuffer;
9
+ itemSize: number;
10
+ bufferType: string;
11
+ isFreed: boolean;
12
+
13
+ insertBulk(blocks: any[], offsets: number[]): void;
14
+ deleteBulk(offsets: number[]): void;
15
+ resetWithCapacity(capacity: number): void;
16
+ defrag(offsetValues: MapIterator<number> | number[], occupiedCapacity: number, newCapacity: number): void;
17
+ extendBuffer(occupiedCapacity: number, newCapacity: number): void;
18
+ free(): void;
19
+ }
20
+
21
+ interface BufferOrchestrator {
22
+ offsetMap: Map<string, number>;
23
+ tombstoneOffsets: number[];
24
+ _length: number;
25
+ _capacity: number;
26
+ getOffset(key: string): number | undefined;
27
+ nextOffset(): number | boolean;
28
+ autoExtendBuffers(itemsLength: number, bufferManagersMap: BufferManagersMap): void;
29
+ updateBulk(items: any[], bufferManagersMap: BufferManagersMap, bufferKeys?: string[]): void;
30
+ deleteBulk(keys: string[], bufferManagersMap: BufferManagersMap): void;
31
+ resetWithCapacity(bufferManagersMap: BufferManagersMap, capacity: number | null): void;
32
+ }
33
+
34
+
35
+ export {
36
+ BufferManagersMap,
37
+ BufferManager,
38
+ BufferOrchestrator
39
+ }