@woosh/meep-engine 2.91.1 → 2.91.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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.91.1",
8
+ "version": "2.91.2",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -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}
@@ -1 +1 @@
1
- {"version":3,"file":"RowFirstTable.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/table/RowFirstTable.js"],"names":[],"mappings":"AAUA;IACI;;;;OAIG;IACH,qCAoDC;IA/CG;;;OAGG;IACH,wBAAgB;IAEhB;;;OAGG;IACH,gBAFU,qBAAsB,CAET;IAEvB;;;OAGG;IACH,MAFU,WAAW,CAES;IAE9B;;;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;;;OAGG;IACH,QAFa,MAAM,CA4BlB;IAED;;;OAGG;IACH,iCAiCC;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;mBAzekB,+BAA+B"}
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;;;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;mBA7ekB,+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 = new ArrayBuffer(0);
40
+ this.data = makeArrayBuffer(0, shared_array);
39
41
 
40
42
  /**
41
43
  *
@@ -132,7 +134,10 @@ export class RowFirstTable {
132
134
  const bytesPerRecord = this.bytesPerRecord;
133
135
  const byteSize = rowCount * bytesPerRecord;
134
136
  try {
135
- this.data = new ArrayBuffer(byteSize);
137
+ // can be either ArrayBuffer or SharedArrayBuffer
138
+ const BufferConstructor = this.data.constructor;
139
+
140
+ this.data = new BufferConstructor(byteSize);
136
141
  } catch (e) {
137
142
  throw new Error("failed to create a new array buffer of size: " + byteSize);
138
143
  }
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TableRecord.spec.d.ts.map
@@ -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,YAuBE;IAGN;;;;OAIG;IACH,eAHW,MAAM,qCAMhB;CAEJ"}
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"}
@@ -75,6 +75,7 @@ export class EntityProxyScope {
75
75
  const type = typeof v;
76
76
  if (type === "object" && typeof v.set === "function") {
77
77
  v.set(value);
78
+ return true;
78
79
  } else {
79
80
  throw new Error(`Terminal property '${p}' is of wrong type`);
80
81
  }