Ejemplo n.º 1
0
        public void clientCorrection(Player p, UserMessage um)
        {
            while(um.Time > buffer[head].Time && head != tail){
                head = (head + 1) % capacity;
            }

            if(head != tail && um.Time.Equals(buffer[head].Time)){

                if(VectorUtils.Distance(buffer[head].Position, um.Position) > 1){

                    DateTime currentTime = um.Time;
                    Input currentInput = um.Input;
                    p.Position = um.Position;
                    p.FallSpeed = um.FallSpeed;

                    head = (head + 1) % capacity;
                    int index = head;

                    while(index != tail){
                        float deltaTime = (float) (buffer[index].Time - currentTime).TotalSeconds;

                        p.Update(deltaTime, currentInput);

                        currentTime = buffer[index].Time;
                        currentInput = buffer[index].Input;

                        buffer[index].Position = p.Position;
                        buffer[index].FallSpeed = p.FallSpeed;
                        index = (index + 1) % capacity;

                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void Update(float frameTime)
        {
            if (inputManager.Input.LeftMouseButton) {
                BlockUpdate bu = new BlockUpdate(clientId);
                bu.Added = true;
                bu.Position = GetWorldMouse();
                bu.BlockType = (byte) blockType;
                bu.Layer = (byte) player.Layer;
                SendPacket(bu);
            }

            if (inputManager.Input.RightMouseButton) {
                BlockUpdate bu = new BlockUpdate(clientId);
                bu.Added = false;
                bu.Position = GetWorldMouse();
                bu.Layer = (byte) player.Layer;
                SendPacket(bu);
            }

            player.LookAt(GetWorldMouse());
            player.Update(frameTime, inputManager.Input);
            UpdateCam();

            UserMessage uMsg = new UserMessage(clientId);
            uMsg.Position = player.Position;
            uMsg.Ticktime = frameTime;
            uMsg.EyePosition = GetWorldMouse();
            uMsg.FallSpeed = player.FallSpeed;
            uMsg.Input = inputManager.Input;
            uMsg.Layer = (byte) player.Layer;
            uMsg.Nolcip = player.Noclip;
            SendPacket(uMsg);

            uMsgBuffer.insert(uMsg);
        }
Ejemplo n.º 3
0
 public static new UserMessage decode(ref Lidgren.Network.NetIncomingMessage msg)
 {
     UserMessage um = new UserMessage (Packet.decode (ref msg).ClientId);
     um.time = DateTime.FromBinary (msg.ReadInt64 ());
     um.input.Up = msg.ReadBoolean ();
     um.input.Down = msg.ReadBoolean ();
     um.input.Left = msg.ReadBoolean ();
     um.input.Right = msg.ReadBoolean ();
     um.position = new Vector2f (msg.ReadFloat (), msg.ReadFloat ());
     um.ticktime = msg.ReadFloat();
     um.EyePosition = new Vector2f(msg.ReadFloat(), msg.ReadFloat());
     um.fallSpeed = msg.ReadFloat();
     um.layer = msg.ReadByte();
     um.noclip = msg.ReadBoolean();
     return um;
 }
Ejemplo n.º 4
0
 public void insert(UserMessage um)
 {
     buffer[tail] = um;
     tail = (tail + 1) % capacity;
 }