private UnitState ExecuteResult(UnitState state, StateCommand command) { if (this.lastSimulateFrame == 0) { this.lastSimulateFrame = command.frame; } state.Rotate = command.result.rotate; state.Velocity = command.result.velocity; return(state); }
private StateResult ExecuteInput(UnitState state, StateCommand command) { state.Rotate = CalculaAngle(command.input.axisX, command.input.axisY); state.Velocity = VelocityConst.Accelerate; StateResult result = new StateResult(); result.rotate = state.Rotate; result.velocity = state.Velocity; return(result); }
private void OnSimulateInput() { if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { StateCommand inputCommand = CollectCommandInput(); Actor_ClientCommond clientCommond = new Actor_ClientCommond(); clientCommond.Input.Add(inputCommand.ToCommand()); SessionComponent.Instance.Session.Send(clientCommond); this.SimulateQueue.AddLast(inputCommand); } }
private StateCommand CollectCommandInput() { StateCommand stateCommand = new StateCommand(); stateCommand.frame = this.PredictedState.Frame; stateCommand.sequence = ++this.Sequence; stateCommand.input = new StateInput(); stateCommand.input.axisX = Input.GetAxis("Horizontal"); stateCommand.input.axisY = Input.GetAxis("Vertical"); return(stateCommand); }
// 处理服务器命令 public void Verify(Command command) { StateCommand simulate = this.SimulateQueue.First.Value; simulate.result.rotate = command.Result.Rotate; simulate.result.velocity = command.Result.Velocity; this.lastSimulateFrame = simulate.frame; this.VerifyState = this.VerifyState.Inertance(command.Frame - this.VerifyState.Frame); this.VerifyState = ExecuteResult(this.VerifyState, simulate); this.SimulateQueue.RemoveFirst(); }