示例#1
0
        private bool _CheckBorderServerFrame(bool isForce = false)
        {
            if (State != EGameState.Playing)
            {
                return(false);
            }
            var frame  = GetOrCreateFrame(Tick);
            var inputs = frame.Inputs;

            if (!isForce)
            {
                //是否所有的输入  都已经等到
                for (int i = 0; i < inputs.Length; i++)
                {
                    if (inputs[i] == null)
                    {
                        return(false);
                    }
                }
            }

            //将所有未到的包 给予默认的输入
            for (int i = 0; i < inputs.Length; i++)
            {
                if (inputs[i] == null)
                {
                    inputs[i] = new Msg_PlayerInput(Tick, (byte)i)
                    {
                        IsMiss = true
                    };
                }
            }

            //Debug.Log($" Border input {Tick} isUpdate:{isForce} _tickSinceGameStart:{_tickSinceGameStart}");
            var msg    = new Msg_ServerFrames();
            int count  = Tick < 2 ? Tick + 1 : 3;
            var frames = new ServerFrame[count];

            for (int i = 0; i < count; i++)
            {
                frames[count - i - 1] = _allHistoryFrames[Tick - i];
            }

            msg.startTick = frames[0].tick;
            msg.frames    = frames;
            BorderUdp(EMsgSC.G2C_FrameData, msg);
            if (_firstFrameTimeStamp <= 0)
            {
                _firstFrameTimeStamp = _timeSinceLoaded;
            }

            if (_gameStartTimestampMs < 0)
            {
                _gameStartTimestampMs =
                    LTime.realtimeSinceStartupMS + NetworkDefine.UPDATE_DELTATIME * _ServerTickDealy;
            }

            Tick++;
            return(true);
        }
示例#2
0
 public virtual void OnServerFrames(Msg_ServerFrames msg)
 {
 }
示例#3
0
        private void BorderServerFrame(int deltaTime)
        {
            waitTimer += deltaTime;
            if (State != EGameState.Playing)
            {
                return;
            }
            while (true)   // 如果落后太多 就一直追帧
            {
                var iTick = (int)Tick;
                if (allHistoryFrames.Count <= iTick)
                {
                    return;
                }

                var frame = allHistoryFrames[iTick];
                if (frame == null)
                {
                    return;
                }

                var inputs = frame.Inputs;
                //超时等待 移除超时玩家
                if (waitTimer > NetworkDefine.MAX_DELAY_TIME_MS)
                {
                    waitTimer = 0;
                    //移除还没有到来的帧的Player
                    for (int i = 0; i < inputs.Length; i++)
                    {
                        if (inputs[i] == null)
                        {
                            if (Players[i] != null)
                            {
                                //Log($"Overtime wait remove localId = {i}");
                            }

                            allNeedWaitInputPlayerIds.Remove((byte)i);
                        }
                    }
                }

                //是否所有的输入  都已经等到
                foreach (var id in allNeedWaitInputPlayerIds)
                {
                    if (inputs[id] == null)
                    {
                        return;
                    }
                }

                //将所有未到的包 给予默认的输入
                for (int i = 0; i < inputs.Length; i++)
                {
                    if (inputs[i] == null)
                    {
                        inputs[i] = new Msg_PlayerInput(Tick, (byte)i, null);
                    }
                }

                //Debug.Log("Border input " + Tick);
                var msg    = new Msg_ServerFrames();
                int count  = Tick < 2 ? iTick + 1 : 3;
                var frames = new ServerFrame[count];
                for (int i = 0; i < count; i++)
                {
                    frames[count - i - 1] = allHistoryFrames[iTick - i];
                }

                msg.startTick = frames[0].tick;
                msg.frames    = frames;
                BorderUdp(EMsgSC.G2C_FrameData, msg);
                if (firstFrameTimeStamp <= 0)
                {
                    firstFrameTimeStamp = timeSinceLoaded;
                }

                Tick++;
            }
        }
 public override void OnServerFrames(Msg_ServerFrames msg)
 {
 }
 public void OnServerFrames(Msg_ServerFrames msg)
 {
     EventHelper.Trigger(EEvent.OnServerFrame, msg);
 }
示例#6
0
        private void OnEvent_OnServerFrame(object param)
        {
            Msg_ServerFrames msg = param as Msg_ServerFrames;

            this.OnServerFrame(msg);
        }
示例#7
0
 public void OnServerFrame(Msg_ServerFrames msg)
 {
     this._hasRecvInputMsg = true;
     this._cmdBuffer.PushServerFrames(msg.frames, true);
 }
示例#8
0
        protected void G2C_FrameData(object reader)
        {
            Msg_ServerFrames msg = reader as Msg_ServerFrames;

            _handler.OnServerFrames(msg);
        }