示例#1
0
 private void ClearRound()
 {
     lockedFrame = new FSPFrameData();
     curFrameId  = 0;
     ResetRoundFlag();
     foreach (FSPPlayer t in listPlayer)
     {
         t?.ClearRound();
     }
 }
示例#2
0
        public bool Send(FSPFrameData frame)
        {
            if (!IsActived())
            {
                Debuger.LogWarning("Session已经不活跃了!");
                return(false);
            }

            tempSendData.frame = frame;
            int len = ProtoBuffUtility.Serialize(tempSendData, sendBufferTemp);

            return(kcp.Send(sendBufferTemp, len) == 0);
        }
示例#3
0
        private void AddServerFrame(FSPFrameData frame)
        {
            if (frame.frameID <= 0)
            {
                ExecuteFrame(frame.frameID, frame);
                return;
            }

            frame.frameID          = frame.frameID * fspParam.clientFrameRateMultiple;
            serverLockedFrameIndex = frame.frameID + fspParam.clientFrameRateMultiple - 1;
            frameDatas.Add(frame.frameID, frame);
            fspFrameController.AddFrameID(frame.frameID);
        }
示例#4
0
        private void SendFSPLocal(int cmd, params int[] args)
        {
            if (nextLocalFrameData == null || nextLocalFrameData.frameID != clientCurrentFrameIndex + 1)
            {
                nextLocalFrameData = new FSPFrameData {
                    frameID = clientCurrentFrameIndex + 1
                };
                frameDatas.Add(nextLocalFrameData.frameID, nextLocalFrameData);
            }
            FSPMessage msg = new FSPMessage
            {
                cmd      = cmd,
                args     = args,
                playerID = PlayerId
            };

            nextLocalFrameData.msgs.Add(msg);
        }
示例#5
0
        private bool SendInternal(FSPFrameData frame)
        {
            if (frame.frameID != 0 && frame.frameID <= lastAddFrameID)
            {
                return(true);
            }

            if (session != null)
            {
                if (session.Send(frame))
                {
                    lastAddFrameID = frame.frameID;
                    return(true);
                }
            }

            return(false);
        }
示例#6
0
        public void SendToClient(FSPFrameData frame)
        {
            if (frame != null)
            {
                if (!frameCache.Contains(frame))
                {
                    frameCache.Enqueue(frame);
                }
            }


            while (frameCache.Count > 0)
            {
                if (SendInternal(frameCache.Peek()))
                {
                    frameCache.Dequeue();
                }
            }
        }
示例#7
0
        public void EnterFrame()
        {
            foreach (var player in listPlayersExitOnNextFrame)
            {
                player.Release();
            }
            listPlayersExitOnNextFrame.Clear();
            HandleGameState();
            if (state == FSPGameState.None)
            {
                return;
            }

            if (lockedFrame.frameID != 0 || !lockedFrame.IsEmpty())
            {
                for (int i = 0; i < listPlayer.Count; i++)
                {
                    FSPPlayer player = listPlayer[i];
                    player.SendToClient(lockedFrame);
                    if (player.WaitForExit)
                    {
                        listPlayersExitOnNextFrame.Add(player);
                        listPlayer.RemoveAt(i);
                        --i;
                    }
                }
            }

            if (lockedFrame.frameID == 0)
            {
                lockedFrame = new FSPFrameData();
            }

            if (state == FSPGameState.RoundBegin || state == FSPGameState.ControlStart)
            {
                curFrameId++;
                lockedFrame = new FSPFrameData {
                    frameID = curFrameId
                };
            }
        }
示例#8
0
        private void ExecuteFrame(int frameId, FSPFrameData frame)
        {
            if (frame != null && !frame.IsEmpty())
            {
                foreach (var msg in frame.msgs)
                {
                    switch (msg.cmd)
                    {
                    case FSPProtoCmd.GameBegin: HandleGameBegin(msg.args[0]); break;

                    case FSPProtoCmd.RoundBegin: HandleRoundBegin(msg.args[0]); break;

                    case FSPProtoCmd.ControlStart: HandleControlStart(msg.args[0]); break;

                    case FSPProtoCmd.RoundEnd: HandleRoundEnd(msg.args[0]); break;

                    case FSPProtoCmd.GameEnd: HandleGameEnd(msg.args[0]); break;

                    case FSPProtoCmd.GameExit: HandleGameExit(msg.playerID); break;
                    }
                }
            }
            frameListener?.Invoke(frameId, frame);
        }
示例#9
0
 /// <summary>
 /// 收到一个服务器发送的 FSPFrameData 数据
 /// </summary>
 /// <param name="frame"></param>
 private void OnFSPListener(FSPFrameData frame)
 {
     AddServerFrame(frame);
 }