@adatechnology/game-terrain 0.9.11 → 0.9.13
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.d.ts +2 -0
- package/dist/index.global.js +46 -12
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -541,6 +541,8 @@ interface Terrain {
|
|
|
541
541
|
/** Changes whenever a crack is added or grows, so a renderer redraws only then. */
|
|
542
542
|
readonly cracksVersion: number;
|
|
543
543
|
debris(): readonly TerrainDebris[];
|
|
544
|
+
/** Changes whenever a debris piece is thrown, moves or leaves, so a renderer rewrites the pieces only then (a pile at rest costs nothing per frame). */
|
|
545
|
+
readonly debrisVersion: number;
|
|
544
546
|
/** Cells on fire now, as world points. */
|
|
545
547
|
burningPoints(): readonly (readonly [number, number])[];
|
|
546
548
|
/** Goes up when the marks change. */
|
package/dist/index.global.js
CHANGED
|
@@ -545,6 +545,7 @@ var GameTerrain = (() => {
|
|
|
545
545
|
function createDebrisStore(max) {
|
|
546
546
|
const list = [];
|
|
547
547
|
let serial = 0;
|
|
548
|
+
let version = 0;
|
|
548
549
|
function makeRoom() {
|
|
549
550
|
if (list.length < max()) return;
|
|
550
551
|
let at = 0;
|
|
@@ -565,7 +566,11 @@ var GameTerrain = (() => {
|
|
|
565
566
|
}
|
|
566
567
|
return {
|
|
567
568
|
list,
|
|
569
|
+
get version() {
|
|
570
|
+
return version;
|
|
571
|
+
},
|
|
568
572
|
throwPiece(spec) {
|
|
573
|
+
version++;
|
|
569
574
|
makeRoom();
|
|
570
575
|
list.push({ ...spec, id: ++serial, born: serial, atRest: false, bounces: 0 });
|
|
571
576
|
},
|
|
@@ -575,9 +580,13 @@ var GameTerrain = (() => {
|
|
|
575
580
|
if (piece.atRest) {
|
|
576
581
|
const under = world.heightAt(piece.position[0], piece.position[2]) + piece.radius * 0.6;
|
|
577
582
|
if (piece.position[1] > under + REST_GAP) piece.atRest = false;
|
|
578
|
-
else if (piece.position[1] < under - REST_GAP)
|
|
583
|
+
else if (piece.position[1] < under - REST_GAP) {
|
|
584
|
+
piece.position[1] = under;
|
|
585
|
+
version++;
|
|
586
|
+
}
|
|
579
587
|
if (piece.atRest) continue;
|
|
580
588
|
}
|
|
589
|
+
version++;
|
|
581
590
|
const { position, velocity } = piece;
|
|
582
591
|
velocity[1] -= world.gravity * dt;
|
|
583
592
|
position[0] += velocity[0] * dt;
|
|
@@ -599,6 +608,7 @@ var GameTerrain = (() => {
|
|
|
599
608
|
}
|
|
600
609
|
},
|
|
601
610
|
clear() {
|
|
611
|
+
version++;
|
|
602
612
|
list.length = 0;
|
|
603
613
|
serial = 0;
|
|
604
614
|
}
|
|
@@ -864,6 +874,9 @@ var GameTerrain = (() => {
|
|
|
864
874
|
var RIM_REACH = 1.45;
|
|
865
875
|
var FLAME_MINIMUM = 200;
|
|
866
876
|
var FLAME_REACH = 0.6;
|
|
877
|
+
var SCORCH_STEPS = 64;
|
|
878
|
+
var BURN_AWAY_STEPS = 1e3;
|
|
879
|
+
var visibleStep = (value, steps) => Math.floor(value * steps);
|
|
867
880
|
var BLAST_HEIGHT_REACH = 0.35;
|
|
868
881
|
var BLAST_SOOT_REACH = 1.2;
|
|
869
882
|
var BLAST_SOOT = 0.9;
|
|
@@ -1752,19 +1765,25 @@ var GameTerrain = (() => {
|
|
|
1752
1765
|
}
|
|
1753
1766
|
function burn(spec) {
|
|
1754
1767
|
if (spec.temperature < FLAME_MINIMUM) return;
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
const
|
|
1768
|
+
burnDisc(spec.x, spec.z, spec.radius, spec.seconds);
|
|
1769
|
+
}
|
|
1770
|
+
function burnDisc(x, z, radius, seconds) {
|
|
1771
|
+
const column0 = clampIndex(Math.floor((x - radius - x0) / cellSize), columns);
|
|
1772
|
+
const column1 = clampIndex(Math.ceil((x + radius - x0) / cellSize), columns);
|
|
1773
|
+
const row0 = clampIndex(Math.floor((z - radius - z0) / cellSize), rows);
|
|
1774
|
+
const row1 = clampIndex(Math.ceil((z + radius - z0) / cellSize), rows);
|
|
1775
|
+
const reach = radius * radius;
|
|
1759
1776
|
let melted = false;
|
|
1760
1777
|
for (let row = row0; row <= row1; row++) {
|
|
1778
|
+
const dz = z0 + row * cellSize - z;
|
|
1761
1779
|
for (let column = column0; column <= column1; column++) {
|
|
1762
|
-
|
|
1780
|
+
const dx = x0 + column * cellSize - x;
|
|
1781
|
+
if (dx * dx + dz * dz > reach) continue;
|
|
1763
1782
|
if (hasWater && base[row * stride + column] < surface[row * stride + column]) continue;
|
|
1764
|
-
melted = burnVertex(column, row,
|
|
1783
|
+
melted = burnVertex(column, row, seconds) || melted;
|
|
1765
1784
|
}
|
|
1766
1785
|
}
|
|
1767
|
-
if (melted) emitDeform(
|
|
1786
|
+
if (melted) emitDeform(x, z, radius);
|
|
1768
1787
|
}
|
|
1769
1788
|
function soot(x, z, radius) {
|
|
1770
1789
|
if (radius <= 0) return;
|
|
@@ -1791,8 +1810,9 @@ var GameTerrain = (() => {
|
|
|
1791
1810
|
if (!response) return false;
|
|
1792
1811
|
const before = scorch[index];
|
|
1793
1812
|
scorch[index] = Math.max(before, Math.min(response.maxScorch, before + response.scorchPerSecond * seconds));
|
|
1813
|
+
const dugBefore = dug[index];
|
|
1794
1814
|
if (response.burnsAway) removeFromVertex(index, response.burnsAway * seconds);
|
|
1795
|
-
if (scorch[index] !== before ||
|
|
1815
|
+
if (visibleStep(scorch[index], SCORCH_STEPS) !== visibleStep(before, SCORCH_STEPS) || visibleStep(dug[index], BURN_AWAY_STEPS) !== visibleStep(dugBefore, BURN_AWAY_STEPS)) touchVertex(column, row);
|
|
1796
1816
|
if (response.flammable) ignite(x0 + column * cellSize, z0 + row * cellSize);
|
|
1797
1817
|
return (response.burnsAway ?? 0) > 0;
|
|
1798
1818
|
}
|
|
@@ -1804,13 +1824,24 @@ var GameTerrain = (() => {
|
|
|
1804
1824
|
if (scorch[index] >= 1) return;
|
|
1805
1825
|
burning.set(key, FIRE_SECONDS);
|
|
1806
1826
|
}
|
|
1827
|
+
const fireKeys = [];
|
|
1828
|
+
const fireLeft = [];
|
|
1829
|
+
const keepFireCell = (remaining, key) => {
|
|
1830
|
+
fireKeys.push(key);
|
|
1831
|
+
fireLeft.push(remaining);
|
|
1832
|
+
};
|
|
1807
1833
|
function updateFire(dt) {
|
|
1808
|
-
|
|
1834
|
+
fireKeys.length = 0;
|
|
1835
|
+
fireLeft.length = 0;
|
|
1836
|
+
burning.forEach(keepFireCell);
|
|
1837
|
+
for (let cell = 0; cell < fireKeys.length; cell++) {
|
|
1838
|
+
const key = fireKeys[cell];
|
|
1839
|
+
const remaining = fireLeft[cell];
|
|
1809
1840
|
const cellRow = Math.floor(key / 65536);
|
|
1810
1841
|
const cellColumn = key - cellRow * 65536;
|
|
1811
1842
|
const x = x0 + (cellColumn + 0.5) * FIRE_CELL;
|
|
1812
1843
|
const z = z0 + (cellRow + 0.5) * FIRE_CELL;
|
|
1813
|
-
|
|
1844
|
+
burnDisc(x, z, FIRE_CELL * 0.75, dt);
|
|
1814
1845
|
if (random() < FIRE_SPREAD_PER_SECOND * dt) {
|
|
1815
1846
|
const angle = Math.floor(random() * 4) * (Math.PI / 2);
|
|
1816
1847
|
const nextX = x + Math.cos(angle) * FIRE_CELL;
|
|
@@ -1918,7 +1949,7 @@ var GameTerrain = (() => {
|
|
|
1918
1949
|
case "fire":
|
|
1919
1950
|
case "heat":
|
|
1920
1951
|
if (y - heightAt(x, z) > (hit.radius ?? 0.2) + FLAME_REACH) return null;
|
|
1921
|
-
|
|
1952
|
+
if ((hit.temperature ?? 0) >= FLAME_MINIMUM) burnDisc(x, z, hit.radius ?? 0.2, hit.duration ?? 0.016);
|
|
1922
1953
|
return null;
|
|
1923
1954
|
default:
|
|
1924
1955
|
return null;
|
|
@@ -2071,6 +2102,9 @@ var GameTerrain = (() => {
|
|
|
2071
2102
|
return cracks.version;
|
|
2072
2103
|
},
|
|
2073
2104
|
debris: () => debrisStore.list,
|
|
2105
|
+
get debrisVersion() {
|
|
2106
|
+
return debrisStore.version;
|
|
2107
|
+
},
|
|
2074
2108
|
burningPoints: () => [...burning.keys()].map((key) => {
|
|
2075
2109
|
const cellRow = Math.floor(key / 65536);
|
|
2076
2110
|
const cellColumn = key - cellRow * 65536;
|