private TrueSyncManagedBehaviour NewManagedBehavior(ITrueSyncBehaviour trueSyncBehavior)
        {
            TrueSyncManagedBehaviour result = new TrueSyncManagedBehaviour(trueSyncBehavior);
            mapBehaviorToManagedBehavior[trueSyncBehavior] = result;

            return result;
        }
        private void initBehaviors()
        {
            behaviorsByPlayer = new Dictionary<byte, List<TrueSyncManagedBehaviour>>();

            var playersEnum = lockstep.Players.GetEnumerator();
            while (playersEnum.MoveNext()) {
                TSPlayer p = playersEnum.Current.Value;

                List<TrueSyncManagedBehaviour> behaviorsInstatiated = new List<TrueSyncManagedBehaviour>();

                for (int index = 0, length = playerPrefabs.Length; index < length; index++) {
                    GameObject prefab = playerPrefabs[index];

                    GameObject prefabInst = Instantiate(prefab);
                    InitializeGameObject(prefabInst, prefabInst.transform.position.ToTSVector(), prefabInst.transform.rotation.ToTSQuaternion());

                    TrueSyncBehaviour[] behaviours = prefabInst.GetComponentsInChildren<TrueSyncBehaviour>();
                    for (int index2 = 0, length2 = behaviours.Length; index2 < length2; index2++) {
                        TrueSyncBehaviour behaviour = behaviours[index2];

                        behaviour.owner = p.playerInfo;
                        behaviour.localOwner = lockstep.LocalPlayer.playerInfo;
                        behaviour.numberOfPlayers = lockstep.Players.Count;

                        TrueSyncManagedBehaviour tsmb = NewManagedBehavior(behaviour);
                        tsmb.owner = behaviour.owner;
                        tsmb.localOwner = behaviour.localOwner;

                        behaviorsInstatiated.Add(tsmb);
                    }
                }

                behaviorsByPlayer.Add(p.ID, behaviorsInstatiated);
            }
        }
        public void RegisterTrueSyncObject(TrueSyncObject i_TrueSyncObject)
        {
            if (i_TrueSyncObject == null)
            {
                return;
            }

            // Add True Sync Behaviours to QueuedBehaviours.

            for (int index = 0; index < i_TrueSyncObject.behaviourCount; ++index)
            {
                TrueSyncBehaviour trueSyncBehaviour = i_TrueSyncObject.GetTrueSyncBehaviourByIndex(index);

                if (trueSyncBehaviour == null)
                {
                    continue;
                }

                TrueSyncManagedBehaviour trueSyncManagedBehaviour = NewManagedBehavior(trueSyncBehaviour);
                m_QueuedBehaviours.Add(trueSyncManagedBehaviour);
            }

            // Initialize Object.

            InitializeObject(i_TrueSyncObject);

            // Callback

            i_TrueSyncObject.OnRegistration();
        }
Exemple #4
0
        void OnGameStarted()
        {
            TrueSyncManagedBehaviour.OnGameStarted(generalBehaviours, behaviorsByPlayer);
            instance.scheduler.UpdateAllCoroutines();

            CheckQueuedBehaviours();
        }
        // INTERNALS

        private void ProcessQueuedBehaviours()
        {
            if (m_QueuedBehaviours.Count > 0)
            {
                // Add all queued to general.

                m_GeneralBehaviours.AddRange(m_QueuedBehaviours);

                SortList(m_GeneralBehaviours);

                // Assign player queued behaviours to player and remove from general.

                AssignQueuedToPlayers();

                // Setup data on new behaviours.

                for (int index = 0; index < m_QueuedBehaviours.Count; ++index)
                {
                    TrueSyncManagedBehaviour tsmb = m_QueuedBehaviours[index];

                    if (tsmb == null)
                    {
                        continue;
                    }

                    tsmb.SetGameInfo(m_Lockstep.LocalPlayer.playerInfo, m_Lockstep.Players.Count);
                    tsmb.OnSyncedStart();
                }

                // Clear queue.

                m_QueuedBehaviours.Clear();
            }
        }
        private void RemoveFromTSMBList(List <TrueSyncManagedBehaviour> i_TsmbList, List <TrueSyncBehaviour> i_Behaviours)
        {
            m_TsManagedBehaviourCache.Clear();

            for (int index = 0; index < i_TsmbList.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = i_TsmbList[index];

                if (tsmb == null)
                {
                    continue;
                }

                TrueSyncBehaviour bh = (TrueSyncBehaviour)tsmb.trueSyncBehavior;
                if (i_Behaviours.Contains(bh))
                {
                    m_TsManagedBehaviourCache.Add(tsmb);
                }
            }

            for (int index = 0; index < m_TsManagedBehaviourCache.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_TsManagedBehaviourCache[index];

                if (tsmb == null)
                {
                    continue;
                }

                i_TsmbList.Remove(tsmb);
            }

            m_TsManagedBehaviourCache.Clear();
        }
