fix: Changes Map.Sector.Items to link list. (#1547)
### Summary
Eliminates `IPooledEnumerable<T>` and `eable.Free()` from `Map` for items. This drastically simplifies code that iterates in range, for example:
```cs
foreach (var item in m.GetItemsInRange(5))
{
}
```
The code above no longer requires an eable and calling `Free()`.
This commit is contained in:
parent
1330c4a830
commit
24858f3989
42 changed files with 577 additions and 419 deletions
|
|
@ -35,7 +35,6 @@ public static class PooledEnumeration
|
|||
ClientSelector = SelectClients;
|
||||
EntitySelector = SelectEntities;
|
||||
MobileSelector = SelectMobiles<Mobile>;
|
||||
ItemSelector = SelectItems<Item>;
|
||||
MultiSelector = SelectMultis;
|
||||
MultiTileSelector = SelectMultiTiles;
|
||||
}
|
||||
|
|
@ -43,7 +42,6 @@ public static class PooledEnumeration
|
|||
public static Selector<NetState> ClientSelector { get; set; }
|
||||
public static Selector<IEntity> EntitySelector { get; set; }
|
||||
public static Selector<Mobile> MobileSelector { get; set; }
|
||||
public static Selector<Item> ItemSelector { get; set; }
|
||||
public static Selector<BaseMulti> MultiSelector { get; set; }
|
||||
public static Selector<StaticTile[]> MultiTileSelector { get; set; }
|
||||
|
||||
|
|
@ -66,26 +64,20 @@ public static class PooledEnumeration
|
|||
public static IEnumerable<IEntity> SelectEntities(Map.Sector s, Rectangle2D bounds)
|
||||
{
|
||||
var entities = new List<IEntity>(s.Mobiles.Count + s.Items.Count);
|
||||
for (int i = s.Mobiles.Count - 1, j = s.Items.Count - 1; i >= 0 || j >= 0; --i, --j)
|
||||
for (int i = s.Mobiles.Count - 1; i >= 0; --i)
|
||||
{
|
||||
if (j >= 0)
|
||||
Mobile mob = s.Mobiles[i];
|
||||
if (mob is { Deleted: false } && bounds.Contains(mob.Location))
|
||||
{
|
||||
Item item = s.Items[j];
|
||||
if (item is { Deleted: false, Parent: null } && bounds.Contains(item.Location))
|
||||
{
|
||||
entities.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 0)
|
||||
{
|
||||
Mobile mob = s.Mobiles[i];
|
||||
if (mob is { Deleted: false } && bounds.Contains(mob.Location))
|
||||
{
|
||||
entities.Add(mob);
|
||||
}
|
||||
entities.Add(mob);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in s.Items)
|
||||
{
|
||||
entities.Add(item);
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
|
|
@ -102,19 +94,6 @@ public static class PooledEnumeration
|
|||
return entities;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> SelectItems<T>(Map.Sector s, Rectangle2D bounds) where T : Item
|
||||
{
|
||||
var entities = new List<T>(s.Items.Count);
|
||||
for (int i = s.Items.Count - 1; i >= 0; --i)
|
||||
{
|
||||
if (s.Items[i] is T { Deleted: false, Parent: null } item && bounds.Contains(item.Location))
|
||||
{
|
||||
entities.Add(item);
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
public static IEnumerable<BaseMulti> SelectMultis(Map.Sector s, Rectangle2D bounds)
|
||||
{
|
||||
var entities = new List<BaseMulti>(s.Multis.Count);
|
||||
|
|
@ -195,9 +174,6 @@ public static class PooledEnumeration
|
|||
public static PooledEnumerable<T> GetMobiles<T>(Map map, Rectangle2D bounds) where T : Mobile =>
|
||||
PooledEnumerable<T>.Instantiate(map, bounds, SelectMobiles<T>);
|
||||
|
||||
public static PooledEnumerable<T> GetItems<T>(Map map, Rectangle2D bounds) where T : Item =>
|
||||
PooledEnumerable<T>.Instantiate(map, bounds, SelectItems<T>);
|
||||
|
||||
public static PooledEnumerable<BaseMulti> GetMultis(Map map, Rectangle2D bounds) =>
|
||||
PooledEnumerable<BaseMulti>.Instantiate(map, bounds, MultiSelector ?? SelectMultis);
|
||||
|
||||
|
|
@ -363,7 +339,7 @@ public static class PooledEnumeration
|
|||
|
||||
#pragma warning disable CA1000 // Do not declare static members on generic types
|
||||
public static PooledEnumerable<T> Instantiate(
|
||||
Map map, Rectangle2D bounds, PooledEnumeration.Selector<T> selector
|
||||
Map map, Rectangle2D bounds, Selector<T> selector
|
||||
)
|
||||
{
|
||||
PooledEnumerable<T> e = null;
|
||||
|
|
@ -376,7 +352,7 @@ public static class PooledEnumeration
|
|||
}
|
||||
}
|
||||
|
||||
var pool = PooledEnumeration.EnumerateSectors(map, bounds).SelectMany(s => selector(s, bounds));
|
||||
var pool = EnumerateSectors(map, bounds).SelectMany(s => selector(s, bounds));
|
||||
|
||||
if (e == null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue