@woosh/meep-engine 2.49.2 → 2.49.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.
Files changed (48) hide show
  1. package/package.json +1 -1
  2. package/src/core/bvh2/binary/IndexedBinaryBVH.spec.js +20 -0
  3. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.d.ts +4 -0
  4. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.spec.js +30 -0
  5. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +6 -1
  6. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +5 -1
  7. package/src/core/cache/Cache.d.ts +2 -0
  8. package/src/core/cache/Cache.js +1 -1
  9. package/src/core/cache/Cache.spec.js +19 -0
  10. package/src/core/codegen/LineBuilder.js +8 -1
  11. package/src/core/codegen/LineBuilder.spec.js +34 -0
  12. package/src/core/collection/array/arrayQuickSort.js +11 -2
  13. package/src/core/collection/array/array_contains_duplicates.js +6 -1
  14. package/src/core/collection/array/typed/is_typed_array_equals.js +13 -4
  15. package/src/core/collection/array/typed/is_typed_array_equals.spec.js +71 -0
  16. package/src/core/collection/table/RowFirstTable.js +1 -1
  17. package/src/core/collection/table/RowFirstTable.spec.js +36 -0
  18. package/src/core/collection/table/RowFirstTableSpec.js +3 -0
  19. package/src/core/color/hsv2rgb.js +8 -3
  20. package/src/core/color/hsv2rgb.spec.js +43 -0
  21. package/src/core/geom/3d/aabb/aabb3_array_intersects_ray_array.js +2 -1
  22. package/src/core/graph/SquareMatrix.js +1 -9
  23. package/src/core/{land → lang}/reactive/compileReactiveExpression.spec.js +2 -2
  24. package/src/core/model/reactive/trigger/ReactiveTrigger.js +1 -1
  25. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +1 -1
  26. package/src/engine/ecs/dynamic_actions/actions/definition/WhiteToBlackboardActionDescription.js +1 -1
  27. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.js +1 -1
  28. package/src/engine/ecs/fow/FogOfWarRevealer.js +0 -27
  29. package/src/engine/ecs/fow/serialization/FogOfWarRevealerSerializationAdapter.js +29 -0
  30. package/src/engine/ecs/transform/TransformSerializationAdapter.spec.js +28 -0
  31. package/src/engine/knowledge/database/StaticKnowledgeDataTable.spec.js +5 -0
  32. package/src/engine/options/Option.js +36 -14
  33. package/src/engine/options/Option.spec.js +69 -0
  34. package/src/engine/reference/v2/Reference.d.ts +2 -0
  35. package/src/engine/reference/v2/Reference.js +3 -0
  36. package/src/engine/reference/v2/Reference.spec.js +44 -0
  37. package/src/core/bvh2/bvh3/BVHNodeProxy.js +0 -53
  38. package/src/generation/GridGeneratorConfigurator.js +0 -0
  39. /package/src/core/{land → lang}/reactive/AbstractCachingParser.js +0 -0
  40. /package/src/core/{land → lang}/reactive/ReactiveOperatorType.js +0 -0
  41. /package/src/core/{land → lang}/reactive/compileReactiveExpression.js +0 -0
  42. /package/src/core/{land → lang}/reactive/nearley/Reactive.ne +0 -0
  43. /package/src/core/{land → lang}/reactive/pegjs/Reactive.peg +0 -0
  44. /package/src/core/{land → lang}/reactive/pegjs/ReactivePegCompiler.js +0 -0
  45. /package/src/core/{land → lang}/reactive/pegjs/ReactivePegParser.js +0 -0
  46. /package/src/core/{land → lang}/reactive/pegjs/parser.js +0 -0
  47. /package/src/core/{land → lang}/reactive/validateReactiveExpression.js +0 -0
  48. /package/src/generation/rules/{CellMatcherContainsTag.spec.js → CellMatcherLayerBitMaskTest.spec.js} +0 -0
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.49.2",
8
+ "version": "2.49.3",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -5,3 +5,23 @@ test("constructor does not throw", () => {
5
5
  });
6
6
 
7
7
 
