private void Tick(object sender, TickEventArgs e) { var initialCount = packets.Count; // Move items along transporter foreach (var item in packets) { item.Location += speed; if (item.Location <= length) { continue; } // Output items at end var removed = output.Add(item.Packet); if (removed == item.Packet.Amount) { removePackets.Add(item); } else { item.Packet = item.Packet.NewAmount(item.Packet.Amount - removed); } } // Remove output items foreach (var item in removePackets) { packets.Remove(item); } removePackets.Clear(); // Add new items to transporter and remove from connected input var amount = rate.GetAmount(e.Tick); if (amount > 0) { var ps = input.Remove(filter, amount); foreach (var packet in ps) { packets.Add(new MovingPacket { Packet = packet, Location = 0, }); } } if (initialCount > 0 || packets.Count > 0) { OnPacketsMoved(new PacketsMovedArgs { Packets = packets }); } }
/// <summary> /// Construct a new device stream context. /// </summary> /// <param name="device"></param> /// <param name="initial_buffer_size"></param> public DeviceStream(IDevice <TMessage> device, int initial_buffer_size = 256) { this.device = device; buffer = new SequentialCircularBuffer <TMessage>(initial_buffer_size); device.Handle += (sender, args) => { buffer.Add(args.Received); }; sendQueue = new MessageQueue <TMessage>(device.Send, device.Name + " Buffer"); }
TransformerEnumerator(IFn xform, IEnumerator sourceEnum, bool multi) { _sourceEnum = sourceEnum; _xf = (IFn)xform.invoke(new TransformHelper(o => _buffer = _buffer.Add(o))); _multi = multi; }