@woosh/meep-engine 2.43.23 → 2.43.24

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/editor/Editor.js CHANGED
@@ -71,8 +71,8 @@ import { ObservedIntegerEditor } from "./ecs/component/editors/ObservedIntegerEd
71
71
 
72
72
  import '../../../../css/editor/EntityEditorView.scss';
73
73
  import '../../../../css/editor/EditorView.scss';
74
- import {ParameterTrackSet} from "../engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.js";
75
- import {ParameterTrackSetEditor} from "./ecs/component/editors/ecs/ParameterTrackSetEditor.js";
74
+ import { ParameterTrackSet } from "../engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.js";
75
+ import { ParameterTrackSetEditor } from "./ecs/component/editors/ecs/ParameterTrackSetEditor.js";
76
76
 
77
77
  /**
78
78
  * @template T
@@ -485,6 +485,7 @@ function Editor() {
485
485
  resetSoundEmitterTracks(dataset);
486
486
 
487
487
  const serializer = new BinaryBufferSerializer();
488
+ serializer.engine = self.engine;
488
489
  serializer.registry = engine.binarySerializationRegistry;
489
490
 
490
491
  const state = new EncodingBinaryBuffer();
@@ -29,6 +29,8 @@ import { noop } from "../core/function/Functions.js";
29
29
  import SoundListenerSystem from "./sound/ecs/SoundListenerSystem.js";
30
30
  import SoundListener from "./sound/ecs/SoundListener.js";
31
31
  import { getURLHash } from "./platform/GetURLHash.js";
32
+ import Stats from "three/examples/jsm/libs/stats.module.js";
33
+ import EmptyView from "../view/elements/EmptyView.js";
32
34
 
33
35
  /**
34
36
  *
@@ -68,6 +70,22 @@ export class EngineHarness {
68
70
  this.p = null;
69
71
  }
70
72
 
73
+ /**
74
+ *
75
+ * @param {Engine} engine
76
+ */
77
+ static addFpsCounter(engine) {
78
+ const stats = new Stats();
79
+
80
+ engine.graphics.on.postRender.add(stats.update, stats);
81
+
82
+ const view = new EmptyView({
83
+ el: stats.domElement
84
+ });
85
+
86
+ engine.viewStack.addChild(view);
87
+ }
88
+
71
89
  /**
72
90
  * @param {(config:EngineConfiguration,engine:Engine)=>*} configuration
73
91
  * @param {boolean} [enable_localization] Whether or not to load localization data
@@ -228,6 +246,7 @@ export class EngineHarness {
228
246
  * @param {boolean} [cameraController=true]
229
247
  * @param {boolean} [cameraAutoClip]
230
248
  * @param shadowmapResolution
249
+ * @param showFps
231
250
  */