Exemple #7
0
        private void initBehaviors()
        {
            behaviorsByPlayer = new Dictionary <byte, List <TrueSyncManagedBehaviour> >();

            foreach (TSPlayer p in lockstep.Players.Values)
            {
                List <TrueSyncManagedBehaviour> behaviorsInstatiated = new List <TrueSyncManagedBehaviour>();

                foreach (GameObject prefab in playerPrefabs)
                {
                    GameObject prefabInst = Instantiate(prefab);
                    InitializeGameObject(prefabInst, prefabInst.transform.position.ToTSVector(), prefabInst.transform.rotation.ToTSQuaternion());

                    TrueSyncBehaviour[] behaviours = prefabInst.GetComponentsInChildren <TrueSyncBehaviour>();
                    foreach (TrueSyncBehaviour behaviour in behaviours)
                    {
                        behaviour.owner           = p.playerInfo;
                        behaviour.localOwner      = lockstep.LocalPlayer.playerInfo;
                        behaviour.numberOfPlayers = lockstep.Players.Count;

                        TrueSyncManagedBehaviour tsmb = NewManagedBehavior(behaviour);
                        tsmb.owner      = behaviour.owner;
                        tsmb.localOwner = behaviour.localOwner;

                        behaviorsInstatiated.Add(tsmb);
                    }
                }

                behaviorsByPlayer.Add(p.ID, behaviorsInstatiated);
            }
        }
        // UTILS

        private TrueSyncManagedBehaviour NewManagedBehavior(ITrueSyncBehaviour i_TrueSyncBehavior)
        {
            TrueSyncManagedBehaviour result = new TrueSyncManagedBehaviour(i_TrueSyncBehavior);

            m_ManagedBehaviourMap[i_TrueSyncBehavior] = result;

            return(result);
        }
Exemple #9
0
        /// <summary>
        ///  从generalBehaviours剔除玩家的TrueSyncBehaviour,填充到behaviorsByPlayer
        /// </summary>
        /// <param name="behaviours"></param>
        /// <param name="realOwnerId">表示TrueSyncManagedBehaviour的owner是否配置了</param>
        private void initGeneralBehaviors(IEnumerable <TrueSyncManagedBehaviour> behaviours, bool realOwnerId)
        {
            List <TSPlayer> playersList = new List <TSPlayer>(lockstep.Players.Values);//拷贝一份playerList 个人觉得不用拷贝
            List <TrueSyncManagedBehaviour> itemsToRemove = new List <TrueSyncManagedBehaviour>();

            var behavioursEnum = behaviours.GetEnumerator();

            while (behavioursEnum.MoveNext())
            {
                TrueSyncManagedBehaviour tsmb = behavioursEnum.Current;

                if (!(tsmb.trueSyncBehavior is TrueSyncBehaviour))
                {
                    continue;
                }

                TrueSyncBehaviour bh = (TrueSyncBehaviour)tsmb.trueSyncBehavior;
                //TrueSyncBehaviour已经被分配好owner了
                if (realOwnerId)
                {
                    bh.ownerIndex = bh.owner.Id;
                }
                //根据ownerIndex去找匹配的玩家OwnerID
                else
                {
                    if (bh.ownerIndex >= 0 && bh.ownerIndex < playersList.Count)
                    {
                        bh.ownerIndex = playersList[bh.ownerIndex].ID;
                    }
                }

                //如果找到相应的玩家ID,配置owner
                if (behaviorsByPlayer.ContainsKey((byte)bh.ownerIndex))
                {
                    bh.owner = lockstep.Players[(byte)bh.ownerIndex].playerInfo;

                    behaviorsByPlayer[(byte)bh.ownerIndex].Add(tsmb);
                    itemsToRemove.Add(tsmb);
                }
                //没有匹配玩家,那么就是属于公用
                else
                {
                    bh.ownerIndex = -1;
                }

                bh.localOwner      = lockstep.LocalPlayer.playerInfo;
                bh.numberOfPlayers = lockstep.Players.Count;

                tsmb.owner      = bh.owner;//有可能Owner为空
                tsmb.localOwner = bh.localOwner;
            }

            //如果收集到玩家的TrueSyncManagedBehaviour,那么就从公用容器移除掉
            for (int index = 0, length = itemsToRemove.Count; index < length; index++)
            {
                generalBehaviours.Remove(itemsToRemove[index]);
            }
        }
