예제 #1
0
        void OnGameStarted()
        {
            FrameSyncManagedBehaviour.OnGameStarted(generalBehaviours, behaviorsByPlayer);
            instance.scheduler.UpdateAllCoroutines();

            CheckQueuedBehaviours();
        }
예제 #2
0
        private FrameSyncManagedBehaviour NewManagedBehavior(IFrameSyncBehaviour FrameSyncBehavior)
        {
            FrameSyncManagedBehaviour result = new FrameSyncManagedBehaviour(FrameSyncBehavior);

            mapBehaviorToManagedBehavior[FrameSyncBehavior] = result;

            return(result);
        }
예제 #3
0
        private void initGeneralBehaviors(IEnumerable <FrameSyncManagedBehaviour> behaviours, bool realOwnerId)
        {
            List <FPPlayer> playersList = new List <FPPlayer>(lockstep.Players.Values);
            List <FrameSyncManagedBehaviour> itemsToRemove = new List <FrameSyncManagedBehaviour>();

            var behavioursEnum = behaviours.GetEnumerator();

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

                if (!(tsmb.FrameSyncBehavior is FrameSyncBehaviour))
                {
                    continue;
                }

                FrameSyncBehaviour bh = (FrameSyncBehaviour)tsmb.FrameSyncBehavior;

                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;
                }

                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]);
            }
        }
예제 #4
0
        private void initBehaviors()
        {
            behaviorsByPlayer = new Dictionary <byte, List <FrameSyncManagedBehaviour> >();
            List <FPVector> playerPosition = new List <FPVector>();

            playerPosition.Add(new FPVector(-5.0f, 0, 0));
            playerPosition.Add(new FPVector(-5.0f, 0, 5.0f));
            int playerIndex = 0;

            var playersEnum = lockstep.Players.GetEnumerator();

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

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

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

                    GameObject prefabInst = Instantiate(prefab);
                    prefabInst.transform.position = playerPosition[playerIndex].ToVector();
                    InitializeGameObject(prefabInst, prefabInst.transform.position.ToFPVector(), prefabInst.transform.rotation.ToFPQuaternion());

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

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

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

                        behaviorsInstatiated.Add(tsmb);
                    }
                }

                behaviorsByPlayer.Add(p.ID, behaviorsInstatiated);

                playerIndex++;
            }
        }
예제 #5
0
        private void CheckQueuedBehaviours()
        {
            if (queuedBehaviours.Count > 0)
            {
                generalBehaviours.AddRange(queuedBehaviours);
                initGeneralBehaviors(queuedBehaviours, true);

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

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

                queuedBehaviours.Clear();
            }
        }
예제 #6
0
        private void RemoveFromTSMBList(List <FrameSyncManagedBehaviour> tsmbList, List <FrameSyncBehaviour> behaviours)
        {
            List <FrameSyncManagedBehaviour> toRemove = new List <FrameSyncManagedBehaviour>();

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

                if ((tsmb.FrameSyncBehavior is FrameSyncBehaviour) && behaviours.Contains((FrameSyncBehaviour)tsmb.FrameSyncBehavior))
                {
                    toRemove.Add(tsmb);
                }
            }

            for (int index = 0, length = toRemove.Count; index < length; index++)
            {
                FrameSyncManagedBehaviour tsmb = toRemove[index];
                tsmbList.Remove(tsmb);
            }
        }
예제 #7
0
        void GetLocalData(InputDataBase playerInputData)
        {
            FrameSyncInput.CurrentInputData = (InputData)playerInputData;

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

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

            FrameSyncInput.CurrentInputData = null;
        }
예제 #8
0
        /**
         * @brief Removes objets related to a provided player.
         *
         * @param playerId Target player's id.
         **/
        public static void RemovePlayer(int playerId)
        {
            if (instance != null && instance.lockstep != null)
            {
                List <FrameSyncManagedBehaviour> behaviorsList = instance.behaviorsByPlayer[(byte)playerId];

                for (int index = 0, length = behaviorsList.Count; index < length; index++)
                {
                    FrameSyncManagedBehaviour tsmb = behaviorsList[index];
                    tsmb.disabled = true;

                    FPCollider[] tsColliders = ((FrameSyncBehaviour)tsmb.FrameSyncBehavior).gameObject.GetComponentsInChildren <FPCollider>();
                    if (tsColliders != null)
                    {
                        for (int index2 = 0, length2 = tsColliders.Length; index2 < length2; index2++)
                        {
                            FPCollider tsCollider = tsColliders[index2];

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

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

                            if (!tsCollider2D.Body.TSDisabled)
                            {
                                DestroyFPRigidBody(tsCollider2D.gameObject, tsCollider2D.Body);
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
        void OnStepUpdate(List <InputDataBase> allInputData)
        {
            time += lockedTimeStep;

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

            FrameSyncInput.SetAllInputs(null);

            for (int index = 0, length = generalBehaviours.Count; index < length; index++)
            {
                FrameSyncManagedBehaviour 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 <FrameSyncManagedBehaviour> managedBehavioursByPlayer = behaviorsByPlayer[playerInputData.ownerID];
                    for (int index2 = 0, length2 = managedBehavioursByPlayer.Count; index2 < length2; index2++)
                    {
                        FrameSyncManagedBehaviour bh = managedBehavioursByPlayer[index2];

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

            FrameSyncInput.SetAllInputs(allInputData);

            FrameSyncInput.CurrentSimulationData = null;
            for (int index = 0, length = generalBehaviours.Count; index < length; index++)
            {
                FrameSyncManagedBehaviour 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))
                {
                    FrameSyncInput.CurrentSimulationData = (InputData)playerInputData;

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

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

                FrameSyncInput.CurrentSimulationData = null;
            }

            CheckQueuedBehaviours();
        }
예제 #10
0
 void OnPlayerDisconnection(byte playerId)
 {
     FrameSyncManagedBehaviour.OnPlayerDisconnection(generalBehaviours, behaviorsByPlayer, playerId);
 }