@woosh/meep-engine 2.88.2 → 2.88.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.
package/build/meep.cjs CHANGED
@@ -57551,6 +57551,12 @@ class TerrainTile {
57551
57551
  */
57552
57552
  __initial_height_range = new NumericInterval(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY);
57553
57553
 
57554
+ /**
57555
+ * Used to track number of times tile was built
57556
+ * @type {number}
57557
+ */
57558
+ version = 0;
57559
+
57554
57560
  constructor() {
57555
57561
 
57556
57562
  this.mesh.name = "TerrainTile";
@@ -58038,6 +58044,8 @@ class TerrainTile {
58038
58044
  // console.timeEnd('total');
58039
58045
  // console.groupEnd();
58040
58046
 
58047
+ this.version++;
58048
+
58041
58049
  return mesh;
58042
58050
  }
58043
58051
  }
@@ -58181,7 +58189,10 @@ class TerrainTileManager {
58181
58189
  for (let i = 0; i < n; i++) {
58182
58190
  const terrainTile = tiles[i];
58183
58191
 
58184
- if (!terrainTile.isBuilt && !terrainTile.isBuildInProgress) {
58192
+ if (
58193
+ !terrainTile.isBuilt
58194
+ && !terrainTile.isBuildInProgress
58195
+ ) {
58185
58196
 
58186
58197
  const bb = terrainTile.external_bvh;
58187
58198
 
@@ -58338,7 +58349,6 @@ class TerrainTileManager {
58338
58349
  }
58339
58350
 
58340
58351
  initializeTiles() {
58341
-
58342
58352
  const total_size = this.totalSize;
58343
58353
 
58344
58354
  const gridSize = total_size.clone();
@@ -58350,6 +58360,10 @@ class TerrainTileManager {
58350
58360
 
58351
58361
  const tiles = this.tiles;
58352
58362
 
58363
+ if (tiles.length > 0) {
58364
+ throw new Error(`There are already ${tiles.length} initialized tiles, those must be destroyed before initialization can happen`);
58365
+ }
58366
+
58353
58367
  //populate tiles
58354
58368
  const tile_resolution_y = gridSize.y;
58355
58369
  const tile_resolution_x = gridSize.x;
@@ -58653,13 +58667,20 @@ class TerrainTileManager {
58653
58667
  *
58654
58668
  * @param {number} x
58655
58669
  * @param {number} y
58656
- * @param {function} resolve
58657
- * @param {function} reject
58670
+ * @param {function(tile:TerrainTile)} resolve
58671
+ * @param {function(reason:*)} reject
58658
58672
  */
58659
58673
  build(x, y, resolve, reject) {
58660
58674
 
58661
- const tileIndex = this.computeTileIndex(x, y);
58662
- const tile = this.tiles[tileIndex];
58675
+ const tile_index = this.computeTileIndex(x, y);
58676
+
58677
+ const tile = this.tiles[tile_index];
58678
+
58679
+ if (tile.isBuildInProgress) {
58680
+ throw new Error('Tile is already in process of being built');
58681
+ }
58682
+
58683
+ const start_version = tile.version;
58663
58684
 
58664
58685
  tile.isBuilt = false;
58665
58686
  tile.isBuildInProgress = true;
@@ -58675,17 +58696,29 @@ class TerrainTileManager {
58675
58696
  ).then((tileData) => {
58676
58697
 
58677
58698
  //check that the tile under index is still the same tile
58678
- if (this.tiles[tileIndex] !== tile) {
58699
+ if (this.tiles[tile_index] !== tile) {
58679
58700
  //the original tile was destroyed
58680
58701
  reject('Original tile was destroyed during build process');
58681
58702
  return;
58682
58703
  }
58683
58704
 
58684
- if (!tile.isBuildInProgress) {
58685
- reject('Build request has been cancelled');
58705
+ if (tile.version !== start_version) {
58706
+ reject(`Tile version changed, likely due to concurrent build request. Expected version ${start_version}, actual version ${tile.version}`);
58686
58707
  return;
58687
58708
  }
58688
58709
 
58710
+ if (!tile.isBuildInProgress) {
58711
+ if (tile.isBuilt) {
58712
+ // tile already built
58713
+ resolve(tile);
58714
+ return;
58715
+ } else {
58716
+
58717
+ reject('Build request has been cancelled');
58718
+ return;
58719
+ }
58720
+ }
58721
+
58689
58722
  // const processName = 'building tile x = ' + x + ", y = " + y;
58690
58723
  // console.time(processName);
58691
58724
 
@@ -58707,7 +58740,14 @@ class TerrainTileManager {
58707
58740
  this.on.tileBuilt.send1(tile);
58708
58741
 
58709
58742
  resolve(tile);
58710
- }, reject);
58743
+ }, (reason) => {
58744
+
58745
+ tile.isBuilt = false;
58746
+ tile.isBuildInProgress = false;
58747
+
58748
+ reject(reason);
58749
+
58750
+ });
58711
58751
  }
58712
58752
  }
58713
58753