8
+ test("build a tree with a single leaf", () => {
9
+ const bvh = new IndexedBinaryBVH();
10
+
11
+ bvh.initialize(1);
12
+ bvh.writeLeaf(0, -1, -3, -7, 11, 13, 17);
13
+
14
+ bvh.unsortedBuiltIntermediate();
15
+
16
+ expect(bvh.leafNodeCount).toBe(1);
17
+ expect(bvh.binaryNodeCount).toBe(0);
18
+
19
+ expect(bvh.x0).toBe(-1);
20
+ expect(bvh.y0).toBe(-3);
21
+ expect(bvh.z0).toBe(-7);
22
+
23
+ expect(bvh.x1).toBe(11);
24
+ expect(bvh.y1).toBe(13);
25
+ expect(bvh.z1).toBe(17);
26
+
27
+ });
@@ -13,6 +13,8 @@ export class ExplicitBinaryBoundingVolumeHierarchy {
13
13
 
14
14
  collect_nodes_all(destination: ArrayLike<number>, destination_offset: number): void
15
15
 
16
+ node_set_aabb_primitive(node_id: number, x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void
17
+
16
18
  node_set_aabb(node: number, aabb: ArrayLike<number>): void
17
19
 
18
20
  node_get_aabb(node: number, aabb: ArrayLike<number>): void
@@ -37,6 +39,8 @@ export class ExplicitBinaryBoundingVolumeHierarchy {
37
39
 
38
40
  node_get_height(node: number): number
39
41
 
42
+ swap_nodes(node_a_id: number, node_b_id: number): boolean
43
+
40
44
  release_all(): void
41
45
 
42
46
  trim(): void
@@ -218,3 +218,33 @@ test("node property setters/getters", () => {
218
218
 
219
219
  expect(actual_aabb).toEqual(Array.from(expected_aabb));
220
220
  });
221
+
222
+
223
+ test("node_set_aabb_primitive", () => {
224
+ const bvh = new ExplicitBinaryBoundingVolumeHierarchy();
225
+
226
+ const node = bvh.allocate_node();
227
+
228
+ bvh.node_set_aabb_primitive(node, -1, -3, -5, 7, 11, 13);
229
+
230
+ const aabb = [];
231
+
232
+ bvh.node_get_aabb(node, aabb);
233
+
234
+ expect(aabb).toEqual([-1, -3, -5, 7, 11, 13]);
235
+ });
236
+
237
+ test("swap two detached nodes", () => {
238
+ const bvh = new ExplicitBinaryBoundingVolumeHierarchy();
239
+
240
+ const a = bvh.allocate_node();
241
+ const b = bvh.allocate_node();
242
+
243
+ bvh.node_set_user_data(a, 7);
244
+ bvh.node_set_user_data(b, 11);
245
+
246
+ bvh.swap_nodes(a, b);
247
+
248
+ expect(bvh.node_get_user_data(a)).toBe(11);
249
+ expect(bvh.node_get_user_data(b)).toBe(7);
250
+ });
@@ -8,7 +8,12 @@ import { compute_triangle_group_aabb3 } from "../../../engine/graphics/sh3/path_
8
8
  * @param {number[]|Float32Array} positions_array
9
9
  * @param {number} [batch_size] can batch triangles in groups of up-to this many triangles per BVH leaf
10
10
  */
11
- export function ebvh_build_for_geometry_incremental(bvh, index_array, positions_array, batch_size = 1) {
11
+ export function ebvh_build_for_geometry_incremental(
12
+ bvh,
13
+ index_array, positions_array,
14
+ batch_size = 1
15
+ ) {
16
+
12
17
  bvh.release_all();
13
18
  const triangle_count = index_array.length / 3;
14
19
 
@@ -11,8 +11,12 @@ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
11
11
  * @param {number} destination_offset
12
12
  * @param {ExplicitBinaryBoundingVolumeHierarchy} bvh
13
13
  * @param {number} node
14
+ * @returns {number} number of collected elements
14
15
  */
15
- export function bvh_collect_user_data(destination, destination_offset, bvh, node) {
16
+ export function bvh_collect_user_data(
17
+ destination, destination_offset,
18
+ bvh, node
19
+ ) {
16
20
 
17
21
  if (node === NULL_NODE) {
18
22
  return 0;
@@ -33,6 +33,8 @@ export class Cache<K, V> {
33
33
 
34
34
  remove(k: K): boolean
35
35
 
36
+ evictOne(): boolean
37
+
36
38
  clear(): void
37
39
 
38
40
  drop(): void
@@ -18,7 +18,7 @@ export class Cache {
18
18
  * @param {function(value:Value):number} [valueWeigher= value=>1]
19
19
  * @param {function(Key):number} [keyHashFunction]
20
20
  * @param {function(Key, Key):boolean} [keyEqualityFunction]
21
- * @param {number} capacity initial capacity for the cache, helps prevent early resizing
21
+ * @param {number} [capacity] initial capacity for the cache, helps prevent early resizing
22
22
  * @constructor
23
23
  */
24
24
  constructor({
@@ -18,6 +18,19 @@ test("elements beyond capacity are evicted", () => {
18
18
 
19
19
  });
20
20
 
21
+ test("trying to insert an element into the cache that's larger than the cache capacity should result in the item not being inserted", () => {
22
+ const cache = new Cache({
23
+ maxWeight: 1,
24
+ keyWeigher(key) {
25
+ return key;
26
+ }
27
+ });
28
+
29
+ cache.put(2, "hello");
30
+
31
+ expect(cache.contains(2)).toBe(false);
32
+ });
33
+
21
34
  test("removeListener is called when element is evicted", () => {
22
35
 
23
36
  const removeListener = jest.fn();
@@ -140,3 +153,9 @@ test("clear with a single entry", () => {
140
153
  expect(cache.contains("x")).toBe(false);
141
154
 
142
155
  });
156
+
157
+ test("calling 'evictOne' on empty cache should return false", () => {
158
+ const cache = new Cache();
159
+
160
+ expect(cache.evictOne()).toBe(false);
161
+ });
@@ -39,6 +39,14 @@ class LineBuilder {
39
39
  */
40
40
  indentSpaces = DEFAULT_INDENT_SPACES;
41
41
 
42
+ /**
43
+ * Number of lines
44
+ * @return {number}
45
+ */
46
+ get count() {
47
+ return this.lines.length;
48
+ }
49
+
42
50
  /**
43
51
  *
44
52
  * @return {boolean}
@@ -115,7 +123,6 @@ class LineBuilder {
115
123
  clear() {
116
124
  this.lines = [];
117
125
  this.indentation = 0;
118
- this.indentSpaces = DEFAULT_INDENT_SPACES;
119
126
  }
120
127
 
121
128
  /**
@@ -5,3 +5,37 @@ test("Empty builder should produce empty string", () => {
5
5
 
6
6
  expect(b.build()).toEqual("");
7
7
  });
8
+
9
+ test("build simple indented fragment", () => {
10
+ const b = new LineBuilder();
11
+
12
+ b.indentSpaces = 1;
13
+
14
+ b.add('a');
15
+ b.indent();
16
+ b.add('b');
17
+ b.dedent();
18
+ b.add('c');
19
+
20
+ expect(b.build()).toEqual('a\n b\nc');
21
+ });
22
+
23
+ test("adding another line builder copies lines correctly", () => {
24
+ const a = new LineBuilder();
25
+
26
+ const b = new LineBuilder();
27
+
28
+ b.add('a');
29
+
30
+ a.addLines(b);
31
+
32
+ expect(a.build()).toEqual('a');
33
+ });
34
+
35
+ test("fromText parses correct number of lines", () => {
36
+
37
+ const builder = LineBuilder.fromText('a\nb');
38
+
39
+ expect(builder.count).toBe(2);
40
+
41
+ });
@@ -12,7 +12,12 @@ const stack = [];
12
12
  * @param {function(T[],number, number):*} [swap_operator]
13
13
  * @param {*} [swap_context]
14
14
  */
15
- export function arrayQuickSort(data, score_function, score_function_context, start, end, swap_operator = arraySwapElements, swap_context = undefined) {
15
+ export function arrayQuickSort(
16
+ data,
17
+ score_function, score_function_context,
18
+ start, end,
19
+ swap_operator = arraySwapElements, swap_context = undefined
20
+ ) {
16
21
  if (start >= end) {
17
22
  // section of 0 size, nothing to sort
18
23
  return;
@@ -79,7 +84,11 @@ export function arrayQuickSort(data, score_function, score_function_context, sta
79
84
  * @param {number} start
80
85
  * @param {number} end
81
86
  */
82
- export function array_quick_sort_by_comparator(data, compare_function, compare_function_context, start, end) {
87
+ export function array_quick_sort_by_comparator(
88
+ data,
89
+ compare_function, compare_function_context,
90
+ start, end
91
+ ) {
83
92
  if (start >= end) {
84
93
  // section of 0 size, nothing to sort
85
94
  return;
@@ -5,7 +5,12 @@
5
5
  * @param {number} [end_index] last index to be included in the search
6
6
  * @return {boolean}
7
7
  */
8
- export function array_contains_duplicates(source, start_index = 0, end_index = source.length - 1) {
8
+ export function array_contains_duplicates(
9
+ source,
10
+ start_index = 0,
11
+ end_index = source.length - 1
12
+ ) {
13
+
9
14
  for (let k = start_index; k <= end_index; k++) {
10
15
 
11
16
  const element = source[k];
@@ -3,11 +3,16 @@ import { isArrayEqualStrict } from "../isArrayEqualStrict.js";
3
3
 
4
4
  /**
5
5
  *
6
- * @param {Uint8Array} a
7
- * @param {Uint8Array} b
6
+ * @param {Uint8Array|Uint32Array} a
7
+ * @param {Uint8Array|Uint32Array} b
8
8
  * @returns {boolean}
9
9
  */
10
10
  export function is_typed_array_equals(a, b) {
11
+ if (a === b) {
12
+ // quick shortcut
13
+ return true;
14
+ }
15
+
11
16
  const a_length = a.length;
12
17
  const b_length = b.length;
13
18
 
@@ -26,13 +31,15 @@ export function is_typed_array_equals(a, b) {
26
31
  return false;
27
32
  }
28
33
 
29
- const bytes_per_element = a.constructor.BYTES_PER_ELEMENT;
34
+ const a_constructor = a.constructor;
35
+ const b_constructor = b.constructor;
30
36
 
31
- if (bytes_per_element !== b.constructor.BYTES_PER_ELEMENT) {
37
+ if (a_constructor !== b_constructor) {
32
38
  // incompatible constructors
33
39
  return false;
34
40
  }
35
41
 
42
+
36
43
  const a_buffer = a.buffer;
37
44
  const b_buffer = b.buffer;
38
45
 
@@ -45,6 +52,8 @@ export function is_typed_array_equals(a, b) {
45
52
  let a_proxy = a;
46
53
  let b_proxy = b;
47
54
 
55
+ const bytes_per_element = a_constructor.BYTES_PER_ELEMENT;
56
+
48
57
  if (bytes_per_element < 4 && byte_length % 4 === 0) {
49
58
  // 4 byte alignment, can use uint32
50
59
  a_proxy = new Uint32Array(a_buffer, a.byteOffset, byte_length / 4);
@@ -0,0 +1,71 @@
1
+ import { is_typed_array_equals } from "./is_typed_array_equals.js";
2
+
3
+ test("small uint32 arrays", () => {
4
+ expect(is_typed_array_equals(
5
+ new Uint32Array(0),
6
+ new Uint32Array(0)
7
+ )).toBe(true);
8
+
9
+ expect(is_typed_array_equals(
10
+ new Uint32Array([1, 3, 5]),
11
+ new Uint32Array([1, 3, 5])
12
+ )).toBe(true);
13
+
14
+ expect(is_typed_array_equals(
15
+ new Uint32Array([7, 3]),
16
+ new Uint32Array([1, 3])
17
+ )).toBe(false);
18
+
19
+ expect(is_typed_array_equals(
20
+ new Uint32Array([1, 3]),
21
+ new Uint32Array([7, 3])
22
+ )).toBe(false);
23
+
24
+ expect(is_typed_array_equals(
25
+ new Uint32Array([1, 7]),
26
+ new Uint32Array([1, 3])
27
+ )).toBe(false);
28
+
29
+ expect(is_typed_array_equals(
30
+ new Uint32Array([1, 3]),
31
+ new Uint32Array([1, 7])
32
+ )).toBe(false);
33
+
34
+ expect(is_typed_array_equals(
35
+ new Uint32Array([1, 3]),
36
+ new Uint32Array([1, 3, 7])
37
+ )).toBe(false);
38
+
39
+ expect(is_typed_array_equals(
40
+ new Uint32Array([1, 3, 7]),
41
+ new Uint32Array([1, 3])
42
+ )).toBe(false);
43
+
44
+ });
45
+
46
+ test("large uin32 array", () => {
47
+ expect(is_typed_array_equals(
48
+ new Uint32Array(1024),
49
+ new Uint32Array(1024),
50
+ )).toBe(true);
51
+
52
+ expect(is_typed_array_equals(
53
+ new Uint32Array(1024),
54
+ new Uint32Array(1023),
55
+ )).toBe(false);
56
+
57
+ expect(is_typed_array_equals(
58
+ new Uint32Array(1023),
59
+ new Uint32Array(1024),
60
+ )).toBe(false);
61
+
62
+ const a = new Uint32Array(1024);
63
+ const b = new Uint32Array(1024);
64
+
65
+ a[127] = 1;
66
+
67
+ expect(is_typed_array_equals(
68
+ a,
69
+ b,
70
+ )).toBe(false);
71
+ });
@@ -98,7 +98,7 @@ RowFirstTable.prototype.hash = function () {
98
98
 
99
99
  const byteLength = this.data.byteLength;
100
100
 
101
- const tap_count = 32;
101
+ const tap_count = 31;
102
102
 
103
103
  const step_size = max2(
104
104
  Math.floor(byteLength / (tap_count * 4)),
@@ -285,3 +285,39 @@ test('reverse_rows empty', () => {
285
285
 
286
286
  expect(a.length).toBe(0);
287
287
  });
288
+
289
+ test("hash on an empty ", () => {
290
+ const table = new RowFirstTable(new RowFirstTableSpec([BinaryDataType.Uint8]));
291
+
292
+ expect(() => table.hash()).not.toThrow();
293
+ expect(table.hash()).toEqual(table.hash());
294
+ expect(typeof table.hash() === "number").toBe(true);
295
+ expect(Number.isInteger(table.hash())).toBe(true);
296
+ });
297
+
298
+ test("equals method", () => {
299
+ const a = new RowFirstTable(new RowFirstTableSpec([BinaryDataType.Uint8]));
300
+ const b = new RowFirstTable(new RowFirstTableSpec([BinaryDataType.Uint8]));
301
+
302
+ expect(a.equals(b)).toBe(true);
303
+
304
+ a.addRow([1]);
305
+
306
+ expect(a.equals(b)).toBe(false);
307
+ expect(b.equals(a)).toBe(false);
308
+
309
+ b.addRow([3]);
310
+
311
+ expect(a.equals(b)).toBe(false);
312
+ });
313
+
314
+ test("toRowArray", () => {
315
+ const a = new RowFirstTable(new RowFirstTableSpec([BinaryDataType.Uint8, BinaryDataType.Float64]));
316
+ a.addRow([3, 7.11]);
317
+ a.addRow([5, 13.17]);
318
+
319
+ expect(a.toRowArray()).toEqual([
320
+ [3, 7.11],
321
+ [5, 13.17],
322
+ ]);
323
+ });
@@ -9,6 +9,7 @@ import { computeStringHash } from "../../primitives/strings/computeStringHash.js
9
9
  import { isArrayEqualStrict } from "../array/isArrayEqualStrict.js";
10
10
  import { BinaryDataType } from "../../binary/type/BinaryDataType.js";
11
11
  import { DataTypeByteSizes } from "../../binary/type/DataTypeByteSizes.js";
12
+ import { assert } from "../../assert.js";
12
13
 
13
14
  /**
14
15
  * @readonly
@@ -158,6 +159,8 @@ function genCellReader(type, offset, endianType = EndianType.BigEndian) {
158
159
  * @constructor
159
160
  */
160
161
  export function RowFirstTableSpec(types, endianType = EndianType.BigEndian) {
162
+ assert.isArray(types, 'types');
163
+
161
164
  const numTypes = types.length;
162
165
 
163
166
  /**
@@ -10,22 +10,27 @@ import { float2uint8 } from "../binary/float2uint8.js";
10
10
  */
11
11
  export function hsv2rgb(h, s, v) {
12
12
 
13
- let _h = h % 1;
13
+ let _h = h;
14
14
 
15
15
  if (_h < 0) {
16
- _h = h + 1;
16
+ _h = _h + Math.ceil(Math.abs(_h));
17
17
  }
18
18
 
19
+ _h = _h % 1;
20
+
19
21
  const _s = clamp01(s);
20
22
  const _v = clamp01(v);
21
23
 
22
24
  let r, g, b, i, f, p, q, t;
23
25
 
24
- i = Math.floor(h * 6);
26
+ i = Math.floor(_h * 6);
27
+
25
28
  f = _h * 6 - i;
29
+
26
30
  p = _v * (1 - _s);
27
31
  q = _v * (1 - f * _s);
28
32
  t = _v * (1 - (1 - f) * _s);
33
+
29
34
  switch (i % 6) {
30
35
  case 0:
31
36
  r = _v, g = t, b = p;
@@ -0,0 +1,43 @@
1
+ import { hsv2rgb } from "./hsv2rgb.js";
2
+
3
+ function validate_element(number) {
4
+ expect(typeof number).toBe('number');
5
+ expect(Number.isNaN(number)).toBe(false);
6
+
7
+ expect(number).toBeLessThanOrEqual(255);
8
+ expect(number).toBeGreaterThanOrEqual(0);
9
+ }
10
+
11
+ function validate_rgb(rgb) {
12
+ expect(rgb).not.toBeUndefined();
13
+ expect(rgb).not.toBeNull();
14
+ expect(typeof rgb).toBe('object');
15
+
16
+ validate_element(rgb.r);
17
+ validate_element(rgb.g);
18
+ validate_element(rgb.b);
19
+ }
20
+
21
+ test("sanity test", () => {
22
+
23
+ validate_rgb(hsv2rgb(0, 0, 0));
24
+ validate_rgb(hsv2rgb(0, 0, 1));
25
+ validate_rgb(hsv2rgb(0, 1, 0));
26
+ validate_rgb(hsv2rgb(0, 1, 1));
27
+ validate_rgb(hsv2rgb(1, 0, 0));
28
+ validate_rgb(hsv2rgb(1, 0, 1));
29
+ validate_rgb(hsv2rgb(1, 1, 0));
30
+ validate_rgb(hsv2rgb(1, 1, 1));
31
+
32
+ validate_rgb(hsv2rgb(0.5, 0.5, 0.5));
33
+
34
+ validate_rgb(hsv2rgb(0.1, 0.5, 0.5));
35
+ validate_rgb(hsv2rgb(0.2, 0.5, 0.5));
36
+ validate_rgb(hsv2rgb(0.3, 0.5, 0.5));
37
+ validate_rgb(hsv2rgb(0.4, 0.5, 0.5));
38
+ validate_rgb(hsv2rgb(0.6, 0.5, 0.5));
39
+ validate_rgb(hsv2rgb(0.7, 0.5, 0.5));
40
+ validate_rgb(hsv2rgb(0.8, 0.5, 0.5));
41
+ validate_rgb(hsv2rgb(0.9, 0.5, 0.5));
42
+
43
+ });
@@ -7,7 +7,8 @@ import { aabb3_intersects_ray } from "./aabb3_intersects_ray.js";
7
7
  * @returns {boolean}
8
8
  */
9
9
  export function aabb3_array_intersects_ray_array(aabb, ray) {
10
- return aabb3_intersects_ray(aabb[0], aabb[1], aabb[2], aabb[3], aabb[4], aabb[5],
10
+ return aabb3_intersects_ray(
11
+ aabb[0], aabb[1], aabb[2], aabb[3], aabb[4], aabb[5],
11
12
  ray[0], ray[1], ray[2],
12
13
  ray[3], ray[4], ray[5]
13
14
  );
@@ -53,15 +53,7 @@ export class SquareMatrix {
53
53
  * @param {SquareMatrix} other
54
54
  */
55
55
  subtract(other) {
56
- const size = this.size;
57
- const data_length = size * size;
58
-
59
- const this_data = this.data;
60
- const other_data = other.data;
61
-
62
- for (let i = 0; i < data_length; i++) {
63
- this_data[i] -= other_data[i];
64
- }
56
+ this.subtractMatrices(this,other);
65
57
  }
66
58
 
67
59
  /**
@@ -9,11 +9,11 @@ import { ReactiveGreaterThanOrEqual } from "../../model/reactive/model/comparati
9
9
  import { ReactiveLessThan } from "../../model/reactive/model/comparative/ReactiveLessThan.js";
10
10
  import { ReactiveLessThanOrEqual } from "../../model/reactive/model/comparative/ReactiveLessThanOrEqual.js";
11
11
  import { ReactiveNotEquals } from "../../model/reactive/model/comparative/ReactiveNotEquals.js";
12
- import { ReactiveAnd } from "../../model/reactive/model/logic/ReactiveAnd.d.ts";
12
+ import { ReactiveAnd } from "../../model/reactive/model/logic/ReactiveAnd.js";
13
13
  import { ReactiveNot } from "../../model/reactive/model/logic/ReactiveNot.js";
14
14
  import { ReactiveOr } from "../../model/reactive/model/logic/ReactiveOr.js";
15
15
  import { ReactiveLiteralNumber } from "../../model/reactive/model/terminal/ReactiveLiteralNumber.js";
16
- import { ReactiveReference } from "../../model/reactive/model/terminal/ReactiveReference.d.ts";
16
+ import { ReactiveReference } from "../../model/reactive/model/terminal/ReactiveReference.js";
17
17
  import { compileReactiveExpression } from "./compileReactiveExpression.js";
18
18
 
19
19
  test('compile: REFERENCE', () => {
@@ -1,5 +1,5 @@
1
1
  import { assert } from "../../../assert.js";
2
- import { compileReactiveExpression } from "../../../land/reactive/compileReactiveExpression.js";
2
+ import { compileReactiveExpression } from "../../../lang/reactive/compileReactiveExpression.js";
3
3
  import DataType from "../../../parser/simple/DataType.js";
4
4
  import { inferReactiveExpressionTypes } from "../transform/ReactiveTypeInferrence.js";
5
5
 
@@ -2,7 +2,7 @@ import { AbstractActionDescription } from "./AbstractActionDescription.js";
2
2
  import { assert } from "../../../../../core/assert.js";
3
3
  import { ActionBehavior } from "../../../../intelligence/behavior/primitive/ActionBehavior.js";
4
4
  import { Transform } from "../../../transform/Transform.js";
5
- import { compileReactiveExpression } from "../../../../../core/land/reactive/compileReactiveExpression.js";
5
+ import { compileReactiveExpression } from "../../../../../core/lang/reactive/compileReactiveExpression.js";
6
6
 
7
7
  export class SendRequestActionDescription extends AbstractActionDescription {
8
8
  constructor() {
@@ -1,7 +1,7 @@
1
1
  import { AbstractActionDescription } from "./AbstractActionDescription.js";
2
2
  import { ActionBehavior } from "../../../../intelligence/behavior/primitive/ActionBehavior.js";
3
3
  import { Blackboard } from "../../../../intelligence/blackboard/Blackboard.js";
4
- import { compileReactiveExpression } from "../../../../../core/land/reactive/compileReactiveExpression.js";
4
+ import { compileReactiveExpression } from "../../../../../core/lang/reactive/compileReactiveExpression.js";
5
5
  import { assert } from "../../../../../core/assert.js";
6
6
 
7
7
  export class WhiteToBlackboardActionDescription extends AbstractActionDescription {
@@ -2,7 +2,7 @@ import UUID from "../../../../core/UUID.js";
2
2
  import { assert } from "../../../../core/assert.js";
3
3
  import { inferReactiveExpressionTypes } from "../../../../core/model/reactive/transform/ReactiveTypeInferrence.js";
4
4
  import DataType from "../../../../core/parser/simple/DataType.js";
5
- import { compileReactiveExpression } from "../../../../core/land/reactive/compileReactiveExpression.js";
5
+ import { compileReactiveExpression } from "../../../../core/lang/reactive/compileReactiveExpression.js";
6
6
  import { deserializeActionFromJSON } from "../actions/definition/deserializeActionFromJSON.js";
7
7
  import { DynamicRuleCooldownDescription } from "./DynamicRuleCooldownDescription.js";
8
8
 
@@ -1,5 +1,4 @@
1
1
  import Vector1 from "../../../core/geom/Vector1.js";
2
- import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
3
2
 
4
3
  export class FogOfWarRevealer {
5
4
  constructor() {
@@ -28,29 +27,3 @@ export class FogOfWarRevealer {
28
27
  FogOfWarRevealer.typeName = 'FogOfWarRevealer';
29
28
 
30
29
 
31
- export class FogOfWarRevealerSerializationAdapter extends BinaryClassSerializationAdapter {
32
- constructor() {
33
- super();
34
-
35
- this.klass = FogOfWarRevealer;
36
- this.version = 0;
37
- }
38
-
39
- /**
40
- *
41
- * @param {BinaryBuffer} buffer
42
- * @param {FogOfWarRevealer} value
43
- */
44
- serialize(buffer, value) {
45
- value.radius.toBinaryBuffer(buffer);
46
- }
47
-
48
- /**
49
- *
50
- * @param {BinaryBuffer} buffer
51
- * @param {FogOfWarRevealer} value
52
- */
53
- deserialize(buffer, value) {
54
- value.radius.fromBinaryBuffer(buffer);
55
- }
56
- }
@@ -0,0 +1,29 @@
1
+ import { BinaryClassSerializationAdapter } from "../../storage/binary/BinaryClassSerializationAdapter.js";
2
+ import { FogOfWarRevealer } from "../FogOfWarRevealer.js";
3
+
4
+ export class FogOfWarRevealerSerializationAdapter extends BinaryClassSerializationAdapter {
5
+ constructor() {
6
+ super();
7
+
8
+ this.klass = FogOfWarRevealer;
9
+ this.version = 0;
10
+ }
11
+
12
+ /**
13
+ *
14
+ * @param {BinaryBuffer} buffer
15
+ * @param {FogOfWarRevealer} value
16
+ */
17
+ serialize(buffer, value) {
18
+ value.radius.toBinaryBuffer(buffer);
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @param {BinaryBuffer} buffer
24
+ * @param {FogOfWarRevealer} value
25
+ */
26
+ deserialize(buffer, value) {
27
+ value.radius.fromBinaryBuffer(buffer);
28
+ }
29
+ }
@@ -0,0 +1,28 @@
1
+ import { TransformSerializationAdapter } from "./TransformSerializationAdapter.js";
2
+ import { Transform } from "./Transform.js";
3
+ import { BinaryBuffer } from "../../../core/binary/BinaryBuffer.js";
4
+
5
+ test("to/from consistency", () => {
6
+ const adapter = new TransformSerializationAdapter();
7
+
8
+ const expected = new Transform();
9
+ expected.position.set(1, 3, -7.3);
10
+ expected.scale.set(-5, 7, -13.8);
11
+ expected.rotation.set(17, -27, 31, 37);
12
+
13
+ expected.rotation.normalize();
14
+
15
+ const buffer = new BinaryBuffer();
16
+
17
+ adapter.serialize(buffer, expected);
18
+
19
+ buffer.position = 0;
20
+
21
+ const actual = new Transform();
22
+
23
+ adapter.deserialize(buffer, actual);
24
+
25
+ expect(actual.position.roughlyEquals(expected.position)).toBe(true);
26
+ expect(actual.scale.roughlyEquals(expected.scale)).toBe(true);
27
+ expect(actual.rotation.roughlyEquals(expected.rotation, 0.001)).toBe(true);
28
+ });
@@ -0,0 +1,5 @@
1
+ import { StaticKnowledgeDataTable } from "./StaticKnowledgeDataTable.js";
2
+
3
+ test("constructor does not throw", () => {
4
+ expect(() => new StaticKnowledgeDataTable()).not.toThrow();
5
+ });
@@ -1,8 +1,16 @@
1
1
  import { noop } from "../../core/function/Functions.js";
2
2
  import Signal from "../../core/events/signal/Signal.js";
3
3
  import { OptionAbstract } from "./OptionAbstract.js";
4
+ import { assert } from "../../core/assert.js";
4
5
 
5
6
  export class Option extends OptionAbstract {
7
+
8
+ on = {
9
+ written: new Signal(),
10
+ writeFailed: new Signal(),
11
+ settingsUpdated: new Signal()
12
+ };
13
+
6
14
  /**
7
15
  *
8
16
  * @param {string} id
@@ -16,18 +24,32 @@ export class Option extends OptionAbstract {
16
24
  }) {
17
25
  super(id);
18
26
 
27
+ assert.isFunction(read, 'read');
28
+
19
29
  const self = this;
20
30
 
21
31
  function wrappedWrite(v) {
22
- const result = write(v);
23
-
24
- if (result !== undefined && typeof result.then === "function") {
25
- result.then(
26
- () => self.on.written.dispatch(v),
27
- (e) => self.on.writeFailed.dispatch(v, e)
28
- );
29
- } else {
30
- self.on.written.dispatch(v);
32
+ let result;
33
+
34
+ let exception_thrown = false;
35
+
36
+ try {
37
+ result = write(v);
38
+ } catch (e) {
39
+ exception_thrown = true;
40
+
41
+ self.on.writeFailed.send2(v, e);
42
+ }
43
+
44
+ if (!exception_thrown) {
45
+ if (result !== undefined && typeof result.then === "function") {
46
+ result.then(
47
+ () => self.on.written.send1(v),
48
+ (e) => self.on.writeFailed.send2(v, e)
49
+ );
50
+ } else {
51
+ self.on.written.send1(v);
52
+ }
31
53
  }
32
54
 
33
55
  return result;
@@ -43,13 +65,13 @@ export class Option extends OptionAbstract {
43
65
  */
44
66
  this.isTransient = (settings.transient === true);
45
67
 
46
- this.on = {
47
- written: new Signal(),
48
- writeFailed: new Signal(),
49
- settingsUpdated: new Signal()
50
- };
51
68
  }
52
69
 
70
+ /**
71
+ *
72
+ * @param {string} key
73
+ * @param {number|boolean|string} value
74
+ */
53
75
  setSetting(key, value) {
54
76
  this.settings[key] = value;
55
77
 
@@ -0,0 +1,69 @@
1
+ import { Option } from "./Option.js";
2
+ import { returnOne } from "../../core/function/Functions.js";
3
+
4
+ test("constructing a simple valid option", () => {
5
+ const option = new Option("x", returnOne);
6
+
7
+ expect(option.id).toEqual('x');
8
+ });
9
+
10
+ test("'written' signal is invoked after write succeeds", () => {
11
+
12
+ let value = 13;
13
+
14
+ const opt = new Option("x", () => value, v => value = v);
15
+
16
+ const callback = jest.fn();
17
+
18
+ opt.on.written.add(callback);
19
+
20
+ opt.write(7);
21
+
22
+ expect(callback).toHaveBeenCalledTimes(1);
23
+
24
+ });
25
+
26
+ test("'writeFailed' signal is invoked after write throws", () => {
27
+
28
+ let value = 13;
29
+
30
+ const opt = new Option("x", () => value, v => value = v);
31
+
32
+ const callback = jest.fn();
33
+
34
+ opt.on.written.add(callback);
35
+
36
+ opt.write(7);
37
+
38
+ expect(callback).toHaveBeenCalledTimes(1);
39
+ });
40
+
41
+ test("toJSON", () => {
42
+
43
+ let value = 13;
44
+
45
+ const opt = new Option("x", () => value, v => value = v);
46
+
47
+ expect(opt.toJSON()).toBe(13);
48
+
49
+ });
50
+
51
+ test("fromJSON", () => {
52
+
53
+ let value = 1;
54
+
55
+ const opt = new Option("x", () => value, v => value = v);
56
+
57
+ opt.fromJSON(17);
58
+
59
+ expect(value).toBe(17);
60
+
61
+
62
+ });
63
+
64
+ test("computePath on a detached option should be just the ID of that option", () => {
65
+ const op = new Option("x", returnOne);
66
+
67
+ expect(op.computePath()).toEqual(["x"]);
68
+ });
69
+
@@ -3,6 +3,8 @@ import Signal from "../../../core/events/signal/Signal";
3
3
  export class Reference<T> {
4
4
  readonly onReleased: Signal<Reference<T>, T>
5
5
 
6
+ readonly bound: boolean
7
+
6
8
  getValue(): T | null
7
9
 
8
10
  release(): void
@@ -27,6 +27,9 @@ export class Reference {
27
27
  */
28
28
  #is_bound = false;
29
29
 
30
+ get bound(){
31
+ return this.#is_bound;
32
+ }
30
33
 
31
34
  /**
32
35
  *
@@ -0,0 +1,44 @@
1
+ import { Reference } from "./Reference.js";
2
+
3
+ test("constructor does not throw", () => {
4
+ expect(() => new Reference()).not.toThrow();
5
+ });
6
+
7
+ test("newly created reference is unbound", () => {
8
+
9
+ const ref = new Reference();
10
+
11
+ expect(ref.bound).toBe(false);
12
+
13
+ });
14
+
15
+ test("bind sets value", () => {
16
+ const ref = new Reference();
17
+
18
+ ref.bind(7);
19
+
20
+ expect(ref.getValue()).toBe(7);
21
+ expect(ref.bound).toBe(true);
22
+ });
23
+
24
+ test("re-binding a live reference throws an exception", () => {
25
+
26
+ const ref = new Reference();
27
+
28
+ ref.bind(7);
29
+
30
+ expect(() => ref.bind(13)).toThrow();
31
+
32
+ });
33
+
34
+ test("release resets reference", () => {
35
+
36
+ const ref = new Reference();
37
+
38
+ ref.bind(7);
39
+
40
+ ref.release();
41
+
42
+ expect(ref.getValue()).toBeNull();
43
+ expect(ref.bound).toBe(false);
44
+ });
@@ -1,53 +0,0 @@
1
- export class BVHNodeProxy {
2
- constructor() {
3
- /**
4
- *
5
- * @type {number}
6
- * @private
7
- */
8
- this.__node = -1;
9
-
10
- /**
11
- *
12
- * @type {ExplicitBinaryBoundingVolumeHierarchy|null}
13
- * @private
14
- */
15
- this.__tree = null;
16
- }
17
-
18
- /**
19
- *
20
- * @param {number} node
21
- * @param {ExplicitBinaryBoundingVolumeHierarchy} tree
22
- */
23
- bind(node, tree) {
24
- this.__node = node;
25
- this.__tree = tree;
26
- }
27
-
28
- /**
29
- *
30
- * @param {number} x0
31
- * @param {number} y0
32
- * @param {number} z0
33
- * @param {number} x1
34
- * @param {number} y1
35
- * @param {number} z1
36
- */
37
- set_bounds(x0, y0, z0, x1, y1, z1) {
38
- this.__tree.node_set_aabb_primitive(this.__node,
39
- x0, y0, z0, x1, y1, z1
40
- );
41
- }
42
-
43
- disconnect() {
44
- this.__tree.remove_leaf(this.__node);
45
- }
46
-
47
- destroy() {
48
- this.__tree.release_node(this.__node);
49
-
50
- this.__tree = null;
51
- this.__node = -1;
52
- }
53
- }
File without changes