Ejemplo n.º 1
0
        private SyncedData UpdateData()
        {
            bool       flag = this.replayMode == ReplayMode.LOAD_REPLAY;
            SyncedData result;

            if (flag)             // 加载回放模式
            {
                result = null;
            }
            else // 非加载回放模式
            {
                SyncedData @new = SyncedData.pool.GetNew();                 // 从池中获取
                @new.Init(this.localPlayer.ID, this.ticks);
                this.GetLocalData(@new.inputData); // 把玩家操作数据放入SyncedData实例中
                this.localPlayer.AddData(@new);    // 把SyncedData实例放入本地玩家的操作数据字典中

                bool flag2 = this.communicator != null;
                if (flag2)                                                                                                                   // 有通信器
                {
                    this.localPlayer.GetSendData(this.ticks, this._syncedDataCacheUpdateData);                                               // 把最新的操作数据放入_syncedDataCacheUpdateData中
                    this.communicator.OpRaiseEvent(199, SyncedData.Encode(this._syncedDataCacheUpdateData), true, this.auxActivePlayersIds); // 发送操作数据
                }
                result = @new;
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 收集本地玩家的输入,并通过服务器发送给其他玩家 OnSyncInput在这调用
        /// </summary>
        /// <returns></returns>
        private SyncedData UpdateData()
        {
            SyncedData result;

            if (this.replayMode == ReplayMode.LOAD_REPLAY)
            {
                result = null;
            }
            else
            {
                SyncedData syncedData = SyncedData.pool.GetNew();
                syncedData.Init(this.localPlayer.ID, this.ticks); //本地玩家ID来构造一个空数据包,等待输入数据填充
                this.GetLocalData(syncedData.inputData);          //TrueSyncManager.GetLocalData, 调用OnSyncedInput();获取本地玩家输入
                this.localPlayer.AddData(syncedData);             //本地数据直接塞给本地玩家(controls key:ticks value:syncedData 存储玩家每个tick的数据),下面还需要把本地数据发送给远端
                if (this.communicator != null)
                {
                    //因为_syncedDataCacheUpdateData只有一个,所以只获取了一个SyncedData
                    this.localPlayer.GetSendData(this.ticks, this._syncedDataCacheUpdateData);//从TSplayer的controls里取数据
                    //把本地玩家的输入数据发给远端玩家
                    this.communicator.OpRaiseEvent(SEND_CODE, SyncedData.Encode(this._syncedDataCacheUpdateData), true, this.auxActivePlayersIds);
                }
                result = syncedData;
            }
            return(result);
        }
        // 如果不是录像模式;获取本地玩家的输入操作,添加到本地玩家的当前帧同步数据;发送本地玩家操作给其他玩家
        private SyncedData UpdateData()
        {
            bool       flag = this.replayMode == ReplayMode.LOAD_REPLAY;
            SyncedData result;

            if (flag)
            {
                result = null;
            }
            else
            {
                // 获取本地玩家的输入操作,添加到本地玩家的当前帧同步数据
                SyncedData @new = SyncedData.pool.GetNew();
                @new.Init(this.localPlayer.ID, this.ticks);
                this.GetLocalData(@new.inputData);
                this.localPlayer.AddData(@new);
                bool flag2 = this.communicator != null;
                if (flag2)
                {
                    // 发送本地玩家操作给其他玩家
                    this.localPlayer.GetSendData(this.ticks, this._syncedDataCacheUpdateData);
                    // 199
                    this.communicator.OpRaiseEvent(SEND_CODE, SyncedData.Encode(this._syncedDataCacheUpdateData), true, this.auxActivePlayersIds);
                }
                result = @new;
            }
            return(result);
        }
Ejemplo n.º 4
0
        private SyncedData UpdateData()
        {
            bool       flag = this.replayMode == ReplayMode.LOAD_REPLAY;
            SyncedData result;

            if (flag)
            {
                result = null;
            }
            else
            {
                SyncedData syncedData = new SyncedData(this.localPlayer.ID, this.ticks);
                this.GetLocalData(syncedData.inputData);
                this.localPlayer.AddData(syncedData);
                bool flag2 = this.communicator != null;
                if (flag2)
                {
                    SyncedData[] sendData = this.localPlayer.GetSendData(this.ticks, 1);
                    bool         flag3    = sendData.Length != 0;
                    if (flag3)
                    {
                        this.communicator.OpRaiseEvent(199, SyncedData.Encode(sendData), true, this.GetActivePlayers());
                    }
                }
                result = syncedData;
            }
            return(result);
        }
Ejemplo n.º 5
0
        private void DropLagPlayers()
        {
            List <TSPlayer> list    = new List <TSPlayer>();
            int             refTick = this.GetRefTick(this.GetSyncedDataTick());
            bool            flag    = refTick >= 0;

            if (flag)
            {
                foreach (TSPlayer current in this.players.Values)
                {
                    bool flag2 = !current.IsDataReady(refTick);
                    if (flag2)
                    {
                        current.dropCount++;
                        this.CheckDrop(current);
                        list.Add(current);
                    }
                }
            }
            foreach (TSPlayer current2 in list)
            {
                SyncedData[] sendDataForDrop = current2.GetSendDataForDrop(this.localPlayer.ID, 1);
                bool         flag3           = sendDataForDrop.Length != 0;
                if (flag3)
                {
                    this.communicator.OpRaiseEvent(199, SyncedData.Encode(sendDataForDrop), true, null);
                }
            }
        }
        private void DropLagPlayers()
        {
            List <TSPlayer> list    = new List <TSPlayer>();
            int             refTick = this.GetRefTick(this.GetSyncedDataTick());
            bool            flag    = refTick >= 0;

            if (flag)
            {
                int i     = 0;
                int count = this.activePlayers.Count;
                while (i < count)
                {
                    TSPlayer tSPlayer = this.activePlayers[i];
                    bool     flag2    = !tSPlayer.IsDataReady(refTick);
                    if (flag2)
                    {
                        tSPlayer.dropCount++;
                        list.Add(tSPlayer);
                    }
                    i++;
                }
            }
            int j      = 0;
            int count2 = list.Count;

            while (j < count2)
            {
                TSPlayer p = list[j];
                this.CheckDrop(p);
                bool sendDataForDrop = list[j].GetSendDataForDrop(this.localPlayer.ID, this._syncedDataCacheDrop);
                if (sendDataForDrop)
                {
                    // 199
                    this.communicator.OpRaiseEvent(SEND_CODE, SyncedData.Encode(this._syncedDataCacheDrop), true, null);
                    SyncedData.pool.GiveBack(this._syncedDataCacheDrop[0]);
                }
                j++;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Lag:落后, 延迟
        /// </summary>
        private void DropLagPlayers()
        {
            Debug.Log("DropLagPlayers");
            List <TSPlayer> list    = new List <TSPlayer>();
            int             refTick = GetRefTick(GetSyncedDataTick());

            if (refTick >= 0)
            {
                int i     = 0;
                int count = activePlayers.Count;
                while (i < count)
                {
                    TSPlayer tSPlayer = activePlayers[i];
                    if (!tSPlayer.IsDataReady(refTick))
                    {
                        tSPlayer.dropCount++;
                        list.Add(tSPlayer);
                    }
                    i++;
                }
            }
            int j      = 0;
            int count2 = list.Count;

            while (j < count2)
            {
                TSPlayer p = list[j];
                CheckDrop(p);
                bool sendDataForDrop = list[j].GetSendDataForDrop(localPlayer.ID, _syncedDataCacheDrop);
                if (sendDataForDrop)
                {
                    communicator.OpRaiseEvent(SEND_CODE, SyncedData.Encode(_syncedDataCacheDrop), true, null);
                    SyncedData.pool.GiveBack(_syncedDataCacheDrop[0]);
                }
                j++;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 收集本地输入,通过服务器发送给其他玩家
        /// </summary>
        /// <returns></returns>
        private SyncedData UpdateData()
        {
            Debug.Log("UpdateData");
            SyncedData result;

            if (replayMode == ReplayMode.LOAD_REPLAY)
            {
                result = null;
            }
            else
            {
                SyncedData @new = SyncedData.pool.GetNew();
                @new.Init(localPlayer.ID, ticks);
                GetLocalData(@new.inputData); //调用OnSyncedInput();输入数据给到@new.inputData里面
                localPlayer.AddData(@new);    //数据塞给TSPlayer的controls
                if (communicator != null)
                {
                    localPlayer.GetSendData(ticks, _syncedDataCacheUpdateData);                                                     //从TSplayer的controls里取数据
                    communicator.OpRaiseEvent(SEND_CODE, SyncedData.Encode(_syncedDataCacheUpdateData), true, auxActivePlayersIds); //将自己的输入数据发给其他玩家
                }
                result = @new;
            }
            return(result);
        }