bugfix/fix-duplicate-send-of-ticks

This commit is contained in:
Thilo Behnke
2022-07-10 23:10:51 +02:00
parent dde0fc8b5c
commit dc65803ca3
2 changed files with 28 additions and 25 deletions

View File

@@ -14,14 +14,9 @@
$: if (networkTickEvents && $networkTickEvents.hasNext) {
const tick = networkTickEvents.next() as HostSessionSnapshot;
if (tick != null) {
if (lastTick && lastTick.ts >= tick.ts) {
// TODO: How is this possible?
console.error(`!!!! Duplicated Tick ${tick.ts} (vs ${lastTick.ts}) !!!!`)
} else {
inputs = tick.inputs;
gameField.update(tick.objects, tick.state);
lastTick = tick;
}
inputs = tick.inputs;
gameField.update(tick.objects, tick.state);
lastTick = tick;
}
}

View File

@@ -19,6 +19,8 @@
let cachedSessionId;
let relevantKeyboardEvents: Readable<Input[]>;
let lastTick: number = null;
$: if (!cachedSessionId && session && isPlayer(session.you)) {
cachedSessionId = session.session_id;
console.log("NetworkSessionWrapper ready, now setting up sessionEvents")
@@ -29,26 +31,32 @@
}
$: if (session && session.type === SessionType.HOST && session.state === SessionState.RUNNING) {
console.debug("sending host snapshot")
const state: GameState = $gameField.state;
networkEvents.produce({
state,
inputs: $sessionInputs,
session_id: session.session_id,
objects: $gameField.objects,
player_id: session.you.id,
ts: $gameField.ts
})
if (lastTick != $gameField.ts) {
console.debug("sending host snapshot")
const state: GameState = $gameField.state;
networkEvents.produce({
state,
inputs: $sessionInputs,
session_id: session.session_id,
objects: $gameField.objects,
player_id: session.you.id,
ts: $gameField.ts
});
lastTick = $gameField.ts;
}
}
$: if (session && session.type === SessionType.PEER && session.state === SessionState.RUNNING) {
console.debug("sending peer snapshot")
networkEvents.produce({
inputs: $relevantKeyboardEvents,
session_id: session.session_id,
player_id: session.you.id,
ts: $gameField.ts
})
if (lastTick != $gameField.ts) {
console.debug("sending peer snapshot")
networkEvents.produce({
inputs: $relevantKeyboardEvents,
session_id: session.session_id,
player_id: session.you.id,
ts: $gameField.ts
})
lastTick = $gameField.ts;
}
}
$: console.debug($networkSessionStateEvents)