Exemple #10
0
        private void initGeneralBehaviors(IEnumerable <TrueSyncManagedBehaviour> behaviours, bool realOwnerId)
        {
            List <TSPlayer> playersList = new List <TSPlayer>(lockstep.Players.Values);
            List <TrueSyncManagedBehaviour> itemsToRemove = new List <TrueSyncManagedBehaviour>();

            var behavioursEnum = behaviours.GetEnumerator();

            while (behavioursEnum.MoveNext())
            {
                TrueSyncManagedBehaviour tsmb = behavioursEnum.Current;

                if (!(tsmb.trueSyncBehavior is TrueSyncBehaviour))
                {
                    continue;
                }

                TrueSyncBehaviour bh = (TrueSyncBehaviour)tsmb.trueSyncBehavior;

                if (realOwnerId)
                {
                    bh.ownerIndex = bh.owner.Id;
                }
                else
                {
                    if (bh.ownerIndex >= 0 && bh.ownerIndex < playersList.Count)
                    {
                        bh.ownerIndex = playersList[bh.ownerIndex].ID;
                    }
                }

                //检查该bh的ownerIndex是否属于玩家,属于玩家那么就从generalBehaviours列表中移除,从而加入到behavioursByPlayer
                if (behaviorsByPlayer.ContainsKey((byte)bh.ownerIndex))
                {
                    bh.owner = lockstep.Players[(byte)bh.ownerIndex].playerInfo;

                    behaviorsByPlayer[(byte)bh.ownerIndex].Add(tsmb);
                    itemsToRemove.Add(tsmb);
                }
                else
                {
                    bh.ownerIndex = -1;
                }

                bh.localOwner      = lockstep.LocalPlayer.playerInfo;
                bh.numberOfPlayers = lockstep.Players.Count;

                tsmb.owner      = bh.owner;
                tsmb.localOwner = bh.localOwner;
            }

            for (int index = 0, length = itemsToRemove.Count; index < length; index++)
            {
                generalBehaviours.Remove(itemsToRemove[index]);
            }
        }
        private void AssignQueuedToPlayers()
        {
            m_TsManagedBehaviourCache.Clear();

            for (int index = 0; index < m_QueuedBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_QueuedBehaviours[index];

                if (tsmb == null)
                {
                    continue;
                }

                TrueSyncBehaviour bh = (TrueSyncBehaviour)tsmb.trueSyncBehavior;

                List <TrueSyncManagedBehaviour> tsmbList = null;
                if (m_BehavioursPerPlayer.TryGetValue((byte)bh.ownerIndex, out tsmbList))
                {
                    bh.owner = m_Lockstep.Players[(byte)bh.ownerIndex].playerInfo;

                    m_TsManagedBehaviourCache.Add(tsmb);
                    tsmbList.Add(tsmb);

                    SortList(tsmbList);
                }
                else
                {
                    bh.owner      = m_NullPlayerInfo;
                    bh.ownerIndex = -1;
                }

                bh.localOwner      = m_Lockstep.LocalPlayer.playerInfo;
                bh.numberOfPlayers = m_Lockstep.Players.Count;

                tsmb.owner      = bh.owner;
                tsmb.localOwner = bh.localOwner;
            }

            for (int index = 0; index < m_TsManagedBehaviourCache.Count; ++index)
            {
                TrueSyncManagedBehaviour item = m_TsManagedBehaviourCache[index];

                if (item == null)
                {
                    continue;
                }

                m_GeneralBehaviours.Remove(item);
            }

            m_TsManagedBehaviourCache.Clear();
        }
        private void CheckQueuedBehaviours()
        {
            if (queuedBehaviours.Count > 0) {
                generalBehaviours.AddRange(queuedBehaviours);
                initGeneralBehaviors(queuedBehaviours, true);

                for (int index = 0, length = queuedBehaviours.Count; index < length; index++) {
                    TrueSyncManagedBehaviour tsmb = queuedBehaviours[index];

                    tsmb.SetGameInfo(lockstep.LocalPlayer.playerInfo, lockstep.Players.Count);
                    tsmb.OnSyncedStart();
                }

                queuedBehaviours.Clear();
            }
        }
        private void RemoveFromTSMBList(List<TrueSyncManagedBehaviour> tsmbList, List<TrueSyncBehaviour> behaviours)
        {
            List<TrueSyncManagedBehaviour> toRemove = new List<TrueSyncManagedBehaviour>();
            for (int index = 0, length = tsmbList.Count; index < length; index++) {
                TrueSyncManagedBehaviour tsmb = tsmbList[index];

                if ((tsmb.trueSyncBehavior is TrueSyncBehaviour) && behaviours.Contains((TrueSyncBehaviour)tsmb.trueSyncBehavior)) {
                    toRemove.Add(tsmb);
                }
            }

            for (int index = 0, length = toRemove.Count; index < length; index++) {
                TrueSyncManagedBehaviour tsmb = toRemove[index];
                tsmbList.Remove(tsmb);
            }
        }
