Beispiel #1
0
 protected void FixedUpdate()
 {
     LockstepManager.Simulate();
     if (ReplayManager.IsPlayingBack)
     {
         if (hashChecked == false)
         {
             if (LockstepManager.FrameCount == hashFrame)
             {
                 hashChecked = true;
                 long newHash = AgentController.GetStateHash();
                 if (newHash != prevHash)
                 {
                     Debug.Log("Desynced!");
                 }
                 else
                 {
                     Debug.Log("Synced!");
                 }
             }
         }
     }
     else
     {
         hashFrame   = LockstepManager.FrameCount - 1;
         prevHash    = stateHash;
         stateHash   = AgentController.GetStateHash();
         hashChecked = false;
     }
 }
        public static void Reset()
        {
            LockstepManager.Deactivate();
            GameObject copy = GameObject.Instantiate(MainGameManager.gameObject);

            GameObject.Destroy(MainGameManager.gameObject);
        }
Beispiel #3
0
 void OnDisable()
 {
     if (Quited)
     {
         return;
     }
     LockstepManager.Deactivate();
 }
Beispiel #4
0
 protected virtual void Update()
 {
     timeToNextSimulate -= Time.smoothDeltaTime * Time.timeScale;
     if (timeToNextSimulate <= float.Epsilon)
     {
         timeToNextSimulate = LockstepManager.BaseDeltaTime;
     }
     LockstepManager.Visualize();
 }
Beispiel #5
0
 void OnDisable()
 {
     Instance = null;
     if (Quited)
     {
         return;
     }
     LockstepManager.Deactivate();
 }
Beispiel #6
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;
         }
     }
 }
        void Awake()
        {
            NetworkHelper networkHelper = gameObject.GetComponent <NetworkHelper>();

            if (networkHelper == null)
            {
                networkHelper = gameObject.AddComponent <DefaultNetworkHelper>();
            }

            //Currently deterministic but not guaranteed by Unity
            // may be add as serialized Array as property?  [SerializeField] private BehaviourHelper[] helpers; ?
            BehaviourHelper[] helpers = this.gameObject.GetComponents <BehaviourHelper>();
            LockstepManager.Initialize(helpers, networkHelper);
        }
        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);
        }
Beispiel #9
0
        void Awake()
        {
            Instance = this;

            foreach (var save in m_Savers)
            {
                save.Save();
            }

            foreach (var save in m_Savers)
            {
                save.Apply();
            }
            LockstepManager.Initialize(this);
        }
        public static void Simulate()
        {
            TweakFramerate();
            ForeSight--;
            Frame frame = frames [LockstepManager.InfluenceFrameCount];

            if (frame.Commands.IsNotNull())
            {
                for (int i = 0; i < frame.Commands.Count; i++)
                {
                    Command com = frame.Commands [i];

                    LockstepManager.Execute(com);
                }
            }
            //frames[LockstepManager.InfluenceFrameCount] = null;
        }
        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);
            }
        }
        internal static void Deactivate()
        {
            DefaultMessageRaiser.EarlyDeactivate();

            if (Started == false)
            {
                return;
            }
            Selector.Clear();
            AgentController.Deactivate();
            MainGameManager.MainInterfacingHelper.Deactivate();
            BehaviourHelperManager.Deactivate();
            ProjectileManager.Deactivate();
            ClientManager.Deactivate();
            LockstepManager.Deactivate();

            TeamManager.Deactivate();
            ClientManager.NetworkHelper.Disconnect();
            Started = false;

            DefaultMessageRaiser.LateDeactivate();
        }
        public static void Simulate()
        {
            if (FreeSimulate)
            {
                return;
            }
            TweakFramerate();
            ForeSight--;
            Frame frame = frames [LockstepManager.InfluenceFrameCount];

            if (frame.Commands.IsNotNull())
            {
                for (int i = 0; i < frame.Commands.Count; i++)
                {
                    Command com = frame.Commands [i];
                    LockstepManager.Execute(com);
                }
            }
            frames[LockstepManager.InfluenceFrameCount] = null;
            if (LockstepManager.InfluenceFrameCount == EndFrame)
            {
                FreeSimulate = true;
            }
        }
Beispiel #14
0
 public static void LoadLevel(int levelName)
 {
     LockstepManager.Deactivate();
     SceneManager.LoadScene(levelName);
 }
 public static void LoadLevel(string levelName)
 {
     LockstepManager.Deactivate();
     Application.LoadLevel(levelName);
 }
 void Awake()
 {
     Instance = this;
 }
Beispiel #17
0
 void FixedUpdate()
 {
     LockstepManager.Simulate();
 }
Beispiel #18
0
 protected void Start()
 {
     Instance = this;
     LockstepManager.Initialize(this);
     this.Startup();
 }
Beispiel #19
0
 void OnApplicationQuit()
 {
     LockstepManager.Quit();
 }
Beispiel #20
0
 void LateUpdate()
 {
     LockstepManager.LateVisualize();
 }
Beispiel #21
0
 void OnApplicationQuit()
 {
     Quited = true;
     LockstepManager.Quit();
 }
Beispiel #22
0
 void OnApplicationQuit()
 {
     Instance = null;
     Quited   = true;
     LockstepManager.Quit();
 }
Beispiel #23
0
 protected virtual void LateUpdate()
 {
     LockstepManager.LateVisualize();
 }
Beispiel #24
0
 protected virtual void FixedUpdate()
 {
     LockstepManager.Simulate();
 }
Beispiel #25
0
 void Update()
 {
     LockstepManager.Visualize();
 }
 void Awake()
 {
     Instance = this;
 }
 void Start()
 {
     Instance = this;
     LockstepManager.Initialize(this);
     Startup();
 }