232
251
  static async buildBasics({
233
252
  engine,
@@ -246,9 +265,14 @@ export class EngineHarness {
246
265
  cameraFarDistance,
247
266
  cameraController = true,
248
267
  cameraAutoClip = false,
249
- shadowmapResolution
268
+ shadowmapResolution,
269
+ showFps = true
250
270
  }) {
251
271
 
272
+ if (showFps) {
273
+ EngineHarness.addFpsCounter(engine);
274
+ }
275
+
252
276
  if (enableLights) {
253
277
  await EngineHarness.buildLights({ engine: engine, shadowmapResolution });
254
278
  }
@@ -8,9 +8,13 @@ import { assert } from "../../../core/assert.js";
8
8
  */
9
9
  export function camera_compute_distance_to_fit_length(length, fov) {
10
10
  assert.isNumber(length, 'length');
11
+ assert.greaterThanOrEqual(length, 0, 'length < 0');
12
+
11
13
  assert.isNumber(fov, 'fov');
12
14
  assert.greaterThan(fov, 0, 'fov <= 0');
13
15
  assert.lessThan(fov, Math.PI, 'fov >= pi');
14
16
 
15
- return Math.abs((length / 2) / Math.sin(fov / 2));
17
+ const signed_distance = (length * 0.5) / Math.tan(fov * 0.5);
18
+
19
+ return Math.abs(signed_distance);
16
20
  }
@@ -1,3 +1,29 @@
1
+ import { array_quick_sort_by_comparator } from "../../../../../../core/collection/array/arrayQuickSort.js";
2
+
3
+ /**
4
+ *
5
+ * @param {THREE.Object3D} a
6
+ * @param {THREE.Object3D} b
7
+ * @returns {number}
8
+ */
9
+ function compare_by_material(a, b) {
10
+
11
+ const a_mat = a.material;
12
+ const b_mat = b.material;
13
+
14
+ if (a_mat === b_mat) {
15
+ return 0;
16
+ }
17
+
18
+ if (a_mat === undefined) {
19
+ return 1;
20
+ } else if (b_mat === undefined) {
21
+ return -1;
22
+ }
23
+
24
+ return a_mat.id - b_mat.id;
25
+ }
26
+
1
27
  export class AbstractRenderAdapter {
2
28
  constructor() {
3
29
 
@@ -16,6 +42,13 @@ export class AbstractRenderAdapter {
16
42
  this.__objects = [];
17
43
  }
18
44
 
45
+ /**
46
+ * Sorting objects by material will help reduce context switching and number of graphics API calls
47
+ */
48
+ sort_by_material() {
49
+ array_quick_sort_by_comparator(this.__objects, compare_by_material, null, 0, this.__object_count - 1);
50
+ }
51
+
19
52
  /**
20
53
  *
21
54
  * @param {THREE.BufferGeometry} geometry
@@ -110,6 +110,7 @@ async function main(engine) {
110
110
  // sg.draw_method = 2;
111
111
  // sg.draw_method = DRAW_METHOD_INSTANCED;
112
112
  // sg.draw_method = random() > 0.5 ? DRAW_METHOD_INSTANCED : 2;
113
+ sg.setFlag(ShadedGeometryFlags.DrawMethodLocked);
113
114
  sg.clearFlag(ShadedGeometryFlags.CastShadow | ShadedGeometryFlags.ReceiveShadow);
114
115
 
115
116
  new EntityBuilder()
@@ -1,7 +1,6 @@
1
1
  import { BinaryBuffer } from "../../core/binary/BinaryBuffer.js";
2
2
  import BinaryBufferDeSerializer from "../ecs/storage/BinaryBufferDeSerializer.js";
3
-
4
- const scratch_buffer = new BinaryBuffer();
3
+ import { BinaryObjectSerializationAdapter } from "../ecs/storage/binary/object/BinaryObjectSerializationAdapter.js";
5
4
 
6
5
  class LocalAPI {
7
6
  /**
@@ -10,8 +9,23 @@ class LocalAPI {
10
9
  */
11
10
  engine = null;
12
11
 
12
+ _object_serde = new BinaryObjectSerializationAdapter();
13
+
14
+ get _registry() {
15
+ return this.engine.binarySerializationRegistry;
16
+ }
17
+
13
18
  /**
14
19
  *
20
+ * @return {EntityComponentDataset}
21
+ * @private
22
+ */
23
+ get _current_dataset() {
24
+ return this.engine.entityManager.dataset;
25
+ }
26
+
27
+ /**
28
+ * Server sent us a new world state
15
29
  * @param {BinaryBuffer} buffer
16
30
  */
17
31
  async writeCurrentSceneDataset(buffer) {
@@ -19,7 +33,9 @@ class LocalAPI {
19
33
 
20
34
  const engine = this.engine;
21
35
 
22
- const ecd = engine.entityManager.dataset;
36
+ deSerializer.registry = this._registry;
37
+
38
+ const ecd = this._current_dataset;
23
39
 
24
40
  ecd.clear();
25
41
 
@@ -31,6 +47,30 @@ class LocalAPI {
31
47
 
32
48
  await p;
33
49
  }
50
+
51
+ /**
52
+ *
53
+ * @param {BinaryBuffer} buffer
54
+ * @return {Promise<void>}
55
+ */
56
+ async createEntity(buffer) {
57
+ // create entity on the current scene with a given ID
58
+
59
+ const entity_id = buffer.readUintVar();
60
+
61
+ this._current_dataset.createEntitySpecific(entity_id);
62
+ }
63
+
64
+ async addComponentToEntity(buffer) {
65
+ const entity_id = buffer.readUintVar();
66
+
67
+ this._object_serde.registry = this._registry;
68
+ const component_instance = this._object_serde.deserialize(buffer);
69
+
70
+ this._current_dataset.addComponentToEntity(entity_id, component_instance);
71
+
72
+ }
73
+
34
74
  }
35
75
 
36
76
  export class RemoteController {
@@ -59,10 +99,10 @@ export class RemoteController {
59
99
  async __handle_message(data) {
60
100
  // console.log(`received message `, data);
61
101
 
62
- scratch_buffer.fromArrayBuffer(data);
102
+ const buffer = BinaryBuffer.fromArrayBuffer(data);
63
103
 
64
104
  // read packet ID
65
- const packet_id = scratch_buffer.readUTF8String();
105
+ const packet_id = buffer.readUTF8String();
66
106
 
67
107
  console.log(`packet ID: ${packet_id}`);
68
108
 
@@ -72,7 +112,7 @@ export class RemoteController {
72
112
  }
73
113
 
74
114
  try {
75
- await this.localAPI[packet_id](scratch_buffer);
115
+ await this.localAPI[packet_id](buffer);
76
116
  } catch (e) {
77
117
  //
78
118
  console.error(`Failed to process remote call to '${packet_id}':`, e);
@@ -1,6 +1,7 @@
1
1
  import { EngineHarness } from "../EngineHarness.js";
2
2
  import { RemoteController } from "./RemoteController.js";
3
3
  import { ShadedGeometrySystem } from "../graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
4
+ import { initializeGameBinarySerializationRegistry } from "../../../model/game/GameBinarySerializationRegistry.js";
4
5
 
5
6
  const harness = new EngineHarness();
6
7
 
@@ -15,6 +16,8 @@ async function main(engine) {
15
16
  engine
16
17
  });
17
18
 
19
+ initializeGameBinarySerializationRegistry(engine.binarySerializationRegistry);
20
+
18
21
  const remote = new RemoteController();
19
22
 
20
23
  remote.attach(engine);
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.43.23",
8
+ "version": "2.43.24",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",