Fixes #2682. Thanks @DatMoshu for the detailed report and repro. While fixing it I audited the other map, item and multi enumerators for the same class of defect. None repeats #2682 itself, but four others turned up. All are fixed here. ## Fixes - **`StaticTileEnumerator` (#2682)**: `SetMulti` returned `SetTile()` for the first multi whose bounds contained the point. If that multi had no tile at the cell, the enumeration ended and every later multi in the sector was skipped. Movement and line of sight lost a floor that stood inside another multi's bounding box. It now moves on to the next multi. - **`MultiBoundsEnumerator`**: deduplication used one static `HashSet` that every new query cleared. A query run inside another made the outer query skip multis or return them twice. Each multi is now yielded only from the sector that holds its `Location`; the bounds filter guarantees that sector is visited. A per-enumerator set covers a multi that isn't registered in that sector (components changed after placement). Normal queries allocate nothing. - **`Item`/`Mobile`/`ClientDistanceEnumerator`**: ring sectors were bounded only by `sx >= _sectorStartX`. Ring cells past the map edge resolved to the shared invalid sector, once per cell. Entities at off-map coordinates were returned more than once, and sectors outside the query were created lazily. The check now covers all four sides. Results match the bounds enumerators, which never returned off-map entities. - **`BaseBoat.MovingEntitiesEnumerator`**: `GetMovingEntities` handles a null map, but the enumerator constructor still called `boat.Map.GetMobilesInBounds` and threw. A boat with no map now gets empty enumerators. - **`BaseDoor.ChainEnumerator`**: the walk stopped only on returning to the start door. Links are set in pairs, so `[ChainLink A B C` followed by `[Link B C` leaves A→B→C→B, and enumerating that chain never ended. The walk now stops on any door it has already yielded. Only reachable when `UseChainedFunctionality` is true, which is off in base and in all shipped content. ## Testing - A regression test for each fix except the boat null guard. Each failed before its fix and passes after. - Server.Tests 910/910. UOContent.Tests 1185 passed, 2 skipped. - Test note: the `MultiComponentList(List<MultiTileEntry>)` constructor drops entries after the first whose `Flags` are 0. The new test multis use non-zero flags.
143 lines
4.9 KiB
C#
143 lines
4.9 KiB
C#
/*************************************************************************
|
|
* ModernUO *
|
|
* Copyright 2019-2026 - ModernUO Development Team *
|
|
* Email: hi@modernuo.com *
|
|
* File: Map.StaticTileEnumerator.cs *
|
|
* *
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
*************************************************************************/
|
|
|
|
using System.Runtime.CompilerServices;
|
|
using Server.Items;
|
|
|
|
namespace Server;
|
|
|
|
public partial class Map
|
|
{
|
|
public readonly ref struct StaticTileEnumerable
|
|
{
|
|
public static StaticTileEnumerable Empty
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get => new();
|
|
}
|
|
|
|
private readonly Map _map;
|
|
private readonly Point2D _location;
|
|
private readonly bool _includeStatics;
|
|
private readonly bool _includeMultis;
|
|
|
|
public StaticTileEnumerable(Map map, Point2D loc, bool includeStatics = true, bool includeMultis = true)
|
|
{
|
|
_map = map;
|
|
_location = loc;
|
|
_includeStatics = includeStatics;
|
|
_includeMultis = includeMultis;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public StaticTileEnumerator GetEnumerator() => new(_map, _location, _includeStatics, _includeMultis);
|
|
}
|
|
|
|
public ref struct StaticTileEnumerator
|
|
{
|
|
private readonly Map _map;
|
|
private readonly Point2D _point;
|
|
|
|
private StaticTile[] _tiles;
|
|
private MultiSectorEnumerator<BaseMulti> _multis;
|
|
private BaseMulti _currentMulti;
|
|
|
|
private int _index;
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public StaticTileEnumerator(Map map, Point2D p, bool includeStatics, bool includeMultis)
|
|
{
|
|
_map = map;
|
|
_point = p;
|
|
|
|
if (_map == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (includeStatics)
|
|
{
|
|
var tiles = map.Tiles.GetStaticBlock(p.X >> TileMatrix.SectorShift, p.Y >> TileMatrix.SectorShift);
|
|
_tiles = tiles[p.X & 0x7][p.Y & 0x7];
|
|
_index = -1;
|
|
}
|
|
|
|
_multis = includeMultis
|
|
? _map.GetMultisInSector(p).GetEnumerator()
|
|
: MultiSectorEnumerable<BaseMulti>.Empty.GetEnumerator();
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
private bool SetMulti()
|
|
{
|
|
ref var multis = ref _multis;
|
|
ref readonly var p = ref _point;
|
|
|
|
while (multis.MoveNext())
|
|
{
|
|
var multi = multis.Current;
|
|
_currentMulti = multi;
|
|
var components = multi!.Components;
|
|
var location = multi!.Location;
|
|
|
|
var offsetX = p.X - location.X - components.Min.X;
|
|
var offsetY = p.Y - location.Y - components.Min.Y;
|
|
|
|
if (offsetX >= 0 && offsetY >= 0 && offsetX < components.Width && offsetY < components.Height)
|
|
{
|
|
_tiles = multi.Components.Tiles[offsetX][offsetY];
|
|
_index = -1;
|
|
|
|
// A multi can have no tile at this cell; later multis in the sector still may
|
|
if (SetTile())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
private bool SetTile() => _tiles != null && ++_index < _tiles.Length;
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public bool MoveNext() => _map != null && (SetTile() || SetMulti());
|
|
|
|
public StaticTile Current
|
|
{
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
get
|
|
{
|
|
if (_currentMulti == null)
|
|
{
|
|
return _tiles[_index];
|
|
}
|
|
|
|
var location = _currentMulti.Location;
|
|
ref readonly var tile = ref _tiles[_index];
|
|
return new StaticTile
|
|
{
|
|
m_ID = tile.m_ID,
|
|
X = tile.m_X,
|
|
Y = tile.m_Y,
|
|
Z = tile.m_Z + location.Z,
|
|
m_Hue = tile.m_Hue
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|