fix: Removes GetObjectsInRange and fixes boat planks closing (#1579)

## BREAKING CHANGE

- Deletes `map.GetObjectsInRange` and `map.GetObejctsInBounds`

### Notes

Developers are expected to enumerate mobiles and items separately now using `map.GetMobilesInRange` and `map.GetItemsInRange`. This helps keep the code streamlined so we don't have to maintain multiple copies of ref struct enumerators that do the same thing.


### Fixes

- [X] Fixes bug with planks closing
- [X] Fixes issue with iterating items/mobiles from a null map
This commit is contained in:
Kamron Batman 2023-11-03 13:45:18 -07:00 • committed by GitHub
parent cb1638591b
commit 977fdc2c5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 543 additions and 461 deletions

View file

@ -21,6 +21,9 @@ namespace Server;
public partial class Map
{
private static ValueLinkList<Item> _emptyItemLinkList = new();
public static ref readonly ValueLinkList<Item> EmptyItemLinkList => ref _emptyItemLinkList;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ItemAtEnumerable<Item> GetItemsAt(Point3D p) => GetItemsAt<Item>(p);
@ -110,7 +113,15 @@ public partial class Map
{
_started = false;
_location = loc;
_linkList = ref map.GetRealSector(loc.m_X, loc.m_Y).Items;
if (map == null)
{
_linkList = ref EmptyItemLinkList;
}
else
{
_linkList = ref map.GetRealSector(loc.m_X, loc.m_Y).Items;
}
_version = 0;
_current = null;
}

View file

@ -21,6 +21,9 @@ namespace Server;
public partial class Map
{
private static ValueLinkList<Mobile> _emptyMobileLinkList = new();
public static ref readonly ValueLinkList<Mobile> EmptyMobileLinkList => ref _emptyMobileLinkList;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MobileAtEnumerable<Mobile> GetMobilesAt(Point3D p) => GetMobilesAt<Mobile>(p);
@ -110,7 +113,14 @@ public partial class Map
{
_started = false;
_location = loc;
_linkList = ref map.GetRealSector(loc.m_X, loc.m_Y).Mobiles;
if (map == null)
{
_linkList = ref EmptyMobileLinkList;
}
else
{
_linkList = ref map.GetRealSector(loc.m_X, loc.m_Y).Mobiles;
}
_version = 0;
_current = null;
}

View file

@ -865,25 +865,15 @@ public sealed partial class Map : IComparable<Map>, ISpanFormattable, ISpanParsa
public IPooledEnumerable<StaticTile[]> GetMultiTilesAt(int x, int y) =>
PooledEnumeration.GetMultiTiles(this, new Rectangle2D(x, y, 1, 1));
public IPooledEnumerable<IEntity> GetObjectsInRange(Point3D p) => GetObjectsInRange(p, Core.GlobalMaxUpdateRange);
public IPooledEnumerable<IEntity> GetObjectsInRange(Point3D p, int range) =>
GetObjectsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1));
public IPooledEnumerable<IEntity> GetObjectsInBounds(Rectangle2D bounds) =>
PooledEnumeration.GetEntities(this, bounds);
public bool CanFit(
Point3D p, int height, bool checkBlocksFit = false, bool checkMobiles = true,
bool requireSurface = true
) =>
CanFit(p.m_X, p.m_Y, p.m_Z, height, checkBlocksFit, checkMobiles, requireSurface);
) => CanFit(p.m_X, p.m_Y, p.m_Z, height, checkBlocksFit, checkMobiles, requireSurface);
public bool CanFit(
Point2D p, int z, int height, bool checkBlocksFit = false, bool checkMobiles = true,
bool requireSurface = true
) =>
CanFit(p.m_X, p.m_Y, z, height, checkBlocksFit, checkMobiles, requireSurface);
) => CanFit(p.m_X, p.m_Y, z, height, checkBlocksFit, checkMobiles, requireSurface);
public bool CanFit(
int x, int y, int z, int height, bool checkBlocksFit = false, bool checkMobiles = true,

View file

@ -17,7 +17,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Collections;
using Server.Items;
namespace Server;
@ -32,32 +31,13 @@ public static class PooledEnumeration
static PooledEnumeration()
{
EntitySelector = SelectEntities;
MultiSelector = SelectMultis;
MultiTileSelector = SelectMultiTiles;
}
public static Selector<IEntity> EntitySelector { get; set; }
public static Selector<Mobile> MobileSelector { get; set; }
public static Selector<BaseMulti> MultiSelector { get; set; }
public static Selector<StaticTile[]> MultiTileSelector { get; set; }
public static IEnumerable<IEntity> SelectEntities(Map.Sector s, Rectangle2D bounds)
{
var entities = new List<IEntity>(s.Mobiles.Count + s.Items.Count);
foreach (var mob in s.Mobiles)
{
entities.Add(mob);
}
foreach (var item in s.Items)
{
entities.Add(item);
}
return entities;
}
public static IEnumerable<BaseMulti> SelectMultis(Map.Sector s, Rectangle2D bounds)
{
var entities = new List<BaseMulti>(s.Multis.Count);
@ -126,9 +106,6 @@ public static class PooledEnumeration
}
}
public static PooledEnumerable<IEntity> GetEntities(Map map, Rectangle2D bounds) =>
PooledEnumerable<IEntity>.Instantiate(map, bounds, EntitySelector ?? SelectEntities);
public static PooledEnumerable<BaseMulti> GetMultis(Map map, Rectangle2D bounds) =>
PooledEnumerable<BaseMulti>.Instantiate(map, bounds, MultiSelector ?? SelectMultis);