void OnRecievedState(uint timestep, MatchState state) { if (timestep < InputHistory.Oldest.Timestep) { return; } CurrentState = state; var start = timestep != 0 ? timestep - 1 : 0; foreach (var timedInput in InputHistory.StartingWith(start)) { if (timedInput.Timestep >= InputHistory.Current.Timestep) { break; } if (timedInput.Timestep < timestep || timedInput.Timestep == 0) { InputContext.Reset(timedInput.Input); } else { InputContext.Update(timedInput.Input); InputContext.Predict(); CurrentState = Simulation.Simulate(CurrentState, InputContext); } } InputHistory.DropBefore(timestep); }
void ForwardSimulate() { MatchInput input = InputHistory.Current.Input; var newestTimestep = InputHistory.Newest.Timestep; var state = CurrentState; while (input.IsValid && InputHistory.Current.Timestep < newestTimestep) { InputContext.Update(input); Simulation.Simulate(ref state, InputContext); input = InputHistory.Step(); } CurrentState = state; }
void ForwardSimulate(uint timestep, ArraySlice <MatchInput> inputs) { InputHistory.MergeWith(timestep, inputs); MatchInput input = InputHistory.Current.Input; InputContext.Reset(input); int count = 0; var newestTimestep = InputHistory.Newest.Timestep; while (input.IsValid && InputHistory.Current.Timestep < newestTimestep) { count++; InputContext.Update(input); CurrentState = Simulation.Simulate(CurrentState, InputContext); input = InputHistory.Step(); } }
public override void Update() { base.Update(); if (LocalInput == null) { LocalInput = new MatchInput[1]; LocalInput[0] = InputSource.SampleInput(); } NetworkClient.SendInput(Timestep, InputSource.ValidMask, LocalInput); if (!CurrentInput.IsValid) { return; } InputContext.Update(CurrentInput); CurrentState = Simulation.Simulate(CurrentState, InputContext); LocalInput[0] = InputSource.SampleInput(); CurrentInput.Reset(); Timestep++; }
void FastForwardServerState() { if (latestServerState == null || latestServerStateTimestamp < InputHistory.Oldest.Timestep) { return; } CurrentState = latestServerState; var start = latestServerStateTimestamp != 0 ? latestServerStateTimestamp - 1 : 0; foreach (var timedInput in InputHistory.StartingWith(start)) { if (timedInput.Timestep >= InputHistory.Current.Timestep) { break; } var input = timedInput.Input; if (latestServerInput != null) { input.MergeWith(latestServerInput.Value); } if (timedInput.Timestep < latestServerStateTimestamp || timedInput.Timestep == 0) { InputContext.Reset(input); } else { InputContext.Update(input); InputContext.Predict(); var state = CurrentState; Simulation.Simulate(ref state, InputContext); CurrentState = state; } } InputHistory.DropBefore(latestServerStateTimestamp); latestServerState = null; }