BlueGit

projects-timfalken-com meteors

t1181/t1182: docs (NL) and build

timfa Grok Bot · pushed by timfa

Authored 2026-11-14 · 3 days ago

Hash
7515cbf58570bd0fa8e1bc0d4f04ed427d74020c
Parent
2f23a459
3 files changed +467 −9
README.md +11 −0
@@ -196,6 +196,17 @@ op een stapel weer een kleur krijgt. Wie al zijn kolommen vol heeft, is toeschou
196 196 en geen doelwit meer. De laatste die overblijft wint; 1e/2e/3e staan 5 seconden
197 197 op het podium en daarna ga je terug naar de lobby.
198 198
199 ### Vliegende blokken en mini-velden (vloeiend)
200
201 - Een blok dat je wegschiet vliegt **meteen** lokaal weg (geen wachten op de
202 server). Zodra de server antwoordt (raak/mis, doelkolom) buigt dezelfde
203 vlucht vloeiend af naar het echte doel; geen sprong, geen tweede blok.
204 - Een tegenstander ziet de vlucht vanaf jouw mini-veld vertrekken zodra het
205 serverbericht binnenkomt, als volledige boog (iets ingekort bij vertraging).
206 - Op de mini-velden van tegenstanders vallen blokken tussen de
207 serverupdates door vloeiend verder (voorspelling met hun valsnelheid).
208 Landen of lijnen wissen wordt nooit voorspeld: dat komt altijd van de server.
209
199 210 ### Wat Tim moet instellen
200 211
201 212 Online werkt pas als OAuth is ingesteld. Zolang dat niet zo is, blijft solo
@@ -196,6 +196,17 @@ op een stapel weer een kleur krijgt. Wie al zijn kolommen vol heeft, is toeschou
196en geen doelwit meer. De laatste die overblijft wint; 1e/2e/3e staan 5 seconden
196en geen doelwit meer. De laatste die overblijft wint; 1e/2e/3e staan 5 seconden
197op het podium en daarna ga je terug naar de lobby.
197op het podium en daarna ga je terug naar de lobby.
198
198
199### Vliegende blokken en mini-velden (vloeiend)
200
201- Een blok dat je wegschiet vliegt **meteen** lokaal weg (geen wachten op de
202 server). Zodra de server antwoordt (raak/mis, doelkolom) buigt dezelfde
203 vlucht vloeiend af naar het echte doel; geen sprong, geen tweede blok.
204- Een tegenstander ziet de vlucht vanaf jouw mini-veld vertrekken zodra het
205 serverbericht binnenkomt, als volledige boog (iets ingekort bij vertraging).
206- Op de mini-velden van tegenstanders vallen blokken tussen de
207 serverupdates door vloeiend verder (voorspelling met hun valsnelheid).
208 Landen of lijnen wissen wordt nooit voorspeld: dat komt altijd van de server.
209
199### Wat Tim moet instellen
210### Wat Tim moet instellen
200
211
201Online werkt pas als OAuth is ingesteld. Zolang dat niet zo is, blijft solo
212Online werkt pas als OAuth is ingesteld. Zolang dat niet zo is, blijft solo
build/game.js +410 −9
@@ -8462,6 +8462,237 @@ if (typeof module !== 'undefined' && module.exports && typeof MiniLayout !== 'un
8462 8462 * /workspace/meteors/src/miniLayout.js
8463 8463 */
8464 8464
8465 /*
8466 * Start File:
8467 * /workspace/meteors/src/miniPredict.js
8468 */
8469 'use strict';
8470
8471 /**
8472 * t1182: client-side prediction for falling blocks on opponents' mini
8473 * fields. Purely visual. Between snapshots (one per poll, ~0.75 s) a
8474 * block whose authoritative state is 'falling' keeps descending at that
8475 * player's fallSpeed (13 / fallTime cells/s), with sub-cell motion. It
8476 * never goes below the first obstacle in its column, so a landing, lock
8477 * or match is never predicted — those only appear when the next
8478 * snapshot says so. When a snapshot arrives the shown position is
8479 * reconciled smoothly: a block that lags catches up a little faster, a
8480 * block that ran ahead falls more slowly until the truth catches up
8481 * (it never moves up), and a large difference snaps.
8482 */
8483 var MiniPredict = {
8484 FIELD_HEIGHT: 13,
8485 /** Seconds over which a lagging block closes its gap (on top of fallSpeed). */
8486 RECONCILE_S: 0.16,
8487 /** Cells: further off than this → snap to the authoritative pose. */
8488 SNAP_CELLS: 1.5,
8489 /** Never extrapolate further than this past the last snapshot (s). */
8490 MAX_EXTRAP_S: 1.5,
8491 /** Share of fallSpeed used while a block that ran ahead waits for the truth. */
8492 AHEAD_SPEED_SHARE: 0.5,
8493 /** Largest frame step used for the smoothing integrator (s). */
8494 MAX_FRAME_S: 0.1
8495 };
8496
8497 /** Arrival samples kept for the sender-clock offset estimate. */
8498 MiniPredict.OFFSET_SAMPLES = 16;
8499
8500 MiniPredict.create = function ()
8501 {
8502 return { snap: null, at: 0, lastFrame: 0, shown: Object.create(null), offsets: [], sig: null };
8503 };
8504
8505 /** Cheap content signature for snapshots without a sender time. */
8506 MiniPredict.signature = function (snapshot)
8507 {
8508 if (!snapshot || !snapshot.blocks)
8509 { return ''; }
8510 var s = String(snapshot.blocks.length);
8511 for (var i = 0; i < snapshot.blocks.length; i++)
8512 {
8513 var b = snapshot.blocks[i];
8514 s += '|' + b.id + ':' + b.y + ':' + b.state;
8515 }
8516 return s;
8517 };
8518
8519 MiniPredict.fallSpeedFor = function (planet)
8520 {
8521 var ft = planet && (planet.fallTime != null ? planet.fallTime : planet.fall_time);
8522 ft = Number(ft);
8523 if (!(ft > 0))
8524 { ft = 3; }
8525 return this.FIELD_HEIGHT / ft;
8526 };
8527
8528 /**
8529 * Record an authoritative snapshot. A poll can repeat the same
8530 * snapshot (the opponent has not polled since); that must not restart
8531 * the extrapolation. With a sender time `t` (ms, sender clock) the
8532 * snapshot's moment is mapped to our clock via the smallest observed
8533 * arrival offset, so a late-arriving snapshot is placed at the time it
8534 * was really taken. Returns true when the snapshot is new.
8535 */
8536 MiniPredict.update = function (st, snapshot, now)
8537 {
8538 if (snapshot === st.snap)
8539 { return false; }
8540 if (!snapshot)
8541 {
8542 st.snap = null;
8543 st.sig = null;
8544 return false;
8545 }
8546 var hasT = snapshot.t != null && isFinite(snapshot.t);
8547 if (st.snap && hasT && st.snap.t === snapshot.t)
8548 {
8549 st.snap = snapshot;
8550 return false;
8551 }
8552 if (!hasT)
8553 {
8554 var sig = this.signature(snapshot);
8555 if (st.snap && sig === st.sig)
8556 {
8557 st.snap = snapshot;
8558 return false;
8559 }
8560 st.sig = sig;
8561 st.snap = snapshot;
8562 st.at = now;
8563 return true;
8564 }
8565 st.offsets.push(now - snapshot.t);
8566 if (st.offsets.length > this.OFFSET_SAMPLES)
8567 { st.offsets.shift(); }
8568 var off = Math.min.apply(null, st.offsets);
8569 st.snap = snapshot;
8570 st.sig = null;
8571 // Never in the future, never older than the extrapolation cap.
8572 st.at = Math.max(now - this.MAX_EXTRAP_S * 1000, Math.min(now, snapshot.t + off));
8573 return true;
8574 };
8575
8576 /**
8577 * Predicted y for every falling block at time `now`, clamped above the
8578 * first non-falling block (or the floor) below it in its column, chaining
8579 * falling blocks in the same column bottom-up. Returns id → y.
8580 */
8581 MiniPredict.predict = function (snapshot, sinceS, fallSpeed)
8582 {
8583 var out = Object.create(null);
8584 if (!snapshot || !snapshot.blocks)
8585 { return out; }
8586 var dt = Math.max(0, Math.min(this.MAX_EXTRAP_S, sinceS || 0));
8587 var cols = Object.create(null);
8588 var blocks = snapshot.blocks;
8589 for (var i = 0; i < blocks.length; i++)
8590 {
8591 var b = blocks[i];
8592 (cols[b.col] = cols[b.col] || []).push(b);
8593 }
8594 for (var c in cols)
8595 {
8596 var list = cols[c].slice().sort(function (a, b) { return a.y - b.y; });
8597 var floor = 0; // lowest y the next block may occupy
8598 for (var k = 0; k < list.length; k++)
8599 {
8600 var blk = list[k];
8601 if (blk.state === 'falling')
8602 {
8603 var y = Math.max(floor, blk.y - fallSpeed * dt);
8604 if (y > blk.y)
8605 { y = blk.y; } // only ever predict downwards
8606 out[blk.id] = y;
8607 floor = y + 1;
8608 }
8609 else
8610 { floor = Math.max(floor, blk.y + 1); }
8611 }
8612 }
8613 return out;
8614 };
8615
8616 /**
8617 * Advance the shown positions to `now` and return id → display y for
8618 * falling blocks. Non-falling blocks are not in the map (draw them at
8619 * their authoritative y).
8620 */
8621 MiniPredict.step = function (st, now, fallSpeed)
8622 {
8623 var frame = st.lastFrame ? Math.min(this.MAX_FRAME_S, Math.max(0, (now - st.lastFrame) / 1000)) : 0;
8624 st.lastFrame = now;
8625 var target = this.predict(st.snap, (now - st.at) / 1000, fallSpeed);
8626 var shown = Object.create(null);
8627 var floors = this._floors(st.snap, target);
8628 for (var id in target)
8629 {
8630 var t = target[id];
8631 var s = st.shown[id];
8632 if (s == null || !isFinite(s) || Math.abs(s - t) > this.SNAP_CELLS)
8633 { s = t; }
8634 else if (s > t)
8635 {
8636 // Lagging: fall at fallSpeed plus a share of the gap.
8637 s -= (fallSpeed + (s - t) / this.RECONCILE_S) * frame;
8638 if (s < t)
8639 { s = t; }
8640 }
8641 else if (s < t)
8642 {
8643 // Ran ahead: keep falling, slower, never upwards.
8644 s -= fallSpeed * this.AHEAD_SPEED_SHARE * frame;
8645 }
8646 var fl = floors[id] != null ? floors[id] : 0;
8647 if (s < fl)
8648 { s = fl; }
8649 shown[id] = s;
8650 }
8651 st.shown = shown;
8652 return shown;
8653 };
8654
8655 /** Floor (lowest allowed y) for each falling block given the targets. */
8656 MiniPredict._floors = function (snapshot, target)
8657 {
8658 var out = Object.create(null);
8659 if (!snapshot || !snapshot.blocks)
8660 { return out; }
8661 var cols = Object.create(null);
8662 for (var i = 0; i < snapshot.blocks.length; i++)
8663 {
8664 var b = snapshot.blocks[i];
8665 (cols[b.col] = cols[b.col] || []).push(b);
8666 }
8667 for (var c in cols)
8668 {
8669 var list = cols[c].slice().sort(function (a, b) { return a.y - b.y; });
8670 var floor = 0;
8671 for (var k = 0; k < list.length; k++)
8672 {
8673 var blk = list[k];
8674 if (blk.state === 'falling')
8675 {
8676 out[blk.id] = floor;
8677 floor = (target[blk.id] != null ? target[blk.id] : blk.y) + 1;
8678 }
8679 else
8680 { floor = Math.max(floor, blk.y + 1); }
8681 }
8682 }
8683 return out;
8684 };
8685
8686 if (typeof globalThis !== 'undefined')
8687 { globalThis.MiniPredict = MiniPredict; }
8688 if (typeof module !== 'undefined' && module.exports)
8689 { module.exports = MiniPredict; }
8690
8691 /*
8692 * End File:
8693 * /workspace/meteors/src/miniPredict.js
8694 */
8695
8465 8696 /*
8466 8697 * Start File:
8467 8698 * /workspace/meteors/src/online.js
@@ -8492,6 +8723,10 @@ var Online = {
8492 8723 error: '',
8493 8724 _timer: null,
8494 8725 _pendingShots: [],
8726 _pollInFlight: false,
8727 _flushPending: false,
8728 _lastPollAt: 0,
8729 _getPayload: null,
8495 8730 _flights: [],
8496 8731 _lastStatus: null,
8497 8732 onChange: null,
@@ -8703,8 +8938,16 @@ Online.poll = function (opts)
8703 8938 }
8704 8939 var self = this;
8705 8940 var prevStatus = this.lobby && this.lobby.status;
8941 this._pollInFlight = true;
8942 this._lastPollAt = Date.now();
8706 8943 return this.request('poll', body).then(function (data)
8707 8944 {
8945 self._pollInFlight = false;
8946 if (self._flushPending)
8947 {
8948 self._flushPending = false;
8949 self.flushShotsSoon();
8950 }
8708 8951 self._handleTransitions(prevStatus, data);
8709 8952 if (self.onChange)
8710 8953 { self.onChange(self); }
@@ -8739,6 +8982,7 @@ Online.startPolling = function (getPayload)
8739 8982 {
8740 8983 this.stopPolling();
8741 8984 var self = this;
8985 this._getPayload = getPayload || null;
8742 8986 var tick = function ()
8743 8987 {
8744 8988 var payload = getPayload ? getPayload() : {};
@@ -8748,8 +8992,68 @@ Online.startPolling = function (getPayload)
8748 8992 this._timer = setInterval(tick, this.POLL_MS);
8749 8993 };
8750 8994
8995 /** Minimum gap between an extra shot flush and the previous poll (ms). */
8996 Online.FLUSH_MIN_GAP_MS = 120;
8997
8998 /**
8999 * Pure decision for flushShotsSoon (t1181): 'now', 'later' (wait for the
9000 * in-flight poll or the min gap) or 'none' (nothing to send / not polling).
9001 */
9002 Online.flushDecision = function (state)
9003 {
9004 if (!state || !state.polling || !(state.pending > 0))
9005 { return 'none'; }
9006 if (state.inFlight)
9007 { return 'later'; }
9008 if (state.sinceLast < (state.minGap != null ? state.minGap : this.FLUSH_MIN_GAP_MS))
9009 { return 'later'; }
9010 return 'now';
9011 };
9012
9013 /**
9014 * Send freshly cleared shots on the next possible poll instead of up to
9015 * POLL_MS later, so the server's hit/miss result (and the retarget of the
9016 * local flight) arrives in about one round trip. Network cadence only;
9017 * the server still decides hits, targets and delivery (t1181).
9018 */
9019 Online.flushShotsSoon = function ()
9020 {
9021 var self = this;
9022 var d = this.flushDecision({
9023 polling: !!this._timer,
9024 pending: this._pendingShots.length,
9025 inFlight: this._pollInFlight,
9026 sinceLast: Date.now() - (this._lastPollAt || 0)
9027 });
9028 if (d === 'none')
9029 { return d; }
9030 if (d === 'later')
9031 {
9032 if (this._pollInFlight)
9033 { this._flushPending = true; }
9034 else if (!this._flushTimer)
9035 {
9036 var wait = Math.max(0, this.FLUSH_MIN_GAP_MS - (Date.now() - (this._lastPollAt || 0)));
9037 this._flushTimer = setTimeout(function ()
9038 {
9039 self._flushTimer = null;
9040 self.flushShotsSoon();
9041 }, wait);
9042 }
9043 return d;
9044 }
9045 this.poll(this._getPayload ? this._getPayload() : {});
9046 return d;
9047 };
9048
8751 9049 Online.stopPolling = function ()
8752 9050 {
9051 if (this._flushTimer)
9052 {
9053 clearTimeout(this._flushTimer);
9054 this._flushTimer = null;
9055 }
9056 this._flushPending = false;
8753 9057 if (this._timer)
8754 9058 {
8755 9059 clearInterval(this._timer);
@@ -8851,7 +9155,7 @@ Online.renderMinis = function (container)
8851 9155 ? I18n.t('hud.miniPoints', { n: p.score || 0 })
8852 9156 : ('Points ' + (p.score || 0));
8853 9157 }
8854 this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet);
9158 this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet, this._predictMini(p));
8855 9159 }
8856 9160 for (var id in existing)
8857 9161 {
@@ -8872,7 +9176,28 @@ function miniColor (planet, color)
8872 9176 }
8873 9177
8874 9178
8875 Online._drawMini = function (canvas, snapshot, planet)
9179 /**
9180 * t1182: smoothed display y for an opponent's falling blocks (see
9181 * src/miniPredict.js). Returns id → y, or null without the module.
9182 */
9183 Online._predictMini = function (p, now)
9184 {
9185 var MP = typeof MiniPredict !== 'undefined' ? MiniPredict : null;
9186 if (!MP || !p)
9187 { return null; }
9188 if (!this._miniPredict)
9189 { this._miniPredict = Object.create(null); }
9190 var st = this._miniPredict[p.id];
9191 if (!st)
9192 { st = this._miniPredict[p.id] = MP.create(); }
9193 now = now != null ? now : (typeof performance !== 'undefined' ? performance.now() : Date.now());
9194 MP.update(st, p.snapshot, now);
9195 if (p.eliminated)
9196 { return null; }
9197 return MP.step(st, now, MP.fallSpeedFor(p.planet));
9198 };
9199
9200 Online._drawMini = function (canvas, snapshot, planet, shownY)
8876 9201 {
8877 9202 if (!canvas)
8878 9203 { return; }
@@ -8919,7 +9244,8 @@ Online._drawMini = function (canvas, snapshot, planet)
8919 9244 {
8920 9245 var b = blocks[i];
8921 9246 var x = b.col * tw;
8922 var y = canvas.height - (b.y + 1) * th;
9247 var by = (shownY && shownY[b.id] != null) ? shownY[b.id] : b.y;
9248 var y = canvas.height - (by + 1) * th;
8923 9249 if (b.state === 'locked')
8924 9250 { ctx.fillStyle = '#3a3d4a'; }
8925 9251 else if (b.color < 0)
@@ -9732,6 +10058,17 @@ Online.spawnFlights = function (results, locals)
9732 10058 {
9733 10059 var r = results[i];
9734 10060 var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));
10061 // Own shot already flying locally since the clear (t1181):
10062 // pick it up at its current pose and fly on to the real target.
10063 var cid = r.client_id != null ? String(r.client_id) : null;
10064 if (cid && this._previewIds[cid] && this._isOwnShot(r))
10065 {
10066 var own = this._findFlight(cid);
10067 this._flightSeen[sid] = now;
10068 if (own)
10069 { this.retargetFlight(own, r, locals[cid] || {}, now); }
10070 continue;
10071 }
9735 10072 if (this._flightSeen[sid])
9736 10073 {
9737 10074 if (this._previewIds[sid])
@@ -9837,12 +10174,11 @@ Online.spawnFlights = function (results, locals)
9837 10174 el.style.height = full + 'px';
9838 10175 layer.appendChild(el);
9839 10176
10177 // A flight seen late (poll delay) still starts at the sender's
10178 // field and plays the whole arc, just a bit faster, so it lands
10179 // about when the server delivers it — never a mid-arc pop-in (t1181).
9840 10180 var t0 = now;
9841 if (r.age != null && isFinite(r.age) && r.age > 0)
9842 {
9843 var u0 = Math.min(0.95, (r.age * 1000) / duration);
9844 t0 = now - u0 * duration;
9845 }
10181 duration = this.lateFlightDuration(r.age, duration);
9846 10182 var height = miss
9847 10183 ? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
9848 10184 : this.arcHeight(start, end);
@@ -9879,6 +10215,52 @@ Online.spawnFlights = function (results, locals)
9879 10215 this._flightLocals = {};
9880 10216 };
9881 10217
10218 /** Shortest share of the normal flight a late-seen flight may get. */
10219 Online.LATE_MIN_SHARE = 0.5;
10220
10221 /** Duration (ms) for a flight first seen `age` seconds after it was fired. */
10222 Online.lateFlightDuration = function (age, duration)
10223 {
10224 if (age == null || !isFinite(age) || age <= 0)
10225 { return duration; }
10226 return Math.max(duration * this.LATE_MIN_SHARE, duration - age * 1000);
10227 };
10228
10229 /** Remaining duration (ms) after a local preview has flown `elapsedMs`. */
10230 Online.retargetDuration = function (elapsedMs, duration)
10231 {
10232 if (!(elapsedMs > 0))
10233 { return duration; }
10234 return Math.max(duration * this.LATE_MIN_SHARE, duration - elapsedMs);
10235 };
10236
10237 Online._isOwnShot = function (r)
10238 {
10239 var mine = this.me && this.me.id;
10240 var from = r.from_id || r.from_user || null;
10241 return !from || (mine != null && String(from) === String(mine));
10242 };
10243
10244 /**
10245 * Sender side (t1181): start the flight the moment the block leaves the
10246 * field, before any server round trip. It rises out of the exit cell;
10247 * the poll answer retargets it (hit → opponent mini, miss → off-screen).
10248 */
10249 Online.startLocalShot = function (shot, start)
10250 {
10251 if (!shot || !start)
10252 { return null; }
10253 return this.previewExit({
10254 id: shot.id,
10255 col: shot.col,
10256 y: shot.y,
10257 vy: shot.vy,
10258 color: shot.color,
10259 start: start,
10260 from_id: null
10261 });
10262 };
10263
9882 10264 Online.rememberFlightLocal = function (shot, startX, startY)
9883 10265 {
9884 10266 if (!this._flightLocals)
@@ -10045,6 +10427,7 @@ Online.previewExit = function (info)
10045 10427 });
10046 10428 this._previewIds[sid] = true;
10047 10429 this._flightSeen[sid] = now;
10430 return true;
10048 10431 };
10049 10432
10050 10433 /** True while a field sprite should stay hidden — the flight is its visual. */
@@ -10086,6 +10469,8 @@ Online.retargetFlight = function (f, r, meta, now)
10086 10469 var miss = !!r.miss;
10087 10470 var kind = this.flightKind(fromId, targetId, miss);
10088 10471 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
10472 if (f.preview)
10473 { duration = this.retargetDuration(now - f.t0, duration); }
10089 10474
10090 10475 var landCol = null;
10091 10476 if (r.land_col != null && isFinite(r.land_col))
@@ -10202,6 +10587,9 @@ Online.pointAllowedOnArc = function (p, field, start, end, slop)
10202 10587 return false;
10203 10588 };
10204 10589
10590 /** How long a local preview may wait at its apex for the server (ms). */
10591 Online.PREVIEW_HOLD_MS = 2500;
10592
10205 10593 Online.tickFlights = function (now)
10206 10594 {
10207 10595 now = now || performance.now();
@@ -10210,6 +10598,8 @@ Online.tickFlights = function (now)
10210 10598 {
10211 10599 var f = this._flights[i];
10212 10600 var raw = (now - f.t0) / f.duration;
10601 if (f.preview && raw >= 0.999 && now - f.t0 < f.duration + this.PREVIEW_HOLD_MS)
10602 { raw = 0.999; }
10213 10603 if (raw >= 1)
10214 10604 {
10215 10605 if (f.el && f.el.parentNode)
@@ -10282,6 +10672,7 @@ Online.clearFlights = function ()
10282 10672 this._flightSeen = Object.create(null);
10283 10673 this._pendingLandCol = Object.create(null);
10284 10674 this._previewIds = Object.create(null);
10675 this._miniPredict = Object.create(null);
10285 10676 };
10286 10677
10287 10678 if (typeof globalThis !== 'undefined')
@@ -13715,8 +14106,14 @@ function tickOnline (dt)
13715 14106 var s = shots[i];
13716 14107 var start = fieldToViewport(s.col, s.y);
13717 14108 Online.rememberFlightLocal(s, start.x, start.y);
14109 // Draw the flight locally right away (t1181); the server
14110 // answer only retargets it.
14111 if (Online.startLocalShot)
14112 { Online.startLocalShot(s, start); }
13718 14113 }
13719 14114 Online.queueShots(shots);
14115 if (shots.length && Online.flushShotsSoon)
14116 { Online.flushShotsSoon(); }
13720 14117 }
13721 14118 Online.tickFlights();
13722 14119 Online.renderMinis(document.getElementById('minis'));
@@ -14168,8 +14565,12 @@ function onlinePayload ()
14168 14565 {
14169 14566 if (!app.online || !app.core)
14170 14567 { return {}; }
14568 var snap = app.core.fieldSnapshot();
14569 // t1182: sender time (ms) so opponents can place the snapshot in
14570 // time and predict falling blocks smoothly. Visual only.
14571 snap.t = Math.round(typeof performance !== 'undefined' ? performance.now() : Date.now());
14171 14572 return {
14172 snapshot: app.core.fieldSnapshot(),
14573 snapshot: snap,
14173 14574 score: app.core.score,
14174 14575 eliminated: app.core.state === 'gameover' || app.spectating || app.eliminatedReported
14175 14576 };
@@ -8462,6 +8462,237 @@ if (typeof module !== 'undefined' && module.exports && typeof MiniLayout !== 'un
8462 * /workspace/meteors/src/miniLayout.js
8462 * /workspace/meteors/src/miniLayout.js
8463 */
8463 */
8464
8464
8465/*
8466 * Start File:
8467 * /workspace/meteors/src/miniPredict.js
8468 */
8469'use strict';
8470
8471/**
8472 * t1182: client-side prediction for falling blocks on opponents' mini
8473 * fields. Purely visual. Between snapshots (one per poll, ~0.75 s) a
8474 * block whose authoritative state is 'falling' keeps descending at that
8475 * player's fallSpeed (13 / fallTime cells/s), with sub-cell motion. It
8476 * never goes below the first obstacle in its column, so a landing, lock
8477 * or match is never predicted — those only appear when the next
8478 * snapshot says so. When a snapshot arrives the shown position is
8479 * reconciled smoothly: a block that lags catches up a little faster, a
8480 * block that ran ahead falls more slowly until the truth catches up
8481 * (it never moves up), and a large difference snaps.
8482 */
8483var MiniPredict = {
8484 FIELD_HEIGHT: 13,
8485 /** Seconds over which a lagging block closes its gap (on top of fallSpeed). */
8486 RECONCILE_S: 0.16,
8487 /** Cells: further off than this → snap to the authoritative pose. */
8488 SNAP_CELLS: 1.5,
8489 /** Never extrapolate further than this past the last snapshot (s). */
8490 MAX_EXTRAP_S: 1.5,
8491 /** Share of fallSpeed used while a block that ran ahead waits for the truth. */
8492 AHEAD_SPEED_SHARE: 0.5,
8493 /** Largest frame step used for the smoothing integrator (s). */
8494 MAX_FRAME_S: 0.1
8495};
8496
8497/** Arrival samples kept for the sender-clock offset estimate. */
8498MiniPredict.OFFSET_SAMPLES = 16;
8499
8500MiniPredict.create = function ()
8501{
8502 return { snap: null, at: 0, lastFrame: 0, shown: Object.create(null), offsets: [], sig: null };
8503};
8504
8505/** Cheap content signature for snapshots without a sender time. */
8506MiniPredict.signature = function (snapshot)
8507{
8508 if (!snapshot || !snapshot.blocks)
8509 { return ''; }
8510 var s = String(snapshot.blocks.length);
8511 for (var i = 0; i < snapshot.blocks.length; i++)
8512 {
8513 var b = snapshot.blocks[i];
8514 s += '|' + b.id + ':' + b.y + ':' + b.state;
8515 }
8516 return s;
8517};
8518
8519MiniPredict.fallSpeedFor = function (planet)
8520{
8521 var ft = planet && (planet.fallTime != null ? planet.fallTime : planet.fall_time);
8522 ft = Number(ft);
8523 if (!(ft > 0))
8524 { ft = 3; }
8525 return this.FIELD_HEIGHT / ft;
8526};
8527
8528/**
8529 * Record an authoritative snapshot. A poll can repeat the same
8530 * snapshot (the opponent has not polled since); that must not restart
8531 * the extrapolation. With a sender time `t` (ms, sender clock) the
8532 * snapshot's moment is mapped to our clock via the smallest observed
8533 * arrival offset, so a late-arriving snapshot is placed at the time it
8534 * was really taken. Returns true when the snapshot is new.
8535 */
8536MiniPredict.update = function (st, snapshot, now)
8537{
8538 if (snapshot === st.snap)
8539 { return false; }
8540 if (!snapshot)
8541 {
8542 st.snap = null;
8543 st.sig = null;
8544 return false;
8545 }
8546 var hasT = snapshot.t != null && isFinite(snapshot.t);
8547 if (st.snap && hasT && st.snap.t === snapshot.t)
8548 {
8549 st.snap = snapshot;
8550 return false;
8551 }
8552 if (!hasT)
8553 {
8554 var sig = this.signature(snapshot);
8555 if (st.snap && sig === st.sig)
8556 {
8557 st.snap = snapshot;
8558 return false;
8559 }
8560 st.sig = sig;
8561 st.snap = snapshot;
8562 st.at = now;
8563 return true;
8564 }
8565 st.offsets.push(now - snapshot.t);
8566 if (st.offsets.length > this.OFFSET_SAMPLES)
8567 { st.offsets.shift(); }
8568 var off = Math.min.apply(null, st.offsets);
8569 st.snap = snapshot;
8570 st.sig = null;
8571 // Never in the future, never older than the extrapolation cap.
8572 st.at = Math.max(now - this.MAX_EXTRAP_S * 1000, Math.min(now, snapshot.t + off));
8573 return true;
8574};
8575
8576/**
8577 * Predicted y for every falling block at time `now`, clamped above the
8578 * first non-falling block (or the floor) below it in its column, chaining
8579 * falling blocks in the same column bottom-up. Returns id → y.
8580 */
8581MiniPredict.predict = function (snapshot, sinceS, fallSpeed)
8582{
8583 var out = Object.create(null);
8584 if (!snapshot || !snapshot.blocks)
8585 { return out; }
8586 var dt = Math.max(0, Math.min(this.MAX_EXTRAP_S, sinceS || 0));
8587 var cols = Object.create(null);
8588 var blocks = snapshot.blocks;
8589 for (var i = 0; i < blocks.length; i++)
8590 {
8591 var b = blocks[i];
8592 (cols[b.col] = cols[b.col] || []).push(b);
8593 }
8594 for (var c in cols)
8595 {
8596 var list = cols[c].slice().sort(function (a, b) { return a.y - b.y; });
8597 var floor = 0; // lowest y the next block may occupy
8598 for (var k = 0; k < list.length; k++)
8599 {
8600 var blk = list[k];
8601 if (blk.state === 'falling')
8602 {
8603 var y = Math.max(floor, blk.y - fallSpeed * dt);
8604 if (y > blk.y)
8605 { y = blk.y; } // only ever predict downwards
8606 out[blk.id] = y;
8607 floor = y + 1;
8608 }
8609 else
8610 { floor = Math.max(floor, blk.y + 1); }
8611 }
8612 }
8613 return out;
8614};
8615
8616/**
8617 * Advance the shown positions to `now` and return id → display y for
8618 * falling blocks. Non-falling blocks are not in the map (draw them at
8619 * their authoritative y).
8620 */
8621MiniPredict.step = function (st, now, fallSpeed)
8622{
8623 var frame = st.lastFrame ? Math.min(this.MAX_FRAME_S, Math.max(0, (now - st.lastFrame) / 1000)) : 0;
8624 st.lastFrame = now;
8625 var target = this.predict(st.snap, (now - st.at) / 1000, fallSpeed);
8626 var shown = Object.create(null);
8627 var floors = this._floors(st.snap, target);
8628 for (var id in target)
8629 {
8630 var t = target[id];
8631 var s = st.shown[id];
8632 if (s == null || !isFinite(s) || Math.abs(s - t) > this.SNAP_CELLS)
8633 { s = t; }
8634 else if (s > t)
8635 {
8636 // Lagging: fall at fallSpeed plus a share of the gap.
8637 s -= (fallSpeed + (s - t) / this.RECONCILE_S) * frame;
8638 if (s < t)
8639 { s = t; }
8640 }
8641 else if (s < t)
8642 {
8643 // Ran ahead: keep falling, slower, never upwards.
8644 s -= fallSpeed * this.AHEAD_SPEED_SHARE * frame;
8645 }
8646 var fl = floors[id] != null ? floors[id] : 0;
8647 if (s < fl)
8648 { s = fl; }
8649 shown[id] = s;
8650 }
8651 st.shown = shown;
8652 return shown;
8653};
8654
8655/** Floor (lowest allowed y) for each falling block given the targets. */
8656MiniPredict._floors = function (snapshot, target)
8657{
8658 var out = Object.create(null);
8659 if (!snapshot || !snapshot.blocks)
8660 { return out; }
8661 var cols = Object.create(null);
8662 for (var i = 0; i < snapshot.blocks.length; i++)
8663 {
8664 var b = snapshot.blocks[i];
8665 (cols[b.col] = cols[b.col] || []).push(b);
8666 }
8667 for (var c in cols)
8668 {
8669 var list = cols[c].slice().sort(function (a, b) { return a.y - b.y; });
8670 var floor = 0;
8671 for (var k = 0; k < list.length; k++)
8672 {
8673 var blk = list[k];
8674 if (blk.state === 'falling')
8675 {
8676 out[blk.id] = floor;
8677 floor = (target[blk.id] != null ? target[blk.id] : blk.y) + 1;
8678 }
8679 else
8680 { floor = Math.max(floor, blk.y + 1); }
8681 }
8682 }
8683 return out;
8684};
8685
8686if (typeof globalThis !== 'undefined')
8687{ globalThis.MiniPredict = MiniPredict; }
8688if (typeof module !== 'undefined' && module.exports)
8689{ module.exports = MiniPredict; }
8690
8691/*
8692 * End File:
8693 * /workspace/meteors/src/miniPredict.js
8694 */
8695
8465/*
8696/*
8466 * Start File:
8697 * Start File:
8467 * /workspace/meteors/src/online.js
8698 * /workspace/meteors/src/online.js
@@ -8492,6 +8723,10 @@ var Online = {
8492 error: '',
8723 error: '',
8493 _timer: null,
8724 _timer: null,
8494 _pendingShots: [],
8725 _pendingShots: [],
8726 _pollInFlight: false,
8727 _flushPending: false,
8728 _lastPollAt: 0,
8729 _getPayload: null,
8495 _flights: [],
8730 _flights: [],
8496 _lastStatus: null,
8731 _lastStatus: null,
8497 onChange: null,
8732 onChange: null,
@@ -8703,8 +8938,16 @@ Online.poll = function (opts)
8703 }
8938 }
8704 var self = this;
8939 var self = this;
8705 var prevStatus = this.lobby && this.lobby.status;
8940 var prevStatus = this.lobby && this.lobby.status;
8941 this._pollInFlight = true;
8942 this._lastPollAt = Date.now();
8706 return this.request('poll', body).then(function (data)
8943 return this.request('poll', body).then(function (data)
8707 {
8944 {
8945 self._pollInFlight = false;
8946 if (self._flushPending)
8947 {
8948 self._flushPending = false;
8949 self.flushShotsSoon();
8950 }
8708 self._handleTransitions(prevStatus, data);
8951 self._handleTransitions(prevStatus, data);
8709 if (self.onChange)
8952 if (self.onChange)
8710 { self.onChange(self); }
8953 { self.onChange(self); }
@@ -8739,6 +8982,7 @@ Online.startPolling = function (getPayload)
8739{
8982{
8740 this.stopPolling();
8983 this.stopPolling();
8741 var self = this;
8984 var self = this;
8985 this._getPayload = getPayload || null;
8742 var tick = function ()
8986 var tick = function ()
8743 {
8987 {
8744 var payload = getPayload ? getPayload() : {};
8988 var payload = getPayload ? getPayload() : {};
@@ -8748,8 +8992,68 @@ Online.startPolling = function (getPayload)
8748 this._timer = setInterval(tick, this.POLL_MS);
8992 this._timer = setInterval(tick, this.POLL_MS);
8749};
8993};
8750
8994
8995/** Minimum gap between an extra shot flush and the previous poll (ms). */
8996Online.FLUSH_MIN_GAP_MS = 120;
8997
8998/**
8999 * Pure decision for flushShotsSoon (t1181): 'now', 'later' (wait for the
9000 * in-flight poll or the min gap) or 'none' (nothing to send / not polling).
9001 */
9002Online.flushDecision = function (state)
9003{
9004 if (!state || !state.polling || !(state.pending > 0))
9005 { return 'none'; }
9006 if (state.inFlight)
9007 { return 'later'; }
9008 if (state.sinceLast < (state.minGap != null ? state.minGap : this.FLUSH_MIN_GAP_MS))
9009 { return 'later'; }
9010 return 'now';
9011};
9012
9013/**
9014 * Send freshly cleared shots on the next possible poll instead of up to
9015 * POLL_MS later, so the server's hit/miss result (and the retarget of the
9016 * local flight) arrives in about one round trip. Network cadence only;
9017 * the server still decides hits, targets and delivery (t1181).
9018 */
9019Online.flushShotsSoon = function ()
9020{
9021 var self = this;
9022 var d = this.flushDecision({
9023 polling: !!this._timer,
9024 pending: this._pendingShots.length,
9025 inFlight: this._pollInFlight,
9026 sinceLast: Date.now() - (this._lastPollAt || 0)
9027 });
9028 if (d === 'none')
9029 { return d; }
9030 if (d === 'later')
9031 {
9032 if (this._pollInFlight)
9033 { this._flushPending = true; }
9034 else if (!this._flushTimer)
9035 {
9036 var wait = Math.max(0, this.FLUSH_MIN_GAP_MS - (Date.now() - (this._lastPollAt || 0)));
9037 this._flushTimer = setTimeout(function ()
9038 {
9039 self._flushTimer = null;
9040 self.flushShotsSoon();
9041 }, wait);
9042 }
9043 return d;
9044 }
9045 this.poll(this._getPayload ? this._getPayload() : {});
9046 return d;
9047};
9048
8751Online.stopPolling = function ()
9049Online.stopPolling = function ()
8752{
9050{
9051 if (this._flushTimer)
9052 {
9053 clearTimeout(this._flushTimer);
9054 this._flushTimer = null;
9055 }
9056 this._flushPending = false;
8753 if (this._timer)
9057 if (this._timer)
8754 {
9058 {
8755 clearInterval(this._timer);
9059 clearInterval(this._timer);
@@ -8851,7 +9155,7 @@ Online.renderMinis = function (container)
8851 ? I18n.t('hud.miniPoints', { n: p.score || 0 })
9155 ? I18n.t('hud.miniPoints', { n: p.score || 0 })
8852 : ('Points ' + (p.score || 0));
9156 : ('Points ' + (p.score || 0));
8853 }
9157 }
8854 this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet);
9158 this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet, this._predictMini(p));
8855 }
9159 }
8856 for (var id in existing)
9160 for (var id in existing)
8857 {
9161 {
@@ -8872,7 +9176,28 @@ function miniColor (planet, color)
8872}
9176}
8873
9177
8874
9178
8875Online._drawMini = function (canvas, snapshot, planet)
9179/**
9180 * t1182: smoothed display y for an opponent's falling blocks (see
9181 * src/miniPredict.js). Returns id → y, or null without the module.
9182 */
9183Online._predictMini = function (p, now)
9184{
9185 var MP = typeof MiniPredict !== 'undefined' ? MiniPredict : null;
9186 if (!MP || !p)
9187 { return null; }
9188 if (!this._miniPredict)
9189 { this._miniPredict = Object.create(null); }
9190 var st = this._miniPredict[p.id];
9191 if (!st)
9192 { st = this._miniPredict[p.id] = MP.create(); }
9193 now = now != null ? now : (typeof performance !== 'undefined' ? performance.now() : Date.now());
9194 MP.update(st, p.snapshot, now);
9195 if (p.eliminated)
9196 { return null; }
9197 return MP.step(st, now, MP.fallSpeedFor(p.planet));
9198};
9199
9200Online._drawMini = function (canvas, snapshot, planet, shownY)
8876{
9201{
8877 if (!canvas)
9202 if (!canvas)
8878 { return; }
9203 { return; }
@@ -8919,7 +9244,8 @@ Online._drawMini = function (canvas, snapshot, planet)
8919 {
9244 {
8920 var b = blocks[i];
9245 var b = blocks[i];
8921 var x = b.col * tw;
9246 var x = b.col * tw;
8922 var y = canvas.height - (b.y + 1) * th;
9247 var by = (shownY && shownY[b.id] != null) ? shownY[b.id] : b.y;
9248 var y = canvas.height - (by + 1) * th;
8923 if (b.state === 'locked')
9249 if (b.state === 'locked')
8924 { ctx.fillStyle = '#3a3d4a'; }
9250 { ctx.fillStyle = '#3a3d4a'; }
8925 else if (b.color < 0)
9251 else if (b.color < 0)
@@ -9732,6 +10058,17 @@ Online.spawnFlights = function (results, locals)
9732 {
10058 {
9733 var r = results[i];
10059 var r = results[i];
9734 var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));
10060 var sid = String(r.id != null ? r.id : (r.client_id || ('tmp-' + i)));
10061 // Own shot already flying locally since the clear (t1181):
10062 // pick it up at its current pose and fly on to the real target.
10063 var cid = r.client_id != null ? String(r.client_id) : null;
10064 if (cid && this._previewIds[cid] && this._isOwnShot(r))
10065 {
10066 var own = this._findFlight(cid);
10067 this._flightSeen[sid] = now;
10068 if (own)
10069 { this.retargetFlight(own, r, locals[cid] || {}, now); }
10070 continue;
10071 }
9735 if (this._flightSeen[sid])
10072 if (this._flightSeen[sid])
9736 {
10073 {
9737 if (this._previewIds[sid])
10074 if (this._previewIds[sid])
@@ -9837,12 +10174,11 @@ Online.spawnFlights = function (results, locals)
9837 el.style.height = full + 'px';
10174 el.style.height = full + 'px';
9838 layer.appendChild(el);
10175 layer.appendChild(el);
9839
10176
10177 // A flight seen late (poll delay) still starts at the sender's
10178 // field and plays the whole arc, just a bit faster, so it lands
10179 // about when the server delivers it — never a mid-arc pop-in (t1181).
9840 var t0 = now;
10180 var t0 = now;
9841 if (r.age != null && isFinite(r.age) && r.age > 0)
10181 duration = this.lateFlightDuration(r.age, duration);
9842 {
9843 var u0 = Math.min(0.95, (r.age * 1000) / duration);
9844 t0 = now - u0 * duration;
9845 }
9846 var height = miss
10182 var height = miss
9847 ? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
10183 ? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
9848 : this.arcHeight(start, end);
10184 : this.arcHeight(start, end);
@@ -9879,6 +10215,52 @@ Online.spawnFlights = function (results, locals)
9879 this._flightLocals = {};
10215 this._flightLocals = {};
9880};
10216};
9881
10217
10218/** Shortest share of the normal flight a late-seen flight may get. */
10219Online.LATE_MIN_SHARE = 0.5;
10220
10221/** Duration (ms) for a flight first seen `age` seconds after it was fired. */
10222Online.lateFlightDuration = function (age, duration)
10223{
10224 if (age == null || !isFinite(age) || age <= 0)
10225 { return duration; }
10226 return Math.max(duration * this.LATE_MIN_SHARE, duration - age * 1000);
10227};
10228
10229/** Remaining duration (ms) after a local preview has flown `elapsedMs`. */
10230Online.retargetDuration = function (elapsedMs, duration)
10231{
10232 if (!(elapsedMs > 0))
10233 { return duration; }
10234 return Math.max(duration * this.LATE_MIN_SHARE, duration - elapsedMs);
10235};
10236
10237Online._isOwnShot = function (r)
10238{
10239 var mine = this.me && this.me.id;
10240 var from = r.from_id || r.from_user || null;
10241 return !from || (mine != null && String(from) === String(mine));
10242};
10243
10244/**
10245 * Sender side (t1181): start the flight the moment the block leaves the
10246 * field, before any server round trip. It rises out of the exit cell;
10247 * the poll answer retargets it (hit → opponent mini, miss → off-screen).
10248 */
10249Online.startLocalShot = function (shot, start)
10250{
10251 if (!shot || !start)
10252 { return null; }
10253 return this.previewExit({
10254 id: shot.id,
10255 col: shot.col,
10256 y: shot.y,
10257 vy: shot.vy,
10258 color: shot.color,
10259 start: start,
10260 from_id: null
10261 });
10262};
10263
9882Online.rememberFlightLocal = function (shot, startX, startY)
10264Online.rememberFlightLocal = function (shot, startX, startY)
9883{
10265{
9884 if (!this._flightLocals)
10266 if (!this._flightLocals)
@@ -10045,6 +10427,7 @@ Online.previewExit = function (info)
10045 });
10427 });
10046 this._previewIds[sid] = true;
10428 this._previewIds[sid] = true;
10047 this._flightSeen[sid] = now;
10429 this._flightSeen[sid] = now;
10430 return true;
10048};
10431};
10049
10432
10050/** True while a field sprite should stay hidden — the flight is its visual. */
10433/** True while a field sprite should stay hidden — the flight is its visual. */
@@ -10086,6 +10469,8 @@ Online.retargetFlight = function (f, r, meta, now)
10086 var miss = !!r.miss;
10469 var miss = !!r.miss;
10087 var kind = this.flightKind(fromId, targetId, miss);
10470 var kind = this.flightKind(fromId, targetId, miss);
10088 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
10471 var duration = (r.flight_duration || this.FLIGHT_DURATION) * 1000;
10472 if (f.preview)
10473 { duration = this.retargetDuration(now - f.t0, duration); }
10089
10474
10090 var landCol = null;
10475 var landCol = null;
10091 if (r.land_col != null && isFinite(r.land_col))
10476 if (r.land_col != null && isFinite(r.land_col))
@@ -10202,6 +10587,9 @@ Online.pointAllowedOnArc = function (p, field, start, end, slop)
10202 return false;
10587 return false;
10203};
10588};
10204
10589
10590/** How long a local preview may wait at its apex for the server (ms). */
10591Online.PREVIEW_HOLD_MS = 2500;
10592
10205Online.tickFlights = function (now)
10593Online.tickFlights = function (now)
10206{
10594{
10207 now = now || performance.now();
10595 now = now || performance.now();
@@ -10210,6 +10598,8 @@ Online.tickFlights = function (now)
10210 {
10598 {
10211 var f = this._flights[i];
10599 var f = this._flights[i];
10212 var raw = (now - f.t0) / f.duration;
10600 var raw = (now - f.t0) / f.duration;
10601 if (f.preview && raw >= 0.999 && now - f.t0 < f.duration + this.PREVIEW_HOLD_MS)
10602 { raw = 0.999; }
10213 if (raw >= 1)
10603 if (raw >= 1)
10214 {
10604 {
10215 if (f.el && f.el.parentNode)
10605 if (f.el && f.el.parentNode)
@@ -10282,6 +10672,7 @@ Online.clearFlights = function ()
10282 this._flightSeen = Object.create(null);
10672 this._flightSeen = Object.create(null);
10283 this._pendingLandCol = Object.create(null);
10673 this._pendingLandCol = Object.create(null);
10284 this._previewIds = Object.create(null);
10674 this._previewIds = Object.create(null);
10675 this._miniPredict = Object.create(null);
10285};
10676};
10286
10677
10287if (typeof globalThis !== 'undefined')
10678if (typeof globalThis !== 'undefined')
@@ -13715,8 +14106,14 @@ function tickOnline (dt)
13715 var s = shots[i];
14106 var s = shots[i];
13716 var start = fieldToViewport(s.col, s.y);
14107 var start = fieldToViewport(s.col, s.y);
13717 Online.rememberFlightLocal(s, start.x, start.y);
14108 Online.rememberFlightLocal(s, start.x, start.y);
14109 // Draw the flight locally right away (t1181); the server
14110 // answer only retargets it.
14111 if (Online.startLocalShot)
14112 { Online.startLocalShot(s, start); }
13718 }
14113 }
13719 Online.queueShots(shots);
14114 Online.queueShots(shots);
14115 if (shots.length && Online.flushShotsSoon)
14116 { Online.flushShotsSoon(); }
13720 }
14117 }
13721 Online.tickFlights();
14118 Online.tickFlights();
13722 Online.renderMinis(document.getElementById('minis'));
14119 Online.renderMinis(document.getElementById('minis'));
@@ -14168,8 +14565,12 @@ function onlinePayload ()
14168{
14565{
14169 if (!app.online || !app.core)
14566 if (!app.online || !app.core)
14170 { return {}; }
14567 { return {}; }
14568 var snap = app.core.fieldSnapshot();
14569 // t1182: sender time (ms) so opponents can place the snapshot in
14570 // time and predict falling blocks smoothly. Visual only.
14571 snap.t = Math.round(typeof performance !== 'undefined' ? performance.now() : Date.now());
14171 return {
14572 return {
14172 snapshot: app.core.fieldSnapshot(),
14573 snapshot: snap,
14173 score: app.core.score,
14574 score: app.core.score,
14174 eliminated: app.core.state === 'gameover' || app.spectating || app.eliminatedReported
14575 eliminated: app.core.state === 'gameover' || app.spectating || app.eliminatedReported
14175 };
14576 };
docs/ASSUMPTIONS.md +46 −0
@@ -952,3 +952,49 @@ Aanname:
952 952 achtergrondtab springt niet). Werkt op desktop en mobiel. Bij
953 953 `prefers-reduced-motion` vliegen er geen blokjes en springt de titel
954 954 zonder animatie naar boven; het getal telt in hetzelfde tempo op.
955
956 ## t1181 — vliegende blokken lokaal en vloeiend
957
958 **Oorzaak van het haperen.** De vlucht van een weggeschoten blok werd pas
959 gemaakt als de poll-response met `shot_results` terugkwam. Schoten wachtten
960 op de volgende poll (`setInterval`, 750 ms) plus de round trip, terwijl
961 `cullOffTop` het blok al had weggehaald: 140–740 ms niets, daarna verscheen
962 de vlucht ineens. De lokale preview (`previewExit`) bestond wel maar werd
963 nooit aangeroepen. Ontvangers lieten late vluchten halverwege de boog
964 beginnen (terugdateren met `age`).
965
966 **Oplossing (alleen presentatie, spellogica en payload ongewijzigd).**
967 - Zender: `Online.startLocalShot` start op het lokale clear-moment direct een
968 vlucht (`previewExit`), uit `tickOnline`.
969 - `Online.flushShotsSoon` stuurt schoten meteen mee met een extra poll
970 (minstens `FLUSH_MIN_GAP_MS` = 120 ms tussen polls, nooit twee tegelijk).
971 - Serverantwoord: dezelfde vlucht wordt via `retargetFlight` vanuit de
972 huidige positie naar het echte doel gebogen, met de resterende duur.
973 - Is de server traag, dan wacht de preview bij de top
974 (`PREVIEW_HOLD_MS` = 2500 ms) in plaats van te verdwijnen.
975 - Ontvanger: altijd de hele boog vanaf het veld van de zender, duur
976 `max(50%, duur − age)` (`LATE_MIN_SHARE`).
977 - Animatie per frame met `requestAnimationFrame` op tijd (niet op poll/tick).
978
979 Tests: `test/flight-local.test.js`; browser: `test/t1181-flights-playwright.py`
980 (desktop-zender + mobiele ontvanger).
981
982 ## t1182 — voorspelling op mini-velden
983
984 - `src/miniPredict.js` (`MiniPredict`): tussen twee snapshots vallen
985 blokken met `state: 'falling'` verder met de valsnelheid van die speler
986 (`13 / planet.fallTime`), met sub-cel posities.
987 - Nooit voorspeld: landen, vastzetten of lijnen wissen. Een voorspeld blok
988 stopt bovenop het eerste obstakel in zijn kolom en wacht op de server.
989 - Snapshot krijgt `t` (zendertijd, ms, alleen visueel). De ontvanger zet die
990 om naar de eigen klok met de kleinste waargenomen aankomst-offset
991 (laatste 16), zodat een laat binnenkomende snapshot op het juiste moment
992 wordt geplaatst. Dezelfde snapshot opnieuw = geen herstart.
993 - Bijsturen: achterlopend blok haalt in (`RECONCILE_S` = 0,16 s), een blok
994 dat vooruitloopt valt even langzamer (50%) — nooit omhoog. Meer dan
995 `SNAP_CELLS` = 1,5 cel verschil: direct naar de serverpositie.
996 - Extrapolatie maximaal `MAX_EXTRAP_S` = 1,5 s na de laatste snapshot.
997
998 Tests: `test/mini-predict.test.js`, plus de mini-meting in
999 `test/t1181-flights-playwright.py`.
1000
@@ -952,3 +952,49 @@ Aanname:
952 achtergrondtab springt niet). Werkt op desktop en mobiel. Bij
952 achtergrondtab springt niet). Werkt op desktop en mobiel. Bij
953 `prefers-reduced-motion` vliegen er geen blokjes en springt de titel
953 `prefers-reduced-motion` vliegen er geen blokjes en springt de titel
954 zonder animatie naar boven; het getal telt in hetzelfde tempo op.
954 zonder animatie naar boven; het getal telt in hetzelfde tempo op.
955
956## t1181 — vliegende blokken lokaal en vloeiend
957
958**Oorzaak van het haperen.** De vlucht van een weggeschoten blok werd pas
959gemaakt als de poll-response met `shot_results` terugkwam. Schoten wachtten
960op de volgende poll (`setInterval`, 750 ms) plus de round trip, terwijl
961`cullOffTop` het blok al had weggehaald: 140–740 ms niets, daarna verscheen
962de vlucht ineens. De lokale preview (`previewExit`) bestond wel maar werd
963nooit aangeroepen. Ontvangers lieten late vluchten halverwege de boog
964beginnen (terugdateren met `age`).
965
966**Oplossing (alleen presentatie, spellogica en payload ongewijzigd).**
967- Zender: `Online.startLocalShot` start op het lokale clear-moment direct een
968 vlucht (`previewExit`), uit `tickOnline`.
969- `Online.flushShotsSoon` stuurt schoten meteen mee met een extra poll
970 (minstens `FLUSH_MIN_GAP_MS` = 120 ms tussen polls, nooit twee tegelijk).
971- Serverantwoord: dezelfde vlucht wordt via `retargetFlight` vanuit de
972 huidige positie naar het echte doel gebogen, met de resterende duur.
973- Is de server traag, dan wacht de preview bij de top
974 (`PREVIEW_HOLD_MS` = 2500 ms) in plaats van te verdwijnen.
975- Ontvanger: altijd de hele boog vanaf het veld van de zender, duur
976 `max(50%, duur − age)` (`LATE_MIN_SHARE`).
977- Animatie per frame met `requestAnimationFrame` op tijd (niet op poll/tick).
978
979Tests: `test/flight-local.test.js`; browser: `test/t1181-flights-playwright.py`
980(desktop-zender + mobiele ontvanger).
981
982## t1182 — voorspelling op mini-velden
983
984- `src/miniPredict.js` (`MiniPredict`): tussen twee snapshots vallen
985 blokken met `state: 'falling'` verder met de valsnelheid van die speler
986 (`13 / planet.fallTime`), met sub-cel posities.
987- Nooit voorspeld: landen, vastzetten of lijnen wissen. Een voorspeld blok
988 stopt bovenop het eerste obstakel in zijn kolom en wacht op de server.
989- Snapshot krijgt `t` (zendertijd, ms, alleen visueel). De ontvanger zet die
990 om naar de eigen klok met de kleinste waargenomen aankomst-offset
991 (laatste 16), zodat een laat binnenkomende snapshot op het juiste moment
992 wordt geplaatst. Dezelfde snapshot opnieuw = geen herstart.
993- Bijsturen: achterlopend blok haalt in (`RECONCILE_S` = 0,16 s), een blok
994 dat vooruitloopt valt even langzamer (50%) — nooit omhoog. Meer dan
995 `SNAP_CELLS` = 1,5 cel verschil: direct naar de serverpositie.
996- Extrapolatie maximaal `MAX_EXTRAP_S` = 1,5 s na de laatste snapshot.
997
998Tests: `test/mini-predict.test.js`, plus de mini-meting in
999`test/t1181-flights-playwright.py`.
1000