Exemple #14
0
        // 将注册行为占存列表列queuedBehaviours的行为调initGeneralBehaviors分配拥有者。调OnSyncedStart方法
        private void CheckQueuedBehaviours()
        {
            if (queuedBehaviours.Count > 0)
            {
                generalBehaviours.AddRange(queuedBehaviours);
                initGeneralBehaviors(queuedBehaviours, true);

                for (int index = 0, length = queuedBehaviours.Count; index < length; index++)
                {
                    TrueSyncManagedBehaviour tsmb = queuedBehaviours[index];
                    tsmb.OnSyncedStart();
                }

                queuedBehaviours.Clear();
            }
        }
        void GetLocalData(InputDataBase playerInputData)
        {
            TrueSyncInput.CurrentInputData = (InputData) playerInputData;

            if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID)) {
                List<TrueSyncManagedBehaviour> managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
                for (int index = 0, length = managedBehavioursByPlayer.Count; index < length; index++) {
                    TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index];

                    if (bh != null && !bh.disabled) {
                        bh.OnSyncedInput();
                    }
                }
            }

            TrueSyncInput.CurrentInputData = null;
        }
Exemple #16
0
        // 对行为列表分配拥有者, 在Start(), CheckQueuedBehaviours()里调用
        private void initGeneralBehaviors(IEnumerable <TrueSyncManagedBehaviour> behaviours, bool realOwnerId)
        {
            List <TSPlayer> playersList = new List <TSPlayer>(lockstep.Players.Values);
            List <TrueSyncManagedBehaviour> itemsToRemove = new List <TrueSyncManagedBehaviour>();

            var behavioursEnum = behaviours.GetEnumerator();

            while (behavioursEnum.MoveNext())
            {
                TrueSyncManagedBehaviour tsmb = behavioursEnum.Current;

                if (!(tsmb.trueSyncBehavior is TrueSyncBehaviour))
                {
                    continue;
                }

                TrueSyncBehaviour bh = (TrueSyncBehaviour)tsmb.trueSyncBehavior;

                /***
                 * if (realOwnerId) {
                 * bh.ownerIndex = bh.owner.Id;
                 * } else {
                 * if (bh.ownerIndex >= 0 && bh.ownerIndex < playersList.Count) {
                 * bh.ownerIndex = playersList[bh.ownerIndex].ID;
                 * }
                 * }
                 *
                 * if (behaviorsByPlayer.ContainsKey((byte)bh.ownerIndex)) {
                 * bh.owner = lockstep.Players[(byte)bh.ownerIndex].playerInfo;
                 *
                 * behaviorsByPlayer[(byte)bh.ownerIndex].Add(tsmb);
                 * itemsToRemove.Add(tsmb);
                 * } else {
                 * bh.ownerIndex = -1;
                 * }
                 ***/
                tsmb.owner = bh.owner;
            }

            for (int index = 0, length = itemsToRemove.Count; index < length; index++)
            {
                generalBehaviours.Remove(itemsToRemove[index]);
            }
        }
