@adatechnology/game-terrain 0.4.0 → 0.5.1
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 +18 -1
- package/dist/index.global.js +92 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +92 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -102,8 +102,20 @@ interface TerrainStratum {
|
|
|
102
102
|
readonly resistance: number;
|
|
103
103
|
/** Joules on one spot of bare bars before they give way (default `DEFAULT_BAR_YIELD_JOULES`). */
|
|
104
104
|
readonly yieldJoules?: number;
|
|
105
|
+
/** Metres across one bar (default `DEFAULT_BAR_DIAMETER`): with `yieldPa` it says what weight bare bars hold. */
|
|
106
|
+
readonly diameter?: number;
|
|
107
|
+
/** Pascals at which the steel yields (default `DEFAULT_BAR_YIELD_PA`). */
|
|
108
|
+
readonly yieldPa?: number;
|
|
105
109
|
};
|
|
106
110
|
}
|
|
111
|
+
/** Weight standing still on the ground: a body, a fridge, a car. */
|
|
112
|
+
interface TerrainLoad {
|
|
113
|
+
readonly x: number;
|
|
114
|
+
readonly z: number;
|
|
115
|
+
/** Metres: half the side of the footprint it stands on. */
|
|
116
|
+
readonly radius: number;
|
|
117
|
+
readonly newtons: number;
|
|
118
|
+
}
|
|
107
119
|
/** What a column of ground is made of. The strata end at the digging limit: under them nothing is removed. */
|
|
108
120
|
interface TerrainProfile {
|
|
109
121
|
readonly id: string;
|
|
@@ -351,6 +363,8 @@ interface Terrain {
|
|
|
351
363
|
}): void;
|
|
352
364
|
/** Applies a world hit (`Hit` of the destruction contract); null when it does nothing to the ground. */
|
|
353
365
|
applyHit(hit: Hit): TerrainBlowResult | null;
|
|
366
|
+
/** What stands still on the ground now. Where it stands over bare bars they sag under it, and past what they hold they give way; a slab over a void then opens. True when it opened. */
|
|
367
|
+
bear(loads: readonly TerrainLoad[]): boolean;
|
|
354
368
|
/** Height a foot stands at: the ground less what it sinks in. */
|
|
355
369
|
footAt(x: number, z: number): number;
|
|
356
370
|
/** What is left of the walking speed here, 0..1. */
|
|
@@ -424,6 +438,9 @@ declare const TERRAIN_MATERIALS: readonly TerrainMaterial[];
|
|
|
424
438
|
declare const TERRAIN_PROFILES: readonly TerrainProfile[];
|
|
425
439
|
/** About twelve grenades (200 kJ) on the same spot of bare bars. */
|
|
426
440
|
declare const DEFAULT_BAR_YIELD_JOULES = 2400000;
|
|
441
|
+
/** A 10 mm bar of CA-50 steel: bare, a mesh of them at 15 cm holds about 450 kg on a spot. */
|
|
442
|
+
declare const DEFAULT_BAR_DIAMETER = 0.01;
|
|
443
|
+
declare const DEFAULT_BAR_YIELD_PA = 500000000;
|
|
427
444
|
/** The profile of a floor with nothing else said: a plain slab. */
|
|
428
445
|
declare const DEFAULT_PROFILE = "concrete_slab";
|
|
429
446
|
|
|
@@ -477,4 +494,4 @@ interface WaterLift {
|
|
|
477
494
|
/** Archimedes on a body in a liquid: what it displaces lifts it, so a light log floats and a concrete block goes to the bed. */
|
|
478
495
|
declare function waterLift(params: WaterLiftParams): WaterLift;
|
|
479
496
|
|
|
480
|
-
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_YIELD_JOULES, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainUnits, type TerrainWater, type TerrainWaterHere, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };
|
|
497
|
+
export { CRACK_REFERENCE_JOULES, type CrackSegment, DEFAULT_BAR_DIAMETER, DEFAULT_BAR_YIELD_JOULES, DEFAULT_BAR_YIELD_PA, DEFAULT_PROFILE, DEFAULT_TERRAIN_BUDGET, type Footprints, TERRAIN_MATERIALS, TERRAIN_PATTERNS, TERRAIN_PROFILES, type Terrain, type TerrainBlow, type TerrainBlowResponse, type TerrainBlowResult, type TerrainBreachResponse, type TerrainBudget, type TerrainChunk, type TerrainColumn, type TerrainCrack, type TerrainCrackResponse, type TerrainDebris, type TerrainDebrisKind, type TerrainDecal, type TerrainDecalKind, type TerrainFireResponse, type TerrainFooting, type TerrainImplOptions, type TerrainLoad, type TerrainMark, type TerrainMaterial, type TerrainOptions, type TerrainPattern, type TerrainProfile, type TerrainRegion, type TerrainSnapshot, type TerrainStats, type TerrainStratum, type TerrainUnits, type TerrainWater, type TerrainWaterHere, type WaterLift, type WaterLiftParams, crackLines, createFootprints, createTerrain, createTerrainImpl, waterLift };
|
package/dist/index.global.js
CHANGED
|
@@ -22,7 +22,9 @@ var GameTerrain = (() => {
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
CRACK_REFERENCE_JOULES: () => CRACK_REFERENCE_JOULES,
|
|
25
|
+
DEFAULT_BAR_DIAMETER: () => DEFAULT_BAR_DIAMETER,
|
|
25
26
|
DEFAULT_BAR_YIELD_JOULES: () => DEFAULT_BAR_YIELD_JOULES,
|
|
27
|
+
DEFAULT_BAR_YIELD_PA: () => DEFAULT_BAR_YIELD_PA,
|
|
26
28
|
DEFAULT_PROFILE: () => DEFAULT_PROFILE,
|
|
27
29
|
DEFAULT_TERRAIN_BUDGET: () => DEFAULT_TERRAIN_BUDGET,
|
|
28
30
|
TERRAIN_MATERIALS: () => TERRAIN_MATERIALS,
|
|
@@ -280,6 +282,8 @@ var GameTerrain = (() => {
|
|
|
280
282
|
{ id: "shallow_water", water: { liquid: "water", depth: 0.3, drag: 0.65, blowShare: WATER_BLOW_SHARE }, strata: [{ material: "mud", thickness: 0.15 }, { material: "soil", thickness: 1.5 }, { material: "stone", thickness: 0.5 }] }
|
|
281
283
|
];
|
|
282
284
|
var DEFAULT_BAR_YIELD_JOULES = 24e5;
|
|
285
|
+
var DEFAULT_BAR_DIAMETER = 0.01;
|
|
286
|
+
var DEFAULT_BAR_YIELD_PA = 5e8;
|
|
283
287
|
var DEFAULT_PROFILE = "concrete_slab";
|
|
284
288
|
|
|
285
289
|
// src/random.ts
|
|
@@ -571,6 +575,7 @@ var GameTerrain = (() => {
|
|
|
571
575
|
var RIGID_WIDENING = 2.5;
|
|
572
576
|
var COLLAPSE_DEPTH_SHARE = 0.75;
|
|
573
577
|
var COLLAPSE_SPREAD_BEND = 0.5;
|
|
578
|
+
var BARS_SHARE_REACH = 0.6;
|
|
574
579
|
var RIM_REACH = 1.45;
|
|
575
580
|
var FLAME_MINIMUM = 200;
|
|
576
581
|
var FLAME_REACH = 0.6;
|
|
@@ -1090,19 +1095,95 @@ var GameTerrain = (() => {
|
|
|
1090
1095
|
}
|
|
1091
1096
|
}
|
|
1092
1097
|
}
|
|
1093
|
-
if (collapsed)
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1098
|
+
if (collapsed) giveWay({ x, z, reach, profile });
|
|
1099
|
+
return collapsed;
|
|
1100
|
+
}
|
|
1101
|
+
function giveWay(spec) {
|
|
1102
|
+
const { x, z, reach, profile } = spec;
|
|
1103
|
+
emitDeform(x, z, reach);
|
|
1104
|
+
if (profile.drop === void 0) return;
|
|
1105
|
+
const limit = maxDepthOfProfile(profile);
|
|
1106
|
+
const column0 = clampIndex(Math.floor((x - reach - x0) / cellSize), columns);
|
|
1107
|
+
const column1 = clampIndex(Math.ceil((x + reach - x0) / cellSize), columns);
|
|
1108
|
+
const row0 = clampIndex(Math.floor((z - reach - z0) / cellSize), rows);
|
|
1109
|
+
const row1 = clampIndex(Math.ceil((z + reach - z0) / cellSize), rows);
|
|
1110
|
+
for (let row = row0; row <= row1; row++) {
|
|
1111
|
+
for (let column = column0; column <= column1; column++) {
|
|
1112
|
+
const index = row * stride + column;
|
|
1113
|
+
if (barBend[index] >= COLLAPSE_SPREAD_BEND && dug[index] < limit + profile.drop) {
|
|
1114
|
+
dug[index] = limit + profile.drop;
|
|
1115
|
+
touchVertex(column, row);
|
|
1102
1116
|
}
|
|
1103
1117
|
}
|
|
1104
1118
|
}
|
|
1105
|
-
|
|
1119
|
+
}
|
|
1120
|
+
function barsOf(profile) {
|
|
1121
|
+
const bars = profile.strata.find((stratum) => stratum.reinforcement);
|
|
1122
|
+
if (!bars?.reinforcement) return null;
|
|
1123
|
+
let cover = bars.reinforcement.cover;
|
|
1124
|
+
for (const stratum of profile.strata) {
|
|
1125
|
+
if (stratum === bars) break;
|
|
1126
|
+
cover += stratum.thickness;
|
|
1127
|
+
}
|
|
1128
|
+
return { stratum: bars, cover };
|
|
1129
|
+
}
|
|
1130
|
+
function bearAll(loads) {
|
|
1131
|
+
const bends = /* @__PURE__ */ new Map();
|
|
1132
|
+
const touched2 = [];
|
|
1133
|
+
for (const load of loads) {
|
|
1134
|
+
const spread = spreadLoad(load, bends);
|
|
1135
|
+
if (spread) touched2.push({ load, ...spread });
|
|
1136
|
+
}
|
|
1137
|
+
let opened = false;
|
|
1138
|
+
for (const [index, bend] of bends) {
|
|
1139
|
+
if (barBend[index] >= bend) continue;
|
|
1140
|
+
barBend[index] = bend;
|
|
1141
|
+
const column = index % stride;
|
|
1142
|
+
const row = (index - column) / stride;
|
|
1143
|
+
touchVertex(column, row);
|
|
1144
|
+
const profile = profileList[profileIndex[index]];
|
|
1145
|
+
const limit = maxDepthOfProfile(profile);
|
|
1146
|
+
if (bend >= 1 && profile.drop !== void 0 && dug[index] >= limit * COLLAPSE_DEPTH_SHARE && dug[index] < limit + profile.drop) {
|
|
1147
|
+
dug[index] = limit + profile.drop;
|
|
1148
|
+
opened = true;
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (opened) for (const { load, reach, profile } of touched2) giveWay({ x: load.x, z: load.z, reach, profile });
|
|
1152
|
+
return opened;
|
|
1153
|
+
}
|
|
1154
|
+
function spreadLoad(load, bends) {
|
|
1155
|
+
if (!contains(load.x, load.z) || load.newtons <= 0) return null;
|
|
1156
|
+
const profile = profileList[profileIndex[vertexOf(load.x, load.z).index]];
|
|
1157
|
+
const bars = barsOf(profile);
|
|
1158
|
+
if (!bars) return null;
|
|
1159
|
+
const reinforcement = bars.stratum.reinforcement;
|
|
1160
|
+
const moment = (reinforcement.yieldPa ?? DEFAULT_BAR_YIELD_PA) * (reinforcement.diameter ?? DEFAULT_BAR_DIAMETER) ** 3 / 6;
|
|
1161
|
+
const holds = 8 * moment / reinforcement.spacing;
|
|
1162
|
+
const footprint = load.radius * Math.SQRT2 + cellSize;
|
|
1163
|
+
const reach = Math.max(footprint, BARS_SHARE_REACH);
|
|
1164
|
+
const column0 = clampIndex(Math.floor((load.x - reach - x0) / cellSize), columns);
|
|
1165
|
+
const column1 = clampIndex(Math.ceil((load.x + reach - x0) / cellSize), columns);
|
|
1166
|
+
const row0 = clampIndex(Math.floor((load.z - reach - z0) / cellSize), rows);
|
|
1167
|
+
const row1 = clampIndex(Math.ceil((load.z + reach - z0) / cellSize), rows);
|
|
1168
|
+
const bare = [];
|
|
1169
|
+
let under = 0;
|
|
1170
|
+
let onBars = 0;
|
|
1171
|
+
for (let row = row0; row <= row1; row++) {
|
|
1172
|
+
for (let column = column0; column <= column1; column++) {
|
|
1173
|
+
const distance = Math.hypot(x0 + column * cellSize - load.x, z0 + row * cellSize - load.z);
|
|
1174
|
+
if (distance >= reach) continue;
|
|
1175
|
+
const index = row * stride + column;
|
|
1176
|
+
const isBare = dug[index] >= bars.cover;
|
|
1177
|
+
if (isBare) bare.push(index);
|
|
1178
|
+
if (distance >= footprint) continue;
|
|
1179
|
+
under++;
|
|
1180
|
+
if (isBare) onBars++;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (onBars === 0) return null;
|
|
1184
|
+
const bend = load.newtons * (onBars / under) / holds;
|
|
1185
|
+
for (const index of bare) bends.set(index, (bends.get(index) ?? 0) + bend);
|
|
1186
|
+
return { reach, profile };
|
|
1106
1187
|
}
|
|
1107
1188
|
const maxDepthOfProfile = (profile) => maxDepthOf[indexOfProfile.get(profile.id)];
|
|
1108
1189
|
function rebarShowing(profile, depth) {
|
|
@@ -1377,6 +1458,7 @@ var GameTerrain = (() => {
|
|
|
1377
1458
|
strike,
|
|
1378
1459
|
burn,
|
|
1379
1460
|
applyHit,
|
|
1461
|
+
bear: bearAll,
|
|
1380
1462
|
onDeform(listener) {
|
|
1381
1463
|
deformListeners.add(listener);
|
|
1382
1464
|
return () => deformListeners.delete(listener);
|