Ejemplo n.º 1
0
 internal void ApplyRecord(AbstractLockstep lockStep)
 {
     foreach (KeyValuePair <byte, FPPlayer> current in this.players)
     {
         bool flag = lockStep.localPlayer == null;
         if (flag)
         {
             lockStep.localPlayer = current.Value;
         }
         lockStep.players.Add(current.Key, current.Value);
         lockStep.activePlayers.Add(current.Value);
         lockStep.UpdateActivePlayers();
     }
 }
        public AbstractLockstep(float deltaTime, ICommunicator communicator, IPhysicsManagerBase physicsManager, int syncWindow, int panicWindow, int rollbackWindow, FrameSyncEventCallback OnGameStarted, FrameSyncEventCallback OnGamePaused, FrameSyncEventCallback OnGameUnPaused, FrameSyncEventCallback OnGameEnded, FrameSyncPlayerDisconnectionCallback OnPlayerDisconnection, FrameSyncUpdateCallback OnStepUpdate, FrameSyncInputCallback GetLocalData, FrameSyncInputDataProvider InputDataProvider)
        {
            AbstractLockstep.instance  = this;
            this.deltaTime             = deltaTime;
            this.syncWindow            = syncWindow;
            this.panicWindow           = panicWindow;
            this.rollbackWindow        = rollbackWindow;
            this.totalWindow           = syncWindow + rollbackWindow;
            this.StepUpdate            = OnStepUpdate;
            this.OnGameStarted         = OnGameStarted;
            this.OnGamePaused          = OnGamePaused;
            this.OnGameUnPaused        = OnGameUnPaused;
            this.OnGameEnded           = OnGameEnded;
            this.OnPlayerDisconnection = OnPlayerDisconnection;
            this.GetLocalData          = GetLocalData;
            this.InputDataProvider     = InputDataProvider;
            this.ticks                = 0;
            this.players              = new Dictionary <byte, FPPlayer>(4);
            this.activePlayers        = new List <FPPlayer>(4);
            this.auxPlayersSyncedData = new List <SyncedData>(4);
            this.auxPlayersInputData  = new List <InputDataBase>(4);
            this.communicator         = communicator;
            bool flag = communicator != null;

            if (flag)
            {
                this.communicator.AddEventListener(new OnEventReceived(this.OnEventDataReceived));
            }
            this.physicsManager    = physicsManager;
            this.compoundStats     = new CompoundStats();
            this.bufferSyncedInfo  = new GenericBufferWindow <SyncedInfo>(3);
            this.checksumOk        = true;
            this.simulationState   = AbstractLockstep.SimulationState.NOT_STARTED;
            this.bodiesToDestroy   = new Dictionary <int, List <IBody> >();
            this.playersDisconnect = new Dictionary <int, List <byte> >();
            this.ReplayMode        = ReplayRecord.replayMode;
        }
Ejemplo n.º 3
0
 public CoroutineScheduler(AbstractLockstep lockStep)
 {
     this.lockStep = lockStep;
 }
Ejemplo n.º 4
0
        void Start()
        {
            instance = this;
            Application.runInBackground = true;

            ICommunicator communicator = null;

//            if (!PhotonNetwork.connected || !PhotonNetwork.inRoom) {
//                Debug.LogWarning("You are not connected to Photon. FrameSync will start in offline mode.");
//            } else {
//                communicator = new PhotonFrameSyncCommunicator(PhotonNetwork.networkingPeer);
//            }


//             if (NetMgr.Instance.srvConn.status == Connection.Status.None)
//             {
//                 Debug.LogWarning("You are not connected to Server. FrameSync will start in offline mode.");
//             }
//             else
//             {
//                 communicator = new RealSyncCommunicator();
//             }

            FrameSyncConfig activeConfig = ActiveConfig;

            lockstep = AbstractLockstep.NewInstance(
                lockedTimeStep.AsFloat(),
                communicator,
                PhysicsManager.instance,
                activeConfig.syncWindow,
                activeConfig.panicWindow,
                activeConfig.rollbackWindow,
                OnGameStarted,
                OnGamePaused,
                OnGameUnPaused,
                OnGameEnded,
                OnPlayerDisconnection,
                OnStepUpdate,
                GetLocalData,
                ProvideInputData
                );

            if (ReplayRecord.replayMode == ReplayMode.LOAD_REPLAY)
            {
                //               ReplayPicker.replayToLoad.Load();

                ReplayRecord replayRecord = ReplayRecord.replayToLoad;
                if (replayRecord == null)
                {
                    Debug.LogError("Replay Record can't be loaded");
                    gameObject.SetActive(false);
                    return;
                }
                else
                {
                    lockstep.ReplayRecord = replayRecord;
                }
            }

            if (activeConfig.showStats)
            {
                this.gameObject.AddComponent <FrameSyncStats>().Lockstep = lockstep;
            }

            scheduler = new CoroutineScheduler(lockstep);

            if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY)
            {
                if (communicator == null)
                {
                    lockstep.AddPlayer(0, "Local_Player", true);
                }
                else
                {
                    //                    List<PhotonPlayer> players = new List<PhotonPlayer>(PhotonNetwork.playerList);
                    //                    players.Sort(UnityUtils.playerComparer);
                    //
                    //                    for (int index = 0, length = players.Count; index < length; index++) {
                    //                        PhotonPlayer p = players[index];
                    //                        lockstep.AddPlayer((byte) p.ID, p.NickName, p.IsLocal);
                    //                    }

//                     for (int i = 0; i < GameData.Instance.RoomPlayers.Count; i++)
//                     {
//                         KBEngine.Avatar player = GameData.Instance.RoomPlayers[i];
//                         lockstep.AddPlayer((byte)(i + 1), player.id.ToString(), player.isPlayer());
//                     }
                }
            }

            FrameSyncBehaviour[] behavioursArray = FindObjectsOfType <FrameSyncBehaviour>();
            for (int index = 0, length = behavioursArray.Length; index < length; index++)
            {
                generalBehaviours.Add(NewManagedBehavior(behavioursArray[index]));
            }

            initBehaviors();
            initGeneralBehaviors(generalBehaviours, false);

            PhysicsManager.instance.OnRemoveBody(OnRemovedRigidBody);

            startState = StartState.BEHAVIOR_INITIALIZED;
        }