Exemple #17
0
        /// <summary>
        ///@brief Removes objets related to a provided player.
        ///DV 移除与所提供的player相关的对象 :移除玩家
        ///@param playerId Target player's id.
        /// </summary>
        public static void RemovePlayer(int playerId)
        {
            if (instance != null && instance.lockstep != null)
            {
                List <TrueSyncManagedBehaviour> behaviorsList = instance.behaviorsByPlayer[(byte)playerId];

                for (int index = 0, length = behaviorsList.Count; index < length; index++)
                {
                    TrueSyncManagedBehaviour tsmb = behaviorsList[index];
                    tsmb.disabled = true;//第一步将该玩家的 行为全部禁止帧更新

                    //第二步将这些行为的GameObject上拥有TSCollider、TSCollider2D的物理全部掉DestroyTSRigidBody
                    TSCollider[] tsColliders = ((TrueSyncBehaviour)tsmb.trueSyncBehavior).gameObject.GetComponentsInChildren <TSCollider>();
                    if (tsColliders != null)
                    {
                        for (int index2 = 0, length2 = tsColliders.Length; index2 < length2; index2++)
                        {
                            TSCollider tsCollider = tsColliders[index2];

                            if (!tsCollider.Body.TSDisabled)
                            {
                                DestroyTSRigidBody(tsCollider.gameObject, tsCollider.Body);
                            }
                        }
                    }

                    TSCollider2D[] tsCollider2Ds = ((TrueSyncBehaviour)tsmb.trueSyncBehavior).gameObject.GetComponentsInChildren <TSCollider2D>();
                    if (tsCollider2Ds != null)
                    {
                        for (int index2 = 0, length2 = tsCollider2Ds.Length; index2 < length2; index2++)
                        {
                            TSCollider2D tsCollider2D = tsCollider2Ds[index2];

                            if (!tsCollider2D.Body.TSDisabled)
                            {
                                DestroyTSRigidBody(tsCollider2D.gameObject, tsCollider2D.Body);
                            }
                        }
                    }
                }
            }
        }
        private void GetLocalData(InputData i_PlayerInputData)
        {
            /////////////////////////////////////////////////////////////////////////////
            // This is to skip the second unnecessary call when synced windows is 0.
            // Bug already reported to Jeff.
            // This condition should never trigger when sync window is greater than 0.
            /////////////////////////////////////////////////////////////////////////////

            if (m_LastGetLocalDataTick == ticks)
            {
                return;
            }

            // Cahce current tick.

            m_LastGetLocalDataTick = ticks;

            /////////////////////////////////////////////////////////////////////////////

            TrueSyncInput.CurrentInputData = i_PlayerInputData;

            // Synced input on player behaviours.

            List <TrueSyncManagedBehaviour> tsmbList = null;

            if (m_BehavioursPerPlayer.TryGetValue(i_PlayerInputData.ownerID, out tsmbList))
            {
                for (int index = 0; index < tsmbList.Count; ++index)
                {
                    TrueSyncManagedBehaviour tsmb = tsmbList[index];

                    if (tsmb == null || tsmb.disabled)
                    {
                        continue;
                    }

                    tsmb.OnSyncedInput();
                }
            }

            TrueSyncInput.CurrentInputData = null;
        }
        private void OnPlayerDisconnection(byte i_PlayerId)
        {
            if (m_GeneralBehaviours != null)
            {
                for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
                {
                    TrueSyncManagedBehaviour bh = m_GeneralBehaviours[index];
                    bh.OnPlayerDisconnection((int)i_PlayerId);
                }
            }

            foreach (List <TrueSyncManagedBehaviour> behaviors in m_BehavioursPerPlayer.Values)
            {
                for (int index = 0; index < behaviors.Count; ++index)
                {
                    TrueSyncManagedBehaviour bh = behaviors[index];
                    bh.OnPlayerDisconnection((int)i_PlayerId);
                }
            }
        }
        private void OnGameEnded()
        {
            if (m_GeneralBehaviours != null)
            {
                for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
                {
                    TrueSyncManagedBehaviour bh = m_GeneralBehaviours[index];
                    bh.OnGameEnded();
                }
            }

            foreach (List <TrueSyncManagedBehaviour> behaviors in m_BehavioursPerPlayer.Values)
            {
                for (int index = 0; index < behaviors.Count; ++index)
                {
                    TrueSyncManagedBehaviour bh = behaviors[index];
                    bh.OnGameEnded();
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// 实例化该脚本上挂载的prefab,有多少个玩家就实例化多少个prefab,同时查找TrueSyncBehaviour脚本。并配置key:OwnerID,value:TrusSyncMangedBehaviour到behaviorsByPlayer容器上方便管理
        /// 初始化玩家的同步组件
        /// </summary>
        private void initBehaviors()
        {
            behaviorsByPlayer = new Dictionary <byte, List <TrueSyncManagedBehaviour> >();

            var playersEnum = lockstep.Players.GetEnumerator();

            while (playersEnum.MoveNext())
            {
                TSPlayer p = playersEnum.Current.Value;

                List <TrueSyncManagedBehaviour> behaviorsInstatiated = new List <TrueSyncManagedBehaviour>();

                for (int index = 0, length = playerPrefabs.Length; index < length; index++)
                {
                    GameObject prefab = playerPrefabs[index];

                    GameObject prefabInst = Instantiate(prefab);
                    //初始化ICollider和TSTransform 添加到TS物理引擎中管理
                    InitializeGameObject(prefabInst, prefabInst.transform.position.ToTSVector(), prefabInst.transform.rotation.ToTSQuaternion());
                    //查找该prafab是否有TrueSyncBehaviour脚本,如果有需要配置相应的TrueSyncManagedBehaviour
                    TrueSyncBehaviour[] behaviours = prefabInst.GetComponentsInChildren <TrueSyncBehaviour>();
                    for (int index2 = 0, length2 = behaviours.Length; index2 < length2; index2++)
                    {
                        TrueSyncBehaviour behaviour = behaviours[index2];

                        behaviour.owner           = p.playerInfo;                      //配置玩家信息TSPlayerInfo
                        behaviour.localOwner      = lockstep.LocalPlayer.playerInfo;   //配置当前房间本地玩家信息TSPlayerInfo
                        behaviour.numberOfPlayers = lockstep.Players.Count;            //配置玩家人数

                        TrueSyncManagedBehaviour tsmb = NewManagedBehavior(behaviour); //一个TrueSyncBehaviour要生成一个TrueSyncManagedBehaviour来接收lockstep的声明周期回调(OnSyncedInput OnPreSyncedUpdate)
                        tsmb.owner      = behaviour.owner;                             //配置玩家信息TSPlayerInfo
                        tsmb.localOwner = behaviour.localOwner;                        //配置当前房间本地玩家信息TSPlayerInfo

                        behaviorsInstatiated.Add(tsmb);                                //一个玩家对应所有需要同步的组件塞到容器里
                    }
                }

                behaviorsByPlayer.Add(p.ID, behaviorsInstatiated);//一个玩家下面可能有多个组件需要同步
            }
        }
Exemple #22
0
 void OnPlayerDisconnection(byte playerId)
 {
     TrueSyncManagedBehaviour.OnPlayerDisconnection(generalBehaviours, behaviorsByPlayer, playerId);
 }
Exemple #23
0
        void OnStepUpdate(List <InputDataBase> allInputData)
        {
            time += lockedTimeStep;

            if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
            {
                CheckGameObjectsSafeMap();
            }

            TrueSyncInput.SetAllInputs(null);

            for (int index = 0, length = generalBehaviours.Count; index < length; index++)
            {
                TrueSyncManagedBehaviour bh = generalBehaviours[index];

                if (bh != null && !bh.disabled)
                {
                    bh.OnPreSyncedUpdate();
                    instance.scheduler.UpdateAllCoroutines();
                }
            }

            for (int index = 0, length = allInputData.Count; index < length; index++)
            {
                InputDataBase playerInputData = allInputData[index];

                if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID))
                {
                    List <TrueSyncManagedBehaviour> managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
                    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++)
                    {
                        TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

                        if (bh != null && !bh.disabled)
                        {
                            bh.OnPreSyncedUpdate();
                            instance.scheduler.UpdateAllCoroutines();
                        }
                    }
                }
            }

            TrueSyncInput.SetAllInputs(allInputData);

            TrueSyncInput.CurrentSimulationData = null;
            for (int index = 0, length = generalBehaviours.Count; index < length; index++)
            {
                TrueSyncManagedBehaviour bh = generalBehaviours[index];

                if (bh != null && !bh.disabled)
                {
                    bh.OnSyncedUpdate();
                    instance.scheduler.UpdateAllCoroutines();
                }
            }

            for (int index = 0, length = allInputData.Count; index < length; index++)
            {
                InputDataBase playerInputData = allInputData[index];

                if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID))
                {
                    TrueSyncInput.CurrentSimulationData = (InputData)playerInputData;

                    List <TrueSyncManagedBehaviour> managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
                    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++)
                    {
                        TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

                        if (bh != null && !bh.disabled)
                        {
                            bh.OnSyncedUpdate();
                            instance.scheduler.UpdateAllCoroutines();
                        }
                    }
                }

                TrueSyncInput.CurrentSimulationData = null;
            }

            CheckQueuedBehaviours();
        }
