viewer: don't re-apply matching tentative echoes

After a drag-drop the viewer paints a local preview of the move synchronously,
then the server's tentative echo of the same turn buffer arrived a few hundred
ms later and went through replaceState again. Rebuilding every piece while the
drop animation was still in flight made the piece show at its destination
instantly while also tweening there from the drop point. Matching echoes now
short-circuit like stale ones already did — they only trigger the move sound,
which used to be the echo replace's job (local previews are silent).

Also delay the self-contained harness's tentative echo by 300ms so it lands
mid-animation like on the real platform instead of masking such races.
This commit is contained in:
coyotte508 2026-08-17 09:50:20 +00:00
commit 7a54e8e2dd
2 changed files with 21 additions and 3 deletions

View file

@ -658,6 +658,16 @@ export default class Game extends Vue {
// Applying it would transiently show a phantom or regressed move; the echo
// for the current buffer (if any) will follow, so just drop this one.
return;
} else if (state) {
// Matching tentative echo: the server replayed exactly the current turn
// buffer, which the local preview already painted synchronously when the
// move was made (sendMove/undo). Replacing the state again would rebuild
// every piece while the drop animation is still in flight — the piece
// shows at its destination instantly AND tweens there from the drop point.
// Only play the move sound the replace would have played (local previews
// are silent, see replaceState's fake flag).
this.playMoveSound();
return;
}
this.replaceState(state, false);
@ -690,7 +700,13 @@ export default class Game extends Vue {
this.createPieces();
if (!fake && this.preferences.sound && this.G?.log[this.G?.log.length - 1].type == 'move') {
if (!fake) {
this.playMoveSound();
}
}
playMoveSound() {
if (this.preferences.sound && this.G?.log[this.G?.log.length - 1].type == 'move') {
const move = (this.G?.log[this.G?.log.length - 1] as LogMove).move;
if (move.name == MoveName.Pass && this.G.currentPlayers.includes(this.player!)) {
(document.getElementById('notification')!.cloneNode(true) as HTMLAudioElement).play();

View file

@ -38,8 +38,10 @@ function launchSelfContained(selector = '#app') {
console.log('new game state', newState);
if (newState.newTurn === false) {
// Tentative: just echo the state back to the acting player
emitter.emit('state', cloneDeep(strip ? stripSecret(newState, playerIndex) : newState));
// Tentative: just echo the state back to the acting player. Delayed like on
// the real platform, where the echo arrives over the network mid-animation.
const echo = cloneDeep(strip ? stripSecret(newState, playerIndex) : newState);
setTimeout(() => emitter.emit('state', echo), 300);
return;
}