/// <summary> /// Gets the slots that have changed. /// </summary> /// <param name="slotInfo">The data of the last scan.</param> /// <param name="slotFlags">Flags for the slots to check.</param> /// <returns>A List of slots that changed.</returns> /// <remarks> /// <para>The returned slots are slots that have been swapped, removed, or added to the game.</para> /// <para>The data of the scan is saved in <paramref name="slotInfo"/>. It is compared to next time it is used with this method. /// A new <see cref="SlotInfo"/> object will return every slot.</para> /// </remarks> /// <seealso cref="SlotInfo"/> public List <int> GetUpdatedSlots(SlotInfo slotInfo, SlotFlags slotFlags = SlotFlags.All) { using (LockHandler.Passive) { object listLock = new object(); List <int> changedSlots = new List <int>(); var slots = GetSlots(slotFlags); for (int slot = 0; slot < SlotCount; slot++) //Parallel.For(0, SlotCount, (slot) => { SlotIdentity slotIdentity = slots.Contains(slot) ? GetSlotIdentity(slot) : null; bool changed = true; // Slot emptied if (slotIdentity == null && slotInfo.SlotIdentities[slot] != null) { slotInfo.SlotIdentities[slot].Dispose(); slotInfo.SlotIdentities[slot] = null; } // Slot joined else if (slotIdentity != null && slotInfo.SlotIdentities[slot] == null) { slotInfo.SlotIdentities[slot] = slotIdentity; } // Slot swapped else if (slotIdentity != null && slotInfo.SlotIdentities[slot] != null && !Identity.Compare(slotInfo.SlotIdentities[slot], slotIdentity)) { slotInfo.SlotIdentities[slot].Dispose(); slotInfo.SlotIdentities[slot] = slotIdentity; } // Slot did not change else { if (slotIdentity != null) { slotIdentity.Dispose(); } changed = false; } if (changed) { lock (listLock) changedSlots.Add(slot); } } return(changedSlots); } }
public bool CompareIdentities(SlotIdentity other) { return(Identity.CompareIdentities(this, other)); }