@woosh/meep-engine 2.91.1 → 2.91.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/package.json +1 -1
- package/src/core/binary/makeArrayBuffer.d.ts +8 -0
- package/src/core/binary/makeArrayBuffer.d.ts.map +1 -0
- package/src/core/binary/makeArrayBuffer.js +21 -0
- package/src/core/collection/table/RowFirstTable.d.ts +8 -1
- package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
- package/src/core/collection/table/RowFirstTable.js +21 -3
- package/src/core/collection/table/bind/TableRecord.d.ts +19 -0
- package/src/core/collection/table/bind/TableRecord.d.ts.map +1 -0
- package/src/core/collection/table/bind/TableRecord.js +87 -0
- package/src/core/collection/table/bind/TableRecord.spec.d.ts +2 -0
- package/src/core/collection/table/bind/TableRecord.spec.d.ts.map +1 -0
- package/src/core/collection/table/bind/TableRecord.spec.js +27 -0
- package/src/engine/ecs/binding/EntityProxyScope.d.ts.map +1 -1
- package/src/engine/ecs/binding/EntityProxyScope.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} byte_size
|
|
4
|
+
* @param {boolean} [shared]
|
|
5
|
+
* @return {ArrayBuffer|SharedArrayBuffer}
|
|
6
|
+
*/
|
|
7
|
+
export function makeArrayBuffer(byte_size: number, shared?: boolean): ArrayBuffer | SharedArrayBuffer;
|
|
8
|
+
//# sourceMappingURL=makeArrayBuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/makeArrayBuffer.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,2CAJW,MAAM,WACN,OAAO,GACN,WAAW,GAAC,iBAAiB,CAcxC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assert } from "../assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} byte_size
|
|
6
|
+
* @param {boolean} [shared]
|
|
7
|
+
* @return {ArrayBuffer|SharedArrayBuffer}
|
|
8
|
+
*/
|
|
9
|
+
export function makeArrayBuffer(byte_size, shared = false) {
|
|
10
|
+
assert.isNonNegativeInteger(byte_size, 'size');
|
|
11
|
+
|
|
12
|
+
if (shared) {
|
|
13
|
+
if (crossOriginIsolated) {
|
|
14
|
+
return new SharedArrayBuffer(byte_size);
|
|
15
|
+
} else {
|
|
16
|
+
console.error(`SharedArrayBuffer not supported because origin is not isolated, defaulting to ArrayBuffer instead`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return new ArrayBuffer(byte_size);
|
|
21
|
+
}
|
|
@@ -2,9 +2,10 @@ export class RowFirstTable {
|
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
* @param {RowFirstTableSpec} spec
|
|
5
|
+
* @param {boolean} [shared_array] should we use SharedArrayBuffer instead of ArrayBuffer?
|
|
5
6
|
* @constructor
|
|
6
7
|
*/
|
|
7
|
-
constructor(spec: RowFirstTableSpec);
|
|
8
|
+
constructor(spec: RowFirstTableSpec, shared_array?: boolean);
|
|
8
9
|
/**
|
|
9
10
|
*
|
|
10
11
|
* @type {RowFirstTableSpec}
|
|
@@ -57,6 +58,12 @@ export class RowFirstTable {
|
|
|
57
58
|
* @type {function(DataView, number, number[]): void}
|
|
58
59
|
*/
|
|
59
60
|
writeRowMethod: (arg0: DataView, arg1: number, arg2: number[]) => void;
|
|
61
|
+
/**
|
|
62
|
+
* NOTE: capacity is set automatically
|
|
63
|
+
* NOTE: length is not set automatically, you have to do that yourself
|
|
64
|
+
* @param {ArrayBuffer|SharedArrayBuffer} buffer
|
|
65
|
+
*/
|
|
66
|
+
set array_buffer(arg: ArrayBuffer | SharedArrayBuffer);
|
|
60
67
|
/**
|
|
61
68
|
*
|
|
62
69
|
* @returns {number}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowFirstTable.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/table/RowFirstTable.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RowFirstTable.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/table/RowFirstTable.js"],"names":[],"mappings":"AAWA;IACI;;;;;OAKG;IACH,oDAHW,OAAO,EAuDjB;IA/CG;;;OAGG;IACH,wBAAgB;IAEhB;;;OAGG;IACH,gBAFU,qBAAsB,CAET;IAEvB;;;OAGG;IACH,MAFU,WAAW,CAEuB;IAE5C;;;OAGG;IACH,gBAFU,MAAM,CAEyB;IAEzC;;;OAGG;IACH,QAFU,MAAM,CAED;IAEf;;;OAGG;IACH,UAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,UAFU,QAAQ,CAEE;IAEpB;;MAEC;IAKL;;OAEG;IACH,mBAiBC;IAXG;;;OAGG;IACH,sBAFmB,QAAQ,QAAE,MAAM,QAAE,MAAM,EAAE,KAAG,IAAI,CAEb;IAEvC;;;OAGG;IACH,uBAFmB,QAAQ,QAAE,MAAM,QAAE,MAAM,EAAE,KAAG,IAAI,CAEX;IAG7C;;;;OAIG;IACH,uDAMC;IAED;;;OAGG;IACH,QAFa,MAAM,CA4BlB;IAED;;;OAGG;IACH,iCAoCC;IAED;;OAEG;IACH,aAEC;IAED;;;OAGG;IACH,iBAFW,MAAM,QAYhB;IAED;;;;;OAKG;IACH,yBAJW,MAAM,eACN,MAAM,SACN,MAAM,QAchB;IAED;;;;;OAKG;IACH,wBAJW,MAAM,eACN,MAAM,GACJ,MAAM,CAclB;IAED;;;;OAIG;IACH,kBAHW,MAAM,YACN,MAAM,QAyBhB;IAED;;;;;OAKG;IACH,kBAHW,MAAM,YACN,MAAM,QAqBhB;IAED;;;OAGG;IACH,eAFW,aAAc,QAgBxB;IAED;;;;OAIG;IACH,mDAiCC;IAED;;;;OAIG;IACH,YAFW,aAAa,QAsBvB;IAED;;;OAGG;IACH,cAHW,aAAa,GACX,OAAO,CAyBnB;IAED;;;;OAIG;IACH,wCAEC;IAED;;;;OAIG;IACH,cAHW,MAAM,UACN,MAAM,EAAE,QAIlB;IAED;;OAEG;IACH,qBA4BC;IAED;;OAEG;IACH,cAIC;IAED;;;OAGG;IACH,wBAEC;IAED;;;OAGG;IACH,cAFa,MAAM,EAAE,EAAE,CAgBtB;IAED;;OAEG;IACH,uBAIC;CACJ;mBA1fkB,+BAA+B"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { assert } from "../../assert.js";
|
|
7
|
+
import { makeArrayBuffer } from "../../binary/makeArrayBuffer.js";
|
|
7
8
|
import Signal from "../../events/signal/Signal.js";
|
|
8
9
|
import { max2 } from "../../math/max2.js";
|
|
9
10
|
import { array_copy } from "../array/array_copy.js";
|
|
@@ -12,9 +13,10 @@ export class RowFirstTable {
|
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
14
15
|
* @param {RowFirstTableSpec} spec
|
|
16
|
+
* @param {boolean} [shared_array] should we use SharedArrayBuffer instead of ArrayBuffer?
|
|
15
17
|
* @constructor
|
|
16
18
|
*/
|
|
17
|
-
constructor(spec) {
|
|
19
|
+
constructor(spec, shared_array = false) {
|
|
18
20
|
assert.defined(spec, 'spec');
|
|
19
21
|
assert.notNull(spec, 'spec');
|
|
20
22
|
assert.equal(spec.isRowFirstTableSpec, true, 'spec.isRowFirstTableSpec !== true');
|
|
@@ -35,7 +37,7 @@ export class RowFirstTable {
|
|
|
35
37
|
*
|
|
36
38
|
* @type {ArrayBuffer}
|
|
37
39
|
*/
|
|
38
|
-
this.data =
|
|
40
|
+
this.data = makeArrayBuffer(0, shared_array);
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
*
|
|
@@ -90,6 +92,19 @@ export class RowFirstTable {
|
|
|
90
92
|
this.writeRowMethod = spec.writeRowMethod;
|
|
91
93
|
}
|
|
92
94
|
|
|
95
|
+
/**
|
|
96
|
+
* NOTE: capacity is set automatically
|
|
97
|
+
* NOTE: length is not set automatically, you have to do that yourself
|
|
98
|
+
* @param {ArrayBuffer|SharedArrayBuffer} buffer
|
|
99
|
+
*/
|
|
100
|
+
set array_buffer(buffer) {
|
|
101
|
+
this.data = buffer;
|
|
102
|
+
this.dataView = new DataView(buffer);
|
|
103
|
+
|
|
104
|
+
this.capacity = Math.floor(buffer.byteLength / this.spec.bytesPerRecord);
|
|
105
|
+
this.length = 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
93
108
|
/**
|
|
94
109
|
*
|
|
95
110
|
* @returns {number}
|
|
@@ -132,7 +147,10 @@ export class RowFirstTable {
|
|
|
132
147
|
const bytesPerRecord = this.bytesPerRecord;
|
|
133
148
|
const byteSize = rowCount * bytesPerRecord;
|
|
134
149
|
try {
|
|
135
|
-
|
|
150
|
+
// can be either ArrayBuffer or SharedArrayBuffer
|
|
151
|
+
const BufferConstructor = this.data.constructor;
|
|
152
|
+
|
|
153
|
+
this.data = new BufferConstructor(byteSize);
|
|
136
154
|
} catch (e) {
|
|
137
155
|
throw new Error("failed to create a new array buffer of size: " + byteSize);
|
|
138
156
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class TableRecord {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} schema
|
|
5
|
+
*/
|
|
6
|
+
constructor(schema: any);
|
|
7
|
+
set value(arg: this);
|
|
8
|
+
get value(): this;
|
|
9
|
+
get table_schema(): RowFirstTableSpec;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {RowFirstTable} table
|
|
13
|
+
* @param {number} row_index
|
|
14
|
+
*/
|
|
15
|
+
bind(table: RowFirstTable, row_index: number): void;
|
|
16
|
+
#private;
|
|
17
|
+
}
|
|
18
|
+
import { RowFirstTableSpec } from "../RowFirstTableSpec.js";
|
|
19
|
+
//# sourceMappingURL=TableRecord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableRecord.d.ts","sourceRoot":"","sources":["../../../../../../src/core/collection/table/bind/TableRecord.js"],"names":[],"mappings":"AAGA;IAsDI;;;OAGG;IACH,yBAUC;IApBD,qBAIC;IARD,kBAEC;IAwBD,sCAEC;IAED;;;;OAIG;IACH,sCAFW,MAAM,QAKhB;;CACJ;kCArFiC,yBAAyB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
2
|
+
import { RowFirstTableSpec } from "../RowFirstTableSpec.js";
|
|
3
|
+
|
|
4
|
+
export class TableRecord {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @type {Object<number>}
|
|
9
|
+
*/
|
|
10
|
+
#key_index = {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {Object<BinaryDataType>}
|
|
14
|
+
*/
|
|
15
|
+
#schema;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {RowFirstTable}
|
|
19
|
+
*/
|
|
20
|
+
#table;
|
|
21
|
+
#row_index = 0;
|
|
22
|
+
|
|
23
|
+
#value = new Proxy(this, {
|
|
24
|
+
get: (target, property) => {
|
|
25
|
+
// resolve property to index
|
|
26
|
+
const keyIndex = this.#key_index[property];
|
|
27
|
+
|
|
28
|
+
if (keyIndex === undefined) {
|
|
29
|
+
throw new Error(`Property '${property}' is not part of this schema`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.#table.readCellValue(this.#row_index, keyIndex);
|
|
33
|
+
},
|
|
34
|
+
set: (target, property, value) => {
|
|
35
|
+
|
|
36
|
+
// resolve property to index
|
|
37
|
+
const keyIndex = this.#key_index[property];
|
|
38
|
+
|
|
39
|
+
if (keyIndex === undefined) {
|
|
40
|
+
throw new Error(`Property '${property}' is not part of this schema`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.#table.writeCellValue(this.#row_index, keyIndex, value);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
get value() {
|
|
49
|
+
return this.#value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
set value(object) {
|
|
53
|
+
for (const key in object) {
|
|
54
|
+
this.#value[key] = object[key];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param {Object} schema
|
|
61
|
+
*/
|
|
62
|
+
constructor(schema) {
|
|
63
|
+
assert.notNull(schema, 'schema');
|
|
64
|
+
assert.defined(schema, 'schema');
|
|
65
|
+
|
|
66
|
+
this.#schema = schema;
|
|
67
|
+
const keys = Object.keys(schema);
|
|
68
|
+
|
|
69
|
+
for (let i = 0; i < keys.length; i++) {
|
|
70
|
+
this.#key_index[keys[i]] = i;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get table_schema() {
|
|
75
|
+
return RowFirstTableSpec.get(Object.values(this.#schema));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param {RowFirstTable} table
|
|
81
|
+
* @param {number} row_index
|
|
82
|
+
*/
|
|
83
|
+
bind(table, row_index) {
|
|
84
|
+
this.#table = table;
|
|
85
|
+
this.#row_index = row_index;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableRecord.spec.d.ts","sourceRoot":"","sources":["../../../../../../src/core/collection/table/bind/TableRecord.spec.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BinaryDataType } from "../../../binary/type/BinaryDataType.js";
|
|
2
|
+
import { RowFirstTable } from "../RowFirstTable.js";
|
|
3
|
+
import { TableRecord } from "./TableRecord.js";
|
|
4
|
+
|
|
5
|
+
test("simple 2 field schema", () => {
|
|
6
|
+
|
|
7
|
+
const record = new TableRecord({
|
|
8
|
+
alice: BinaryDataType.Float32,
|
|
9
|
+
bob: BinaryDataType.Uint8
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const table = new RowFirstTable(record.table_schema);
|
|
13
|
+
|
|
14
|
+
table.resize(7);
|
|
15
|
+
|
|
16
|
+
record.bind(table, 0);
|
|
17
|
+
record.value = { alice: 7.2, bob: 42 };
|
|
18
|
+
|
|
19
|
+
record.bind(table, 3);
|
|
20
|
+
record.value = { alice: -11.5, bob: 31 };
|
|
21
|
+
|
|
22
|
+
expect(table.readCellValue(0, 0)).toBeCloseTo(7.2);
|
|
23
|
+
expect(table.readCellValue(0, 1)).toBe(42);
|
|
24
|
+
|
|
25
|
+
expect(table.readCellValue(3, 0)).toBeCloseTo(-11.5);
|
|
26
|
+
expect(table.readCellValue(3, 1)).toBe(31);
|
|
27
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityProxyScope.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/binding/EntityProxyScope.js"],"names":[],"mappings":"AA0CA;IAIQ;;;OAGG;IACH,QAFU,MAAM,CAEA;IAEhB;;;OAGG;IACH,4BAAe;IAEf,
|
|
1
|
+
{"version":3,"file":"EntityProxyScope.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/binding/EntityProxyScope.js"],"names":[],"mappings":"AA0CA;IAIQ;;;OAGG;IACH,QAFU,MAAM,CAEA;IAEhB;;;OAGG;IACH,4BAAe;IAEf,YAwBE;IAGN;;;;OAIG;IACH,eAHW,MAAM,qCAMhB;CAEJ"}
|