/// <summary> /// /// </summary> /// <returns>how much receivers received the event</returns> public int Post(TContext ctx) { var receivers = ListPool <EventReceiver> .Request(); receivers.AddRange(_receivers); var receviersToBeRemove = SetPool <int> .Request(); try{ var postIndex = 0; while (postIndex < receivers.Count) { var receiver = receivers[postIndex]; receiver.action(ctx); postIndex++; if (receiver.type == CallbackType.Once) { receviersToBeRemove.Add(receiver.uniqueId); } } return(receivers.Count); }finally{ ListPool <EventReceiver> .Release(receivers); this.RemoveReceivers(receviersToBeRemove); SetPool <int> .Release(receviersToBeRemove); } }
private void UpdateViews() { var turnToVisibleItems = SetPool <int> .Request(); try{ if (_viewportDirty) { InternalDebug("calculate item views visible"); if (_visibleItems == null) { _visibleItems = SetPool <int> .Request(); } var newVisibleItems = SetPool <int> .Request(); this.layoutCalculator.GetOverlapsInViewport(_viewportRect, newVisibleItems); var oldVisibleItems = _visibleItems; try{ foreach (var index in oldVisibleItems) { if (!newVisibleItems.Contains(index)) { //change to invisible OnItemVisibleChanged(index, false); } } foreach (var index in newVisibleItems) { if (!oldVisibleItems.Contains(index)) { //change to visible OnItemVisibleChanged(index, true); turnToVisibleItems.Add(index); } } }finally{ _visibleItems = newVisibleItems; SetPool <int> .Release(oldVisibleItems); } } if (_itemsDirty) { foreach (var index in _visibleItems) { OnItemUpdate(index); } } else { foreach (var index in turnToVisibleItems) { OnItemUpdate(index); } } if (_layoutDirty) { InternalDebug("calculate item views layout"); foreach (var index in _visibleItems) { OnItemLayout(index); } } else { foreach (var index in turnToVisibleItems) { OnItemLayout(index); } } }finally{ _viewportDirty = false; _itemsDirty = false; _layoutDirty = false; SetPool <int> .Release(turnToVisibleItems); } }