void Move(FP h, FP v) { // Set the movement vector based on the axis input. TSVector cacheMove = new TSVector(h, 0, v); if (TSVector.Distance(cacheMove, Movement) > 0.001f) { // Debug.Log("PlayerMovement::Movement:" + Movement); Movement = cacheMove; KBEngine.Event.fireIn("reqFrameChange", FrameProto.encode(new FrameUser(SyncFrame.CMD.USER, Movement))); // startTime = System.DateTime.Now; } // Normalise the movement vector and make it proportional to the speed per second. //movement = movement.normalized * speed * Time.deltaTime; // Move the player to it's current position plus the movement. // playerRigidbody.MovePosition (transform.position + movement); // Vector3 destposition = transform.position + movement; // }
public void OnSyncedInput() { if (!owner.isPlayer()) { return; } KeyValue = 0; foreach (var item in keyBit) { if (Input.GetKey(item.Key) // && (item.Key == KeyCode.W // || item.Key == KeyCode.LeftShift // //|| item.Key == KeyCode.Mouse0 // || item.Key == KeyCode.Mouse1 /*)*/) { KeyValue |= (UInt16)(1L << item.Value); } // else if (Input.GetKeyDown(item.Key)) // { // KeyValue |= (UInt16)(1L << item.Value); // } } FP accell = Input.GetAxis("Vertical"); FP steer = Input.GetAxis("Horizontal"); KBEngine.Event.fireIn("reqFrameChange", FrameProto.encode(new FrameFPS(CMD.FPS, KeyValue, accell, steer))); }
/** * @brief Sets player inputs. **/ public void OnSyncedInput() { if (!owner.isPlayer()) { return; } FP hor = Input.GetAxis("Horizontal"); FP ver = Input.GetAxis("Vertical"); bool space = Input.GetKey(KeyCode.Space); KBEngine.Event.fireIn("reqFrameChange", FrameProto.encode( new FrameBox(CMD.BOX, new TSVector(hor, 0, ver), space) )); }
private void Update() { if (!isAvatar) { return; } FrameDuration += Time.deltaTime; if (FrameDuration >= DestDuration) { FrameDuration = 0; if (framePool.Count > 0) { DestDuration = playTime / (framePool.Count <= ThresholdFrame ? 1 : framePool.Count / ThresholdFrame); var framedata = framePool.Dequeue(); TSVector movement = TSVector.zero; bool space = false; foreach (var item in framedata.Value.operation) { if (item.cmd_type != (UInt32)CMD.BOX) { continue; } FrameBox msg = FrameProto.decode(item) as FrameBox; movement = msg.movement; space = msg.space; } //KBEngine.Event.fireOut("recieveFrameTick", new object[] {entity.id, movement, space }); } } }
// Update is called once per frame void UpdateOrigin() { if (!isAvatar) { return; } FP dis = TSVector.Distance(Position, destPosition); FP currSpeed = DestDuration <= 0 ? Speed : (Speed * playTime / DestDuration); if (dis <= currSpeed * Time.deltaTime) { Position = destPosition; // Debug.LogError("----------diff time------------------:" + (playTime - FrameDuration)); } else { TSVector tempDirection = destPosition - Position; Position += tempDirection.normalized * currSpeed * Time.deltaTime; } FrameDuration += Time.deltaTime; if (FrameDuration >= DestDuration) { Position = destPosition; if (framePool.Count > 0) { DestDuration = playTime / (framePool.Count <= ThresholdFrame ? 1: framePool.Count / ThresholdFrame); // if(framePool.Count > 8) // Debug.LogError("framePool.Count too big:" + +framePool.Count); var framedata = framePool.Dequeue(); emptyFramesTime = 0.0f; // ThresholdFrame -= 1; // Debug.Log("frame.id:"+ framedata.Key + " framePool.Count" + framePool.Count ); TSVector movement = TSVector.zero; bool space = false; foreach (var item in framedata.Value.operation) { if (item.cmd_type != (UInt32)CMD.BOX) { continue; } FrameBox msg = FrameProto.decode(item) as FrameBox; movement = msg.movement; space = msg.space; } // Debug.Log("d_point:" + point); destPosition += Speed * movement * playTime; FrameDuration = 0.0f; } else if (lastFrameData != null) { // Debug.Log("emptyFramesTime," + emptyFramesTime); emptyFramesTime += Time.deltaTime; if (emptyFramesTime >= playTime) { // ThresholdFrame = (int)(emptyFramesTime / playTime); // Debug.LogError("one frame time out,emptyFramesTime:" + emptyFramesTime + ",ThresholdFrame:"+ ThresholdFrame); } } } }
public void AnalyseDataFromJoystick(FS_ENTITY_DATA data, FP speedRate) { FrameJoystick msg = FrameProto.decode(data) as FrameJoystick; TriggerEvent <FP, FP>(msg.OperationType, speedRate, msg.Angle); }
private void FrameProcess(byte[] message) { if (message.Length == 0) { return; } FrameAction cmd = (FrameAction)message[0]; var body = message.Skip(1).ToArray(); switch (cmd) { case FrameAction.RemoteReceive: if (body.Length > 1) { DestType dstType = (DestType)body[0]; switch (dstType) { case DestType.Unicast: if (body.Length > (1 + 4 + 1)) { byte[] fromAddr = body.Skip(1).Take(4).ToArray(); var strAddr = string.Join("", fromAddr.Select(s => { return(string.Format("{0:X02}", s)); })); FrameProto frameProto = (FrameProto)body.Skip(5).FirstOrDefault(); byte[] frameData = body.Skip(6).ToArray(); switch (frameProto) { case FrameProto.ICMP: break; case FrameProto.UDP: if (frameData.Length > 2) { byte srcPort = frameData[0]; byte dstPort = frameData[1]; byte[] data = frameData.Skip(2).ToArray(); if (!network.ContainsKey(strAddr) || (dstPort != (byte)UdpPort.VirtualUart1)) { break; } //var n = network[strAddr]; List <byte> concat = fromAddr.ToList(); concat.AddRange(data); if (subscriber.Count() > 0) { foreach (var sub in subscriber) { sub.Value(concat.ToArray()); } } } break; } } break; case DestType.Multcast: break; } } break; default: break; } }