Core/AreaTriggers: Optimize target searching
Port From (https://github.com/TrinityCore/TrinityCore/commit/23144d0665504e2e24ee790e900bb8de0df4aa08)
This commit is contained in:
@@ -347,6 +347,21 @@ namespace Game.Entities
|
||||
HandleUnitEnterExit(targetList);
|
||||
}
|
||||
|
||||
void SearchUnits(List<Unit> targetList, float radius, bool check3D)
|
||||
{
|
||||
var check = new AnyUnitInObjectRangeCheck(this, radius, check3D);
|
||||
if (IsServerSide())
|
||||
{
|
||||
var searcher = new PlayerListSearcher(this, targetList, check);
|
||||
Cell.VisitWorldObjects(this, searcher, GetTemplate().MaxSearchRadius);
|
||||
}
|
||||
else
|
||||
{
|
||||
var searcher = new UnitListSearcher(this, targetList, check);
|
||||
Cell.VisitAllObjects(this, searcher, GetTemplate().MaxSearchRadius);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchUnitInSphere(List<Unit> targetList)
|
||||
{
|
||||
float radius = GetTemplate().SphereDatas.Radius;
|
||||
@@ -358,9 +373,7 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
var check = new AnyUnitInObjectRangeCheck(this, radius);
|
||||
var searcher = new UnitListSearcher(this, targetList, check);
|
||||
Cell.VisitAllObjects(this, searcher, GetTemplate().MaxSearchRadius);
|
||||
SearchUnits(targetList, radius, true);
|
||||
}
|
||||
|
||||
void SearchUnitInBox(List<Unit> targetList)
|
||||
@@ -374,9 +387,7 @@ namespace Game.Entities
|
||||
extentsZ = GetTemplate().BoxDatas.Extents[2];
|
||||
}
|
||||
|
||||
var check = new AnyUnitInObjectRangeCheck(this, GetTemplate().MaxSearchRadius, false);
|
||||
var searcher = new UnitListSearcher(this, targetList, check);
|
||||
Cell.VisitAllObjects(this, searcher, GetTemplate().MaxSearchRadius);
|
||||
SearchUnits(targetList, GetTemplate().MaxSearchRadius, false);
|
||||
|
||||
float halfExtentsX = extentsX / 2.0f;
|
||||
float halfExtentsY = extentsY / 2.0f;
|
||||
@@ -398,30 +409,24 @@ namespace Game.Entities
|
||||
|
||||
void SearchUnitInPolygon(List<Unit> targetList)
|
||||
{
|
||||
var check = new AnyUnitInObjectRangeCheck(this, GetTemplate().MaxSearchRadius, false);
|
||||
var searcher = new UnitListSearcher(this, targetList, check);
|
||||
Cell.VisitAllObjects(this, searcher, GetTemplate().MaxSearchRadius);
|
||||
SearchUnits(targetList, GetTemplate().MaxSearchRadius, false);
|
||||
|
||||
float height = GetTemplate().PolygonDatas.Height;
|
||||
float minZ = GetPositionZ() - height;
|
||||
float maxZ = GetPositionZ() + height;
|
||||
|
||||
targetList.RemoveAll(unit =>
|
||||
!CheckIsInPolygon2D(unit) || unit.GetPositionZ() < minZ || unit.GetPositionZ() > maxZ);
|
||||
targetList.RemoveAll(unit => !CheckIsInPolygon2D(unit) || unit.GetPositionZ() < minZ || unit.GetPositionZ() > maxZ);
|
||||
}
|
||||
|
||||
void SearchUnitInCylinder(List<Unit> targetList)
|
||||
{
|
||||
var check = new AnyUnitInObjectRangeCheck(this, GetTemplate().MaxSearchRadius, false);
|
||||
var searcher = new UnitListSearcher(this, targetList, check);
|
||||
Cell.VisitAllObjects(this, searcher, GetTemplate().MaxSearchRadius);
|
||||
SearchUnits(targetList, GetTemplate().MaxSearchRadius, false);
|
||||
|
||||
float height = GetTemplate().CylinderDatas.Height;
|
||||
float minZ = GetPositionZ() - height;
|
||||
float maxZ = GetPositionZ() + height;
|
||||
|
||||
targetList.RemoveAll(unit => unit.GetPositionZ() < minZ
|
||||
|| unit.GetPositionZ() > maxZ);
|
||||
targetList.RemoveAll(unit => unit.GetPositionZ() < minZ || unit.GetPositionZ() > maxZ);
|
||||
}
|
||||
|
||||
void HandleUnitEnterExit(List<Unit> newTargetList)
|
||||
|
||||
@@ -2899,8 +2899,8 @@ namespace Game.Entities
|
||||
if (spellInfo.GetSpellVisual() != 0 && (focusSpell.GetCastTime() == 0 || // if the spell is instant cast
|
||||
spellInfo.HasAttribute(SpellAttr5.DontTurnDuringCast))) // client gets confused if we attempt to turn at the regularly scheduled update packet
|
||||
{
|
||||
List<Player> playersNearby = GetPlayerListInGrid(GetVisibilityRange());
|
||||
foreach (var player in playersNearby)
|
||||
List<Unit> playersNearby = GetPlayerListInGrid(GetVisibilityRange());
|
||||
foreach (Player player in playersNearby)
|
||||
{
|
||||
// only update players that are known to the client (have already been created)
|
||||
if (player.HaveAtClient(this))
|
||||
|
||||
@@ -1578,9 +1578,9 @@ namespace Game.Entities
|
||||
Cell.VisitGridObjects(this, searcher, maxSearchRange);
|
||||
}
|
||||
|
||||
public List<Player> GetPlayerListInGrid(float maxSearchRange)
|
||||
public List<Unit> GetPlayerListInGrid(float maxSearchRange)
|
||||
{
|
||||
List<Player> playerList = new List<Player>();
|
||||
List<Unit> playerList = new List<Unit>();
|
||||
var checker = new AnyPlayerInObjectRangeCheck(this, maxSearchRange);
|
||||
var searcher = new PlayerListSearcher(this, playerList, checker);
|
||||
|
||||
@@ -1633,12 +1633,13 @@ namespace Game.Entities
|
||||
{
|
||||
if (!IsInWorld)
|
||||
return;
|
||||
List<Player> targets = new List<Player>();
|
||||
|
||||
List<Unit> targets = new List<Unit>();
|
||||
var check = new AnyPlayerInObjectRangeCheck(this, GetVisibilityRange(), false);
|
||||
var searcher = new PlayerListSearcher(this, targets, check);
|
||||
|
||||
Cell.VisitWorldObjects(this, searcher, GetVisibilityRange());
|
||||
foreach (var player in targets)
|
||||
foreach (Player player in targets)
|
||||
{
|
||||
if (player == this)
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user