示例#1
0
        //---------------------------------------------------------
        /// <summary>
        /// 驱动游戏状态
        /// </summary>
        public void EnterFrame()
        {
            for (int i = 0; i < m_ListPlayersExitOnNextFrame.Count; i++)
            {
                FSPPlayer player = m_ListPlayersExitOnNextFrame[i];
                FSPServer.Instance.DelSession(player.Sid);
                player.Dispose();
            }
            m_ListPlayersExitOnNextFrame.Clear();

            //在这里处理状态
            HandleGameState();

            //经过上面状态处理之后,有可能状态还会发生变化
            if (m_State == FSPGameState.None)
            {
                return;
            }

            if (m_LockedFrame.frameId != 0 || !m_LockedFrame.IsEmpty())
            {
                //将当前帧扔给Player
                for (int i = 0; i < m_ListPlayer.Count; i++)
                {
                    FSPPlayer player = m_ListPlayer[i];
                    player.SendToClient(m_LockedFrame);
                    if (player.WaitForExit)
                    {
                        m_ListPlayersExitOnNextFrame.Add(player);
                        m_ListPlayer.RemoveAt(i);
                        --i;
                    }
                }
            }

            //0帧每个循环需要额外清除掉再重新统计
            if (m_LockedFrame.frameId == 0)
            {
                m_LockedFrame = new FSPFrame();
                //防止GC
                if (UseDelayGC)
                {
                    m_ListObjectsForDelayGC.Add(m_LockedFrame);
                }
            }


            //在这个阶段,帧号才会不停往上加
            if (m_State == FSPGameState.RoundBegin || m_State == FSPGameState.ControlStart)
            {
                m_CurFrameId++;
                m_LockedFrame         = new FSPFrame();
                m_LockedFrame.frameId = m_CurFrameId;
                //防止GC
                if (UseDelayGC)
                {
                    m_ListObjectsForDelayGC.Add(m_LockedFrame);
                }
            }
        }
示例#2
0
        //=======================================================================================

        /// <summary>
        /// 驱动游戏状态
        /// </summary>
        public void EnterFrame()
        {
            for (int i = 0; i < m_ListPlayersExitOnNextFrame.Count; i++)
            {
                var player = m_ListPlayersExitOnNextFrame[i];
                player.Release();
            }
            m_ListPlayersExitOnNextFrame.Clear();



            //处理游戏状态切换
            HandleGameState();


            //经过上面状态处理之后,有可能状态还会发生变化
            if (m_State == FSPGameState.None)
            {
                return;
            }



            if (m_LockedFrame.frameId != 0 || !m_LockedFrame.IsEmpty())
            {
                //将当前帧扔级Player
                for (int i = 0; i < m_ListPlayer.Count; i++)
                {
                    FSPPlayer player = m_ListPlayer[i];
                    player.SendToClient(m_LockedFrame);

                    if (player.WaitForExit)
                    {
                        m_ListPlayersExitOnNextFrame.Add(player);
                        m_ListPlayer.RemoveAt(i);
                        --i;
                    }
                }
            }


            //0帧每个循环需要额外清除掉再重新统计
            if (m_LockedFrame.frameId == 0)
            {
                m_LockedFrame = new FSPFrame();
            }


            //在这个阶段,帧号才会不停往上加
            if (m_State == FSPGameState.RoundBegin || m_State == FSPGameState.ControlStart)
            {
                m_CurFrameId++;
                m_LockedFrame         = new FSPFrame();
                m_LockedFrame.frameId = m_CurFrameId;
            }
        }
示例#3
0
        //---------------------------------------------------------
        /// <summary>
        /// enter frame
        /// </summary>
        public void EnterFrame()
        {
            //delete exited players
            for (int i = 0; i < mPlayersExitOnNextFrameList.Count; i++)
            {
                FSPPlayer player = mPlayersExitOnNextFrameList[i];
                FSPServer.Instance.DelSession(player.Sid);
                player.Dispose();
            }
            mPlayersExitOnNextFrameList.Clear();

            //hand game state
            HandleGameState();

            //check if game state changes
            if (mState == FSPGameState.None)
            {
                return;
            }

            if (mLockedFrame.frameId != 0 || !mLockedFrame.IsEmpty())
            {
                //send frame to players
                for (int i = 0; i < mPlayerList.Count; i++)
                {
                    FSPPlayer player = mPlayerList[i];
                    player.SendToClient(mLockedFrame);
                    if (player.WaitForExit)
                    {
                        mPlayersExitOnNextFrameList.Add(player);
                        mPlayerList.RemoveAt(i);
                        --i;
                    }
                }
            }

            //clear frame 0 in each iteration
            if (mLockedFrame.frameId == 0)
            {
                mLockedFrame = new FSPFrame();
                //delay GC
                if (UseDelayGC)
                {
                    mListObjectsForDelayGC.Add(mLockedFrame);
                }
            }


            //add up frame id
            if (mState == FSPGameState.RoundBegin || mState == FSPGameState.ControlStart)
            {
                mCurFrameId++;
                mLockedFrame         = new FSPFrame();
                mLockedFrame.frameId = mCurFrameId;
                //防止GC
                if (UseDelayGC)
                {
                    mListObjectsForDelayGC.Add(mLockedFrame);
                }
            }
        }