private void ReadInput(Packet packet) { int maxFrame = Core.Frame; int minFrame = maxFrame - (Core.Config.commandDelayAllowed + PingFrames); while (packet.ReadStopMarker()) { NetworkId netId = packet.ReadNetworkId(); EntityProxy proxy = null; if (OutgoingProxiesByNetworkId.ContainsKey(netId)) { proxy = OutgoingProxiesByNetworkId[netId]; } while (packet.ReadStopMarker()) { Command cmd = Factory.NewCommand(packet.ReadTypeId()); cmd.Sequence = packet.ReadUShort(Command.SEQ_BITS); cmd.ServerFrame = packet.ReadIntVB(); cmd.InputObject.Token = packet.ReadToken(); cmd.ReadInput(connection, packet); // no proxy or entity if (!proxy || !proxy.Entity) { continue; } Entity entity = proxy.Entity; // remote is not controller if (ReferenceEquals(entity.Controller, connection) == false) { continue; } // sequence is old if (NetMath.SeqDistance(cmd.Sequence, entity.CommandSequence, Command.SEQ_SHIFT) <= 0) { continue; } // put on command queue entity.CommandQueue.AddLast(cmd); entity.CommandSequence = cmd.Sequence; } } }
private void ReadResult(Packet packet) { while (packet.CanRead()) { if (packet.ReadBool() == false) { break; } NetworkId netId = packet.ReadNetworkId(); EntityProxy proxy = IncommingProxiesByNetworkId[netId]; Entity entity = proxy.Entity; while (packet.CanRead()) { if (packet.ReadBool() == false) { break; } TypeId typeId = packet.ReadTypeId(); ushort sequence = packet.ReadUShort(Command.SEQ_BITS); IMessageRider resultToken = packet.ReadToken(); Command cmd = null; if (entity != null) { var it = entity.CommandQueue.GetIterator(); while (it.Next()) { int dist = NetMath.SeqDistance(it.val.Sequence, sequence, Command.SEQ_SHIFT); if (dist > 0) { break; } if (dist < 0) { it.val.Flags |= CommandFlags.DISPOSE; } if (dist == 0) { cmd = it.val; break; } } } if (cmd) { cmd.ResultObject.Token = resultToken; cmd.Flags |= CommandFlags.CORRECTION_RECEIVED; if (cmd.Meta.SmoothFrames > 0) { cmd.BeginSmoothing(); } cmd.ReadResult(connection, packet); } else { cmd = Factory.NewCommand(typeId); cmd.ReadResult(connection, packet); cmd.Free(); } } // remove all disposable commands if (entity != null) { while ((entity.CommandQueue.Count > 1) && (entity.CommandQueue.First.Flags & CommandFlags.DISPOSE)) { entity.CommandQueue.RemoveFirst().Free(); } } } }