Exemple #24
0
 void OnGameUnPaused()
 {
     TrueSyncManagedBehaviour.OnGameUnPaused(generalBehaviours, behaviorsByPlayer);
     instance.scheduler.UpdateAllCoroutines();
 }
Exemple #25
0
        /// <summary>
        ///DV 帧更新
        ///是在lockstep创建的时候传这个方法给他
        /// </summary>
        void OnStepUpdate(List <InputDataBase> allInputData)
        {
            // 添加当前时间
            time += lockedTimeStep;

            if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
            {
                // 非录像模式, 检测GameObject CheckGameObjectsSafeMap();
                CheckGameObjectsSafeMap();
            }

            TrueSyncInput.SetAllInputs(null);

            // 遍历generalBehaviours普通行为列表,调行为的OnPreSyncedUpdate()。还会调协程更新instance.scheduler.UpdateAllCoroutines();
            for (int index = 0, length = generalBehaviours.Count; index < length; index++)
            {
                TrueSyncManagedBehaviour bh = generalBehaviours[index];

                if (bh != null && !bh.disabled)
                {
                    bh.OnPreSyncedUpdate();
                    instance.scheduler.UpdateAllCoroutines();
                }
            }

            // 遍历allInputData,和对应玩家的行为列表behaviorsByPlayer。 调行为的OnPreSyncedUpdate()。还会调协程更新instance.scheduler.UpdateAllCoroutines();
            for (int index = 0, length = allInputData.Count; index < length; index++)
            {
                InputDataBase playerInputData = allInputData[index];

                if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID))
                {
                    List <TrueSyncManagedBehaviour> managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
                    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++)
                    {
                        TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

                        if (bh != null && !bh.disabled)
                        {
                            bh.OnPreSyncedUpdate();
                            instance.scheduler.UpdateAllCoroutines();
                        }
                    }
                }
            }

            TrueSyncInput.SetAllInputs(allInputData);

            TrueSyncInput.CurrentSimulationData = null;
            // 遍历generalBehaviours普通行为列表,调行为的OnSyncedUpdate()。还会调协程更新instance.scheduler.UpdateAllCoroutines();
            for (int index = 0, length = generalBehaviours.Count; index < length; index++)
            {
                TrueSyncManagedBehaviour bh = generalBehaviours[index];

                if (bh != null && !bh.disabled)
                {
                    bh.OnSyncedUpdate();
                    instance.scheduler.UpdateAllCoroutines();
                }
            }

            // 遍历allInputData,和对应玩家的行为列表behaviorsByPlayer。 调行为的OnSyncedUpdate()。还会调协程更新instance.scheduler.UpdateAllCoroutines();
            for (int index = 0, length = allInputData.Count; index < length; index++)
            {
                InputDataBase playerInputData = allInputData[index];

                if (behaviorsByPlayer.ContainsKey(playerInputData.ownerID))
                {
                    TrueSyncInput.CurrentSimulationData = (InputData)playerInputData;

                    List <TrueSyncManagedBehaviour> managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
                    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++)
                    {
                        TrueSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

                        if (bh != null && !bh.disabled)
                        {
                            bh.OnSyncedUpdate();
                            instance.scheduler.UpdateAllCoroutines();
                        }
                    }
                }

                TrueSyncInput.CurrentSimulationData = null;
            }

            // 检测占存行为列表CheckQueuedBehaviours()。给他们分配拥有者和调同步开始方法
            CheckQueuedBehaviours();
        }
        private void OnStepUpdate(List <InputData> i_AllInputData)
        {
            // Sync time.

            if (m_TimeScaler != null)
            {
                m_TimeScaler.Sync();
            }

            // PRE SYNC UPDATE

            // Clear input.

            TrueSyncInput.SetAllInputs(null);

            // Synced pre update on general behaviours.

            for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index];

                if (tsmb == null || tsmb.disabled)
                {
                    continue;
                }

                tsmb.OnPreSyncedUpdate();
            }

            // Synced pre update on player behaviours.

            if (i_AllInputData != null)
            {
                for (int index = 0; index < i_AllInputData.Count; ++index)
                {
                    InputData inputData = i_AllInputData[index];

                    if (inputData == null)
                    {
                        continue;
                    }

                    List <TrueSyncManagedBehaviour> tsmbList = null;
                    if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList))
                    {
                        for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex)
                        {
                            TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex];

                            if (tsmb == null || tsmb.disabled)
                            {
                                continue;
                            }

                            tsmb.OnPreSyncedUpdate();
                        }
                    }
                }
            }

            // UPDATE

            // Set input.

            TrueSyncInput.SetAllInputs(i_AllInputData);

            TrueSyncInput.CurrentSimulationData = null;

            // Synced update on general behaviours.

            for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index];

                if (tsmb == null || tsmb.disabled)
                {
                    continue;
                }

                tsmb.OnSyncedUpdate();
            }

            // Synced update on player behaviours.

            if (i_AllInputData != null)
            {
                for (int index = 0; index < i_AllInputData.Count; ++index)
                {
                    InputData inputData = i_AllInputData[index];

                    if (inputData == null)
                    {
                        continue;
                    }

                    List <TrueSyncManagedBehaviour> tsmbList = null;
                    if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList))
                    {
                        TrueSyncInput.CurrentSimulationData = inputData;

                        for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex)
                        {
                            TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex];

                            if (tsmb == null || tsmb.disabled)
                            {
                                continue;
                            }

                            tsmb.OnSyncedUpdate();
                        }
                    }
                }

                TrueSyncInput.CurrentSimulationData = null;
            }

            // LATE UPDATE

            // Clear input.

            TrueSyncInput.SetAllInputs(null);

            // Synced late update on general behaviours.

            for (int index = 0; index < m_GeneralBehaviours.Count; ++index)
            {
                TrueSyncManagedBehaviour tsmb = m_GeneralBehaviours[index];

                if (tsmb == null || tsmb.disabled)
                {
                    continue;
                }

                ITrueSyncBehaviour iTsb = tsmb.trueSyncBehavior;
                if (iTsb != null)
                {
                    if (iTsb is TrueSyncBehaviour)
                    {
                        TrueSyncBehaviour tsb = (TrueSyncBehaviour)iTsb;
                        tsb.OnLateSyncedUpdate();
                    }
                }
            }

            // Synced late update on player behaviours.

            if (i_AllInputData != null)
            {
                for (int index = 0; index < i_AllInputData.Count; ++index)
                {
                    InputData inputData = i_AllInputData[index];

                    if (inputData == null)
                    {
                        continue;
                    }

                    List <TrueSyncManagedBehaviour> tsmbList = null;
                    if (m_BehavioursPerPlayer.TryGetValue(inputData.ownerID, out tsmbList))
                    {
                        for (int tsmbIndex = 0; tsmbIndex < tsmbList.Count; ++tsmbIndex)
                        {
                            TrueSyncManagedBehaviour tsmb = tsmbList[tsmbIndex];

                            if (tsmb == null || tsmb.disabled)
                            {
                                continue;
                            }

                            ITrueSyncBehaviour iTsb = tsmb.trueSyncBehavior;
                            if (iTsb != null)
                            {
                                if (iTsb is TrueSyncBehaviour)
                                {
                                    TrueSyncBehaviour tsb = (TrueSyncBehaviour)iTsb;
                                    tsb.OnLateSyncedUpdate();
                                }
                            }
                        }
                    }
                }
            }

            // Process queued behaviours.

            ProcessQueuedBehaviours();
        }