ModernUO/Projects/UOContent/Mobiles
Kamron Batman a4cabe2fa4
fix: Optimizes FindItemsByType by removing allocations. (#1515)
### Summary
Container enumeration is in dire need of optimization. Thanks to @stefanomerotta for initiating this work with PR #1443. This PR handles a small part of what Stefan started. Also included are some bug fixes.

### Method Signatures

```cs
// Use with foreach without moving/deleting items
FindItemsByTypeEnumerator<T> FindItemsByType<T>(bool recurse = true, Predicate<T> predicate = null)

// Use with foreach when moving/deleting items
QueuedItemsEnumerator<T> EnumerateItemsByType<T>(bool recurse = true, Predicate<T> predicate = null)

// Use when iterating multiple times or queuing
PooledRefQueue<T> QueueItemsByType<T>(bool recurse = true, Predicate<T> predicate = null)

// Use when iterating multiples times or manipulating elements without traversing
PooledRefList<T> ListItemsByType<T>(bool recurse = true, Predicate<T> predicate = null)
```

* `FindItemsByType<T>` has changed from returning `List<T>` to `FindItemsByTypeEnumerator<T>` - This method is not safe to use in situations where an item may get consumed, deleted, or moved.

* `EnumerateItemsByType<T>` was added as a safe way to iterate and manipulate items.
  * **Note**: EnumerateItemsByType will _completely traverse the container_ before iteration starts because it uses `QueueItemsByType` under the hood.

* `QueueItemsByType<T>`  and `ListItemsByType<T>` was added to return a queue or list of items to iterate multiple times and manipulate the items. This isn't the most efficient since it uses a predicate and can result in 2 or 3 total iterations unnecessarily.

### Bug Fixes
- [X] Fishing had an error in the random check that may have caused slight bias.
2023-09-28 19:36:45 -07:00
..
Abilities fix: Fixes stabled, abilities targeting self, and unsummon memory leak (#1418) 2023-07-03 09:45:22 -07:00
AI fix: Hireables should not drop their pack (#1503) 2023-09-17 17:24:59 -07:00
Animals feat: Adds Stamina System to overhaul overweight. (#1465) 2023-09-16 17:52:54 -07:00
Familiars fix: Codegens familiars (#1473) 2023-08-25 20:51:38 -07:00
Guards fix: Codegens guards (#1474) 2023-08-25 20:59:11 -07:00
Healers fix: Codegens healers and fixes flamespurt trap (#1475) 2023-08-25 21:20:13 -07:00
Hireables fix: Hireables should not drop their pack (#1503) 2023-09-17 17:24:59 -07:00
Monsters fix: Codegens familiars (#1473) 2023-08-25 20:51:38 -07:00
Special feat: Adds Stamina System to overhaul overweight. (#1465) 2023-09-16 17:52:54 -07:00
Townfolk fix: Optimizes FindItemsByType by removing allocations. (#1515) 2023-09-28 19:36:45 -07:00
Vendors fix: Fixes arbitrage by adjusting prices. (#1500) 2023-09-15 19:22:35 -07:00
BaseCreature.cs fix: Fixes more packet initializations (#1507) 2023-09-19 00:02:17 -07:00
NPCSpeeds.cs fix: Makes NPC active movement half think speed (#1256) 2022-11-20 20:05:43 -08:00
PlayerMobile.cs fix: Optimizes FindItemsByType by removing allocations. (#1515) 2023-09-28 19:36:45 -07:00
VirtualMountItem.cs feat: Adds Stamina System to overhaul overweight. (#1465) 2023-09-16 17:52:54 -07:00