private void Update()
    {
        LockstepFactory.Update();
        UserInputs userInputs = LockstepUtility.GetUserInputs();

        byte[] dataBytes = MessagePackUtility.Serialize(userInputs);
        NetworkSystem.Publish(RequestCode.Input, dataBytes);
    }
Beispiel #2
0
        public void GetProviders()
        {
            var providers = new List <IMessagePackProvider>();

            MessagePackUtility.GetProviders(providers, -1);

            Assert.AreEqual(1, providers.Count);
        }
Beispiel #3
0
        public void CreateProvider()
        {
            var provider = MessagePackUtility.CreateProvider(MessagePackContext.Empty, -1) as MessagePackProviderComposite;

            Assert.NotNull(provider);
            Assert.AreEqual(1, provider.Formatters.Count);
            Assert.AreEqual(4, provider.Providers.Count);
        }
Beispiel #4
0
        public void GetFormatters()
        {
            var provider   = new MessagePackProvider();
            var formatters = new Dictionary <Type, IMessagePackFormatter>();

            MessagePackUtility.GetFormatters(provider, MessagePackContext.Empty, formatters, -1);

            Assert.AreEqual(1, formatters.Count);

            bool result = formatters.TryGetValue(typeof(bool), out IMessagePackFormatter formatter);

            Assert.True(result);
            Assert.NotNull(formatter);
        }
        public void Serialize()
        {
            IMessagePackProvider           provider  = MessagePackUtility.CreateProvider(MessagePackContext.Empty, -2);
            IMessagePackFormatter <Target> formatter = provider.Get <Target>();

            var target = new Target {
                TargetValue = new Target()
            };
            var writer = new MessagePackWriter();

            formatter.Serialize(ref writer, target);

            Assert.NotNull(writer.Buffer);
            Assert.Pass(writer.Print());
        }
Beispiel #6
0
        public static LockstepTestCaseData NewLockstepTestCaseData(float nextSecond, int userId, IInput[] inputs)
        {
            var inputData = new byte[inputs.Length][];

            for (int i = 0; i < inputData.Length; i++)
            {
                inputData[i] = MessagePackUtility.Serialize(inputs[i]);
            }
            return(new LockstepTestCaseData()
            {
                NextSecond = nextSecond,
                UserInputs = new UserInputs()
                {
                    UserId = userId,
                    InputData = inputData,
                },
            });
        }
Beispiel #7
0
 public static void AddToTimeline(LockstepInputs inputs)
 {
     if (inputs.TickId < 0)
     {
         Index = 0;
         lockstepInputs.Clear();
         OnRestart?.Invoke();
     }
     if (inputs.TickId != lockstepInputs.Count)
     {
         return;
     }
     lockstepInputs.Add(inputs);
     inputTrackDict.Add(inputs.TickId, new List <Dictionary <int, Dictionary <Type, List <IInput> > > >());
     if (inputs.UserInputs != null && inputs.UserInputs.Length > 0)
     {
         for (int i = 0; i < inputs.UserInputs.Length; i++)
         {
             var dict = new Dictionary <int, Dictionary <Type, List <IInput> > >();
             for (int j = 0; j < inputs.UserInputs[i].Length; j++)
             {
                 var userInputs = inputs.UserInputs[i][j];
                 dict.Add(userInputs.UserId, new Dictionary <Type, List <IInput> >());
                 if (userInputs.InputData != null)
                 {
                     for (int k = 0; k < userInputs.InputData.Length; k++)
                     {
                         var input = MessagePackUtility.Deserialize <IInput>(userInputs.InputData[k]);
                         var type  = input.GetType();
                         if (!dict[userInputs.UserId].ContainsKey(type))
                         {
                             dict[userInputs.UserId].Add(type, new List <IInput>());
                         }
                         dict[userInputs.UserId][type].Add(input);
                     }
                 }
             }
             inputTrackDict[inputs.TickId].Add(dict);
         }
     }
 }
Beispiel #8
0
    public static UserInputs GetUserInputs()
    {
        var bytes = new List <byte[]>();
        var e     = inputDict.GetEnumerator();

        while (e.MoveNext())
        {
            for (int i = 0; i < e.Current.Value.Count; i++)
            {
                bytes.Add(MessagePackUtility.Serialize(e.Current.Value[i]));
            }
        }
        UserInputs userInputs = new UserInputs();

        userInputs.Index     = Index;
        userInputs.TickId    = lockstepInputs.Count;
        userInputs.InputData = bytes.ToArray();
        inputDict.Clear();
        Index++;
        return(userInputs);
    }
    public override void OnEnable()
    {
        base.OnEnable();

        NetworkSystem.Receive(RequestCode.Input).Subscribe(data =>
        {
            if (data.Mode == SessionMode.Offline)
            {
                UserInputs userInputs         = MessagePackUtility.Deserialize <UserInputs>(data.Value);
                userInputs.UserId             = 0;
                LockstepInputs lockstepInputs = LockstepUtility.CreateLockstepInputs(userInputs);
                NetworkSystem.Publish(RequestCode.Lockstep, MessagePackUtility.Serialize(lockstepInputs));
            }
        }).AddTo(this.Disposer);

        NetworkSystem.Receive(RequestCode.Lockstep).Subscribe(data =>
        {
            LockstepInputs lockstepInputs = MessagePackUtility.Deserialize <LockstepInputs>(data.Value);
            LockstepUtility.AddToTimeline(lockstepInputs);
        }).AddTo(this.Disposer);
    }