mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-10 18:20:00 +00:00
bugfix/fix-duplicate-send-of-ticks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user