Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/engine/core/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useMultiplayerStore,
getAdaptiveCommandDelay,
getLatencyStats,
getAllPeerIds,
} from '@/store/multiplayerStore';

// Multiplayer message types
Expand Down Expand Up @@ -470,14 +471,27 @@ export class Game extends GameCore {

/**
* Get the set of player IDs that should send commands for lockstep.
* In 2-player multiplayer, this is local player + remote peer.
* Supports up to 8 players: local player + all remote peers.
*/
private getExpectedPlayerIds(): string[] {
const players: string[] = [this.config.playerId];
const remotePeerId = useMultiplayerStore.getState().remotePeerId;
if (remotePeerId) {
players.push(remotePeerId);

// Get all remote peer IDs (supports 2-8 players)
const remotePeerIds = getAllPeerIds();
for (const peerId of remotePeerIds) {
if (!players.includes(peerId)) {
players.push(peerId);
Comment on lines +479 to +483

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align lockstep expected IDs with command player IDs

In multiplayer, getExpectedPlayerIds() now appends getAllPeerIds() (Game.ts 479-483), but those IDs are populated from network peer identifiers (addPeer(guest.pubkey, ...) and the synthetic host-... in useMultiplayer.ts 850-858, 875-881). Lockstep receipts are recorded under command.playerId (Game.ts 639-643), which is sourced from getLocalPlayerId()/slot IDs (useWorkerBridge.ts 136-149). In a normal lobby where player IDs are player1/player2, the peer IDs will never match the command receipts, so hasAllCommandsForTick() will wait indefinitely and the lockstep barrier can stall or desync.

Useful? React with 👍 / 👎.

}
}

// Fallback for legacy single-peer mode
if (remotePeerIds.length === 0) {
const remotePeerId = useMultiplayerStore.getState().remotePeerId;
if (remotePeerId && !players.includes(remotePeerId)) {
players.push(remotePeerId);
}
}

return players;
}

Expand Down
Loading