Exemplo n.º 1
0
 protected override void OnSimulate()
 {
     if (_enabled)
     {
         return;
     }
     ticker++;
     if (ticker >= _checkFrameInterval)
     {
         ticker = 0;
         List <int> hashes;
         if (frameHashes.TryGetValue(LockstepManager.FrameCount - 10, out hashes))
         {
             int  mainHash = hashes[0];
             bool desynced = false;
             for (int i = 1; i < hashes.Count; i++)
             {
                 if (mainHash != hashes[i])
                 {
                     desynced = true;
                 }
             }
             if (desynced)
             {
                 Debug.LogError("DESYCNED");
             }
         }
         if (LockstepManager.FrameCount > lastFrameSent)
         {
             List <byte> newMessage = new List <byte>();
             newMessage.AddRange(BitConverter.GetBytes(LockstepManager.FrameCount));
             newMessage.AddRange(BitConverter.GetBytes(LockstepManager.GetStateHash()));
             if (ClientManager.NetworkHelper.IsServer)
             {
                 ClientManager.NetworkHelper.SendMessageToAll(MessageType.Test, newMessage.ToArray());
             }
             {
                 List <int> newHashes = new List <int>();
                 newHashes.Add(LockstepManager.GetStateHash());
                 if (frameHashes.ContainsKey(LockstepManager.FrameCount))
                 {
                     frameHashes[LockstepManager.FrameCount].AddRange(newHashes);
                 }
                 else
                 {
                     frameHashes.Add(LockstepManager.FrameCount, newHashes);
                 }
             }
             lastFrameSent = LockstepManager.FrameCount;
         }
     }
 }
        public static Replay SerializeCurrent()
        {
            Replay replay = new Replay();

            Frame[] validFrames = new Frame[LockstepManager.InfluenceFrameCount];
            Array.Copy(FrameManager.Frames, 0, validFrames, 0, LockstepManager.InfluenceFrameCount);

            bufferBytes.FastClear();
            cachedWriter.Initialize(bufferBytes);
            Serialize(validFrames, cachedWriter);
            replay.Content = cachedWriter.Canvas.ToArray();
            replay.hash    = LockstepManager.GetStateHash();
            return(replay);
        }
        protected override void OnSimulate()
        {
            long hash = LockstepManager.GetStateHash();

            if (IsPlayingBack)
            {
                if (LockstepManager.FrameCount < Hashes.PeakCount &&
                    Hashes.arrayAllocation[LockstepManager.FrameCount])
                {
                    long lastHash = Hashes [LockstepManager.FrameCount];
                    if (lastHash != hash)
                    {
                        Debug.Log("Desynced");
                    }
                }
            }
            else
            {
                Hashes.InsertAt(hash, LockstepManager.FrameCount);
            }
        }