Esempio n. 1
0
        public Fix64 CalcMaxLag()
        {
            int maxLagSteps = 0;

            foreach (var item in commands)
            {
                int receivingStep = item.Key;
                List <ZeroLagCommand> currStepReceivedCommands = item.Value;
                foreach (var command in currStepReceivedCommands)
                {
                    int currCommandLag = receivingStep - command.stepInd;
                    maxLagSteps = Math.Max(currCommandLag, maxLagSteps);
                }
            }
            var replay = FlatternToReplay();

            foreach (var item in timeouts)
            {
                int receivingStep = item.Key;
                List <TimeoutCommand> currStepReceivedTimeouts = item.Value;
                currStepReceivedTimeouts.ForEach(timeout =>
                {
                    ZeroLagCommand command = replay.GetTimeoutedCommand(timeout);
                    int currCommandLag     = receivingStep - command.stepInd;
                    maxLagSteps            = Math.Max(currCommandLag, maxLagSteps);
                });
            }
            return(maxLagSteps * settings.fixedDt);
        }
Esempio n. 2
0
        public Replay <T, S> FlatternToReplay()
        {
            Replay <T, S> replay = new Replay <T, S>(fixedDt, settings, stepDts);

            foreach (var item in commands)
            {
                List <ZeroLagCommand> currStepReceivedCommands = item.Value;
                foreach (var command in currStepReceivedCommands)
                {
                    replay.ReceiveCommand(command);
                }
            }
            foreach (var timeoutsReceivedOnCurrStep in timeouts.Values)
            {
                foreach (var timeout in timeoutsReceivedOnCurrStep)
                {
                    ZeroLagCommand targetCommand = replay.GetTimeoutedCommand(timeout);
                    targetCommand.OnTimedout(timeout);
                    var targetStepCommands = replay.commands[timeout.targetCommandStep];
                    targetStepCommands.RemoveOne(cmd => cmd.hash == timeout.targetCommandHash);

                    if (timeout.whatToDo == ActionOnTimeout.ExecuteLater)
                    {
                        replay.ReceiveCommand(targetCommand); // Receive command later.
                    }
                }
            }
            return(replay);
        }
Esempio n. 3
0
 private bool DebugCheckCommandAllowed(ZeroLagCommand command)
 {
     if (debugMaxInputStep == -1)
     {
         return(true);
     }
     return(command.stepInd <= debugMaxInputStep);
 }
Esempio n. 4
0
        public virtual ZeroLagCommand GetTimeoutedCommand(TimeoutCommand timeout)
        {
            List <ZeroLagCommand> currTurnCommands;

            if (!commands.TryGetValue(timeout.targetCommandStep, out currTurnCommands))
            {
                return(null);
            }
            ZeroLagCommand targetCommand = currTurnCommands.Find(cmd => cmd.hash == timeout.targetCommandHash);

            return(targetCommand);
        }
Esempio n. 5
0
        public void ReceiveCommand(ZeroLagCommand command)
        {
            List <ZeroLagCommand> currTurnCommands;
            int commandKey = GetCommandKey(command);

            //Debug.Log(commandKey.ToString());
            if (!commands.TryGetValue(commandKey, out currTurnCommands))
            {
                currTurnCommands = new List <ZeroLagCommand>();
                commands.Add(commandKey, currTurnCommands);
            }
            command.hash = command.CalculateHash();
            currTurnCommands.InsertSorted(command, cmd => cmd.hash);
        }
Esempio n. 6
0
 /// <summary>
 /// Each command that received from other PredictiveModels should go here.
 /// </summary>
 public virtual void ReceiveCommand(ZeroLagCommand command)
 {
     if (!DebugCheckCommandAllowed(command))
     {
         return;
     }
     if (stopped)
     {
         return;
     }
     playedGameReplay.ReceiveCommand(command);
     // Declare as not actualized all steps after this command's step.
     // if (command.stepInd == -1)
     //     throw exception.
     lastActualStep = Math.Min(lastActualStep, command.stepInd);
 }
Esempio n. 7
0
        private bool TryConsumeTimeout(TimeoutCommand timeout)
        {
            ZeroLagCommand targetCommand = playedGameReplay.GetTimeoutedCommand(timeout);

            if (targetCommand == null)
            {
                return(false);
            }
            int targetCommandStep = targetCommand.stepInd;

            lastActualStep = Math.Min(lastActualStep, targetCommandStep);
            targetCommand.OnTimedout(timeout);
            playedGameReplay.commands[targetCommandStep].RemoveOne(cmd => cmd.hash == timeout.targetCommandHash);
            if (timeout.whatToDo == ActionOnTimeout.ExecuteLater)
            {
                ReceiveCommand(targetCommand); // Receive command later.
            }
            return(true);
        }
Esempio n. 8
0
 /// <summary>
 /// Commands saved by step they should be executed in.
 /// </summary>
 protected virtual int GetCommandKey(ZeroLagCommand command) => command.stepInd;
Esempio n. 9
0
 /// <summary>
 /// Commands saved by step they received in.
 /// </summary>
 protected override int GetCommandKey(ZeroLagCommand command) => getCurrStep();
Esempio n. 10
0
 public override void ReceiveCommand(ZeroLagCommand command)
 {
     lock (commandsBufferLock)
         commandsThreadBuffer.Add(command);
 }