コード例 #1
0
            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);
            }
コード例 #2
0
            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;
            }
コード例 #3
0
            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();
                }
            }
コード例 #4
0
 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++;
 }
コード例 #5
0
            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;
            }