@pinkaphant/create-kolmo 0.4.2 → 0.5.2
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/README.md +56 -17
- package/bin/create-kolmo.mjs +20 -12
- package/package.json +1 -1
- package/templates/demolition/README.md +17 -0
- package/templates/demolition/index.html +29 -0
- package/templates/demolition/package.json +39 -0
- package/templates/demolition/src/App.tsx +599 -0
- package/templates/{lonedrive → demolition}/tsconfig.json +4 -2
- package/templates/{lonedrive → demolition}/vite.config.ts +3 -1
- package/templates/dust/README.md +9 -1
- package/templates/dust/index.html +15 -1
- package/templates/dust/package.json +10 -8
- package/templates/dust/src/App.tsx +106 -122
- package/templates/dust/tsconfig.json +4 -2
- package/templates/evolution/README.md +15 -0
- package/templates/evolution/index.html +29 -0
- package/templates/{lonedrive → evolution}/package.json +10 -9
- package/templates/evolution/src/App.tsx +619 -0
- package/templates/evolution/src/main.tsx +10 -0
- package/templates/evolution/src/styles.css +237 -0
- package/templates/evolution/tsconfig.json +16 -0
- package/templates/evolution/vite.config.ts +10 -0
- package/templates/longline/README.md +16 -9
- package/templates/longline/index.html +26 -12
- package/templates/longline/package.json +13 -11
- package/templates/longline/src/App.tsx +191 -42
- package/templates/longline/src/highway.ts +222 -0
- package/templates/longline/src/main.tsx +7 -6
- package/templates/longline/tsconfig.json +14 -16
- package/templates/longline/vite.config.ts +5 -23
- package/templates/road/README.md +8 -4
- package/templates/road/index.html +15 -1
- package/templates/road/package.json +7 -7
- package/templates/road/src/App.tsx +21 -6
- package/templates/road/tsconfig.json +1 -0
- package/templates/tugline/README.md +16 -0
- package/templates/tugline/index.html +31 -0
- package/templates/tugline/package.json +41 -0
- package/templates/tugline/src/App.tsx +48 -0
- package/templates/{longline → tugline}/src/components/Boat.tsx +1 -2
- package/templates/{longline → tugline}/src/components/Crates.tsx +2 -2
- package/templates/tugline/src/components/Hud.tsx +281 -0
- package/templates/{longline → tugline}/src/components/Longline.tsx +2 -2
- package/templates/{longline → tugline}/src/components/Ocean.tsx +14 -3
- package/templates/{longline → tugline}/src/components/Radar.tsx +15 -14
- package/templates/{longline → tugline}/src/components/Referee.tsx +6 -4
- package/templates/{longline → tugline}/src/components/Scene.tsx +10 -9
- package/templates/{longline → tugline}/src/components/Sky.tsx +14 -8
- package/templates/{longline → tugline}/src/game/store.test.ts +2 -2
- package/templates/{longline → tugline}/src/game/store.ts +38 -19
- package/templates/tugline/src/main.tsx +13 -0
- package/templates/tugline/src/styles.css +495 -0
- package/templates/tugline/tsconfig.json +18 -0
- package/templates/tugline/vite.config.ts +16 -0
- package/templates/lonedrive/README.md +0 -11
- package/templates/lonedrive/index.html +0 -15
- package/templates/lonedrive/src/App.tsx +0 -149
- package/templates/longline/src/components/Hud.tsx +0 -197
- package/templates/longline/src/styles.css +0 -367
- /package/templates/{lonedrive → demolition}/src/main.tsx +0 -0
- /package/templates/{longline → tugline}/src/components/CameraRig.tsx +0 -0
- /package/templates/{longline → tugline}/src/components/ocean-material.ts +0 -0
- /package/templates/{longline → tugline}/src/components/round-context.ts +0 -0
- /package/templates/{longline → tugline}/src/game/boat-control.ts +0 -0
- /package/templates/{longline → tugline}/src/game/constants.ts +0 -0
- /package/templates/{longline → tugline}/src/game/input.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/input.ts +0 -0
- /package/templates/{longline → tugline}/src/game/logic.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/logic.ts +0 -0
- /package/templates/{longline → tugline}/src/game/physics.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/radar.ts +0 -0
- /package/templates/{longline → tugline}/src/game/registry.ts +0 -0
- /package/templates/{longline → tugline}/src/game/sea.ts +0 -0
- /package/templates/{longline → tugline}/src/game/session.ts +0 -0
- /package/templates/{longline → tugline}/src/game/simulation.test.ts +0 -0
- /package/templates/{longline → tugline}/src/game/simulation.ts +0 -0
- /package/templates/{longline → tugline}/src/game/test-world.ts +0 -0
- /package/templates/{longline → tugline}/src/sfx.ts +0 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import { useBeforePhysicsStep, useRapier } from "@react-three/rapier";
|
|
4
|
+
import {
|
|
5
|
+
ACTOR_GROUND_CLEARANCE,
|
|
6
|
+
Actor,
|
|
7
|
+
ActorTrait,
|
|
8
|
+
Game,
|
|
9
|
+
Hud,
|
|
10
|
+
PilotLink,
|
|
11
|
+
Radar,
|
|
12
|
+
Terrain,
|
|
13
|
+
Vehicle,
|
|
14
|
+
VehicleTrait,
|
|
15
|
+
computeSurfaceSpawnPose,
|
|
16
|
+
createEmptyVehicleCmd,
|
|
17
|
+
kolmoActions,
|
|
18
|
+
kolmoWorld,
|
|
19
|
+
type EcctrlHandle,
|
|
20
|
+
type SurfaceSpawnPose,
|
|
21
|
+
} from "@pinkaphant/kolmo";
|
|
22
|
+
import {
|
|
23
|
+
DERBY_PANEL_ROLES,
|
|
24
|
+
compileKolmogorovCarBundle,
|
|
25
|
+
computeDerbyFitness,
|
|
26
|
+
createDerbyAutopilotMemory,
|
|
27
|
+
formatKolmogorovGene,
|
|
28
|
+
mulberry32,
|
|
29
|
+
stepDerbyAutopilot,
|
|
30
|
+
unpackKolmogorovGene,
|
|
31
|
+
type AutopilotDriveCmd,
|
|
32
|
+
type DerbyAutopilotMemory,
|
|
33
|
+
type DerbyCarKinematics,
|
|
34
|
+
} from "@pinkaphant/kolmo/cars";
|
|
35
|
+
import { isLiveRapierBody, sampleRapierHeightfield, type KhrAssetBundle } from "@khr3/core";
|
|
36
|
+
import type { KhrVehicleJointsHandle } from "@khr3/core/vehicle";
|
|
37
|
+
import type { EcctrlVehicleHandle, VehicleInput } from "@pinkaphant/ecctrl/vehicle";
|
|
38
|
+
|
|
39
|
+
const ARENA_SIZE = 128;
|
|
40
|
+
const ARENA_SEGMENTS = 128;
|
|
41
|
+
const RING_RADIUS = 46;
|
|
42
|
+
const PIT_DROP_Y = -2.2;
|
|
43
|
+
const RIVAL_COUNT = 5;
|
|
44
|
+
const TOTAL_CARS = 1 + RIVAL_COUNT;
|
|
45
|
+
const FIXED_STEP_DT = 1 / 60;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sunken concave `128 m` demolition derby bowl:
|
|
49
|
+
* - Central spine mound (`+1.65 m` ridge along X) for launches
|
|
50
|
+
* - Concave combat dish rising cleanly to a `+3.2 m` rim lip at `r = 46 m`
|
|
51
|
+
* - Steep outer ring-out trench (`-6.5 m`) beyond `r = 50 m`
|
|
52
|
+
*/
|
|
53
|
+
function derbyBowlHeight(x: number, z: number): number {
|
|
54
|
+
const r = Math.hypot(x, z);
|
|
55
|
+
const spine = 1.65 * Math.exp(-(z * z) / 56) * Math.exp(-(x * x) / 680);
|
|
56
|
+
if (r <= RING_RADIUS) {
|
|
57
|
+
const u = r / RING_RADIUS;
|
|
58
|
+
const dish = -1.8 + 4.9 * Math.pow(u, 2.3);
|
|
59
|
+
return dish + spine;
|
|
60
|
+
}
|
|
61
|
+
const over = Math.min(1, (r - RING_RADIUS) / 8.5);
|
|
62
|
+
const smooth = over * over * (3 - 2 * over);
|
|
63
|
+
const lipY = 3.1 + spine;
|
|
64
|
+
return lipY * (1 - smooth) + -6.5 * smooth;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface BoutSlotSpec {
|
|
68
|
+
readonly slot: number;
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly gene: number;
|
|
71
|
+
readonly hex: string;
|
|
72
|
+
readonly label: string;
|
|
73
|
+
readonly bundle: KhrAssetBundle;
|
|
74
|
+
readonly pose: SurfaceSpawnPose;
|
|
75
|
+
readonly isPlayerStart: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createBoutLineup(boutId: number): BoutSlotSpec[] {
|
|
79
|
+
const rng = mulberry32(0xde4b1000 ^ Math.imul(boutId + 1, 0x9e3779b9));
|
|
80
|
+
const spawnRingR = 30;
|
|
81
|
+
const slots: BoutSlotSpec[] = [];
|
|
82
|
+
|
|
83
|
+
for (let i = 0; i < TOTAL_CARS; i++) {
|
|
84
|
+
const hi = (Math.floor(rng() * 0x10000) & 0xffff) >>> 0;
|
|
85
|
+
const lo = (Math.floor(rng() * 0x10000) & 0xffff) >>> 0;
|
|
86
|
+
// Guarantee bit 31 (`6DOF` twin rocket boosters) on all derby brawlers
|
|
87
|
+
const gene = (((hi << 16) | lo) | 0x80000000) >>> 0;
|
|
88
|
+
const bp = unpackKolmogorovGene(gene);
|
|
89
|
+
const hex = formatKolmogorovGene(gene);
|
|
90
|
+
const bundle = compileKolmogorovCarBundle(gene, { armorScale: 0.62 });
|
|
91
|
+
|
|
92
|
+
const angle = (i / TOTAL_CARS) * Math.PI * 2;
|
|
93
|
+
const sx = Math.sin(angle) * spawnRingR;
|
|
94
|
+
const sz = Math.cos(angle) * spawnRingR;
|
|
95
|
+
const inwardHeading = Math.atan2(-sx, -sz);
|
|
96
|
+
const contactPlaneY = -(2 * bp.tireRadiusM);
|
|
97
|
+
const pose = computeSurfaceSpawnPose(derbyBowlHeight, sx, sz, inwardHeading, contactPlaneY, 0.06);
|
|
98
|
+
|
|
99
|
+
slots.push({
|
|
100
|
+
slot: i,
|
|
101
|
+
id: i === 0 ? "player_brawler" : `rival_${i}`,
|
|
102
|
+
gene,
|
|
103
|
+
hex,
|
|
104
|
+
label: i === 0 ? `Brawler ${hex}` : `Rival ${i} (${hex})`,
|
|
105
|
+
bundle,
|
|
106
|
+
pose,
|
|
107
|
+
isPlayerStart: i === 0,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return slots;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface SlotRuntimeStats {
|
|
115
|
+
alive: boolean;
|
|
116
|
+
flippedTimer: number;
|
|
117
|
+
eliminationOrder: number;
|
|
118
|
+
offensiveImpulseNs: number;
|
|
119
|
+
knockouts: number;
|
|
120
|
+
panelsSevered: number;
|
|
121
|
+
lastAttackerSlot: number;
|
|
122
|
+
passiveSpinRad: number;
|
|
123
|
+
perimeterCampSeconds: number;
|
|
124
|
+
prevVx: number;
|
|
125
|
+
prevVy: number;
|
|
126
|
+
prevVz: number;
|
|
127
|
+
detachedMask: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function DerbyReferee({
|
|
131
|
+
boutId,
|
|
132
|
+
lineup,
|
|
133
|
+
vehicleRefs,
|
|
134
|
+
jointsRefs,
|
|
135
|
+
telemetryRef,
|
|
136
|
+
}: {
|
|
137
|
+
boutId: number;
|
|
138
|
+
lineup: readonly BoutSlotSpec[];
|
|
139
|
+
vehicleRefs: React.RefObject<Array<EcctrlVehicleHandle | null>>;
|
|
140
|
+
jointsRefs: React.RefObject<Array<KhrVehicleJointsHandle | null>>;
|
|
141
|
+
telemetryRef: React.RefObject<HTMLSpanElement | null>;
|
|
142
|
+
}) {
|
|
143
|
+
const { world: rapierWorld } = useRapier();
|
|
144
|
+
const autoBoardedBoutRef = useRef(-1);
|
|
145
|
+
|
|
146
|
+
const simRef = useRef<{
|
|
147
|
+
boutId: number;
|
|
148
|
+
eliminations: number;
|
|
149
|
+
memories: DerbyAutopilotMemory[];
|
|
150
|
+
kinematics: DerbyCarKinematics[];
|
|
151
|
+
stats: SlotRuntimeStats[];
|
|
152
|
+
aiCmd: AutopilotDriveCmd;
|
|
153
|
+
vehCmd: VehicleInput;
|
|
154
|
+
quat: THREE.Quaternion;
|
|
155
|
+
fwd: THREE.Vector3;
|
|
156
|
+
up: THREE.Vector3;
|
|
157
|
+
lastHudText: string;
|
|
158
|
+
} | null>(null);
|
|
159
|
+
|
|
160
|
+
if (simRef.current === null || simRef.current.boutId !== boutId) {
|
|
161
|
+
simRef.current = {
|
|
162
|
+
boutId,
|
|
163
|
+
eliminations: 0,
|
|
164
|
+
memories: Array.from({ length: TOTAL_CARS }, () => createDerbyAutopilotMemory()),
|
|
165
|
+
kinematics: Array.from({ length: TOTAL_CARS }, (_, slot) => ({
|
|
166
|
+
slot,
|
|
167
|
+
alive: true,
|
|
168
|
+
x: lineup[slot]?.pose.position[0] ?? 0,
|
|
169
|
+
y: lineup[slot]?.pose.position[1] ?? 0,
|
|
170
|
+
z: lineup[slot]?.pose.position[2] ?? 0,
|
|
171
|
+
vx: 0,
|
|
172
|
+
vz: 0,
|
|
173
|
+
fwdX: 0,
|
|
174
|
+
fwdZ: 1,
|
|
175
|
+
upY: 1,
|
|
176
|
+
hasBoosters: true,
|
|
177
|
+
})),
|
|
178
|
+
stats: Array.from({ length: TOTAL_CARS }, () => ({
|
|
179
|
+
alive: true,
|
|
180
|
+
flippedTimer: 0,
|
|
181
|
+
eliminationOrder: TOTAL_CARS - 1,
|
|
182
|
+
offensiveImpulseNs: 0,
|
|
183
|
+
knockouts: 0,
|
|
184
|
+
panelsSevered: 0,
|
|
185
|
+
lastAttackerSlot: -1,
|
|
186
|
+
passiveSpinRad: 0,
|
|
187
|
+
perimeterCampSeconds: 0,
|
|
188
|
+
prevVx: 0,
|
|
189
|
+
prevVy: 0,
|
|
190
|
+
prevVz: 0,
|
|
191
|
+
detachedMask: 0,
|
|
192
|
+
})),
|
|
193
|
+
aiCmd: {
|
|
194
|
+
forward: false,
|
|
195
|
+
backward: false,
|
|
196
|
+
steerLeft: false,
|
|
197
|
+
steerRight: false,
|
|
198
|
+
brake: false,
|
|
199
|
+
boost: false,
|
|
200
|
+
},
|
|
201
|
+
vehCmd: createEmptyVehicleCmd(false),
|
|
202
|
+
quat: new THREE.Quaternion(),
|
|
203
|
+
fwd: new THREE.Vector3(),
|
|
204
|
+
up: new THREE.Vector3(),
|
|
205
|
+
lastHudText: "",
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
useBeforePhysicsStep((steppingWorld) => {
|
|
210
|
+
const sim = simRef.current;
|
|
211
|
+
if (!sim) return;
|
|
212
|
+
const dt = steppingWorld.timestep > 0 ? steppingWorld.timestep : FIXED_STEP_DT;
|
|
213
|
+
|
|
214
|
+
// Auto-board the player into slot 0 once mounted at the start of each bout
|
|
215
|
+
const actorEnt = kolmoWorld.queryFirst(ActorTrait);
|
|
216
|
+
const pilotedEnt = actorEnt && kolmoWorld.has(actorEnt) ? actorEnt.targetFor(PilotLink) : undefined;
|
|
217
|
+
const pilotedId = pilotedEnt && kolmoWorld.has(pilotedEnt) ? (pilotedEnt.get(VehicleTrait)?.id ?? "") : "";
|
|
218
|
+
|
|
219
|
+
if (autoBoardedBoutRef.current !== boutId && actorEnt && kolmoWorld.has(actorEnt)) {
|
|
220
|
+
const playerHandle = vehicleRefs.current[0];
|
|
221
|
+
if (playerHandle?.body && isLiveRapierBody(rapierWorld, playerHandle.body)) {
|
|
222
|
+
for (const vEnt of kolmoWorld.query(VehicleTrait)) {
|
|
223
|
+
if (vEnt.get(VehicleTrait)?.id === lineup[0]?.id) {
|
|
224
|
+
if (kolmoActions(kolmoWorld).boardVehicle(rapierWorld, actorEnt, vEnt)) {
|
|
225
|
+
autoBoardedBoutRef.current = boutId;
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 1. Sample live Rapier kinematics and detect chassis collision impulses -> breakaway panels
|
|
234
|
+
for (let i = 0; i < TOTAL_CARS; i++) {
|
|
235
|
+
const vh = vehicleRefs.current[i];
|
|
236
|
+
const jh = jointsRefs.current[i];
|
|
237
|
+
const st = sim.stats[i]!;
|
|
238
|
+
const body = vh?.body;
|
|
239
|
+
if (!vh || !body || !isLiveRapierBody(steppingWorld, body)) continue;
|
|
240
|
+
|
|
241
|
+
const pos = body.translation();
|
|
242
|
+
const rot = body.rotation();
|
|
243
|
+
const lv = body.linvel();
|
|
244
|
+
const av = body.angvel();
|
|
245
|
+
|
|
246
|
+
sim.quat.set(rot.x, rot.y, rot.z, rot.w);
|
|
247
|
+
sim.fwd.set(0, 0, 1).applyQuaternion(sim.quat);
|
|
248
|
+
sim.up.set(0, 1, 0).applyQuaternion(sim.quat);
|
|
249
|
+
const fLen = Math.hypot(sim.fwd.x, sim.fwd.z) || 1;
|
|
250
|
+
const fwdX = sim.fwd.x / fLen;
|
|
251
|
+
const fwdZ = sim.fwd.z / fLen;
|
|
252
|
+
|
|
253
|
+
// Delta-V impulse detection on chassis collisions
|
|
254
|
+
const dvx = lv.x - st.prevVx;
|
|
255
|
+
const dvy = lv.y - st.prevVy;
|
|
256
|
+
const dvz = lv.z - st.prevVz;
|
|
257
|
+
st.prevVx = lv.x;
|
|
258
|
+
st.prevVy = lv.y;
|
|
259
|
+
st.prevVz = lv.z;
|
|
260
|
+
|
|
261
|
+
const dvHoriz = Math.hypot(dvx, dvz);
|
|
262
|
+
const dvTotal = Math.hypot(dvHoriz, Math.max(0, Math.abs(dvy) - 9.81 * dt * 2));
|
|
263
|
+
const mass = Math.max(600, body.mass());
|
|
264
|
+
const chassisImpulseNs = dvTotal * mass;
|
|
265
|
+
|
|
266
|
+
// Check nearby opponent within 5.6 m for collision attribution & directional panel shearing
|
|
267
|
+
if (chassisImpulseNs > 210 && jh) {
|
|
268
|
+
let nearestOpp = -1;
|
|
269
|
+
let nearestDist = 5.6;
|
|
270
|
+
let oppDx = 0;
|
|
271
|
+
let oppDz = 0;
|
|
272
|
+
for (let j = 0; j < TOTAL_CARS; j++) {
|
|
273
|
+
if (j === i) continue;
|
|
274
|
+
const ob = vehicleRefs.current[j]?.body;
|
|
275
|
+
if (!ob || !isLiveRapierBody(steppingWorld, ob)) continue;
|
|
276
|
+
const op = ob.translation();
|
|
277
|
+
const dx = op.x - pos.x;
|
|
278
|
+
const dz = op.z - pos.z;
|
|
279
|
+
const d = Math.hypot(dx, dz);
|
|
280
|
+
if (d < nearestDist) {
|
|
281
|
+
nearestDist = d;
|
|
282
|
+
nearestOpp = j;
|
|
283
|
+
oppDx = dx;
|
|
284
|
+
oppDz = dz;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (nearestOpp >= 0) {
|
|
289
|
+
st.lastAttackerSlot = nearestOpp;
|
|
290
|
+
const attackerStats = sim.stats[nearestOpp]!;
|
|
291
|
+
attackerStats.offensiveImpulseNs += chassisImpulseNs;
|
|
292
|
+
|
|
293
|
+
const invD = 1 / Math.max(0.05, nearestDist);
|
|
294
|
+
const nx = oppDx * invD;
|
|
295
|
+
const nz = oppDz * invD;
|
|
296
|
+
const longDot = fwdX * nx + fwdZ * nz;
|
|
297
|
+
const leftDot = sim.fwd.z * nx - sim.fwd.x * nz;
|
|
298
|
+
|
|
299
|
+
for (let rIdx = 0; rIdx < DERBY_PANEL_ROLES.length; rIdx++) {
|
|
300
|
+
const role = DERBY_PANEL_ROLES[rIdx]!;
|
|
301
|
+
let directionalWeight = 0.28;
|
|
302
|
+
if ((role === "hood" || role === "bumper_front") && longDot > 0.35) directionalWeight = 0.95;
|
|
303
|
+
else if ((role === "rear_gate" || role === "bumper_rear") && longDot < -0.35) directionalWeight = 0.95;
|
|
304
|
+
else if (role === "door_fl" && leftDot > 0.3) directionalWeight = 1.05;
|
|
305
|
+
else if (role === "door_fr" && leftDot < -0.3) directionalWeight = 1.05;
|
|
306
|
+
|
|
307
|
+
const rt = jh.getJointRuntime(role);
|
|
308
|
+
if (rt && !rt.detached) {
|
|
309
|
+
const outcome = rt.applyImpactImpulse(chassisImpulseNs * directionalWeight);
|
|
310
|
+
if (outcome === "detached") {
|
|
311
|
+
const bit = 1 << rIdx;
|
|
312
|
+
if ((st.detachedMask & bit) === 0) {
|
|
313
|
+
st.detachedMask |= bit;
|
|
314
|
+
attackerStats.panelsSevered += 1;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} else if (chassisImpulseNs > 520) {
|
|
320
|
+
// Hard ground/wall slam
|
|
321
|
+
for (let rIdx = 0; rIdx < DERBY_PANEL_ROLES.length; rIdx++) {
|
|
322
|
+
const role = DERBY_PANEL_ROLES[rIdx]!;
|
|
323
|
+
const rt = jh.getJointRuntime(role);
|
|
324
|
+
if (rt && !rt.detached) {
|
|
325
|
+
const outcome = rt.applyImpactImpulse(chassisImpulseNs * 0.42);
|
|
326
|
+
if (outcome === "detached") st.detachedMask |= 1 << rIdx;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Sync any panels detached directly via Rapier contact force callbacks
|
|
333
|
+
if (jh) {
|
|
334
|
+
for (let rIdx = 0; rIdx < DERBY_PANEL_ROLES.length; rIdx++) {
|
|
335
|
+
const role = DERBY_PANEL_ROLES[rIdx]!;
|
|
336
|
+
if (jh.getJointRuntime(role)?.detached) {
|
|
337
|
+
st.detachedMask |= 1 << rIdx;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Track ring-out or sustained turtle KO for AI cars (and track player ring-out)
|
|
343
|
+
const radialDist = Math.hypot(pos.x, pos.z);
|
|
344
|
+
const speedXZ = Math.hypot(lv.x, lv.z);
|
|
345
|
+
if (speedXZ < 1.2) st.passiveSpinRad += Math.abs(av.y) * dt;
|
|
346
|
+
if (radialDist > RING_RADIUS * 0.84) st.perimeterCampSeconds += dt;
|
|
347
|
+
|
|
348
|
+
if (st.alive) {
|
|
349
|
+
if (sim.up.y < 0.15 && speedXZ < 1.5) st.flippedTimer += dt;
|
|
350
|
+
else st.flippedTimer = Math.max(0, st.flippedTimer - dt * 2);
|
|
351
|
+
|
|
352
|
+
const isRingOut = pos.y < PIT_DROP_Y || radialDist > RING_RADIUS + 4.5;
|
|
353
|
+
const isTurtledOut = lineup[i]?.id !== pilotedId && st.flippedTimer > 4.0;
|
|
354
|
+
if (isRingOut || isTurtledOut) {
|
|
355
|
+
st.alive = false;
|
|
356
|
+
st.eliminationOrder = sim.eliminations++;
|
|
357
|
+
if (st.lastAttackerSlot >= 0 && st.lastAttackerSlot !== i) {
|
|
358
|
+
sim.stats[st.lastAttackerSlot]!.knockouts += 1;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
sim.kinematics[i] = {
|
|
364
|
+
slot: i,
|
|
365
|
+
alive: st.alive,
|
|
366
|
+
x: pos.x,
|
|
367
|
+
y: pos.y,
|
|
368
|
+
z: pos.z,
|
|
369
|
+
vx: lv.x,
|
|
370
|
+
vz: lv.z,
|
|
371
|
+
fwdX,
|
|
372
|
+
fwdZ,
|
|
373
|
+
upY: sim.up.y,
|
|
374
|
+
hasBoosters: true,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// 2. Step deterministic AI autopilot for every non-piloted vehicle
|
|
379
|
+
for (let i = 0; i < TOTAL_CARS; i++) {
|
|
380
|
+
const spec = lineup[i]!;
|
|
381
|
+
if (spec.id === pilotedId) continue;
|
|
382
|
+
const vh = vehicleRefs.current[i];
|
|
383
|
+
if (!vh) continue;
|
|
384
|
+
const selfKin = sim.kinematics[i]!;
|
|
385
|
+
const cmd = sim.vehCmd;
|
|
386
|
+
|
|
387
|
+
if (!selfKin.alive) {
|
|
388
|
+
cmd.forward = false;
|
|
389
|
+
cmd.backward = false;
|
|
390
|
+
cmd.steerLeft = false;
|
|
391
|
+
cmd.steerRight = false;
|
|
392
|
+
cmd.brake = true;
|
|
393
|
+
cmd.throttleUp = false;
|
|
394
|
+
cmd.boost = false;
|
|
395
|
+
vh.setMovement(cmd);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const ai = stepDerbyAutopilot(selfKin, sim.kinematics, RING_RADIUS, FIXED_STEP_DT, sim.memories[i]!, sim.aiCmd);
|
|
400
|
+
cmd.forward = ai.forward;
|
|
401
|
+
cmd.backward = ai.backward;
|
|
402
|
+
cmd.steerLeft = ai.steerLeft;
|
|
403
|
+
cmd.steerRight = ai.steerRight;
|
|
404
|
+
cmd.brake = ai.brake;
|
|
405
|
+
cmd.throttleUp = ai.boost;
|
|
406
|
+
cmd.boost = ai.boost;
|
|
407
|
+
vh.setMovement(cmd);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// 3. Update top DOM telemetry readout directly (zero React state!)
|
|
411
|
+
const hudNode = telemetryRef.current;
|
|
412
|
+
if (hudNode !== null) {
|
|
413
|
+
let focusSlot = 0;
|
|
414
|
+
for (let i = 0; i < TOTAL_CARS; i++) {
|
|
415
|
+
if (lineup[i]?.id === pilotedId) {
|
|
416
|
+
focusSlot = i;
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const focusJoints = jointsRefs.current[focusSlot];
|
|
421
|
+
let intactPanels: number = DERBY_PANEL_ROLES.length;
|
|
422
|
+
if (focusJoints) {
|
|
423
|
+
intactPanels = 0;
|
|
424
|
+
for (let r = 0; r < DERBY_PANEL_ROLES.length; r++) {
|
|
425
|
+
if (!focusJoints.getJointRuntime(DERBY_PANEL_ROLES[r]!)?.detached) {
|
|
426
|
+
intactPanels += 1;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
let rivalKos = 0;
|
|
431
|
+
for (let i = 1; i < TOTAL_CARS; i++) {
|
|
432
|
+
if (!sim.stats[i]!.alive) rivalKos += 1;
|
|
433
|
+
}
|
|
434
|
+
const focusStats = sim.stats[focusSlot]!;
|
|
435
|
+
const fit = computeDerbyFitness({
|
|
436
|
+
offensiveImpulseNs: focusStats.offensiveImpulseNs,
|
|
437
|
+
knockouts: focusStats.knockouts,
|
|
438
|
+
panelsSevered: focusStats.panelsSevered,
|
|
439
|
+
eliminationOrder: focusStats.alive ? TOTAL_CARS - 1 : focusStats.eliminationOrder,
|
|
440
|
+
popSize: TOTAL_CARS,
|
|
441
|
+
ownPanelsIntactRatio: intactPanels / DERBY_PANEL_ROLES.length,
|
|
442
|
+
ownWheelsFunctionalRatio: 1,
|
|
443
|
+
passiveSpinRad: focusStats.passiveSpinRad,
|
|
444
|
+
perimeterCampSeconds: focusStats.perimeterCampSeconds,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
const statusTag = rivalKos === RIVAL_COUNT ? " · ARENA CHAMPION" : !sim.stats[0]!.alive ? " · RINGED OUT" : "";
|
|
448
|
+
const nextText = `PANELS ${intactPanels}/${DERBY_PANEL_ROLES.length} · KOs ${rivalKos}/${RIVAL_COUNT} · FIT ${fit.toFixed(1)} · [E] EXIT/BOARD · [R] NEW BOUT${statusTag}`;
|
|
449
|
+
if (nextText !== sim.lastHudText) {
|
|
450
|
+
sim.lastHudText = nextText;
|
|
451
|
+
hudNode.textContent = nextText;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export default function App() {
|
|
460
|
+
const actorRef = useRef<EcctrlHandle>(null);
|
|
461
|
+
const telemetryRef = useRef<HTMLSpanElement>(null);
|
|
462
|
+
const [boutId, setBoutId] = useState(0);
|
|
463
|
+
|
|
464
|
+
const vehicleRefs = useRef<Array<EcctrlVehicleHandle | null>>(Array.from({ length: TOTAL_CARS }, () => null));
|
|
465
|
+
const jointsRefs = useRef<Array<KhrVehicleJointsHandle | null>>(Array.from({ length: TOTAL_CARS }, () => null));
|
|
466
|
+
|
|
467
|
+
const arena = useMemo(() => {
|
|
468
|
+
const heights = sampleRapierHeightfield(
|
|
469
|
+
derbyBowlHeight,
|
|
470
|
+
-ARENA_SIZE * 0.5,
|
|
471
|
+
-ARENA_SIZE * 0.5,
|
|
472
|
+
ARENA_SIZE,
|
|
473
|
+
ARENA_SIZE,
|
|
474
|
+
ARENA_SEGMENTS,
|
|
475
|
+
);
|
|
476
|
+
const rimPoints: number[] = [];
|
|
477
|
+
const segs = 48;
|
|
478
|
+
for (let i = 0; i <= segs; i++) {
|
|
479
|
+
const a = (i / segs) * Math.PI * 2;
|
|
480
|
+
rimPoints.push(Math.cos(a) * RING_RADIUS, Math.sin(a) * RING_RADIUS);
|
|
481
|
+
}
|
|
482
|
+
const radarSpec = {
|
|
483
|
+
range: 64,
|
|
484
|
+
headingUp: true,
|
|
485
|
+
roads: [{ id: "derby-rim", halfWidth: 1.2, points: rimPoints, closed: true }],
|
|
486
|
+
};
|
|
487
|
+
return { heights, radarSpec };
|
|
488
|
+
}, []);
|
|
489
|
+
|
|
490
|
+
const lineup = useMemo(() => createBoutLineup(boutId), [boutId]);
|
|
491
|
+
|
|
492
|
+
const startNewBout = useCallback(() => {
|
|
493
|
+
setBoutId((b) => b + 1);
|
|
494
|
+
}, []);
|
|
495
|
+
|
|
496
|
+
useEffect(() => {
|
|
497
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
498
|
+
const tag = document.activeElement?.tagName;
|
|
499
|
+
if (tag === "INPUT" || tag === "BUTTON") return;
|
|
500
|
+
if ((e.code === "KeyB" || (e.code === "KeyR" && e.shiftKey)) && !e.repeat) {
|
|
501
|
+
startNewBout();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (e.code === "KeyR" && !e.repeat) {
|
|
505
|
+
const actorEnt = kolmoWorld.queryFirst(ActorTrait);
|
|
506
|
+
const piloted = actorEnt && kolmoWorld.has(actorEnt) ? actorEnt.targetFor(PilotLink) : undefined;
|
|
507
|
+
if (!piloted) {
|
|
508
|
+
startNewBout();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
window.addEventListener("keydown", onKeyDown);
|
|
513
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
514
|
+
}, [startNewBout]);
|
|
515
|
+
|
|
516
|
+
const playerSpawn = lineup[0]!.pose.position;
|
|
517
|
+
const actorStart: [number, number, number] = [
|
|
518
|
+
playerSpawn[0] - 2.6,
|
|
519
|
+
derbyBowlHeight(playerSpawn[0] - 2.6, playerSpawn[2]) + ACTOR_GROUND_CLEARANCE,
|
|
520
|
+
playerSpawn[2],
|
|
521
|
+
];
|
|
522
|
+
|
|
523
|
+
return (
|
|
524
|
+
<>
|
|
525
|
+
<Game skybox="dusk" dropSpawn>
|
|
526
|
+
<Terrain heights={arena.heights} segments={ARENA_SEGMENTS} size={[ARENA_SIZE, ARENA_SIZE]} color="#54473b" />
|
|
527
|
+
<DerbyReferee
|
|
528
|
+
key={`referee-${boutId}`}
|
|
529
|
+
boutId={boutId}
|
|
530
|
+
lineup={lineup}
|
|
531
|
+
vehicleRefs={vehicleRefs}
|
|
532
|
+
jointsRefs={jointsRefs}
|
|
533
|
+
telemetryRef={telemetryRef}
|
|
534
|
+
/>
|
|
535
|
+
{lineup.map((car, idx) => (
|
|
536
|
+
<Vehicle
|
|
537
|
+
key={`${boutId}-${car.id}`}
|
|
538
|
+
id={car.id}
|
|
539
|
+
label={car.label}
|
|
540
|
+
bundle={car.bundle}
|
|
541
|
+
position={car.pose.position}
|
|
542
|
+
quaternion={car.pose.quaternion}
|
|
543
|
+
vehicleRef={(h) => {
|
|
544
|
+
vehicleRefs.current[idx] = h;
|
|
545
|
+
}}
|
|
546
|
+
jointsRef={(jh) => {
|
|
547
|
+
jointsRefs.current[idx] = jh;
|
|
548
|
+
}}
|
|
549
|
+
/>
|
|
550
|
+
))}
|
|
551
|
+
<Actor key={`actor-${boutId}`} ref={actorRef} view="tps" position={actorStart} />
|
|
552
|
+
</Game>
|
|
553
|
+
|
|
554
|
+
<div
|
|
555
|
+
style={{
|
|
556
|
+
position: "fixed",
|
|
557
|
+
top: 12,
|
|
558
|
+
right: 12,
|
|
559
|
+
zIndex: 10,
|
|
560
|
+
display: "flex",
|
|
561
|
+
alignItems: "center",
|
|
562
|
+
gap: 8,
|
|
563
|
+
padding: "5px 9px",
|
|
564
|
+
borderRadius: 3,
|
|
565
|
+
border: "1px solid oklch(27% 0.010 265)",
|
|
566
|
+
background: "oklch(16.5% 0.008 265)",
|
|
567
|
+
color: "oklch(94% 0.008 85)",
|
|
568
|
+
font: '600 11px/1.3 "IBM Plex Mono", ui-monospace, monospace',
|
|
569
|
+
fontVariantNumeric: "tabular-nums",
|
|
570
|
+
}}
|
|
571
|
+
>
|
|
572
|
+
<span ref={telemetryRef} style={{ color: "oklch(80% 0.165 78)", minWidth: 340 }}>
|
|
573
|
+
{`PANELS 6/6 · KOs 0/${RIVAL_COUNT} · [E] EXIT/BOARD · [R] NEW BOUT`}
|
|
574
|
+
</span>
|
|
575
|
+
<span style={{ width: 1, height: 14, background: "oklch(27% 0.010 265)" }} />
|
|
576
|
+
<button
|
|
577
|
+
type="button"
|
|
578
|
+
onClick={startNewBout}
|
|
579
|
+
style={{
|
|
580
|
+
minHeight: 28,
|
|
581
|
+
padding: "4px 9px",
|
|
582
|
+
borderRadius: 2,
|
|
583
|
+
border: "1px solid oklch(27% 0.010 265)",
|
|
584
|
+
background: "oklch(21% 0.009 265)",
|
|
585
|
+
color: "oklch(94% 0.008 85)",
|
|
586
|
+
font: '600 11px/1.2 "IBM Plex Mono", ui-monospace, monospace',
|
|
587
|
+
fontVariantNumeric: "tabular-nums",
|
|
588
|
+
cursor: "pointer",
|
|
589
|
+
}}
|
|
590
|
+
>
|
|
591
|
+
NEW BOUT
|
|
592
|
+
</button>
|
|
593
|
+
</div>
|
|
594
|
+
|
|
595
|
+
<Hud />
|
|
596
|
+
<Radar spec={arena.radarSpec} />
|
|
597
|
+
</>
|
|
598
|
+
);
|
|
599
|
+
}
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
"moduleResolution": "bundler",
|
|
7
7
|
"jsx": "react-jsx",
|
|
8
8
|
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"noUnusedLocals": true,
|
|
11
|
+
"noUnusedParameters": true,
|
|
9
12
|
"skipLibCheck": true,
|
|
10
|
-
"isolatedModules": true
|
|
11
|
-
"noEmit": true
|
|
13
|
+
"isolatedModules": true
|
|
12
14
|
},
|
|
13
15
|
"include": ["src", "vite.config.ts"]
|
|
14
16
|
}
|
package/templates/dust/README.md
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# Dust
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Coastal island survival sandbox mounting `@pinkaphant/kolmo`'s `<Water />` Gerstner sea, a compact `@khr3/c12` coastal outpost (`<Settlement>`) + fuel depot registered in `<Radar>`, buoyant surf salvage props, a surface-tangent (`computeSurfaceSpawnPose`) buoyant scrap hatchback, and `<Game dropSpawn>` ([`./src/App.tsx`](./src/App.tsx)).
|
|
4
4
|
|
|
5
5
|
- **WASD** / **Arrows**: Walk or drive
|
|
6
|
+
- **Shift**: Sprint (on foot) / boost (vehicle)
|
|
7
|
+
- **Space**: Jump (on foot) / brake (vehicle)
|
|
8
|
+
- **C**: Brake
|
|
6
9
|
- **E** / **F**: Board or exit the scrap hatchback
|
|
10
|
+
- **R**: Flip vehicle upright
|
|
11
|
+
- **V**: Toggle FPS / TPS camera
|
|
12
|
+
- **L**: Toggle vehicle headlights
|
|
13
|
+
- **N**: Cycle day / dusk / night sky
|
|
14
|
+
- **O** or **Drag & Drop `.glb`**: Auto-rig, spawn, and board any car `.glb`
|
|
7
15
|
- **T** / **Right-Click**: Spawn armed vehicle
|
|
8
16
|
|
|
9
17
|
```bash
|
|
@@ -4,8 +4,22 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
6
6
|
<title>Dust</title>
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
9
|
+
<link
|
|
10
|
+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500;600&family=Space+Grotesk:wght@500;600;700&display=swap"
|
|
11
|
+
rel="stylesheet"
|
|
12
|
+
/>
|
|
7
13
|
<style>
|
|
8
|
-
html, body, #root {
|
|
14
|
+
html, body, #root {
|
|
15
|
+
margin: 0;
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
background: oklch(13.5% 0.007 265);
|
|
20
|
+
font-family: "Space Grotesk", system-ui, sans-serif;
|
|
21
|
+
font-variant-numeric: tabular-nums;
|
|
22
|
+
}
|
|
9
23
|
</style>
|
|
10
24
|
</head>
|
|
11
25
|
<body>
|