Core/vmaps: Removed vmap lookup functions duplicating functionality of each other
Port From (https://github.com/TrinityCore/TrinityCore/commit/45ee989c70682c001d4467d97bf1ecedcf7dbcc3)
This commit is contained in:
@@ -174,24 +174,6 @@ namespace Game.Collision
|
||||
ModelIgnoreFlags flags;
|
||||
}
|
||||
|
||||
public class AreaInfoCallback : WorkerCallback
|
||||
{
|
||||
public AreaInfoCallback(ModelInstance[] val)
|
||||
{
|
||||
prims = val;
|
||||
}
|
||||
public override void Invoke(Vector3 point, uint entry)
|
||||
{
|
||||
if (prims[entry] == null)
|
||||
return;
|
||||
|
||||
prims[entry].IntersectPoint(point, aInfo);
|
||||
}
|
||||
|
||||
ModelInstance[] prims;
|
||||
public AreaInfo aInfo = new();
|
||||
}
|
||||
|
||||
public class LocationInfoCallback : WorkerCallback
|
||||
{
|
||||
public LocationInfoCallback(ModelInstance[] val, LocationInfo info)
|
||||
@@ -232,25 +214,6 @@ namespace Game.Collision
|
||||
PhaseShift _phaseShift;
|
||||
}
|
||||
|
||||
public class DynamicTreeAreaInfoCallback : WorkerCallback
|
||||
{
|
||||
public DynamicTreeAreaInfoCallback(PhaseShift phaseShift)
|
||||
{
|
||||
_phaseShift = phaseShift;
|
||||
_areaInfo = new AreaInfo();
|
||||
}
|
||||
|
||||
public override void Invoke(Vector3 p, GameObjectModel obj)
|
||||
{
|
||||
obj.IntersectPoint(p, _areaInfo, _phaseShift);
|
||||
}
|
||||
|
||||
public AreaInfo GetAreaInfo() { return _areaInfo; }
|
||||
|
||||
PhaseShift _phaseShift;
|
||||
AreaInfo _areaInfo;
|
||||
}
|
||||
|
||||
public class DynamicTreeLocationInfoCallback : WorkerCallback
|
||||
{
|
||||
public DynamicTreeLocationInfoCallback(PhaseShift phaseShift)
|
||||
|
||||
@@ -113,31 +113,9 @@ namespace Game.Collision
|
||||
return float.NegativeInfinity;
|
||||
}
|
||||
|
||||
public bool GetAreaInfo(float x, float y, ref float z, PhaseShift phaseShift, out uint flags, out int adtId, out int rootId, out int groupId)
|
||||
public bool GetAreaAndLiquidData(float x, float y, float z, PhaseShift phaseShift, byte? reqLiquidType, out AreaAndLiquidData data)
|
||||
{
|
||||
flags = 0;
|
||||
adtId = 0;
|
||||
rootId = 0;
|
||||
groupId = 0;
|
||||
|
||||
Vector3 v = new(x, y, z + 0.5f);
|
||||
DynamicTreeAreaInfoCallback intersectionCallBack = new(phaseShift);
|
||||
impl.IntersectPoint(v, intersectionCallBack);
|
||||
if (intersectionCallBack.GetAreaInfo().result)
|
||||
{
|
||||
flags = intersectionCallBack.GetAreaInfo().flags;
|
||||
adtId = intersectionCallBack.GetAreaInfo().adtId;
|
||||
rootId = intersectionCallBack.GetAreaInfo().rootId;
|
||||
groupId = intersectionCallBack.GetAreaInfo().groupId;
|
||||
z = intersectionCallBack.GetAreaInfo().ground_Z;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public AreaAndLiquidData GetAreaAndLiquidData(float x, float y, float z, PhaseShift phaseShift, byte reqLiquidType)
|
||||
{
|
||||
AreaAndLiquidData data = new();
|
||||
data = new();
|
||||
|
||||
Vector3 v = new(x, y, z + 0.5f);
|
||||
DynamicTreeLocationInfoCallback intersectionCallBack = new(phaseShift);
|
||||
@@ -147,17 +125,17 @@ namespace Game.Collision
|
||||
data.floorZ = intersectionCallBack.GetLocationInfo().ground_Z;
|
||||
uint liquidType = intersectionCallBack.GetLocationInfo().hitModel.GetLiquidType();
|
||||
float liquidLevel = 0;
|
||||
if (reqLiquidType == 0 || (Global.DB2Mgr.GetLiquidFlags(liquidType) & reqLiquidType) != 0)
|
||||
if (!reqLiquidType.HasValue || (Global.DB2Mgr.GetLiquidFlags(liquidType) & reqLiquidType.Value) != 0)
|
||||
if (intersectionCallBack.GetHitModel().GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), ref liquidLevel))
|
||||
data.liquidInfo = new AreaAndLiquidData.LiquidInfo(liquidType, liquidLevel);
|
||||
|
||||
data.areaInfo = new(intersectionCallBack.GetHitModel().GetNameSetId(), intersectionCallBack.GetLocationInfo().rootId,
|
||||
(int)intersectionCallBack.GetLocationInfo().hitModel.GetWmoID(), intersectionCallBack.GetLocationInfo().hitModel.GetMogpFlags());
|
||||
data.areaInfo = new((int)intersectionCallBack.GetLocationInfo().hitModel.GetWmoID(), intersectionCallBack.GetHitModel().GetNameSetId(), intersectionCallBack.GetLocationInfo().rootId, intersectionCallBack.GetLocationInfo().hitModel.GetMogpFlags(), 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return data;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
DynTreeImpl impl;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,66 +147,12 @@ namespace Game.Collision
|
||||
return MapConst.VMAPInvalidHeightValue;
|
||||
}
|
||||
|
||||
public bool GetAreaInfo(uint mapId, float x, float y, ref float z, out uint flags, out int adtId, out int rootId, out int groupId)
|
||||
|
||||
|
||||
public bool GetAreaAndLiquidData(uint mapId, float x, float y, float z, byte? reqLiquidType, out AreaAndLiquidData data)
|
||||
{
|
||||
flags = 0;
|
||||
adtId = 0;
|
||||
rootId = 0;
|
||||
groupId = 0;
|
||||
if (!Global.DisableMgr.IsVMAPDisabledFor(mapId, DisableFlags.VmapAreaFlag))
|
||||
{
|
||||
var instanceTree = iInstanceMapTrees.LookupByKey(mapId);
|
||||
if (instanceTree != null)
|
||||
{
|
||||
Vector3 pos = ConvertPositionToInternalRep(x, y, z);
|
||||
bool result = instanceTree.GetAreaInfo(ref pos, out flags, out adtId, out rootId, out groupId);
|
||||
// z is not touched by convertPositionToInternalRep(), so just copy
|
||||
z = pos.Z;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
data = new AreaAndLiquidData();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetLiquidLevel(uint mapId, float x, float y, float z, uint reqLiquidType, ref float level, ref float floor, ref uint type, ref uint mogpFlags)
|
||||
{
|
||||
if (!Global.DisableMgr.IsVMAPDisabledFor(mapId, DisableFlags.VmapLiquidStatus))
|
||||
{
|
||||
var instanceTree = iInstanceMapTrees.LookupByKey(mapId);
|
||||
if (instanceTree != null)
|
||||
{
|
||||
LocationInfo info = new();
|
||||
Vector3 pos = ConvertPositionToInternalRep(x, y, z);
|
||||
if (instanceTree.GetLocationInfo(pos, info))
|
||||
{
|
||||
floor = info.ground_Z;
|
||||
Cypher.Assert(floor < float.MaxValue);
|
||||
type = info.hitModel.GetLiquidType(); // entry from LiquidType.dbc
|
||||
mogpFlags = info.hitModel.GetMogpFlags();
|
||||
if (reqLiquidType != 0 && !Convert.ToBoolean(Global.DB2Mgr.GetLiquidFlags(type) & reqLiquidType))
|
||||
return false;
|
||||
if (info.hitInstance.GetLiquidLevel(pos, info, ref level))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public AreaAndLiquidData GetAreaAndLiquidData(uint mapId, float x, float y, float z, uint reqLiquidType)
|
||||
{
|
||||
var data = new AreaAndLiquidData();
|
||||
|
||||
if (Global.DisableMgr.IsVMAPDisabledFor(mapId, DisableFlags.VmapLiquidStatus))
|
||||
{
|
||||
data.floorZ = z;
|
||||
int adtId, rootId, groupId;
|
||||
uint flags;
|
||||
if (GetAreaInfo(mapId, x, y, ref data.floorZ, out flags, out adtId, out rootId, out groupId))
|
||||
data.areaInfo = new(adtId, rootId, groupId, flags);
|
||||
return data;
|
||||
}
|
||||
var instanceTree = iInstanceMapTrees.LookupByKey(mapId);
|
||||
if (instanceTree != null)
|
||||
{
|
||||
@@ -215,18 +161,24 @@ namespace Game.Collision
|
||||
if (instanceTree.GetLocationInfo(pos, info))
|
||||
{
|
||||
data.floorZ = info.ground_Z;
|
||||
uint liquidType = info.hitModel.GetLiquidType();
|
||||
float liquidLevel = 0;
|
||||
if (reqLiquidType == 0 || Convert.ToBoolean(Global.DB2Mgr.GetLiquidFlags(liquidType) & reqLiquidType))
|
||||
if (info.hitInstance.GetLiquidLevel(pos, info, ref liquidLevel))
|
||||
data.liquidInfo = new(liquidType, liquidLevel);
|
||||
|
||||
if (!Global.DisableMgr.IsVMAPDisabledFor(mapId, DisableFlags.VmapLiquidStatus))
|
||||
data.areaInfo = new(info.hitInstance.adtId, info.rootId, (int)info.hitModel.GetWmoID(), info.hitModel.GetMogpFlags());
|
||||
{
|
||||
uint liquidType = info.hitModel.GetLiquidType(); // entry from LiquidType.dbc
|
||||
float liquidLevel = 0;
|
||||
if (!reqLiquidType.HasValue || (Global.DB2Mgr.GetLiquidFlags(liquidType) & reqLiquidType.Value) != 0)
|
||||
if (info.hitInstance.GetLiquidLevel(pos, info, ref liquidLevel))
|
||||
data.liquidInfo = new(liquidType, liquidLevel);
|
||||
}
|
||||
|
||||
if (!Global.DisableMgr.IsVMAPDisabledFor(mapId, DisableFlags.VmapLiquidStatus))
|
||||
data.areaInfo = new((int)info.hitModel.GetWmoID(), info.hitInstance.adtId, info.rootId, info.hitModel.GetMogpFlags(), info.hitInstance.Id);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
return false;
|
||||
}
|
||||
|
||||
public WorldModel AcquireModelInstance(string filename)
|
||||
@@ -336,22 +288,25 @@ namespace Game.Collision
|
||||
|
||||
public class AreaAndLiquidData
|
||||
{
|
||||
public struct AreaInfo
|
||||
public class AreaInfo
|
||||
{
|
||||
public int GroupId;
|
||||
public int AdtId;
|
||||
public int RootId;
|
||||
public int GroupId;
|
||||
public uint MogpFlags;
|
||||
public uint UniqueId;
|
||||
|
||||
public AreaInfo(int adtId, int rootId, int groupId, uint flags)
|
||||
public AreaInfo(int groupId, int adtId, int rootId, uint mogpFlags, uint uniqueId)
|
||||
{
|
||||
GroupId = groupId;
|
||||
AdtId = adtId;
|
||||
RootId = rootId;
|
||||
GroupId = groupId;
|
||||
MogpFlags = flags;
|
||||
MogpFlags = mogpFlags;
|
||||
UniqueId = uniqueId;
|
||||
}
|
||||
}
|
||||
public struct LiquidInfo
|
||||
|
||||
public class LiquidInfo
|
||||
{
|
||||
public uint LiquidType;
|
||||
public float Level;
|
||||
@@ -364,7 +319,7 @@ namespace Game.Collision
|
||||
}
|
||||
|
||||
public float floorZ = MapConst.VMAPInvalidHeightValue;
|
||||
public AreaInfo? areaInfo;
|
||||
public LiquidInfo? liquidInfo;
|
||||
public AreaInfo areaInfo;
|
||||
public LiquidInfo liquidInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,27 +287,6 @@ namespace Game.Collision
|
||||
return $"{mapID:D4}_{tileY:D2}_{tileX:D2}.vmtile";
|
||||
}
|
||||
|
||||
public bool GetAreaInfo(ref Vector3 pos, out uint flags, out int adtId, out int rootId, out int groupId)
|
||||
{
|
||||
flags = 0;
|
||||
adtId = 0;
|
||||
rootId = 0;
|
||||
groupId = 0;
|
||||
|
||||
AreaInfoCallback intersectionCallBack = new(iTreeValues);
|
||||
iTree.IntersectPoint(pos, intersectionCallBack);
|
||||
if (intersectionCallBack.aInfo.result)
|
||||
{
|
||||
flags = intersectionCallBack.aInfo.flags;
|
||||
adtId = intersectionCallBack.aInfo.adtId;
|
||||
rootId = intersectionCallBack.aInfo.rootId;
|
||||
groupId = intersectionCallBack.aInfo.groupId;
|
||||
pos.Z = intersectionCallBack.aInfo.ground_Z;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetLocationInfo(Vector3 pos, LocationInfo info)
|
||||
{
|
||||
LocationInfoCallback intersectionCallBack = new(iTreeValues, info);
|
||||
|
||||
@@ -104,33 +104,6 @@ namespace Game.Collision
|
||||
return hit;
|
||||
}
|
||||
|
||||
public override void IntersectPoint(Vector3 point, AreaInfo info, PhaseShift phaseShift)
|
||||
{
|
||||
if (!IsCollisionEnabled() || !owner.IsSpawned() || !IsMapObject())
|
||||
return;
|
||||
|
||||
if (!owner.IsInPhase(phaseShift))
|
||||
return;
|
||||
|
||||
if (!iBound.contains(point))
|
||||
return;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot.Multiply(point - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot.Multiply(new Vector3(0.0f, 0.0f, -1.0f));
|
||||
float zDist;
|
||||
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
Vector3 modelGround = pModel + zDist * zDirModel;
|
||||
float world_Z = (iInvRot.Multiply(modelGround) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z)
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
info.adtId = owner.GetNameSetId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetLocationInfo(Vector3 point, LocationInfo info, PhaseShift phaseShift)
|
||||
{
|
||||
if (!IsCollisionEnabled() || !owner.IsSpawned() || !IsMapObject())
|
||||
|
||||
@@ -120,37 +120,6 @@ namespace Game.Collision
|
||||
return hit;
|
||||
}
|
||||
|
||||
public void IntersectPoint(Vector3 p, AreaInfo info)
|
||||
{
|
||||
if (iModel == null)
|
||||
return;
|
||||
|
||||
// M2 files don't contain area info, only WMO files
|
||||
if (iModel.IsM2())
|
||||
return;
|
||||
|
||||
if (!iBound.contains(p))
|
||||
return;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot.Multiply(p - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot.Multiply(new Vector3(0.0f, 0.0f, -1.0f));
|
||||
float zDist;
|
||||
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
Vector3 modelGround = pModel + zDist * zDirModel;
|
||||
// Transform back to world space. Note that:
|
||||
// Mat * vec == vec * Mat.transpose()
|
||||
// and for rotation matrices: Mat.inverse() == Mat.transpose()
|
||||
float world_Z = (iInvRot.Multiply(modelGround) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z)
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
info.adtId = adtId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetLiquidLevel(Vector3 p, LocationInfo info, ref float liqHeight)
|
||||
{
|
||||
// child bounds are defined in object space:
|
||||
|
||||
@@ -301,7 +301,7 @@ namespace Game.Collision
|
||||
if ((ignoreFlags & ModelIgnoreFlags.M2) != ModelIgnoreFlags.Nothing)
|
||||
{
|
||||
// M2 models are not taken into account for LoS calculation if caller requested their ignoring.
|
||||
if (Flags.HasFlag(ModelFlags.None))
|
||||
if (IsM2())
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -315,26 +315,6 @@ namespace Game.Collision
|
||||
return isc.hit;
|
||||
}
|
||||
|
||||
public bool IntersectPoint(Vector3 p, Vector3 down, out float dist, AreaInfo info)
|
||||
{
|
||||
dist = 0f;
|
||||
if (groupModels.Empty())
|
||||
return false;
|
||||
|
||||
WModelAreaCallback callback = new(groupModels, down);
|
||||
groupTree.IntersectPoint(p, callback);
|
||||
if (callback.hit != null)
|
||||
{
|
||||
info.rootId = (int)RootWMOID;
|
||||
info.groupId = (int)callback.hit.GetWmoID();
|
||||
info.flags = callback.hit.GetMogpFlags();
|
||||
info.result = true;
|
||||
dist = callback.zDist;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool GetLocationInfo(Vector3 p, Vector3 down, out float dist, GroupLocationInfo info)
|
||||
{
|
||||
dist = 0f;
|
||||
|
||||
Reference in New Issue
Block a user