protected virtual void Tick(object sender, TickEventArgs args)
        {
            var tick   = args.Tick;
            var amount = Rate.GetAmount(tick);

            if (amount == 0)
            {
                if (!IsActive)
                {
                    return;
                }
                IsActive = false;
                OnDeactivated();
                return;
            }

            var activated = Process(amount);

            if (!IsActive && activated)
            {
                IsActive = true;
                OnActivated();
            }
            else if (IsActive && !activated)
            {
                IsActive = false;
                OnDeactivated();
            }
        }
Esempio n. 2
0
        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
                });
            }
        }
Esempio n. 3
0
 protected virtual void OnTick(TickEventArgs e)
 {
     Tick?.Invoke(this, e);
 }