public static PacketDistributed CreatePacket(MessageID packetID) { PacketDistributed packet = null; switch (packetID) { case MessageID.GCErrorBack: { packet = new GCErrorBack(); } break; case MessageID.CGheartbeatClientSend: { packet = new CGheartbeatClientSend(); } break; case MessageID.GCheartbeatServerBack: { packet = new GCheartbeatServerBack(); } break; case MessageID.GCServerMsg: { packet = new GCServerMsg(); } break; case MessageID.OptionEvent: { packet = new OptionEvent(); } break; case MessageID.FrameOpts: { packet = new FrameOpts(); } break; case MessageID.LogicFrame: { packet = new LogicFrame(); } break; case MessageID.NextFrameOpts: { packet = new NextFrameOpts(); } break; case MessageID.GamePlayerInfo: { packet = new GamePlayerInfo(); } break; case MessageID.EnterGame: { packet = new EnterGame(); } break; } if (null != packet) { packet.packetID = packetID; } //netActionTime = DateTime.Now.ToFileTimeUtc(); return(packet); }
public static void PersistLogicFrameValue(this StatePersister persister, ref LogicFrame value) { var innerValue = value.Value; persister.PersistUInt32Value(ref innerValue); value = new LogicFrame(innerValue); }
void Start() { mover = gameObject.AddComponent <LogicFrameMove> (); mover.SetAnimation(animation, "idle", "run"); log = GameObject.Find("LogText").GetComponent <Text> (); LogicFrame.Register(this); }
void RebornCountDown(int time, int aimId) { Reborn(time, aimId); if (time > 0) { rebornTime = time - 1; LogicFrame.InvokeDelay(this, 1.0f, "RebornCountDown", new object[] { rebornTime, aimId }); } }
public EditorPage() { InitializeComponent(); DeviceFrame.Navigate(typeof(DevicePage), null); LogicFrame.Navigate(typeof(LogicPage), null); Loaded += async(sender, e) => { await rMind.Project.rMindProject.GetInstance().RestoreState(); }; }
void handle_logic_frame(cmd_msg msg) { LogicFrame res = proto_man.protobuf_deserialize <LogicFrame>(msg.body); if (res == null) { return; } event_manager.Instance.dispatch_event(event_manager.EVT_LOGIC_FRAME_UPDATE, res); }
public void Death(int aimId, int time, int frame) { Player aimPlayer = Global.entity [aimId].GetComponent <Player> (); aimPlayer.isDeath = true; aimPlayer.mover.StopMove(); aimPlayer.animation.Play("death"); aimPlayer.combo = 0; // 先停顿指定的帧数,再开始重生倒计时 LogicFrame.InvokeDelayByFrame(aimPlayer, frame, "RebornCountDown", new object[] { time, aimId }); }
private void on_logic_update(string name, object udata) { LogicFrame frame = (LogicFrame)udata; if (frame.cur_frameid < this.sync_frameid) { Debug.LogError(frame.cur_frameid); return; } //同步上一帧逻辑操作, 调整我们的位置,调整完以后。 客户端同步到的是 sync_frame if (this.last_frame_opts != null) //同步到正确的点 { this.on_sync_last_logic_frame(this.last_frame_opts); } //end //从sync_frame 开始 ----> frame.frameid -1 //同步丢失的帧 for (int i = 0; i < frame.unsync_frames.Count; i++) { // Debug.LogError(this.sync_frameid + ":" + frame.unsync_frames[i].old_frameid); if (this.sync_frameid >= frame.unsync_frames[i].old_frameid) { continue; } else if (frame.unsync_frames[i].old_frameid >= frame.cur_frameid) { break; } this.on_handler_frame_event(frame.unsync_frames[i]); this.upgrade_exp_by_time(); } //end //获取最后一个操作, frame.frameid 操作,根据这个操作,来处理,来播放动画 this.sync_frameid = frame.cur_frameid; if (frame.unsync_frames.Count > 0) { this.last_frame_opts = frame.unsync_frames[frame.unsync_frames.Count - 1]; this.on_handler_frame_event(this.last_frame_opts); this.upgrade_exp_by_time(); } else { this.last_frame_opts = null; } //end //采集下一个帧的事件,发送给服务器 this.capture_player_opts(); //end }
/// <summary> /// 帧同步调度主函数 /// </summary> /// <param name="eventName"></param> /// <param name="udata"></param> private void OnLogicUpdate(string eventName, object udata) { LogicFrame frame = (LogicFrame)udata; if (frame.frameid < this._syncFrameID)//收到以前发来的操作帧,直接忽略 { return; } //同步自己客户端上一帧的逻辑操作,调整位置到真实位置: //调整完以后,客户端同步到syncFrameID if (this._lastFrameOpts != null) { OnSyncLastLogicFrame(this._lastFrameOpts); //此时,所有玩家的位置都同步到了正确的位置。 } //从syncFrameID+1开始-->frame.frameid-1 //同步丢失的帧,快速同步到当前帧 //所有客户端的数据都被同步到frame.frameid-1 for (int i = 0; i < frame.unsync_frames.Count; i++) { if (this._syncFrameID >= frame.unsync_frames[i].frameid) { continue; } if (frame.unsync_frames[i].frameid >= frame.frameid) { break; } OnHandlerFrameEvent(frame.unsync_frames[i]);//更新动画状态 UpgradeExpByTime(); } //获取最后一个操作 frame.frameid的操作 //根据这个操作来处理,播放动画,产生的位移为“假位移” this._syncFrameID = frame.frameid;//同步到的事件帧ID if (frame.unsync_frames.Count > 0) { this._lastFrameOpts = frame.unsync_frames[frame.unsync_frames.Count - 1]; OnHandlerFrameEvent(this._lastFrameOpts);//更新动画状态 UpgradeExpByTime(); } else { _lastFrameOpts = null; } //采集下一个帧的事件,发送给服务器 CapturePlayerOpts(); }
private void on_server_logic_frame(cmd_msg msg) { LogicFrame res = proto_man.protobuf_deserialize <LogicFrame>(msg.body); if (res == null) { return; } //Debug.Log("当前玩家没有同步的操作" + res.cur_frameid); //当前帧,以及当前玩家没有同步的操作 event_manager.Instance.dispatch_event(logic_update, res); }
private void OnServerLogicFrame(cmd_msg msg) { LogicFrame res = proto_man .protobuf_deserialize <LogicFrame>(msg.body); if (res == null) { return; } //Debug.Log(res.frameid);//当前帧id,和当前玩家没有同步到的操作 EventManager.Instance.DispatchEvent("on_logic_update", res); }
public void MainTick(object sender, ElapsedEventArgs e) { LogicFrame frame = new LogicFrame(FrameIdx++); foreach (var kv in plyLastFrameInfo) { if (FrameIdx - kv.Value > 50) { //掉线 isDiaoxian = true; } else { isDiaoxian = false; } } foreach (var kv in NowOpts) { if (kv.Value.Count == 0) { FrameOpt emptyOpt = new FrameOpt(); emptyOpt.actorId = kv.Key; emptyOpt.optType = eOptType.MVOE; emptyOpt.optContent = "0,0"; frame.frameOpts.Add(emptyOpt); if (isDiaoxian) { //伪造回家包 } } else { frame.frameOpts.Add(kv.Value[0]); } kv.Value.Clear(); } FrameList.AddLast(new LinkedListNode <LogicFrame>(frame)); frame.dtime = (int)TickInteval; //LinkedListNode<LogicFrame> node = FrameList.Last; //Debug.Log("svr frame:" + frame.frameIdx); string ret = JsonConvert.SerializeObject(frame); ByteBuffer byteBuffer = new ByteBuffer(); byteBuffer.AddInt((int)eNetMsgType.FRAME); byteBuffer.AddString(ret); FakeSendMsg(byteBuffer); }
void Start() { player = GetComponent <Player> (); // 技能动画 player.animation.Play("skill1"); // 技能特效 GameObject _skill = Resources.Load <GameObject> ("Prefabs/hero3007/Fx_hero3007_skill_01"); GameObject skill = Instantiate(_skill, (Vector3)player.mover.position, transform.rotation); // 3 秒后销毁特效 Destroy(skill, 3.0f); LogicFrame.Register(this); }
public bool pop(int maxFrameId, out LogicFrame msg) { msg = null; if (replayList.Count == 0) { return(false); } var _msg = replayList.Peek(); if (_msg.frameId <= maxFrameId) { msg = replayList.Dequeue(); return(true); } return(false); }
//¼Ç¼²Ã¼ô public int cast(uint logicFrameID) { RAL.LogicFrame current = replayList.Peek(); while (current != null && current.frameId < logicFrameID) { LogicFrame removedFrame = replayList.Dequeue(); removedFrame.release(_renderActionGenerator); current = replayList.Peek(); } if (current != null) { return(current.frameId); } return(-1); }
/// <summary> /// 发送未同步的帧 /// </summary> /// <param name="player"></param> public void SendUnsyncFrames(GamePlayerInfo player) { //发送消息给客户端 LogicFrame logicFrame = new LogicFrame(); logicFrame.SetFrameId(frameId); for (int i = player.SyncFrameId + 1; i < matchFrames.Count; i++) { logicFrame.AddUnSyncFrames(matchFrames[i]); } //TODO //UDP发送消息给客户端 //upd_send_cmd(Stype.Logic,Cmd.eLogicFrame,body) Program.SendMessage(MessageID.LogicFrame, logicFrame); }
void evt_logic_frame_update(string name, object udata) { LogicFrame frame = (LogicFrame)udata; if (frame.frameid < this.sync_frameid) { return; } /* * Debug.Log(frame.unsyncFrames.Count); * for (int i = 0; i < frame.unsyncFrames.Count; i++) * { * for (int j = 0; j < frame.unsyncFrames[i].opts.Count; j++) * { * Debug.Log(frame.unsyncFrames[i].opts[i].x + "------------------:--------------------" + frame.unsyncFrames[i].opts[i].y); * } * }*/ //同步自己客户端上一帧逻辑操作,调整我们的位置;调整完成后,客户端同步的是sync_frameid //end //从sync_frameid+1开始----------------》frame.frameid-1; //同步丢失的帧,所有的客户端数据同步到 frame.frameid-1 //end //获取最后一个操作,frame.frameid操作,根据这个操作来处理播放动画 this.sync_frameid = frame.frameid;//同步到的事件帧id if (frame.unsyncFrames.Count > 0) { this.last_frame_opt = frame.unsyncFrames[frame.unsyncFrames.Count - 1]; this.on_handler_frame_event(this.last_frame_opt); } else { this.last_frame_opt = null; } //end //采集下一个帧的事件,发送给服务器 //采集玩家当前的操作帧 this.capture_player_opts(); }
void FrameUpdate() { // 取当前帧的指令,并进行相应的计算 JsonObject frameOrder = LogicFrame.getFrameOrder(uid); if (frameOrder != null) { int type = Convert.ToInt32(frameOrder ["type"]); if (type == Global.Frame_Move) // 移动 { int vx = Convert.ToInt32(frameOrder ["vx"]); int vy = Convert.ToInt32(frameOrder ["vy"]); int vz = Convert.ToInt32(frameOrder ["vz"]); mover.StartMove(new VInt3(vx, vy, vz), speedReal); } else if (type == Global.Frame_StopMove) // 停止移动 { mover.StopMove(); } else if (type == Global.Frame_Attack) // 攻击 { OnAttack(); } else if (type == Global.Frame_Skill) // 技能 { int skillCode = Convert.ToInt32(frameOrder ["code"]); OnSkill(skillCode); } } foreach (int uid in Global.entity.Keys) { Player player = Global.entity [uid].GetComponent <Player> (); player.blood.textInfo.text = player.mover.position.ToStringF3(); } string text = ""; text += LogicFrame.frameOrderList.Count + ", " + LogicFrame.frame + ", " + LogicFrame.frameIntervalTimeReal; log.text = text; }
private NetMsgBase ReadAndDecode(ByteBuffer byteBuffer) { int start = 0; int msgType = byteBuffer.GetInt(start, ref start); if (msgType == (int)eNetMsgType.FRAME) { string str = byteBuffer.GetString(start, ref start); LogicFrame frame = JsonConvert.DeserializeObject <LogicFrame>(str); NetFrameMsg msg = new NetFrameMsg(); msg.MsgType = (eNetMsgType)msgType; msg.frame = frame; return(msg); } else { NetSysMsg msg = new NetSysMsg(); msg.MsgType = (eNetMsgType)msgType; msg.localPid = byteBuffer.GetInt(start, ref start); return(msg); } }
public void Update() { logicTimer += Time.deltaTime; int logicCount = 0; //三倍速在视图层处理 逻辑层只管会不会卡死 while (logicTimer >= LogicTickInterval && logicCount < MAX_LOGIC_FRAME_PER_TICK) { if (frames.Count > 0) { LogicFrame nowFrame = frames.Dequeue(); LogicUpdate(nowFrame); LogicLastTickTime = LogicCurTickTime; LogicCurTickTime = Time.time; logicTimer -= LogicTickInterval; logicCount += 1; } else { break; } } }
private void LogicUpdate(LogicFrame frame) { //handle frame if (frame.frameIdx != this.frameIdx + 1) { Debug.Log(this.frameIdx + " " + frame.frameIdx); Debug.Log("zhenshu错误 丢弃"); return; } this.frameIdx = frame.frameIdx; this.LastDtime = frame.dtime; //Debug.Log("opt shu:" + frame.frameOpts.Count); //handle input for (int i = 0; i < frame.frameOpts.Count; i++) { FrameOpt opt = frame.frameOpts[i]; Handle(opt); } battleMgr.Update(frame.dtime); //执行所有update for (int i = 0; i < LogicActorList.Count; i++) { LogicActorList[i].Update(frame.dtime); } //发送本机的命令 //SendLocalOpt(); SendAck(); }
void OnSkill(int skillCode) { switch (skillCode) { // 闪现 case 1: VInt3 targetPosition = mover.position + mover.dir * (VInt)5.0f; mover.position = targetPosition; transform.position = (Vector3)targetPosition; break; // 移动速度增加 case 2: speedReal = speedNormal * (VInt)2.0f; LogicFrame.InvokeDelay(this, 5.0f, "SpeedNormal", null); break; // 攻击速度增加 case 3: atkSpeedReal = atkSpeedNormal * (VInt)2.0f; LogicFrame.InvokeDelay(this, 5.0f, "AttackSpeedNormal", null); break; } }
void OnDestroy() { LogicFrame.Unregister(this); }
void Start() { initPosition = (VInt3)transform.position; mover = gameObject.AddComponent <LogicFrameMove> (); LogicFrame.Register(this); }
private void OnLogicFrame(LogicFrame obj) { if (obj.frameid < this.sync_frameid) { return; } /*print("未同步的帧:" + obj.unsync_frames.Count); * var temp = ""; * foreach (var frameOptionEvent in obj.unsync_frames) * { * foreach (var opt in frameOptionEvent.opts) * { * temp+=($"optType: {opt.optype}, stick: [{opt.x},{opt.y}]\n"); * } * } * * print(temp);*/ // 同步之前收到的最后一帧的处理结果,据此保证所有客户端的处理结果都是一样的 // 同步客户端上一帧逻辑操作,调整位置,调整后,客户端同步到的就是sync_frame if (null != lastOptionEvent) { this.OnAsyncLastLogicFrame(lastOptionEvent); } // 同步丢掉的帧 // 从sync_frame 同步到 obj.frameid-1 foreach (var frame in obj.unsync_frames) { if (this.sync_frameid >= frame.frameid) {// 已经同步 continue; } if (frame.frameid >= obj.frameid) {// 无需同步 break; } //跳帧 this.OnJumpToNextFrame(frame); } //记录下当前帧操作 this.sync_frameid = obj.frameid; if (obj.unsync_frames.Count > 0) { //保留最新帧信息 this.lastOptionEvent = obj.unsync_frames.Last(); //获取最新帧信息,处理逻辑 this.OnHandlerCurrentLogicFrame(this.lastOptionEvent); } else { this.lastOptionEvent = null; } //采集下一帧事件发布给服务器 CollectNextFrameOpts(); }
void OnAttack() { isAttack = true; // 判断要攻击的是哪一个队伍 ArrayList aimList = new ArrayList(); foreach (int uid in Global.myTeamUid) { if (this.uid == uid) { aimList = Global.otherTeamUid; break; } } foreach (int uid in Global.otherTeamUid) { if (this.uid == uid) { aimList = Global.myTeamUid; break; } } // 被攻击者 id,如果为 -1 则表示超出攻击范围 int aimId = -1; // 如果当前距离和敌方所有玩家大于攻击距离则在原地攻击。否则攻击对方距离最近的非状态的玩家 int count = 0; VInt minDistance = VInt.zero;; foreach (int otherUid in aimList) { Player player = Global.entity [otherUid].GetComponent <Player> (); VInt distance = VInt3.Distance(mover.position, player.mover.position); if (distance > atkRange) { count++; } else { if (!player.isDeath) { if (distance < minDistance || minDistance == VInt.zero) { minDistance = distance; aimId = otherUid; } } else { count++; } } } if (count == Global.otherTeamUid.Count) { aimId = -1; } // 转向被攻击者 if (aimId != -1) { transform.LookAt((Vector3)Global.entity [aimId].GetComponent <Player> ().mover.position); } // 攻击动画,控制攻击速度 String animName = "attack" + (combo + 1); VInt animationSpeed = (VInt)animation [animName].length / ((VInt)1.0f / atkSpeedReal); animation [animName].speed = (float)animationSpeed; animation.Play(animName); // 攻击特效 String prefabPath = "Prefabs/hero" + heroCode + "/Fx_hero" + heroCode + "_attack_0" + (combo + 1); GameObject _attack = Resources.Load <GameObject> (prefabPath); GameObject attack = Instantiate(_attack, (Vector3)mover.position, transform.rotation); // 3 秒后销毁特效 Destroy(attack, 3.0f); // 攻击动画进行一段时间后会进行出击 float delay = (float)(atkTime / animationSpeed); LogicFrame.InvokeDelay(this, delay, "AttackHit", new object[] { aimId }); // 控制连击次数 if (combo < 3) { combo++; } else { combo = 0; } lastComboTime = (VInt)Time.time; }
public void AddNewFrame(LogicFrame newFrame) { frames.Enqueue(newFrame); }
public static void PersistLogicFrame(this StatePersister persister, ref LogicFrame value, [CallerArgumentExpression("value")] string name = "") { persister.PersistFieldName(name); persister.PersistLogicFrameValue(ref value); }