Beispiel #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);
        }
Beispiel #2
0
        public void OnPlayerInput(int useId, Msg_PlayerInput msg)
        {
            int localId = 0;

            if (!id2LocalId.TryGetValue(useId, out localId))
            {
                return;
            }
            PlayerInput[] val;
            if (!tick2Inputs.TryGetValue(msg.tick, out val))
            {
                val = new PlayerInput[maxPlayerCount];
                tick2Inputs.Add(msg.tick, val);
            }

            val[localId] = msg.input;
        }
        public void OnPlayerInput(int useId, Msg_PlayerInput msg)
        {
            int localId = 0;

            if (!id2LocalId.TryGetValue(useId, out localId))
            {
                return;
            }
            PlayerInput[] inputs;
            if (!tick2Inputs.TryGetValue(msg.tick, out inputs))
            {
                inputs = new PlayerInput[maxPlayerCount];
                tick2Inputs.Add(msg.tick, inputs);
            }

            inputs[localId] = msg.input;
            CheckInput();
        }
Beispiel #4
0
        private void CheckBorderServerFrame()
        {
            if (State != EGameState.Playing)
            {
                return;
            }
            while (true)   // 如果落后太多 就一直追帧
            {
                if (_allHistoryFrames.Count <= Tick)
                {
                    return;
                }

                var frame = _allHistoryFrames[Tick];
                if (frame == null)
                {
                    return;
                }

                var inputs = frame.Inputs;
                //超时等待 移除超时玩家
                if (_waitTimer > (NetworkDefine.MAX_DELAY_TIME_MS / 1000.0f))
                {
                    _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 ? 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;
                }

                Tick++;
            }
        }