Ejemplo n.º 1
0
        // 更新同步数据
        public void AddDataProjected(int refTick, int window)
        {
            SyncedData syncedData = this.GetData(refTick);

            for (int i = 1; i <= window; i++)
            {
                SyncedData data = this.GetData(refTick + i);
                bool       fake = data.fake;
                if (fake)
                {
                    SyncedData syncedData2 = syncedData.clone();
                    syncedData2.fake = true;
                    syncedData2.tick = refTick + i;
                    bool flag = this.controls.ContainsKey(syncedData2.tick);
                    if (flag)
                    {
                        SyncedData.pool.GiveBack(this.controls[syncedData2.tick]);
                    }
                    this.controls[syncedData2.tick] = syncedData2;
                }
                else
                {
                    bool dirty = data.dirty;
                    if (dirty)
                    {
                        data.dirty = false;
                        syncedData = data;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static List <SyncedData> Decode(byte[] data)
        {
            List <SyncedData> @new = SyncedData.poolList.GetNew();

            @new.Clear();
            int i   = 0;
            int num = BitConverter.ToInt32(data, i);

            i += 4;
            byte ownerID = data[i++];
            byte b       = data[i++];
            bool flag    = data[i++] == 1;
            int  num2    = num;

            while (i < data.Length)
            {
                SyncedData new2 = SyncedData.pool.GetNew();
                new2.Init(ownerID, num2--);
                new2.inputData.Deserialize(data, ref i);
                @new.Add(new2);
            }
            bool flag2 = @new.Count > 0;

            if (flag2)
            {
                @new[0].dropPlayer       = flag;
                @new[0].dropFromPlayerId = b;
            }
            return(@new);
        }
        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.º 4
0
        private static ReplayRecord FromReplayBytes(byte[] replayBytes)
        {
            ReplayRecord replayRecord = new ReplayRecord();
            int          i            = 0;

            while (i < replayBytes.Length)
            {
                byte b   = replayBytes[i++];
                int  num = BitConverter.ToInt32(replayBytes, i);
                i += 4;
                string @string = Encoding.ASCII.GetString(replayBytes, i, num);
                i += num;
                FPPlayer tSPlayer = new FPPlayer(b, @string);
                replayRecord.players.Add(b, tSPlayer);
                int num2 = BitConverter.ToInt32(replayBytes, i);
                i += 4;
                for (int j = 0; j < num2; j++)
                {
                    SyncedData @new = SyncedData.pool.GetNew();
                    @new.tick = BitConverter.ToInt32(replayBytes, i);
                    i        += 4;
                    @new.inputData.Deserialize(replayBytes, ref i);
                    @new.inputData.ownerID = b;
                    tSPlayer.controls.Add(@new.tick, @new);
                }
            }
            return(replayRecord);
        }
Ejemplo n.º 5
0
        public SyncedData clone()
        {
            SyncedData @new = SyncedData.pool.GetNew();

            @new.Init(this.inputData.ownerID, this.tick);
            @new.inputData.CopyFrom(this.inputData);
            return(@new);
        }
Ejemplo n.º 6
0
        internal void AddSyncedData(List <SyncedData> data)
        {
            int i     = 0;
            int count = data.Count;

            while (i < count)
            {
                SyncedData syncedData = data[i].clone();
                this.players[syncedData.inputData.ownerID].AddData(syncedData);
                i++;
            }
        }
Ejemplo n.º 7
0
        // 添加数据
        public void AddData(SyncedData data)
        {
            int  tick = data.tick;
            bool flag = this.controls.ContainsKey(tick);

            if (flag)             // 数据已存在,把数据对象回收到池中
            {
                SyncedData.pool.GiveBack(data);
            }
            else             // 未有数据
            {
                this.controls[tick] = data;
                this.lastTick       = tick;
            }
        }
Ejemplo n.º 8
0
 // 添加数据
 public void AddDataRollback(List <SyncedData> data)
 {
     for (int i = 0; i < data.Count; i++)
     {
         SyncedData data2 = this.GetData(data[i].tick);
         bool       fake  = data2.fake;
         if (fake)                 // 取出的是假数据
         {
             bool flag = data2.EqualsData(data[i]);
             if (!flag)                                                 // 两个数据不想等
             {
                 data[i].dirty = true;                                  // 设置为脏数据
                 SyncedData.pool.GiveBack(this.controls[data[i].tick]); // 回收该位置的数据
                 this.controls[data[i].tick] = data[i];                 // 放入新数据
                 break;                                                 // 中断,没有下一个数据要处理?
             }
             data2.fake  = false;
             data2.dirty = false;
         }
         SyncedData.pool.GiveBack(data[i]);
     }
 }
        private void DropLagPlayers()
        {
            List <FPPlayer> list    = new List <FPPlayer>();
            int             refTick = this.GetRefTick(this.GetSyncedDataTick());
            bool            flag    = refTick >= 0;

            if (flag)
            {
                int i     = 0;
                int count = this.activePlayers.Count;
                while (i < count)
                {
                    FPPlayer 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)
            {
                FPPlayer p = list[j];
                this.CheckDrop(p);
                bool sendDataForDrop = list[j].GetSendDataForDrop(this.localPlayer.ID, this._syncedDataCacheDrop);
                if (sendDataForDrop)
                {
                    this.communicator.OpRaiseEvent(199, SyncedData.Encode(this._syncedDataCacheDrop), true, null);
                    SyncedData.pool.GiveBack(this._syncedDataCacheDrop[0]);
                }
                j++;
            }
        }
Ejemplo n.º 10
0
 public bool EqualsData(SyncedData other)
 {
     return(this.inputData.EqualsData(other.inputData));
 }
Ejemplo n.º 11
0
        private void OnEventDataReceived(byte eventCode, object content)
        {
            bool flag = eventCode == 199;

            if (flag)             // 接收操作数据
            {
                byte[]            data = content as byte[];
                List <SyncedData> list = SyncedData.Decode(data);                // 解码
                bool flag2             = list.Count > 0;
                if (flag2)                                                       // 有数据
                {
                    FPPlayer tSPlayer = this.players[list[0].inputData.ownerID]; // 找到对应的玩家
                    bool     flag3    = !tSPlayer.dropped;
                    if (flag3)                                                   // 该玩家没有掉线
                    {
                        this.OnSyncedDataReceived(tSPlayer, list);               // 处理同步数据
                        bool flag4 = list[0].dropPlayer && tSPlayer.ID != this.localPlayer.ID && !this.players[list[0].dropFromPlayerId].dropped;
                        if (flag4)
                        {
                            tSPlayer.dropCount++;                             // 统计掉线玩家数量
                        }
                    }
                    else                     // 该玩家掉线了,回收数据对象
                    {
                        int i     = 0;
                        int count = list.Count;
                        while (i < count)
                        {
                            SyncedData.pool.GiveBack(list[i]);
                            i++;
                        }
                    }
                    SyncedData.poolList.GiveBack(list);
                }
            }
            else
            {
                bool flag5 = eventCode == 198;
                if (flag5)
                {
                    byte[] infoBytes = content as byte[];
                    this.OnChecksumReceived(SyncedInfo.Decode(infoBytes));
                }
                else
                {
                    bool flag6 = eventCode == 197;
                    if (flag6)
                    {
                        byte[] array = content as byte[];
                        bool   flag7 = array.Length != 0;
                        if (flag7)
                        {
                            bool flag8 = array[0] == 0;
                            if (flag8)
                            {
                                this.Pause();
                            }
                            else
                            {
                                bool flag9 = array[0] == 1;
                                if (flag9)
                                {
                                    this.Run();
                                }
                                else
                                {
                                    bool flag10 = array[0] == 3;
                                    if (flag10)
                                    {
                                        this.End();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        bool flag11 = eventCode == 196;
                        if (flag11)
                        {
                            byte[]     infoBytes2 = content as byte[];
                            SyncedInfo syncedInfo = SyncedInfo.Decode(infoBytes2);
                            this.players[syncedInfo.playerId].sentSyncedStart = true;
                        }
                    }
                }
            }
        }