mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-12 19:19:16 +00:00
working implementation, but still issues with duplicated ticks
This commit is contained in:
@@ -2,20 +2,23 @@
|
||||
import {gameField} from "../store/engine";
|
||||
import {networkTickEvents, sessionInputs} from "../store/session";
|
||||
import type {GameState, HostSessionSnapshot} from "../store/model/session";
|
||||
import Input from "./Input.svelte";
|
||||
|
||||
export let killLoopOnError = true;
|
||||
|
||||
let frame: number;
|
||||
|
||||
let lastTick;
|
||||
let inputs: Input[];
|
||||
|
||||
$: 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.warn(`!!!! Duplicated Tick ${tick.ts} (vs ${lastTick.ts}) !!!!`)
|
||||
console.error(`!!!! Duplicated Tick ${tick.ts} (vs ${lastTick.ts}) !!!!`)
|
||||
} else {
|
||||
inputs = tick.inputs;
|
||||
gameField.update(tick.objects, tick.state);
|
||||
lastTick = tick;
|
||||
}
|
||||
@@ -32,4 +35,4 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot tick={$gameField} inputs={$sessionInputs} handleError={handleError}></slot>
|
||||
<slot tick={$gameField} inputs={inputs} handleError={handleError}></slot>
|
||||
|
||||
Reference in New Issue
Block a user