@homie-rocks/studio 0.51.0 → 0.51.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/CHANGELOG.md +12 -0
- package/guides/game/RULES.md +26 -0
- package/lib/template-history.json +42 -0
- package/package.json +1 -1
- package/rules/correction-path.ts +35 -0
- package/rules/map-index.ts +4 -4
- package/rules/view.ts +196 -28
- package/worker/build-id.mjs +1 -1
- package/worker/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,18 @@ To bring a studio up to date, tell Claude: "Upgrade my studio to the newest Homi
|
|
|
17
17
|
`npx -y @homie-rocks/studio@latest upgrade`, which shows what's new since the version your studio pins (from this
|
|
18
18
|
file) and what the upgrade would change, and changes nothing until you agree.
|
|
19
19
|
|
|
20
|
+
## [0.51.1] - 2026-10-14
|
|
21
|
+
|
|
22
|
+
**Plugin 0.51.1** · A player's own runner never jumps across the screen.
|
|
23
|
+
|
|
24
|
+
Your platformer keeps a player's runner moving smoothly through network corrections and reconnects, with less work per frame on slower phones.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- In server-rules platformers, a player's own box-shaped 2D runner now moves smoothly through network corrections, even after a delayed frame. It goes around blocking platforms without being pulled backwards against the player's held direction, and normal jumps keep their shape.
|
|
29
|
+
- After a dropped connection, the runner glides from its last visible position to where the server moved it. Real respawns and other deliberate placements still happen immediately; games can identify placements made during an outage with `respawned`.
|
|
30
|
+
- Rules games do less repeated movement, collision and drawing preparation each frame, helping play stay smooth on slower phones. These changes preserve the server's movement, hits and scoring.
|
|
31
|
+
|
|
20
32
|
## [0.51.0] - 2026-10-14
|
|
21
33
|
|
|
22
34
|
**Plugin 0.51.0** · Take the money through your own Stripe, keyless by default.
|
package/guides/game/RULES.md
CHANGED
|
@@ -1443,3 +1443,29 @@ catch-up path. It resumes live prediction at once and carries the drawn pose int
|
|
|
1443
1443
|
the normal correction blend, so a counter-dash or jump does not wait for the
|
|
1444
1444
|
unseen impulse's history to finish. This changes drawing only; authority, input
|
|
1445
1445
|
timestamps, cooldowns and replay rules are unchanged.
|
|
1446
|
+
|
|
1447
|
+
Own box-bodied 2D presentation also sweeps from its last displayed position. Reconciliation
|
|
1448
|
+
cannot switch sides of a solid merely because the new predicted origin is on
|
|
1449
|
+
the other side. Travel is limited by elapsed time plus a body-sized blend. Horizontal travel uses the adjacent
|
|
1450
|
+
actual velocities; vertical travel uses the recorded substeps with interpolation headroom, so an apex or landing is not trimmed.
|
|
1451
|
+
A stationary correction spends only blend speed, not the declared terminal falling speed.
|
|
1452
|
+
A large falling-speed limit cannot accelerate a horizontal correction. If sliding cannot reach a correction, a bounded
|
|
1453
|
+
incremental route searches collision-tested edges around the obstruction. No
|
|
1454
|
+
route means holding the last valid position, never crossing a solid. Explicit
|
|
1455
|
+
placements and epoch changes reset presentation immediately. These positions
|
|
1456
|
+
never feed movement, hits, scoring, input timestamps, or authority.
|
|
1457
|
+
|
|
1458
|
+
A platformer can supply `openRoom({ correctionDirection: input => Number(input.r || 0) - Number(input.l || 0) })`
|
|
1459
|
+
for box-bodied 2D presentation. This is horizontal control intent (-1, 0, +1), not authority or a second movement loop.
|
|
1460
|
+
It prevents a visual correction from reversing held controls even when contact sets velocity to zero; neutral input
|
|
1461
|
+
allows convergence in either direction. Actual predicted braking against a newly reversed control remains allowed.
|
|
1462
|
+
|
|
1463
|
+
After a delayed render, box-bodied 2D presentation spends at most 1.4 body widths per drawn frame,
|
|
1464
|
+
then continues toward prediction. This affects drawing only; an explicit placement remains immediate.
|
|
1465
|
+
|
|
1466
|
+
When a player's connection comes back, the server hands the body back where it has it, with a new placement
|
|
1467
|
+
revision. Within three seconds of the link coming back online, box-bodied 2D presentation treats that revision as the
|
|
1468
|
+
same body and draws on from where it was shown, gliding and routing around solids as for any correction. A body that
|
|
1469
|
+
was really placed while the player was away (a respawn, a new round) should still be drawn at once: say so with
|
|
1470
|
+
`openRoom({ respawned: (before, after) => after.diedAt !== before.diedAt })`, where `before` and `after` are the own
|
|
1471
|
+
body as the server last had it before and after the outage.
|
|
@@ -3534,6 +3534,48 @@
|
|
|
3534
3534
|
}
|
|
3535
3535
|
}
|
|
3536
3536
|
}
|
|
3537
|
+
},
|
|
3538
|
+
"0.51.1": {
|
|
3539
|
+
"files": {
|
|
3540
|
+
"CLAUDE.md": "ddf2b2a0376202f6",
|
|
3541
|
+
"README.md": "684b3cca8001673c",
|
|
3542
|
+
"HANDOFF.md": "29337e2ace95b2e7",
|
|
3543
|
+
"games/README.md": "5ad32fe80c61f117",
|
|
3544
|
+
"music/README.md": "a3dc042dadd39df8",
|
|
3545
|
+
"videos/README.md": "16babc3437d5545b",
|
|
3546
|
+
"posts/README.md": "37841aae476bd540",
|
|
3547
|
+
"site/README.md": "1dbdf22c03a1e505",
|
|
3548
|
+
"site/src/worker.mjs": "6cc5c6131eaf6fd0"
|
|
3549
|
+
},
|
|
3550
|
+
"sections": {
|
|
3551
|
+
"AGENTS.md": {
|
|
3552
|
+
"(intro)": "394cbbe934e80722",
|
|
3553
|
+
"## Version-matched authoring guides": "f6261a0e5801b96b",
|
|
3554
|
+
"## Layout": "f3a280b8c96cd068",
|
|
3555
|
+
"## Apps: one screen, roles and parts": "c10aa0441ea89702",
|
|
3556
|
+
"## Commands (all through the pinned CLI in node_modules)": "5222e08ca55e326e",
|
|
3557
|
+
"## The site": "0cb8dd9a6f8a0096",
|
|
3558
|
+
"## Making games": "bb715272fd1a615b",
|
|
3559
|
+
"## The Game Codex and progress": "0738ef719cef3a4c",
|
|
3560
|
+
"## Art direction and models": "a48fff7bf0a5f2fc",
|
|
3561
|
+
"## Running live games (the back office)": "51ebf2ab756f6e4d",
|
|
3562
|
+
"## Servers and AI seats": "1ccfd549d2369a60",
|
|
3563
|
+
"## Selling things (the shop)": "43a3556be93d1235",
|
|
3564
|
+
"## Continuing a build from the Claude app": "0d68081e924ca419",
|
|
3565
|
+
"## Rules": "b2234d80f6cbe71d",
|
|
3566
|
+
"## Telling Homie": "80b46fdd9e578db8",
|
|
3567
|
+
"## Beta": "9d02638207a26e73"
|
|
3568
|
+
}
|
|
3569
|
+
},
|
|
3570
|
+
"named": {
|
|
3571
|
+
"Homie Arcade": {
|
|
3572
|
+
"sections": {
|
|
3573
|
+
"AGENTS.md": {
|
|
3574
|
+
"## Commands (all through the pinned CLI in node_modules)": "611b437f5b3303f0"
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3537
3579
|
}
|
|
3538
3580
|
}
|
|
3539
3581
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homie-rocks/studio",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.1",
|
|
4
4
|
"description": "A studio for games, music and video on its own Cloudflare: scaffold, multiplayer starters on the netplay contract, a port toolkit that makes existing single-player web games multiplayer, the site Worker with public rooms (Table/Lobby Durable Objects and D1, all on the free Workers plan, no payment method), a site with the hub's sections (Home, Games, Music, Videos, Rooms, Posts with feeds) in the studio's own look, an epic landing page for every game, big songs and videos in the studio's own R2 once it has storage (uploaded, checked by SHA-256, served at the same addresses), deploy, and the homie.rocks directory.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Vec3 } from './math.ts';
|
|
2
|
+
|
|
3
|
+
/** A bounded, incremental presentation route. Never participates in simulation.
|
|
4
|
+
* Each edge is accepted by the same body sweep used to draw the runner. Search
|
|
5
|
+
* is spread over frames so an unusual correction cannot monopolize a phone. */
|
|
6
|
+
export function correctionPath(start: Vec3, goal: Vec3, spacing: number) {
|
|
7
|
+
type Node = { x: number; y: number; pos: Vec3; cost: number; estimate: number; parent?: Node };
|
|
8
|
+
const distance = (a: Vec3, b: Vec3) => Math.hypot(a.x-b.x,a.y-b.y);
|
|
9
|
+
const first: Node = {x:0,y:0,pos:start,cost:0,estimate:distance(start,goal)};
|
|
10
|
+
const open = [first], costs = new Map<string,number>([['0,0',0]]);
|
|
11
|
+
let route: Vec3[] | null = null, exhausted = false;
|
|
12
|
+
return {
|
|
13
|
+
goal,
|
|
14
|
+
advance(clear: (from: Vec3,to: Vec3)=>boolean): readonly Vec3[] | null {
|
|
15
|
+
if (route || exhausted) return route;
|
|
16
|
+
for (let budget=0;budget<24 && open.length;budget++) {
|
|
17
|
+
let best=0;for(let i=1;i<open.length;i++)if(open[i].estimate<open[best].estimate)best=i;
|
|
18
|
+
const node=open.splice(best,1)[0];
|
|
19
|
+
if(clear(node.pos,goal)) {
|
|
20
|
+
route=[goal];let n:Node|undefined=node;while(n?.parent){route.unshift(n.pos);n=n.parent;}return route;
|
|
21
|
+
}
|
|
22
|
+
for(const [dx,dy] of [[1,0],[-1,0],[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]]) {
|
|
23
|
+
const x=node.x+dx,y=node.y+dy,key=`${x},${y}`,cost=node.cost+Math.hypot(dx,dy)*spacing;
|
|
24
|
+
if(cost>=(costs.get(key)??Infinity))continue;
|
|
25
|
+
const pos={x:start.x+x*spacing,y:start.y+y*spacing,z:0};
|
|
26
|
+
if(!clear(node.pos,pos))continue;
|
|
27
|
+
costs.set(key,cost);open.push({x,y,pos,cost,estimate:cost+distance(pos,goal),parent:node});
|
|
28
|
+
}
|
|
29
|
+
if(costs.size>4096){exhausted=true;return null;}
|
|
30
|
+
}
|
|
31
|
+
if(!open.length)exhausted=true;
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
package/rules/map-index.ts
CHANGED
|
@@ -61,15 +61,15 @@ function nearbyFlatMap(map: MapShapes, p:Vec3, d:Vec3, radius:number, height:num
|
|
|
61
61
|
const out:any={bounds:map.bounds,boxes:[],circles:[],spheres:[],capsules:[],heightTiles:[]};
|
|
62
62
|
function touches(n:{min:Vec3;max:Vec3}):boolean {
|
|
63
63
|
charge(12);let near=0,far=1;
|
|
64
|
-
for(
|
|
64
|
+
for(let axis=0;axis<(dims===2?2:3);axis++){const k=axes[axis],lo=n.min[k]-(k==='z'?height:radius),hi=n.max[k]+(k==='z'?0:radius);
|
|
65
65
|
if(d[k]===0){if(p[k]<lo-1e-7||p[k]>hi+1e-7)return false;}
|
|
66
|
-
else {let a=(lo-p[k])/d[k],b=(hi-p[k])/d[k];if(a>b)
|
|
66
|
+
else {let a=(lo-p[k])/d[k],b=(hi-p[k])/d[k];if(a>b){const swap=a;a=b;b=swap;}near=Math.max(near,a);far=Math.min(far,b);if(near>far+1e-7)return false;}
|
|
67
67
|
}return true;
|
|
68
68
|
}
|
|
69
69
|
const found:Entry[]=[];
|
|
70
|
-
function visit(n:Node){if(!touches(n))return;if(n.entries){for(const e
|
|
70
|
+
function visit(n:Node){if(!touches(n))return;if(n.entries){for(let i=0;i<n.entries.length;i++){const e=n.entries[i];if(touches(e))found.push(e);}}else{visit(n.left!);visit(n.right!);}}
|
|
71
71
|
visit(root);charge(found.length*Math.ceil(Math.log2(found.length+1)));
|
|
72
|
-
found.sort((a,b)=>a.order-b.order);for(const e
|
|
72
|
+
found.sort((a,b)=>a.order-b.order);for(let i=0;i<found.length;i++){const e=found[i];out[e.key].push(e.value);}
|
|
73
73
|
if(parent)for(const key of ['boxes','circles','spheres','capsules','heightTiles'] as const)for(const raw of map[key]??[]){
|
|
74
74
|
const v:any=raw;let min:Vec3,max:Vec3;
|
|
75
75
|
if(key==='boxes'){min=v.min;max=v.max;}
|
package/rules/view.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { correctionPath } from './correction-path.ts';
|
|
1
2
|
import { disposeMoveContext, sweepMap } from './math.ts';
|
|
2
3
|
import { boundPosition, periodicDelta, blendPosition, relativePoint, wrapPoint } from './topology.mjs';
|
|
3
4
|
import { rayQuery, raySnapshot, type QueryTarget } from './query.ts';
|
|
@@ -108,6 +109,14 @@ export interface OpenRoomOptions {
|
|
|
108
109
|
predict?: Record<string, Predictor>;
|
|
109
110
|
/** Camera axes on the rules' x/y plane for the testing tools. Default: x right, y up. */
|
|
110
111
|
screenBasis?: PortProbeOptions['basis'];
|
|
112
|
+
/** Horizontal intent for box-bodied 2D visual corrections: -1 left, 0 neutral, +1 right. Does not affect simulation. */
|
|
113
|
+
correctionDirection?: (input: Readonly<Record<string, unknown>>, velocity: Vec3) => number;
|
|
114
|
+
/**
|
|
115
|
+
* After this browser's connection comes back, the server hands the own body back where it has it (a new placement
|
|
116
|
+
* revision). A box-bodied 2D runner is then drawn on from where it was shown, not cut across. Say here when that
|
|
117
|
+
* revision is a real placement made while the player was away (a respawn, a new round): it is then drawn at once.
|
|
118
|
+
*/
|
|
119
|
+
respawned?: (before: Entity, after: Entity) => boolean;
|
|
111
120
|
/** Tests: a clock in ms and a way to run without timers. */
|
|
112
121
|
now?: () => number;
|
|
113
122
|
timers?: boolean;
|
|
@@ -224,6 +233,15 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
224
233
|
/* ---------------------------------------------------------------- frames in */
|
|
225
234
|
|
|
226
235
|
const delivery = snapshotDecoder();
|
|
236
|
+
/** Until when a revision of the own body counts as the server handing it back after a reconnect. */
|
|
237
|
+
let returningUntil = 0;
|
|
238
|
+
let unpackedRows = new Map<string, {wire: unknown; value: Unpacked}>();
|
|
239
|
+
const sameRow = (a: unknown, b: unknown): boolean => {
|
|
240
|
+
if (a === b) return true;
|
|
241
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
242
|
+
for (let i = 0; i < a.length; i++) if (!sameRow(a[i], b[i])) return false;
|
|
243
|
+
return true;
|
|
244
|
+
};
|
|
227
245
|
function frameOf(s: Snapshot<unknown> | null): Frame | null {
|
|
228
246
|
if (!s || typeof s !== 'object') return null;
|
|
229
247
|
if (frames.has(s)) return frames.get(s) ?? null;
|
|
@@ -231,13 +249,29 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
231
249
|
const d = delivery.decode(s)?.d as [unknown, unknown, CollisionRevision?] | null;
|
|
232
250
|
if (Array.isArray(d) && Array.isArray(d[0]) && Array.isArray(d[1])) {
|
|
233
251
|
const ents = new Map<string, Unpacked>();
|
|
234
|
-
|
|
252
|
+
// Delta rows and repeated keyframe rows often describe unchanged scenery.
|
|
253
|
+
// Compare the immutable wire arrays before allocating typed vectors/fields.
|
|
254
|
+
// Retain only this frame's rows, not a growing history of transient keys.
|
|
255
|
+
const nextRows = new Map<string, {wire: unknown; value: Unpacked}>();
|
|
256
|
+
for (const w of d[1] as unknown[]) {
|
|
257
|
+
const id = Array.isArray(w) && typeof w[0] === 'string' ? w[0] : '';
|
|
258
|
+
const prior = unpackedRows.get(id);
|
|
259
|
+
const e = prior && sameRow(prior.wire, w) ? prior.value : unpackEntity(schema.kinds, w, dims);
|
|
260
|
+
if (e) { nextRows.set(e.id, prior?.value === e ? prior : {wire:w,value:e}); ents.set(e.id, e); }
|
|
261
|
+
}
|
|
262
|
+
unpackedRows = nextRows;
|
|
235
263
|
f = { collision: d[2], k: s.k, e: Number(s.e) || 0, at: clock(), round: [Number(d[0][0]) || 0, Number(d[0][1]) || 0, Number(d[0][2]) || 0], ents, rows: (Array.isArray(s.c) ? s.c : []) as unknown as number[][] };
|
|
236
264
|
}
|
|
237
265
|
frames.set(s, f);
|
|
238
266
|
return f;
|
|
239
267
|
}
|
|
240
|
-
const
|
|
268
|
+
const entities = new WeakMap<Unpacked, Entity>();
|
|
269
|
+
const entityOf = (u: Unpacked, mine = false, cache = !mine): Entity => {
|
|
270
|
+
if (cache && entities.has(u)) return entities.get(u)!;
|
|
271
|
+
const entity = Object.freeze({ id: u.id, kind: u.kind, pos: u.pos, vel: u.vel, heading: u.heading, grounded: u.grounded, ...(u.seat !== undefined ? { seat: u.seat, owner: u.owner, driver: u.driver, away: u.away, goal: u.goal } : {}), ...(mine ? { mine: true } : {}), ...u.fields, motion: Object.freeze({ ...u.motion }) }) as Entity;
|
|
272
|
+
if (cache) entities.set(u, entity);
|
|
273
|
+
return entity;
|
|
274
|
+
};
|
|
241
275
|
|
|
242
276
|
/* ---------------------------------------------------------------- the own body, on this browser's copy of the clock */
|
|
243
277
|
|
|
@@ -281,7 +315,8 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
281
315
|
let offsets: { delta: Vec3; at: number; path: Vec3; fade: number; last: number; end?: number }[] = [];
|
|
282
316
|
const predict = schema.settings.predict;
|
|
283
317
|
const quantile = (list: number[], q: number): number => [...list].sort((a, b) => a - b)[Math.floor((list.length - 1) * q)] ?? 0;
|
|
284
|
-
|
|
318
|
+
let leadTarget = .5, leadMedian = 0, hostMedian = 0;
|
|
319
|
+
const targetLead = (): number => leadTarget;
|
|
285
320
|
const copyMine = (m: Mine): Mine => ({ ...m, motion: motionOf(m.kind, m.motion) });
|
|
286
321
|
const distance = (a: Vec3, b: Vec3): number => Math.hypot(periodicDelta(b.x,a.x,map.wrap?.x),periodicDelta(b.y,a.y,map.wrap?.y),periodicDelta(b.z,a.z,map.wrap?.z));
|
|
287
322
|
const correction = { count: 0, max: 0, last: 0, catches: 0, snaps: 0, rebases: 0, rebaseReason: '', rebaseError: 0 };
|
|
@@ -357,14 +392,14 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
357
392
|
// The helper's ping ends at the relay. A browser host adds another network leg in both directions.
|
|
358
393
|
// Snapshot stamps use the relay clock, so their observed age measures the complete downstream path.
|
|
359
394
|
const relayRtt = net.stats().rtt ?? 100;
|
|
360
|
-
return net.offline ? 0 : Math.max(relayRtt, 2 *
|
|
395
|
+
return net.offline ? 0 : Math.max(relayRtt, 2 * hostMedian);
|
|
361
396
|
}
|
|
362
397
|
function phaseAt(at: number): number {
|
|
363
398
|
let p = phases[0];
|
|
364
399
|
for (let i = phases.length - 1; i >= 0; i--) if (phases[i].at <= at) { p = phases[i]; break; }
|
|
365
400
|
return p ? p.tick + (at - p.at) / period * p.rate - at / period : 0;
|
|
366
401
|
}
|
|
367
|
-
const medianLead = (): number => leads.length ?
|
|
402
|
+
const medianLead = (): number => leads.length ? leadMedian + phaseAt(clock()) : 0;
|
|
368
403
|
function steer(now: number): void {
|
|
369
404
|
if (!base || !leads.length) return;
|
|
370
405
|
base = { tick: tickAt(now), at: now };
|
|
@@ -384,11 +419,11 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
384
419
|
const rtt = authorityRtt(); calibratedRtt = rtt;
|
|
385
420
|
// Lead samples refer to the clock which stamped them. Do not mix its offset with this clock's jitter.
|
|
386
421
|
const target = targetLead();
|
|
387
|
-
leads.length = 0;
|
|
422
|
+
leads.length = 0; leadTarget = .5; leadMedian = 0;
|
|
388
423
|
leadAfter = clock() + 2 * rtt + period;
|
|
389
424
|
base = { tick: continuousTick ?? k + Math.min(tickHz, Math.ceil(rtt / period + target) + sendEvery - 1), at: clock() };
|
|
390
425
|
stepped = Math.max(k, Math.floor(base.tick) - (continuousTick === null ? 1 : 0));
|
|
391
|
-
entries = []; sentHistory = []; controlChanges = []; pending = []; history.clear(); replayHeld = {}; serverHeld = {}; held = {}; lastSent = ''; leads.length = 0; pressed = new Map(); pulseNumber = new Map(); heldTrack.clear(); if (reason !== 'lead') dropPredictions();
|
|
426
|
+
entries = []; sentHistory = []; controlChanges = []; pending = []; history.clear(); replayHeld = {}; serverHeld = {}; held = {}; lastSent = ''; leads.length = 0; leadTarget = .5; leadMedian = 0; pressed = new Map(); pulseNumber = new Map(); heldTrack.clear(); if (reason !== 'lead') dropPredictions();
|
|
392
427
|
speed = 1; phases.length = 0; phases.push({ ...base, rate: 1 }); catchTick = null; offsets = []; headingBlend = null; correction.rebases += 1;
|
|
393
428
|
const u = mine && latest?.ents.get(mine.id); if (u) adopt(u);
|
|
394
429
|
if (mine) {
|
|
@@ -419,22 +454,35 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
419
454
|
/** `motion` as this browser's own `move` may change it in place: what a snapshot carries is frozen, so every list, map and struct in it is copied. */
|
|
420
455
|
const motionOf = (kindName: string, motion: Record<string, unknown>): Record<string, unknown> => thawFields(kindOf.get(kindName)?.motion ?? [], motion);
|
|
421
456
|
function adopt(u: Unpacked): void {
|
|
457
|
+
presentedEntity = null;
|
|
422
458
|
mine = { id: u.id, kind: u.kind, r: u.r, pos: u.pos, vel: u.vel, heading: u.heading, grounded: u.grounded, motion: motionOf(u.kind, u.motion), fields: predictors[u.kind] ? thawFields(kindOf.get(u.kind)?.fields ?? [], u.fields) : u.fields };
|
|
423
459
|
}
|
|
424
460
|
/** The game's guarded `move` for one tick, counted as the server counts it, with the result rounded as the server rounds it. */
|
|
425
461
|
const substepKinds = new Set<string>();
|
|
462
|
+
const movementCache = new Map<string, {scene: unknown; value: ReturnType<typeof stepMove>}>();
|
|
426
463
|
function runMove(kindName: string, body: { pos: Vec3; vel: Vec3; heading: Vec3; grounded: boolean; motion: Record<string, unknown> }, input: Readonly<Record<string, unknown>>, t: number): typeof body & {steps?: readonly import('./substeps.ts').StepPose[]} {
|
|
427
464
|
const fn = moves[kindName];
|
|
428
465
|
if (!fn || (kindOf.get(kindName)?.control && !body.motion[kindOf.get(kindName)!.control!])) return body;
|
|
429
466
|
moveTick = t;
|
|
430
467
|
// Like snapshot unpacking, prepare the bounded geometry outside the handler
|
|
431
468
|
// quota. Authority debits projection once per tick, not once per mover.
|
|
432
|
-
geometryAt();
|
|
433
|
-
|
|
469
|
+
const scene = geometryAt();
|
|
470
|
+
// Reconciliation often replays the exact same deterministic movement. Cache
|
|
471
|
+
// its full arguments, including tick, self, motion and collision revision.
|
|
472
|
+
// Stateful physics worlds must execute their operations and are excluded.
|
|
473
|
+
const key = map.physics ? '' : JSON.stringify([mine?.id,kindName,t,body.pos,body.vel,body.heading,body.grounded,body.motion,input]);
|
|
474
|
+
const cached = key ? movementCache.get(key) : undefined;
|
|
475
|
+
if (cached?.scene === scene) return {...cached.value,motion:motionOf(kindName,cached.value.motion)};
|
|
476
|
+
let failed = false;
|
|
477
|
+
const out = stepMove(fn, body, input, moveCtx, Math.max(1, Math.floor(schema.settings.budget.tick / 4)), kindOf.get(kindName)?.motion ?? [], dims, (err) => { failed = true; if (!(err instanceof BudgetError)) console.warn('[room] move', err); });
|
|
434
478
|
if (out.steps?.length) substepKinds.add(kindName);
|
|
435
479
|
const kind = kindOf.get(kindName), r = kind?.radius ?? 0;
|
|
436
480
|
const height = kind?.height || 2 * r;
|
|
437
481
|
out.pos = vec3(boundPosition(out.pos,map,r,height,dims), dims);
|
|
482
|
+
if (key && !failed) {
|
|
483
|
+
movementCache.set(key,{scene,value:{...out,motion:motionOf(kindName,out.motion)}});
|
|
484
|
+
if(movementCache.size>128)movementCache.delete(movementCache.keys().next().value!);
|
|
485
|
+
}
|
|
438
486
|
return out;
|
|
439
487
|
}
|
|
440
488
|
/* ---------------------------------------------------------------- the own actions, predicted (0.46.3) */
|
|
@@ -705,8 +753,10 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
705
753
|
}
|
|
706
754
|
if (before && before.e !== f.e) hostAges.length = 0;
|
|
707
755
|
hostAges.push(Math.max(0, net.now() - s.st)); if (hostAges.length > 40) hostAges.shift();
|
|
756
|
+
hostMedian = quantile(hostAges, .5);
|
|
708
757
|
if (before && before.e !== f.e) fxQueue.length = 0;
|
|
709
758
|
const changedEpoch = f.e !== epoch;
|
|
759
|
+
if (changedEpoch) { presented=null; routing=null; route=[]; }
|
|
710
760
|
epoch = f.e;
|
|
711
761
|
const seat = net.seat;
|
|
712
762
|
let me: Unpacked | null = null;
|
|
@@ -716,6 +766,15 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
716
766
|
const row = f.rows.find((x) => x[0] === seat);
|
|
717
767
|
if(changedEpoch)applications.clear();
|
|
718
768
|
if(row?.[6]===471){for(let i=7;i+1<row.length;i+=2)applications.set(row[i],row[i+1]);while(applications.size>128)applications.delete(applications.keys().next().value!);}
|
|
769
|
+
// A return hands the body back at the server's pose with a new revision. It is the same body, still on the
|
|
770
|
+
// screen: keep drawing it from where it is shown unless the game says it was really placed meanwhile.
|
|
771
|
+
const prior = held2.at(-2)?.ents.get(me.id) ?? null;
|
|
772
|
+
if (placed && !changedEpoch && returningUntil > clock() && mine?.id === me.id && mine.r !== me.r && presented?.id === me.id && presented.r === mine.r) {
|
|
773
|
+
let respawn = false;
|
|
774
|
+
if (opts.respawned && prior) { try { respawn = Boolean(opts.respawned(entityOf(prior, true, false), entityOf(me, true, false))); } catch (err) { console.warn('[room] respawned', err); } }
|
|
775
|
+
if (!respawn) { presented.r = me.r; presented.at = clock(); }
|
|
776
|
+
returningUntil = 0;
|
|
777
|
+
}
|
|
719
778
|
if (placed || !base) {
|
|
720
779
|
adopt(me); rebase(f.k, changedEpoch ? 'epoch' : 'placement');
|
|
721
780
|
if (placed) emit('placed', entityOf(me, true));
|
|
@@ -830,6 +889,8 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
830
889
|
// our own +/-5% steering inflates the 40-sample jitter window and winds the clock ever further ahead.
|
|
831
890
|
observedLeadAt = now;
|
|
832
891
|
leads.push(row[3] / 16 - phaseAt(now - rtt)); if (leads.length > 40) leads.shift();
|
|
892
|
+
leadTarget = .5 + Math.max(0, quantile(leads, .5) - quantile(leads, .05));
|
|
893
|
+
leadMedian = quantile(leads.slice(-8), .5);
|
|
833
894
|
const med = medianLead(), target = targetLead();
|
|
834
895
|
// A changing jitter estimate must not discard already stamped input. Slew the
|
|
835
896
|
// clock; late movement is settled by the server's retained history.
|
|
@@ -876,7 +937,7 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
876
937
|
net.on('snapshot', onSnapshot);
|
|
877
938
|
net.on('role', (e) => { if (e.snap) onSnapshot(e.snap); if (net.offline && !net.rulesHosting) setStatus(net.closedWhy ? 'closed' : 'offline'); });
|
|
878
939
|
net.on('link', (e) => {
|
|
879
|
-
if (e.state === 'online') { base = null; if (status !== 'playing') setStatus('connecting'); } else if (e.state === 'closed') setStatus('closed'); else if (e.state === 'alone' || e.state === 'offline') setStatus('offline');
|
|
940
|
+
if (e.state === 'online') { returningUntil = clock() + 3000; base = null; if (status !== 'playing') setStatus('connecting'); } else if (e.state === 'closed') setStatus('closed'); else if (e.state === 'alone' || e.state === 'offline') setStatus('offline');
|
|
880
941
|
});
|
|
881
942
|
net.on('round', (r) => { if (r.results) { results = r.results; if (round) { round = { ...round, results }; emit('round', roundNow()); } } });
|
|
882
943
|
net.on('event', (e) => {
|
|
@@ -923,7 +984,15 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
923
984
|
* the two, by how much of the tick has passed, and the copy is thrown away. So the stick answers on the next
|
|
924
985
|
* drawn frame, not on the next tick.
|
|
925
986
|
*/
|
|
926
|
-
|
|
987
|
+
let routing: ReturnType<typeof correctionPath> | null = null;
|
|
988
|
+
let route: Vec3[] = [];
|
|
989
|
+
let routeDirection = 0;
|
|
990
|
+
let presentedEntity: Entity | null = null;
|
|
991
|
+
let presentationQueued = false;
|
|
992
|
+
let forecast: { mine: Mine; pos: Vec3; motion: Record<string, unknown>; tick: number; key: string; geometry: unknown; next: ReturnType<typeof runMove> } | null = null;
|
|
993
|
+
let presented: { id: string; r: number; pos: Vec3; vel: Vec3; at: number } | null = null;
|
|
994
|
+
function meNow(present = false): Entity | null {
|
|
995
|
+
if (present && presentedEntity) return presentedEntity;
|
|
927
996
|
if (predicting) { const u = mine && predictionFrame?.ents.get(mine.id); return u ? entityOf(u, true) : null; }
|
|
928
997
|
if (solo) return solo.me;
|
|
929
998
|
if (!mine || !latest) return null;
|
|
@@ -946,7 +1015,10 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
946
1015
|
// A recorded substep path needs the whole tick's forecast instead: include
|
|
947
1016
|
// the remaining duration of controls held now, then sample its actual steps.
|
|
948
1017
|
for (const [name, fd] of kind.input) now[name] = (fd.t === 'press' || fd.t === 'pulse') ? (pressed.get(name) ?? (fd.t === 'pulse' && pulseQueue[0]?.name===name ? pulseQueue[0].value : fd.t === 'press' ? false : 0)) : fd.t === 'held' ? coerce(fd, heldMean(name, fd.init, Math.min(clock(), edgeOf(stepped + 1)), false, substepKinds.has(kind.name) ? edgeOf(stepped + 1) : Math.min(clock(), edgeOf(stepped + 1))), dims) : coerce(fd, sample[name] ?? fd.init, dims);
|
|
949
|
-
const
|
|
1018
|
+
const forecastKey = JSON.stringify(now), scene = geometryAt();
|
|
1019
|
+
const reuse = !map.physics && substepKinds.has(kind.name) && forecast && forecast.mine === mine && forecast.pos === mine.pos && forecast.motion === mine.motion && forecast.tick === stepped && forecast.key === forecastKey && forecast.geometry === scene;
|
|
1020
|
+
const next = reuse ? forecast!.next : runMove(kind.name, { pos: mine.pos, vel: mine.vel, heading: mine.heading, grounded: mine.grounded, motion: motionOf(mine.kind, mine.motion) }, Object.freeze(now), stepped + 1);
|
|
1021
|
+
forecast = {mine, pos:mine.pos, motion:mine.motion, tick:stepped, key:forecastKey, geometry:scene, next};
|
|
950
1022
|
// A landing does not take the whole tick (0.46.5): the body met the ground part way through it. How far through is
|
|
951
1023
|
// read from the fall it would have made at the speed it entered the tick with; it is drawn down to the ground by
|
|
952
1024
|
// then and standing from then, not sinking until the tick's end.
|
|
@@ -995,26 +1067,115 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
995
1067
|
// permission to cross a floor. Sweep from a valid movement pose, never feed
|
|
996
1068
|
// the clipped drawing back into prediction or authority.
|
|
997
1069
|
const constrain = (from: Vec3, to: Vec3): Vec3 => {
|
|
998
|
-
if (dims !== 2 || !kind || kind.owner) return to;
|
|
1070
|
+
if (dims !== 2 || !kind || kind.owner || distance(from, to) < 1e-7) return to;
|
|
999
1071
|
const body = {pos: from};
|
|
1000
1072
|
sweepMap(geometryAt(), body, {x:periodicDelta(from.x,to.x,map.wrap?.x),y:periodicDelta(from.y,to.y,map.wrap?.y),z:periodicDelta(from.z,to.z,map.wrap?.z)}, kind.radius, dims,
|
|
1001
1073
|
{shape:kind.shape ?? 'circle',radius:kind.radius,height:kind.height || 2*kind.radius,terrain:kind.terrain});
|
|
1002
1074
|
return body.pos;
|
|
1003
1075
|
};
|
|
1004
|
-
|
|
1076
|
+
// An established box cursor is swept below from the actual displayed side.
|
|
1077
|
+
// Sweeping its target from a second origin first duplicates the same query
|
|
1078
|
+
// and does not add safety. New placements and other body types keep it.
|
|
1079
|
+
const hasCursor = present && dims === 2 && kind?.shape === 'box' && !kind.owner && presented?.id === mine.id && presented.r === mine.r;
|
|
1080
|
+
if (!hasCursor) pos = constrain(safeOrigin, pos);
|
|
1005
1081
|
const offset = visualOffset(clock(), pos, settled);
|
|
1006
|
-
|
|
1082
|
+
const offsetTarget = wrapPoint({ x: pos.x + offset.x, y: pos.y + offset.y, z: pos.z + offset.z },map.wrap);
|
|
1083
|
+
pos = hasCursor ? offsetTarget : constrain(pos, offsetTarget);
|
|
1084
|
+
if (present && dims === 2 && kind?.shape === 'box' && !kind.owner) {
|
|
1085
|
+
const now = clock();
|
|
1086
|
+
if (presented && presented.id === mine.id && presented.r === mine.r) {
|
|
1087
|
+
const from = presented.pos;
|
|
1088
|
+
let forward = velocity.x * presented.vel.x >= 0 ? Math.sign(velocity.x) : 0;
|
|
1089
|
+
if (opts.correctionDirection) {
|
|
1090
|
+
try {
|
|
1091
|
+
const intent = opts.correctionDirection(sample, mine.vel);
|
|
1092
|
+
// An explicit intent must not be overridden by stale replay velocity.
|
|
1093
|
+
// A game can return neutral during genuine braking/reversal inertia.
|
|
1094
|
+
if (Number.isFinite(intent)) forward = Math.sign(intent);
|
|
1095
|
+
}
|
|
1096
|
+
catch (err) { console.warn('[room] correctionDirection', err); }
|
|
1097
|
+
}
|
|
1098
|
+
if ((routing || route.length) && forward !== routeDirection) { routing=null; route=[]; }
|
|
1099
|
+
routeDirection = forward;
|
|
1100
|
+
const routeGoal = routing?.goal ?? route.at(-1);
|
|
1101
|
+
if (routeGoal && distance(routeGoal, pos) > Math.max(2,kind.radius*4)) { routing=null; route=[]; }
|
|
1102
|
+
if (route[0] && forward * periodicDelta(from.x,route[0].x,map.wrap?.x) < -.001) { routing=null; route=[]; }
|
|
1103
|
+
if (route.length) {
|
|
1104
|
+
while(route.length && distance(from,route[0])<.01)route.shift();
|
|
1105
|
+
}
|
|
1106
|
+
const destination = route[0] ?? pos;
|
|
1107
|
+
const elapsed = Math.max(0, now - presented.at);
|
|
1108
|
+
// Bound presentation by time, including expiring offsets and changed catch-up paths.
|
|
1109
|
+
const length = distance(from, destination);
|
|
1110
|
+
// Falling cannot spend a horizontal correction. Corrections add only
|
|
1111
|
+
// blend speed to the actual movement, not a body's declared speed cap.
|
|
1112
|
+
const blendSpeed = kind.radius / Math.max(.1,predict.blendMs/1000);
|
|
1113
|
+
// Include the whole recorded tick's velocities: a takeoff/landing can
|
|
1114
|
+
// change velocity abruptly between samples without being a correction.
|
|
1115
|
+
let verticalSpeed = Math.max(Math.abs(velocity.y),Math.abs(presented.vel.y),Math.abs(mine.vel.y),Math.abs(preview?.vel.y ?? 0));
|
|
1116
|
+
const recorded = preview?.steps;
|
|
1117
|
+
if (recorded) for (let i=0;i<recorded.length;i++) verticalSpeed = Math.max(verticalSpeed,Math.abs(recorded[i].vel.y));
|
|
1118
|
+
// Leave headroom for a substep entered part-way through a render interval.
|
|
1119
|
+
verticalSpeed *= 1.5;
|
|
1120
|
+
const advance = (axis: 'x' | 'y') => {
|
|
1121
|
+
const delta = periodicDelta(from[axis],destination[axis],map.wrap?.[axis]);
|
|
1122
|
+
// A landing can set velocity to zero before the sampled pose reaches
|
|
1123
|
+
// contact. The adjacent movement velocities retain that real travel.
|
|
1124
|
+
const travel = axis === 'y' ? verticalSpeed : Math.max(Math.abs(velocity.x),Math.abs(presented!.vel.x));
|
|
1125
|
+
const allowance = (travel + blendSpeed) * elapsed / 1000;
|
|
1126
|
+
return from[axis]+Math.max(-allowance,Math.min(allowance,delta));
|
|
1127
|
+
};
|
|
1128
|
+
const target = {...wrapPoint({x:advance('x'),y:advance('y'),z:0},map.wrap)};
|
|
1129
|
+
// A route is a correction too: it cannot pull against continuing motion.
|
|
1130
|
+
if (forward * periodicDelta(from.x,target.x,map.wrap?.x) < 0) target.x = from.x;
|
|
1131
|
+
// A stalled frame cannot spend its whole elapsed-time allowance in one
|
|
1132
|
+
// visible jump. Keep backlog travel below 1.4 body widths per drawing;
|
|
1133
|
+
// authority/prediction keep their real clock and placements bypass this.
|
|
1134
|
+
const frameDistance = distance(from,target), frameLimit = Math.max(.1,kind.radius*2.8);
|
|
1135
|
+
if (frameDistance > frameLimit) {
|
|
1136
|
+
const fraction = frameLimit / frameDistance;
|
|
1137
|
+
target.x = from.x + periodicDelta(from.x,target.x,map.wrap?.x)*fraction;
|
|
1138
|
+
target.y = from.y + periodicDelta(from.y,target.y,map.wrap?.y)*fraction;
|
|
1139
|
+
}
|
|
1140
|
+
let next = constrain(from, target);
|
|
1141
|
+
// Slide the residual along the contact, starting on the side actually drawn.
|
|
1142
|
+
if (distance(next, target) > .002) {
|
|
1143
|
+
next = constrain(next, {x:target.x,y:next.y,z:0});
|
|
1144
|
+
next = constrain(next, {x:next.x,y:target.y,z:0});
|
|
1145
|
+
}
|
|
1146
|
+
if (!route.length && distance(next, target) > .01 && distance(from,next) < .01 && length > .1) {
|
|
1147
|
+
routing ??= correctionPath(from,pos,Math.max(.25,2*kind.radius));
|
|
1148
|
+
const found=routing.advance((a,b)=>forward * periodicDelta(a.x,b.x,map.wrap?.x) >= -.001 && distance(constrain(a,b),b)<.002);
|
|
1149
|
+
if(found) { route=[...found]; routing=null; }
|
|
1150
|
+
}
|
|
1151
|
+
pos = next;
|
|
1152
|
+
}
|
|
1153
|
+
if (!presented || presented.id !== mine.id || presented.r !== mine.r) { routing=null;route=[]; }
|
|
1154
|
+
presented = {id:mine.id,r:mine.r,pos,vel:velocity,at:now};
|
|
1155
|
+
}
|
|
1007
1156
|
if (headingBlend) {
|
|
1008
1157
|
const t = predict.blendMs > 0 ? Math.min(1, (clock() - headingBlend.at) / predict.blendMs) : 1;
|
|
1009
1158
|
heading = blendHeading(headingBlend.from, heading, t, dims);
|
|
1010
1159
|
if (t >= 1) headingBlend = null;
|
|
1011
1160
|
}
|
|
1012
|
-
|
|
1161
|
+
const result = entityOf({ ...server, ...(kind && predictors[kind.name] ? { fields: (base ? previewFields : null) ?? mine.fields } : {}), pos, vel: velocity, heading, grounded, motion }, true);
|
|
1162
|
+
// Synchronous readers (HUD, scene, probes) share one presentation. Clear at
|
|
1163
|
+
// the microtask boundary: an rAF clear can run after the next drawing callback,
|
|
1164
|
+
// reusing an old pose and then spending two callbacks' travel at once.
|
|
1165
|
+
// Inputs and snapshots still invalidate immediately.
|
|
1166
|
+
if (present && typeof window !== 'undefined') {
|
|
1167
|
+
presentedEntity = result;
|
|
1168
|
+
if (!presentationQueued) {
|
|
1169
|
+
presentationQueued = true;
|
|
1170
|
+
const clear = () => { presentedEntity = null; presentationQueued = false; };
|
|
1171
|
+
queueMicrotask(clear);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
return result;
|
|
1013
1175
|
}
|
|
1014
|
-
function drawn(id: string): Entity | null {
|
|
1176
|
+
function drawn(id: string, s = net.sample()): Entity | null {
|
|
1015
1177
|
if (solo) return solo.get(id);
|
|
1016
|
-
if (mine && id === mine.id) return meNow();
|
|
1017
|
-
const s = net.sample();
|
|
1178
|
+
if (mine && id === mine.id) return meNow(true);
|
|
1018
1179
|
const a = s ? frameOf(s.a) : latest;
|
|
1019
1180
|
const b = s ? frameOf(s.b) : latest;
|
|
1020
1181
|
const ea = a?.ents.get(id); const eb = b?.ents.get(id);
|
|
@@ -1022,8 +1183,14 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
1022
1183
|
// A placed body jumps: nobody's view glides across a placement.
|
|
1023
1184
|
if (ea.r !== eb.r || a?.e !== b?.e || !s) return entityOf(eb);
|
|
1024
1185
|
const t = s.alpha;
|
|
1186
|
+
// Static pickups and scenery need no new vectors or wrappers for every HUD,
|
|
1187
|
+
// scene and probe traversal. Fields still follow the sampled snapshot.
|
|
1188
|
+
if (ea.grounded === eb.grounded && ['pos','vel','heading'].every(key => {
|
|
1189
|
+
const x=ea[key as 'pos'], y=eb[key as 'pos']; return x.x===y.x && x.y===y.y && x.z===y.z;
|
|
1190
|
+
})) return entityOf(t < 1 ? ea : eb);
|
|
1025
1191
|
const h = blendHeading(ea.heading, eb.heading, t, dims);
|
|
1026
|
-
|
|
1192
|
+
// This interpolated key exists for one read only; caching it retains useless weak entries.
|
|
1193
|
+
return entityOf({ ...(t < 1 ? ea : eb), grounded: t >= 1 ? eb.grounded : ea.grounded && (t === 0 || eb.grounded), pos: vec3(blendPosition(ea.pos, eb.pos, t, map.wrap), dims), vel: vec3({ x: lerp(ea.vel.x, eb.vel.x, t), y: lerp(ea.vel.y, eb.vel.y, t), z: lerp(ea.vel.z, eb.vel.z, t) }, dims), heading: h }, false, false);
|
|
1027
1194
|
}
|
|
1028
1195
|
function get(id: string): Entity | null { const g = ghosts.get(id); return g ? ghostEntity(g) : drawn(id); }
|
|
1029
1196
|
function each(kind: string, fn: (e: Entity) => void): void {
|
|
@@ -1036,7 +1203,7 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
1036
1203
|
// Until the newer snapshot is reached, what the older one holds is still drawn; what only the newer one holds waits for it.
|
|
1037
1204
|
for (const f of [a, s && s.alpha >= 1 ? b : null, a ? null : b]) if (f) for (const u of f.ents.values()) if (u.kind === kind) ids.add(u.id);
|
|
1038
1205
|
if (mine && mine.kind === kind) ids.add(mine.id);
|
|
1039
|
-
for (const id of ids) { const e = drawn(id); if (e) fn(e); }
|
|
1206
|
+
for (const id of ids) { const e = drawn(id, s); if (e) fn(e); }
|
|
1040
1207
|
// A confirmed ghost stands in until the server's own entity is drawn (it arrives a moment behind, interpolated).
|
|
1041
1208
|
for (const g of [...ghosts.values()]) if (g.kind === kind) { if (g.real && ids.has(g.real)) { ghosts.delete(g.id); emit('leave', ghostEntity(g)); } else fn(ghostEntity(g)); }
|
|
1042
1209
|
}
|
|
@@ -1076,25 +1243,25 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
1076
1243
|
net.line(net.full ? 'This room is full · playing on your own until a seat is free' : 'Playing on your own until the next round');
|
|
1077
1244
|
emit('status', 'offline', true);
|
|
1078
1245
|
}
|
|
1079
|
-
|
|
1246
|
+
const extra: Record<string, () => unknown> = {};
|
|
1080
1247
|
const myScore = (): number | null => { if (solo) { const k = schema.kinds.find(k => k.player); return k?.score && solo.me ? Number(solo.me[k.score]) || 0 : null; } const k = myKind(); const u = mine && latest ? latest.ents.get(mine.id) : null; return k?.score && u ? Number(u.fields[k.score]) || 0 : null; };
|
|
1081
1248
|
const busy = (): boolean => solo ? !solo.me : status !== 'playing' || !mine || latest?.ents.get(mine.id)?.away === true;
|
|
1082
1249
|
// The probes the testing tools read (`check`, `shoot`, `perf`, the playtest judge): the same two objects a game written the old way publishes.
|
|
1083
1250
|
net.expose({
|
|
1084
|
-
self: () => { const m = meNow(); return m ? { x: m.pos.x, y: m.pos.y, z: m.pos.z } : null; },
|
|
1251
|
+
self: () => { const m = meNow(true); return m ? { x: m.pos.x, y: m.pos.y, z: m.pos.z } : null; },
|
|
1085
1252
|
peer: (seat: number) => { if (!latest) return null; for (const u of latest.ents.values()) if (u.seat === seat) return { x: u.pos.x, y: u.pos.y, z: u.pos.z }; return null; },
|
|
1086
1253
|
movement: () => { const kinds = schema.kinds.filter(k => k.player); return kinds.length && kinds.every(k => k.maxSpeed === 0) ? 'stationary' : 'spatial'; },
|
|
1087
|
-
prediction: () => ({ ...correction, observedLeadAt, lastSendAt, now: clock(), serverTick: latest?.k, tick: stepped, catchTick, lead: targetLead(), medianLead: medianLead(), rate: speed, rtt: authorityRtt(), hostAge:
|
|
1254
|
+
prediction: () => ({ ...correction, observedLeadAt, lastSendAt, now: clock(), serverTick: latest?.k, tick: stepped, catchTick, lead: targetLead(), medianLead: medianLead(), rate: speed, rtt: authorityRtt(), hostAge: hostMedian, pending: pending.length, applications: [...applications] }),
|
|
1088
1255
|
scores: () => roster().map((r) => ({ seat: r.seat, score: r.score })),
|
|
1089
1256
|
score: myScore, tick: () => latest?.k ?? 0, epoch: () => epoch, hosted: () => net.rulesHosting ? 'browser' : schema.settings.host, status: () => solo ? 'offline' : status,
|
|
1090
1257
|
});
|
|
1091
1258
|
if (typeof window !== 'undefined') {
|
|
1092
1259
|
exposePort(net as Netplay<unknown, unknown, unknown>, {
|
|
1093
1260
|
view: 'top', size: schema.kinds.find((k) => k.player)?.radius ?? 0.5,
|
|
1094
|
-
self: () => { const m = meNow(); return m ? { x: m.pos.x, y: m.pos.y } : null; },
|
|
1261
|
+
self: () => { const m = meNow(true); return m ? { x: m.pos.x, y: m.pos.y } : null; },
|
|
1095
1262
|
basis: opts.screenBasis ?? (() => ({ right: [1, 0], up: [0, 1] })),
|
|
1096
1263
|
score: myScore, busy: () => (typeof extra.busy === 'function' ? Boolean(extra.busy()) : busy()),
|
|
1097
|
-
extra
|
|
1264
|
+
extra,
|
|
1098
1265
|
});
|
|
1099
1266
|
}
|
|
1100
1267
|
const timer = opts.timers === false ? null : setInterval(pump, Math.max(8, period / 2));
|
|
@@ -1143,7 +1310,7 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
1143
1310
|
get viewTick() { return solo ? solo.viewTick : viewTickNow(); },
|
|
1144
1311
|
get status() { return solo ? 'offline' : status; },
|
|
1145
1312
|
get seat() { return solo ? solo.seat : net.seat; },
|
|
1146
|
-
get me() { pump(); return meNow(); },
|
|
1313
|
+
get me() { pump(); return meNow(true); },
|
|
1147
1314
|
each, get,
|
|
1148
1315
|
ray: (from,direction,max,options) => solo ? solo.ray(from,direction,max,options) : viewRay(from,direction,max,options)[0],
|
|
1149
1316
|
rays: options => solo ? solo.rays(options) : raySnapshot(mapAt(latest?.k??0),viewTargets(atTickOf(options)),dims,options,mine?.id),
|
|
@@ -1180,6 +1347,7 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
1180
1347
|
if (changed) pump();
|
|
1181
1348
|
const shown = changed ? meNow()?.pos : null;
|
|
1182
1349
|
for (const [name, fd] of kind?.input ?? []) if ((fd.t === 'press' || fd.t === 'pulse') && coerce(fd,s[name],dims)) { const value=coerce(fd,s[name],dims) as number | boolean; if(fd.t==='pulse'){pulseCount+=1;const target=Math.max(stepped+1,(pulseQueue.at(-1)?.t??stepped)+1);pulseQueue.push({name,value:Number(value),n:pulseCount,t:target});net.send('pulse',[epoch,name,value,target,pulseCount]);} else pressed.set(name,value); }
|
|
1350
|
+
if (changed) presentedEntity = null;
|
|
1183
1351
|
sample = next;
|
|
1184
1352
|
// A discrete action belongs to the present, even while an unseen impulse is
|
|
1185
1353
|
// being drawn from history. Resume the live prediction and let the existing
|
|
@@ -1204,7 +1372,7 @@ export function openRoom<R = unknown>(opts: OpenRoomOptions = {}): Room<R> {
|
|
|
1204
1372
|
get round() { return roundNow(); },
|
|
1205
1373
|
get roster() { return roster(); },
|
|
1206
1374
|
follow(id) { const e = id ? latest?.ents.get(id) : null; net.follow(e && e.seat !== undefined ? e.seat : null); },
|
|
1207
|
-
probe(x) { extra
|
|
1375
|
+
probe(x) { Object.assign(extra, x); },
|
|
1208
1376
|
ask(id, askId, args = {}) { if (solo) return; const e = latest?.ents.get(id); if (e && e.seat !== undefined) agents?.ask(e.seat, askId, args); },
|
|
1209
1377
|
askButtons(id, offer = {}) { if (solo) return []; const e = latest?.ents.get(id); return e && e.seat !== undefined ? agents?.askButtons(e.seat, offer) ?? [] : []; },
|
|
1210
1378
|
tune, get map(){return solo ? solo.map : mapAt(latest?.k??0);}, net: net as Netplay,
|
package/worker/build-id.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by lib/build-identity.mjs; identifies the bundled runtime sources.
|
|
2
|
-
export const STUDIO_BUILD = Object.freeze({"version":"0.51.
|
|
2
|
+
export const STUDIO_BUILD = Object.freeze({"version":"0.51.1","sha256":"6919e263e0a419df6b77a79f359497fb74c099fdfec14d267dc3417413607e6e"});
|
package/worker/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The @homie-rocks/studio version this Worker code is (package.json's; a test keeps them equal). Cache-busts /_homie/site.js. */
|
|
2
|
-
export const STUDIO_VERSION_TAG = '0.51.
|
|
2
|
+
export const STUDIO_VERSION_TAG = '0.51.1';
|