fix: Adds GetClients to map iterators (#1574)
### Summary
Eliminates `IPooledEnumerable<NetState>` and `eable.Free()` from `Map` for clients. This drastically simplifies code that iterates in range, for example:
```cs
foreach (var m in m.GetClientsInRange(5))
{
}
```
The code above no longer requires an eable and calling `Free()`.
This commit is contained in:
parent
469b89370d
commit
cde59a82f2
13 changed files with 347 additions and 162 deletions
|
|
@ -332,11 +332,9 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
{
|
||||
var worldLoc = GetWorldLocation();
|
||||
|
||||
var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -1106,9 +1104,7 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
Span<byte> saWorldItem = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
|
||||
Span<byte> hsWorldItem = stackalloc byte[OutgoingEntityPackets.MaxWorldEntityPacketLength].InitializePacket();
|
||||
|
||||
var eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -1157,15 +1153,11 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
}
|
||||
else if (m_Map != null)
|
||||
{
|
||||
IPooledEnumerable<NetState> eable;
|
||||
|
||||
if (oldLocation.m_X != 0)
|
||||
{
|
||||
eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -1182,9 +1174,7 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
m_Location = location;
|
||||
OnLocationChange(oldRealLocation);
|
||||
|
||||
eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -1352,9 +1342,7 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
return;
|
||||
}
|
||||
|
||||
var eable = map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in map.GetClientsInRange(worldLoc, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -1488,15 +1476,11 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
{
|
||||
if (m_Parent == null)
|
||||
{
|
||||
IPooledEnumerable<NetState> eable;
|
||||
|
||||
if (m_Location.m_X != 0)
|
||||
{
|
||||
eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -1513,9 +1497,7 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
|
||||
SetLastMoved();
|
||||
|
||||
eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -2503,9 +2485,11 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
m_Map == null ? Map.MobileBoundsEnumerable<T>.Empty : m_Map.GetMobilesInRange<T>(m_Parent == null ? m_Location : GetWorldLocation(), range);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public IPooledEnumerable<NetState> GetClientsInRange(int range) =>
|
||||
m_Map.GetClientsInRange(m_Parent == null ? m_Location : GetWorldLocation(), range)
|
||||
?? PooledEnumeration.NullEnumerable<NetState>.Instance;
|
||||
public Map.ClientAtEnumerable GetClientsAt() => m_Map == null ? Map.ClientAtEnumerable.Empty : Map.GetClientsAt(m_Parent == null ? m_Location : GetWorldLocation());
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Map.ClientBoundsEnumerable GetClientsInRange(int range) =>
|
||||
m_Map == null ? Map.ClientBoundsEnumerable.Empty : Map.GetClientsInRange(m_Parent == null ? m_Location : GetWorldLocation(), range);
|
||||
|
||||
public bool GetTempFlag(int flag) => ((LookupCompactInfo()?.m_TempFlags ?? 0) & flag) != 0;
|
||||
|
||||
|
|
@ -3276,11 +3260,10 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
}
|
||||
|
||||
var worldLoc = GetWorldLocation();
|
||||
var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> buffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(text)].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -3308,11 +3291,10 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
}
|
||||
|
||||
var worldLoc = GetWorldLocation();
|
||||
var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> buffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLocalizedLength(args)].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
@ -3776,11 +3758,9 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
|
|||
return;
|
||||
}
|
||||
|
||||
var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength].InitializePacket();
|
||||
|
||||
foreach (var state in eable)
|
||||
foreach (var state in m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange()))
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue