Game state synchronization, snapshot systems, and conflict resolution for consistent multiplayer experience
Implements snapshot interpolation and delta compression for multiplayer game state synchronization. Triggers when you need to reduce network bandwidth or smooth entity movement between server updates.
/plugin marketplace add pluginagentmarketplace/custom-plugin-server-side-game-dev/plugin install server-side-game-dev-plugin@pluginagentmarketplace-game-serverThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/sync-techniques.yamlreferences/GUIDE.mdreferences/STATESYNC_PATTERNS.mdscripts/helper.pyscripts/state_sync_demo.pyEnsure consistent game state across all connected players.
class SnapshotBuffer {
constructor(size = 3, delay = 100) {
this.buffer = [];
this.size = size;
this.delay = delay;
}
add(snapshot) {
this.buffer.push({
time: snapshot.serverTime,
entities: new Map(snapshot.entities)
});
while (this.buffer.length > this.size) {
this.buffer.shift();
}
}
interpolate(renderTime) {
const targetTime = renderTime - this.delay;
const [before, after] = this.findBrackets(targetTime);
if (!before || !after) return this.extrapolate();
const t = (targetTime - before.time) / (after.time - before.time);
return this.lerp(before, after, t);
}
lerp(before, after, t) {
const result = new Map();
for (const [id, a] of before.entities) {
const b = after.entities.get(id);
if (b) {
result.set(id, {
x: a.x + (b.x - a.x) * t,
y: a.y + (b.y - a.y) * t,
z: a.z + (b.z - a.z) * t
});
}
}
return result;
}
}
class DeltaCompressor {
createDelta(baseline, current) {
const delta = { created: [], updated: [], deleted: [] };
for (const [id, entity] of current) {
const prev = baseline.get(id);
if (!prev) {
delta.created.push({ id, ...entity });
} else if (this.changed(prev, entity)) {
delta.updated.push({ id, ...this.diff(prev, entity) });
}
}
for (const [id] of baseline) {
if (!current.has(id)) delta.deleted.push(id);
}
return delta;
}
changed(a, b) {
return a.x !== b.x || a.y !== b.y || a.z !== b.z;
}
diff(prev, curr) {
const d = {};
if (prev.x !== curr.x) d.x = curr.x;
if (prev.y !== curr.y) d.y = curr.y;
if (prev.z !== curr.z) d.z = curr.z;
return d;
}
}
| Model | Latency | Bandwidth | Best For |
|---|---|---|---|
| Snapshot | Medium | High | Simple games |
| Delta | Medium | Low | Most games |
| Lockstep | High | Low | RTS, Fighting |
| Interest Mgmt | Low | Low | MMO |
| Error | Root Cause | Solution |
|---|---|---|
| Teleporting | Empty buffer | Increase buffer size |
| Desync | Non-determinism | Add checksums |
| Rubber-banding | Bad reconciliation | Fix prediction |
| Invisible entities | AoI bug | Check interest radius |
// Check buffer state
console.log(`Buffer: ${buffer.length}/${buffer.size}`);
console.log(`Time span: ${buffer.getTimeSpan()}ms`);
// Verify checksums
const cs1 = computeChecksum(clientState);
const cs2 = computeChecksum(serverState);
console.log(`Match: ${cs1 === cs2}`);
describe('DeltaCompressor', () => {
test('detects changes', () => {
const compressor = new DeltaCompressor();
const baseline = new Map([['e1', { x: 0, y: 0 }]]);
const current = new Map([['e1', { x: 1, y: 0 }]]);
const delta = compressor.createDelta(baseline, current);
expect(delta.updated).toHaveLength(1);
expect(delta.updated[0].x).toBe(1);
});
});
assets/ - Sync templatesreferences/ - Best practicesThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.