ServUO Version
Publish Unknown
Ultima Expansion
None
(what I write here is based off of the RunUO 2.5 source code, but I suspect everything works essentially the same in ServUO).

I have been trying to understand how Item fetches are done, and encountered the various incarnations of the "GetItemsInBounds" / "GetItemsInRange" methods (in Map.cs and Item.cs) that return IPooledEnumerable<Item>. Coming from a C/C++ background I'm not so familiar with the IEnumerable interface.

I do understand, that the ItemEnumerator class only looks in the sectors that it needs to. On the other hand, I was wondering, what exactly is the advantage over doing something like the code below. Something similar is done in the CheckMovement() method in Movement.cs.

Is it that the compiler can more easily optimize?

C#:
public class MapUtility
{
        private static List<Sector> m_Sectors = new List<Sector>();

        // returns items xLower <= x < xLower + xRange;
        public static List<Item> GetItemsInBounds( Map map, int xLower, int yLower, int xRange, int yRange )
        {
                List<Item> Items = new List<Item>;

                m_Sectors.Clear();
                int xSectorLow = xLower >> Map.SectorShift;
                int xSectorHigh = (xLower + xRange - 1) >> Map.SectorShift;
                int ySectorLow = yLower >> Map.SectorShift;
                int ySectorHigh = (yLower + yRange - 1) >> Map.SectorShift;

                for(int x = xSectorLow; x <= xSectorHigh; x++) {
                        for(int y = ySectorLow; y <= ySectorHigh; y++) {
                                m_Sectors.Add( map.GetRealSector( x, y ) );
                        }
                }

                foreach( Sector sector in m_Sectors) {
                        foreach( Item item in sector.Items ) {
                                int x = item.Location.X - xLower;
                                int y = item.Location.Y - yLower;
                                if( x >= 0 && x < xRange && y >= 0 && y < yRange ) {
                                        Items.Add( item );
                                }
                        }
                }
                return Items;
        }
}
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back