/// <summary> /// Releases the first item of the queue (if existing) and adds it to the next module slot. /// </summary> public void ReleaseItem() { lock (_lock) { if (_queue.Items.IsNullOrEmpty() || !IsActive) { return; } var item = _queue.Items.Last(); _queue.Items.Remove(item); // udate itemId if there is a remaining item in the queue if (_queue.Items.LastOrDefault() != null) { _queue.ItemId = _queue.Items.Last().ItemId; } if (_queue.Items.IsNullOrEmpty()) { _module.RemoveItem(_queue); } _module.AddItem(item, Position + 1); } }
public void ItemPassed(ISimulatedItem item) { if (IsActive) { ItemPassedCount++; long itemId = (long)item.ItemId; if (_mosaicControlledJunction.Routings.ContainsKey(itemId)) { int lane = _mosaicControlledJunction.Routings[itemId]; if (lane >= _targetModules.Length) { throw new IndexOutOfRangeException("mosaic routes to port " + lane + " which does not exist in the simulation. origin module was " + _originModule.Name); } _originModule.RemoveItem(item); _targetModules[lane].AddItem(item); } _mosaicControlledJunction.SimulateRouting(item); } }
/// <summary> /// Releases the first item of the queue (if existing) and adds it to the next module slot. /// </summary> public void ReleaseStack() { lock (_lock) { if (!_stack.Items.Any() || !IsActive) { return; } // move whole stack by 1 slot _module.RemoveItem(_stack); var stackCopy = _stack.Clone(); stackCopy.IsFrozen = false; _module.AddItem(stackCopy, Position + 1); _stack.Items.Clear(); } }
public void ItemPassed(ISimulatedItem item) { if (IsActive) { ItemPassedCount++; switch (Mode) { case JunctionDistributionMode.SortOutNothing: return; case JunctionDistributionMode.SortOutEverything: _originModule.RemoveItem(item); _targetModule.AddItem(item); break; case JunctionDistributionMode.SortOutEverySecond: if (ItemPassedCount % 2 == 0) { _originModule.RemoveItem(item); _targetModule.AddItem(item); } break; case JunctionDistributionMode.SortOutRandomly: if (_random.Next(0, 1) == 1) { _originModule.RemoveItem(item); _targetModule.AddItem(item); } break; default: throw new NotImplementedException("JunctionDistributionMode"); } } }