fix: Refactors getting static tiles to use enumerators (#1611)
### Summary
* Refactors getting static/multi tiles to not use allocations.
* `TileList` is now only used during bootstrapping and uses rented buffers to eliminate extra allocations.
* Replaces `StaticTile[] GetStaticTiles` with:
```cs
Map.StaticTileEnumerable GetStaticTiles(int x, int y);
Map.StaticTileEnumerable GetStaticAndMultiTiles(int x, int y);
Map.StaticTileEnumerable GetMultiTiles(int x, int y);
```
* Removes `Synchronized` and `lock` from TileMatrix. It is no longer considered a multi-thread safe system.
This commit is contained in:
parent
3b1637b2da
commit
f21c9687b2
23 changed files with 359 additions and 512 deletions
|
|
@ -462,30 +462,10 @@ namespace Server.Engines.ConPVP
|
|||
return;
|
||||
}
|
||||
|
||||
var statics = Map.Tiles.GetStaticTiles(point.X, point.Y, true);
|
||||
|
||||
if (landTile.ID == 0x244 && statics.Length == 0) // 0x244 = invalid land tile
|
||||
var foundStatics = false;
|
||||
foreach (var t in Map.Tiles.GetStaticAndMultiTiles(point.X, point.Y))
|
||||
{
|
||||
var empty = true;
|
||||
foreach (var item in Map.GetItemsAt(point))
|
||||
{
|
||||
if (item != this)
|
||||
{
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty)
|
||||
{
|
||||
HitObject(point, landTop, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = 0; j < statics.Length; j++)
|
||||
{
|
||||
var t = statics[j];
|
||||
foundStatics = true;
|
||||
|
||||
var id = TileData.ItemTable[t.ID & TileData.MaxItemValue];
|
||||
height = id.CalcHeight;
|
||||
|
|
@ -506,6 +486,25 @@ namespace Server.Engines.ConPVP
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (landTile.ID == 0x244 && foundStatics) // 0x244 = invalid land tile
|
||||
{
|
||||
var empty = true;
|
||||
foreach (var item in Map.GetItemsAt(point))
|
||||
{
|
||||
if (item != this)
|
||||
{
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty)
|
||||
{
|
||||
HitObject(point, landTop, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var rect = new Rectangle2D(pTop.X, pTop.Y, pBottom.X - pTop.X + 1, pBottom.Y - pTop.Y + 1);
|
||||
|
|
@ -640,14 +639,10 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
var myZ = Map?.GetAverageZ(X, Y) ?? 0;
|
||||
|
||||
var statics = Map?.Tiles?.GetStaticTiles(X, Y, true);
|
||||
|
||||
if (statics != null)
|
||||
if (Map?.Tiles != null)
|
||||
{
|
||||
for (var j = 0; j < statics.Length; j++)
|
||||
foreach (var t in Map.Tiles.GetStaticAndMultiTiles(X, Y))
|
||||
{
|
||||
var t = statics[j];
|
||||
|
||||
var id = TileData.ItemTable[t.ID & TileData.MaxItemValue];
|
||||
height = id.CalcHeight;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue