@adatechnology/game-terrain 0.9.10 → 0.9.12

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/dist/index.js CHANGED
@@ -409,6 +409,7 @@ var REST_GAP = 0.01;
409
409
  function createDebrisStore(max) {
410
410
  const list = [];
411
411
  let serial = 0;
412
+ let version = 0;
412
413
  function makeRoom() {
413
414
  if (list.length < max()) return;
414
415
  let at = 0;
@@ -429,7 +430,11 @@ function createDebrisStore(max) {
429
430
  }
430
431
  return {
431
432
  list,
433
+ get version() {
434
+ return version;
435
+ },
432
436
  throwPiece(spec) {
437
+ version++;
433
438
  makeRoom();
434
439
  list.push({ ...spec, id: ++serial, born: serial, atRest: false, bounces: 0 });
435
440
  },
@@ -439,9 +444,13 @@ function createDebrisStore(max) {
439
444
  if (piece.atRest) {
440
445
  const under = world.heightAt(piece.position[0], piece.position[2]) + piece.radius * 0.6;
441
446
  if (piece.position[1] > under + REST_GAP) piece.atRest = false;
442
- else if (piece.position[1] < under - REST_GAP) piece.position[1] = under;
447
+ else if (piece.position[1] < under - REST_GAP) {
448
+ piece.position[1] = under;
449
+ version++;
450
+ }
443
451
  if (piece.atRest) continue;
444
452
  }
453
+ version++;
445
454
  const { position, velocity } = piece;
446
455
  velocity[1] -= world.gravity * dt;
447
456
  position[0] += velocity[0] * dt;
@@ -463,6 +472,7 @@ function createDebrisStore(max) {
463
472
  }
464
473
  },
465
474
  clear() {
475
+ version++;
466
476
  list.length = 0;
467
477
  serial = 0;
468
478
  }
@@ -1668,8 +1678,19 @@ function createTerrain(options) {
1668
1678
  if (scorch[index] >= 1) return;
1669
1679
  burning.set(key, FIRE_SECONDS);
1670
1680
  }
1681
+ const fireKeys = [];
1682
+ const fireLeft = [];
1683
+ const keepFireCell = (remaining, key) => {
1684
+ fireKeys.push(key);
1685
+ fireLeft.push(remaining);
1686
+ };
1671
1687
  function updateFire(dt) {
1672
- for (const [key, remaining] of [...burning]) {
1688
+ fireKeys.length = 0;
1689
+ fireLeft.length = 0;
1690
+ burning.forEach(keepFireCell);
1691
+ for (let cell = 0; cell < fireKeys.length; cell++) {
1692
+ const key = fireKeys[cell];
1693
+ const remaining = fireLeft[cell];
1673
1694
  const cellRow = Math.floor(key / 65536);
1674
1695
  const cellColumn = key - cellRow * 65536;
1675
1696
  const x = x0 + (cellColumn + 0.5) * FIRE_CELL;
@@ -1935,6 +1956,9 @@ function createTerrain(options) {
1935
1956
  return cracks.version;
1936
1957
  },
1937
1958
  debris: () => debrisStore.list,
1959
+ get debrisVersion() {
1960
+ return debrisStore.version;
1961
+ },
1938
1962
  burningPoints: () => [...burning.keys()].map((key) => {
1939
1963
  const cellRow = Math.floor(key / 65536);
1940
1964
  const cellColumn = key - cellRow * 65536;