private void ClearRound() { lockedFrame = new FSPFrameData(); curFrameId = 0; ResetRoundFlag(); foreach (FSPPlayer t in listPlayer) { t?.ClearRound(); } }
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); }
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); }
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); }
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); }
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(); } } }
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 }; } }
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); }
/// <summary> /// 收到一个服务器发送的 FSPFrameData 数据 /// </summary> /// <param name="frame"></param> private void OnFSPListener(FSPFrameData frame) { AddServerFrame(frame); }