/// <summary> /// 接受客户端帧消息,转发给所有客户端 /// </summary> public void OnRecvClient(ref Conn conn, FspFrame frames) { for (int i = 0; i < frames.vkeys.Count; i++) { HandleClientCmd(conn.player, frames.vkeys[i]); } }
public void EnterFrame() { if (m_listPlayer.Count == 0) { return; } HandleState(); // 每一帧的消息发给各客户端 if (m_lockedFrame.frameId != 0 || !m_lockedFrame.IsEmpty()) { for (int i = 0; i < m_listPlayer.Count; i++) { Player player = m_listPlayer[i]; if (m_lockedFrame.vkeys.Count > 0 && m_lockedFrame.vkeys[0].args != null && m_lockedFrame.vkeys[0].args.Length > 0) { Console.WriteLine("发送指令.数量:" + m_lockedFrame.vkeys.Count); } player.Send(m_lockedFrame); } } // 游戏控制时,帧号才会增加,其实进入房间就算开始了 if (m_state == FspGameState.StartControl) { m_curFrameId++; //Console.WriteLine("当前帧率:" + m_curFrameId); m_lockedFrame = new FspFrame(); m_lockedFrame.frameId = m_curFrameId; } }
// 添加一帧的指令列表 public void AddServerFrameUnit(FspFrame frame) { if (frame.frameId <= 0) { ExecuteFrame(0, frame); return; } m_clientNewFrameIndex = frame.frameId; m_dicFrame.Add(frame.frameId, frame); // 添加最新帧 m_frameCtrl.AddNewFrameId(frame.frameId); }
// 正式的游戏逻辑帧 private void ExecuteFrame(int frameId, FspFrame frameMsg) { if (frameMsg != null && frameMsg.vkeys != null) { for (int i = 0; i < frameMsg.vkeys.Count; i++) { FspVKey cmd = frameMsg.vkeys[i]; // 根据keyid做不同逻辑处理 HandleServerCmd(cmd); } } CFrameTimeMgr.Inst.FixedUpdate(); CCreatureMgr.ExecuteFrame(frameId); CSkillMgr.ExecuteFrame(frameId); CBuffMgr.ExecuteFrame(frameId); CBuffTriggerMgr.ExecuteFrame(frameId); }
public void Send(FspFrame frame) { if (frame == null) { return; } if (!m_frameList.Contains(frame)) { m_frameList.Enqueue(frame); } while (m_frameList.Count > 0) { FspFrame fsp = m_frameList.Peek(); FspMsgFrame msg = (FspMsgFrame)NetManager.Inst.GetMessage(eNetMessageID.FspMsgFrame); msg.frameMsg = fsp; FspNetRunTime.Inst.Send(conn, msg); m_frameList.Dequeue(); } }