synchronization-algorithms
29
总安装量
21
周安装量
#12847
全站排名
安装命令
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-game-developer --skill synchronization-algorithms
Agent 安装分布
claude-code
16
gemini-cli
14
antigravity
14
opencode
13
codex
12
cursor
12
Skill 文档
Multiplayer Synchronization
Synchronization Techniques
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â SYNC TECHNIQUES OVERVIEW â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â CLIENT PREDICTION: â
â â Execute input locally before server confirms â
â â Feels responsive, requires reconciliation â
â Best for: FPS, action games â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â INTERPOLATION: â
â â Display positions between known states â
â â Smooth visuals, adds latency â
â Best for: Other players, NPCs â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â ROLLBACK NETCODE: â
â â Rewind game state on correction â
â â Re-simulate with corrected data â
â Best for: Fighting games, precise timing â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â LOCKSTEP: â
â â All clients advance together â
â â Deterministic, waits for slowest â
â Best for: RTS, turn-based â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Client Prediction & Reconciliation
PREDICTION FLOW:
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Frame N: â
â 1. Capture input â
â 2. Predict result locally (immediate response) â
â 3. Store input + predicted state â
â 4. Send input to server â
â â
â Frame N+RTT: â
â 5. Receive server state for Frame N â
â 6. Compare with stored prediction â
â 7. If mismatch: RECONCILE â
â a. Snap to server state â
â b. Re-apply all inputs since Frame N â
â c. Smooth correction to avoid visual pop â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
// â
Production-Ready: Prediction Buffer
public class PredictionBuffer
{
private const int BUFFER_SIZE = 128;
private readonly PredictionEntry[] _buffer = new PredictionEntry[BUFFER_SIZE];
public void Store(uint tick, InputPayload input, PlayerState predictedState)
{
int index = (int)(tick % BUFFER_SIZE);
_buffer[index] = new PredictionEntry
{
Tick = tick,
Input = input,
PredictedState = predictedState
};
}
public void Reconcile(uint serverTick, PlayerState serverState)
{
int index = (int)(serverTick % BUFFER_SIZE);
var entry = _buffer[index];
if (entry.Tick != serverTick) return; // Stale data
float error = Vector3.Distance(entry.PredictedState.Position, serverState.Position);
if (error < 0.01f) return; // Within tolerance
// Misprediction detected - reconcile
PlayerState currentState = serverState;
// Re-simulate all inputs since server tick
for (uint t = serverTick + 1; t <= CurrentTick; t++)
{
int idx = (int)(t % BUFFER_SIZE);
if (_buffer[idx].Tick == t)
{
currentState = SimulateInput(currentState, _buffer[idx].Input);
}
}
// Apply corrected state (with smoothing)
ApplyCorrectedState(currentState);
}
}
Interpolation
INTERPOLATION BUFFER:
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â RECEIVE: [State T-100ms] [State T-50ms] [State T-now] â
â â
â RENDER: Display interpolated position between T-100ms â
â and T-50ms based on current render time â
â â
â WHY: Always have two states to interpolate between â
â (render behind real-time by buffer amount) â
â â
â BUFFER SIZE: â
â ⢠Too small: Choppy when packets delayed â
â ⢠Too large: Everything feels delayed â
â ⢠Typical: 100-200ms for other players â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Rollback Netcode
ROLLBACK FLOW (Fighting Games):
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â 1. Execute frame with predicted opponent input â
â 2. Store complete game state snapshot â
â 3. When actual input arrives: â
â a. If matches prediction: continue â
â b. If mismatch: â
â - Load snapshot from that frame â
â - Re-simulate all frames with correct input â
â - "Rollback" visual to corrected state â
â 4. Hide rollbacks with animation tricks â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ROLLBACK LIMITS:
⢠Max rollback: 7-8 frames (~116ms at 60fps)
⢠Beyond: Game stutters or desyncs
⢠Input delay trade-off: 0-3 frames pre-delay
Lockstep Synchronization
LOCKSTEP (RTS Games):
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Frame 0: All clients send inputs â
â Wait for all inputs â
â Execute deterministically â
â â
â Frame 1: Repeat â
â â
â REQUIREMENTS: â
â ⢠Deterministic simulation (fixed-point math) â
â ⢠Synchronized RNG seeds â
â ⢠Identical execution order â
â â
â PROS: Minimal bandwidth (only inputs) â
â CONS: Latency = slowest player, input delay â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ð§ Troubleshooting
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PROBLEM: Visible rubber-banding â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â SOLUTIONS: â
â â Increase interpolation buffer â
â â Smooth reconciliation (lerp, not snap) â
â â Add visual damping â
â â Check for consistent tick rate â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PROBLEM: Clients desyncing â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â SOLUTIONS: â
â â Use fixed-point math â
â â Sync random number seeds â
â â Periodic full-state resync â
â â Add state hash verification â
â â Check floating-point determinism â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PROBLEM: Too many rollbacks (fighting games) â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â SOLUTIONS: â
â â Add input delay frames (1-3) â
â â Better input prediction â
â â Limit max rollback frames â
â â Disconnect players with bad connections â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Technique Selection
| Game Type | Primary | Secondary | Latency Budget |
|---|---|---|---|
| FPS | Prediction | Interpolation | 50-100ms |
| Fighting | Rollback | Input delay | 50-80ms |
| RTS | Lockstep | – | 200-500ms |
| MMO | Interpolation | Prediction | 100-200ms |
| Racing | Prediction | Extrapolation | 50-100ms |
Use this skill: When building multiplayer systems, optimizing netcode, or fixing desync issues.