mirror of
https://github.com/sndrec/WebMonkeyBall.git
synced 2026-02-03 02:03:33 +00:00
fix effects not simming in multi
This commit is contained in:
@@ -612,7 +612,8 @@ export class Game {
|
||||
advanceFrame: (inputs) => {
|
||||
if (!perf.enabled) {
|
||||
const prev = this.suppressVisualEffects;
|
||||
this.suppressVisualEffects = true;
|
||||
const suppress = this.rollbackSession?.suppressVisuals ?? false;
|
||||
this.suppressVisualEffects = suppress;
|
||||
try {
|
||||
this.advanceOneFrame(inputs);
|
||||
} finally {
|
||||
@@ -622,7 +623,8 @@ export class Game {
|
||||
}
|
||||
const t0 = nowMs();
|
||||
const prev = this.suppressVisualEffects;
|
||||
this.suppressVisualEffects = true;
|
||||
const suppress = this.rollbackSession?.suppressVisuals ?? false;
|
||||
this.suppressVisualEffects = suppress;
|
||||
try {
|
||||
this.advanceOneFrame(inputs);
|
||||
} finally {
|
||||
|
||||
62
src/main.ts
62
src/main.ts
@@ -1136,27 +1136,33 @@ function rollbackAndResim(startFrame: number) {
|
||||
return false;
|
||||
}
|
||||
const resimFrames = current - rollbackFrame;
|
||||
for (let frame = rollbackFrame + 1; frame <= current; frame += 1) {
|
||||
const inputs = buildInputsForFrame(frame);
|
||||
session.advanceTo(frame, inputs);
|
||||
let hash: number | undefined;
|
||||
if (state.hashInterval > 0 && frame % state.hashInterval === 0) {
|
||||
hash = getSimHash();
|
||||
state.hashHistory.set(frame, hash);
|
||||
}
|
||||
if (state.role === 'host') {
|
||||
const bundleInputs: Record<number, QuantizedInput> = {};
|
||||
for (const [playerId, input] of inputs.entries()) {
|
||||
bundleInputs[playerId] = input;
|
||||
const prevSuppress = session.suppressVisuals;
|
||||
session.suppressVisuals = true;
|
||||
try {
|
||||
for (let frame = rollbackFrame + 1; frame <= current; frame += 1) {
|
||||
const inputs = buildInputsForFrame(frame);
|
||||
session.advanceTo(frame, inputs);
|
||||
let hash: number | undefined;
|
||||
if (state.hashInterval > 0 && frame % state.hashInterval === 0) {
|
||||
hash = getSimHash();
|
||||
state.hashHistory.set(frame, hash);
|
||||
}
|
||||
state.hostFrameBuffer.set(frame, {
|
||||
type: 'frame',
|
||||
stageSeq: state.stageSeq,
|
||||
frame,
|
||||
inputs: bundleInputs,
|
||||
});
|
||||
if (state.role === 'host') {
|
||||
const bundleInputs: Record<number, QuantizedInput> = {};
|
||||
for (const [playerId, input] of inputs.entries()) {
|
||||
bundleInputs[playerId] = input;
|
||||
}
|
||||
state.hostFrameBuffer.set(frame, {
|
||||
type: 'frame',
|
||||
stageSeq: state.stageSeq,
|
||||
frame,
|
||||
inputs: bundleInputs,
|
||||
});
|
||||
}
|
||||
trimNetplayHistory(frame);
|
||||
}
|
||||
trimNetplayHistory(frame);
|
||||
} finally {
|
||||
session.suppressVisuals = prevSuppress;
|
||||
}
|
||||
if (netplayPerf.enabled) {
|
||||
const dt = performance.now() - perfStart;
|
||||
@@ -1178,13 +1184,19 @@ function resimFromSnapshot(snapshotFrame: number, targetFrame: number) {
|
||||
const state = netplayState;
|
||||
const session = state.session;
|
||||
const resimFrames = targetFrame - snapshotFrame;
|
||||
for (let frame = snapshotFrame + 1; frame <= targetFrame; frame += 1) {
|
||||
const inputs = buildInputsForFrame(frame);
|
||||
session.advanceTo(frame, inputs);
|
||||
if (state.hashInterval > 0 && frame % state.hashInterval === 0) {
|
||||
state.hashHistory.set(frame, getSimHash());
|
||||
const prevSuppress = session.suppressVisuals;
|
||||
session.suppressVisuals = true;
|
||||
try {
|
||||
for (let frame = snapshotFrame + 1; frame <= targetFrame; frame += 1) {
|
||||
const inputs = buildInputsForFrame(frame);
|
||||
session.advanceTo(frame, inputs);
|
||||
if (state.hashInterval > 0 && frame % state.hashInterval === 0) {
|
||||
state.hashHistory.set(frame, getSimHash());
|
||||
}
|
||||
trimNetplayHistory(frame);
|
||||
}
|
||||
trimNetplayHistory(frame);
|
||||
} finally {
|
||||
session.suppressVisuals = prevSuppress;
|
||||
}
|
||||
if (netplayPerf.enabled) {
|
||||
const dt = performance.now() - perfStart;
|
||||
|
||||
@@ -14,6 +14,7 @@ export class RollbackSession<T> {
|
||||
private stateHistory = new Map<number, T>();
|
||||
private inputHistory = new Map<number, FrameInputs>();
|
||||
private lastFrame = 0;
|
||||
public suppressVisuals = false;
|
||||
|
||||
constructor(callbacks: RollbackCallbacks<T>, maxRollbackFrames = 30) {
|
||||
this.callbacks = callbacks;
|
||||
|
||||
Reference in New Issue
Block a user