multiplayer fix: more strict smoke trace sync

This commit is contained in:
catarrh committed 2026-08-02 00:13:59 +03:00
1 parent 995fcc1ef7
commit 393998b48a
2 files changed
+9 -5

No files matched your search

+7 -3
View File
@@ -41,6 +41,7 @@ let winner;
const seenClientExplosions = new Map(); const seenClientExplosions = new Map();
const carveQueue = []; const carveQueue = [];
let clientCollapseState = null; let clientCollapseState = null;
let nextTraceId = 1;
let score = 0; let score = 0;
let round = 0; let round = 0;
@@ -392,7 +393,10 @@ function executeFire(player, a, p, weaponIndex) {
weapon.ammo -= 1; weapon.ammo -= 1;
player.shotsFired++; player.shotsFired++;
projectileType.create(projectile, player, weapon, px, py, a, p, wind) projectileType.create(projectile, player, weapon, px, py, a, p, wind)
.forEach(x => projectiles.push(x)); .forEach(x => {
x.traceId = nextTraceId++;
projectiles.push(x);
});
state = 'shoot'; state = 'shoot';
} }
@@ -952,7 +956,7 @@ function broadcastWorld() {
napalmParticles: napalmParticles.map(p => ({x: p.x, y: p.y})), napalmParticles: napalmParticles.map(p => ({x: p.x, y: p.y})),
fireCells: fireCells.map(f => ({x: f.x, y: f.y, timeLeft: f.timeLeft})), fireCells: fireCells.map(f => ({x: f.x, y: f.y, timeLeft: f.timeLeft})),
smokeParticles: smokeParticles.map(s => ({x: s.x, y: s.y, vx: s.vx, vy: s.vy, alpha: s.alpha, lifetime: s.lifetime})), smokeParticles: smokeParticles.map(s => ({x: s.x, y: s.y, vx: s.vx, vy: s.vy, alpha: s.alpha, lifetime: s.lifetime})),
trajectories: trajectories.slice(-300).filter((_, i) => i % 3 === 0).map(t => ({x: t.x, y: t.y, a: t.a, c: t.c})), trajectories: trajectories.slice(-300).filter((_, i) => i % 3 === 0).map(t => ({x: t.x, y: t.y, a: t.a, c: t.c, traceId: t.traceId})),
}; };
netBroadcast({type: HOST_MSG.WORLD, snap}); netBroadcast({type: HOST_MSG.WORLD, snap});
} }
@@ -2413,7 +2417,7 @@ function drawTrajectories() {
for (let i=1; i<trajectories.length; i++) { for (let i=1; i<trajectories.length; i++) {
const prev = trajectories[i-1]; const prev = trajectories[i-1];
const curr = trajectories[i]; const curr = trajectories[i];
if (prev.c === curr.c) { if (prev.c === curr.c && prev.traceId === curr.traceId) {
traces.globalAlpha = curr.a / 255; traces.globalAlpha = curr.a / 255;
drawLine(traces, prev.x, prev.y, curr.x, curr.y, curr.c); drawLine(traces, prev.x, prev.y, curr.x, curr.y, curr.c);
} }
+2 -2
View File
@@ -109,7 +109,7 @@ export const PROJECTILE_TYPES = {
trajectory trajectory
.slice(0, trajectory.length-1) .slice(0, trajectory.length-1)
.map(x => ({...x, a:255})) .map(x => ({...x, a:255, traceId: projectile.traceId}))
.forEach(x => trajectories.push(x)); .forEach(x => trajectories.push(x));
} }
@@ -269,7 +269,7 @@ export const PROJECTILE_TYPES = {
trajectory trajectory
.slice(0, trajectory.length-1) .slice(0, trajectory.length-1)
.map(x => ({...x, a:255})) .map(x => ({...x, a:255, traceId: projectile.traceId}))
.forEach(x => trajectories.push(x)); .forEach(x => trajectories.push(x));
} }