working implementation, but still issues with duplicated ticks

This commit is contained in:
Thilo Behnke
2022-07-10 18:33:53 +02:00
parent ff69bd2977
commit 58d4bdfcb1

View File

@@ -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>