Core/GameObjects: Skip gameobjects with M2 models when searching for area info (perf optimization, they dont have any area info)
This commit is contained in:
@@ -49,7 +49,6 @@ namespace Framework.Constants
|
|||||||
public const int MapLiquidTypeMagma = 0x04;
|
public const int MapLiquidTypeMagma = 0x04;
|
||||||
public const int MapLiquidTypeSlime = 0x08;
|
public const int MapLiquidTypeSlime = 0x08;
|
||||||
public const int MapLiquidTypeDarkWater = 0x10;
|
public const int MapLiquidTypeDarkWater = 0x10;
|
||||||
public const int MapLiquidTypeWMOWater = 0x20;
|
|
||||||
public const int MapAllLiquidTypes = (MapLiquidTypeWater | MapLiquidTypeOcean | MapLiquidTypeMagma | MapLiquidTypeSlime);
|
public const int MapAllLiquidTypes = (MapLiquidTypeWater | MapLiquidTypeOcean | MapLiquidTypeMagma | MapLiquidTypeSlime);
|
||||||
public const float LiquidTileSize = (533.333f / 128.0f);
|
public const float LiquidTileSize = (533.333f / 128.0f);
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ namespace Framework.Constants
|
|||||||
public const float MaxFallDistance = 250000.0f;
|
public const float MaxFallDistance = 250000.0f;
|
||||||
|
|
||||||
public const string MapMagic = "MAPS";
|
public const string MapMagic = "MAPS";
|
||||||
public const string MapVersionMagic = "v1.8";
|
public const string MapVersionMagic = "v1.9";
|
||||||
public const string MapAreaMagic = "AREA";
|
public const string MapAreaMagic = "AREA";
|
||||||
public const string MapHeightMagic = "MHGT";
|
public const string MapHeightMagic = "MHGT";
|
||||||
public const string MapLiquidMagic = "MLIQ";
|
public const string MapLiquidMagic = "MLIQ";
|
||||||
@@ -71,7 +70,7 @@ namespace Framework.Constants
|
|||||||
public const string mmapMagic = "MMAP";
|
public const string mmapMagic = "MMAP";
|
||||||
public const int mmapVersion = 8;
|
public const int mmapVersion = 8;
|
||||||
|
|
||||||
public const string VMapMagic = "VMAP_4.6";
|
public const string VMapMagic = "VMAP_4.7";
|
||||||
public const float VMAPInvalidHeightValue = -200000.0f;
|
public const float VMAPInvalidHeightValue = -200000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ using Framework.GameMath;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Framework.Constants;
|
||||||
|
|
||||||
namespace Game.Collision
|
namespace Game.Collision
|
||||||
{
|
{
|
||||||
@@ -27,40 +28,40 @@ namespace Game.Collision
|
|||||||
public static Dictionary<uint, GameobjectModelData> models = new Dictionary<uint, GameobjectModelData>();
|
public static Dictionary<uint, GameobjectModelData> models = new Dictionary<uint, GameobjectModelData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GameObjectModelOwnerBase
|
public abstract class GameObjectModelOwnerBase
|
||||||
{
|
{
|
||||||
public virtual bool IsSpawned() { return false; }
|
public abstract bool IsSpawned();
|
||||||
public virtual uint GetDisplayId() { return 0; }
|
public abstract uint GetDisplayId();
|
||||||
public virtual byte GetNameSetId() { return 0; }
|
public abstract byte GetNameSetId();
|
||||||
public virtual bool IsInPhase(PhaseShift phaseShift) { return false; }
|
public abstract bool IsInPhase(PhaseShift phaseShift);
|
||||||
public virtual Vector3 GetPosition() { return Vector3.Zero; }
|
public abstract Vector3 GetPosition();
|
||||||
public virtual float GetOrientation() { return 0.0f; }
|
public abstract float GetOrientation();
|
||||||
public virtual float GetScale() { return 1.0f; }
|
public abstract float GetScale();
|
||||||
public virtual void DebugVisualizeCorner(Vector3 corner) { }
|
public abstract void DebugVisualizeCorner(Vector3 corner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GameObjectModel : IModel
|
public class GameObjectModel : IModel
|
||||||
{
|
{
|
||||||
bool initialize(GameObjectModelOwnerBase modelOwner)
|
bool initialize(GameObjectModelOwnerBase modelOwner)
|
||||||
{
|
{
|
||||||
var it = StaticModelList.models.LookupByKey(modelOwner.GetDisplayId());
|
var modelData = StaticModelList.models.LookupByKey(modelOwner.GetDisplayId());
|
||||||
if (it == null)
|
if (modelData == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
AxisAlignedBox mdl_box = new AxisAlignedBox(it.bound);
|
AxisAlignedBox mdl_box = new AxisAlignedBox(modelData.bound);
|
||||||
// ignore models with no bounds
|
// ignore models with no bounds
|
||||||
if (mdl_box == AxisAlignedBox.Zero())
|
if (mdl_box == AxisAlignedBox.Zero())
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Server, "GameObject model {0} has zero bounds, loading skipped", it.name);
|
Log.outError(LogFilter.Server, "GameObject model {0} has zero bounds, loading skipped", modelData.name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
iModel = Global.VMapMgr.acquireModelInstance(it.name);
|
iModel = Global.VMapMgr.acquireModelInstance(modelData.name);
|
||||||
|
|
||||||
if (iModel == null)
|
if (iModel == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
name = it.name;
|
name = modelData.name;
|
||||||
iPos = modelOwner.GetPosition();
|
iPos = modelOwner.GetPosition();
|
||||||
iScale = modelOwner.GetScale();
|
iScale = modelOwner.GetScale();
|
||||||
iInvScale = 1.0f / iScale;
|
iInvScale = 1.0f / iScale;
|
||||||
@@ -75,6 +76,7 @@ namespace Game.Collision
|
|||||||
|
|
||||||
iBound = rotated_bounds + iPos;
|
iBound = rotated_bounds + iPos;
|
||||||
owner = modelOwner;
|
owner = modelOwner;
|
||||||
|
isWmo = modelData.isWmo;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +116,7 @@ namespace Game.Collision
|
|||||||
|
|
||||||
public override void IntersectPoint(Vector3 point, AreaInfo info, PhaseShift phaseShift)
|
public override void IntersectPoint(Vector3 point, AreaInfo info, PhaseShift phaseShift)
|
||||||
{
|
{
|
||||||
if (!isCollisionEnabled() || !owner.IsSpawned())
|
if (!isCollisionEnabled() || !owner.IsSpawned() || !isMapObject())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!owner.IsInPhase(phaseShift))
|
if (!owner.IsInPhase(phaseShift))
|
||||||
@@ -176,6 +178,7 @@ namespace Game.Collision
|
|||||||
|
|
||||||
public void enableCollision(bool enable) { _collisionEnabled = enable; }
|
public void enableCollision(bool enable) { _collisionEnabled = enable; }
|
||||||
bool isCollisionEnabled() { return _collisionEnabled; }
|
bool isCollisionEnabled() { return _collisionEnabled; }
|
||||||
|
bool isMapObject() { return isWmo; }
|
||||||
|
|
||||||
public static void LoadGameObjectModelList()
|
public static void LoadGameObjectModelList()
|
||||||
{
|
{
|
||||||
@@ -190,8 +193,12 @@ namespace Game.Collision
|
|||||||
{
|
{
|
||||||
using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
|
||||||
{
|
{
|
||||||
uint name_length, displayId;
|
string magic = reader.ReadStringFromChars(8);
|
||||||
string name;
|
if (magic != MapConst.VMapMagic)
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.Misc, $"File '{MapConst.GAMEOBJECT_MODELS}' has wrong header, expected {MapConst.VMapMagic}.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
long length = reader.BaseStream.Length;
|
long length = reader.BaseStream.Length;
|
||||||
while (true)
|
while (true)
|
||||||
@@ -199,14 +206,14 @@ namespace Game.Collision
|
|||||||
if (reader.BaseStream.Position >= length)
|
if (reader.BaseStream.Position >= length)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
Vector3 v1, v2;
|
uint displayId = reader.ReadUInt32();
|
||||||
displayId = reader.ReadUInt32();
|
bool isWmo = reader.ReadBoolean();
|
||||||
name_length = reader.ReadUInt32();
|
int name_length = reader.ReadInt32();
|
||||||
name = reader.ReadString((int)name_length);
|
string name = reader.ReadString(name_length);
|
||||||
v1 = reader.Read<Vector3>();
|
Vector3 v1 = reader.Read<Vector3>();
|
||||||
v2 = reader.Read<Vector3>();
|
Vector3 v2 = reader.Read<Vector3>();
|
||||||
|
|
||||||
StaticModelList.models.Add(displayId, new GameobjectModelData(name, new AxisAlignedBox(v1, v2)));
|
StaticModelList.models.Add(displayId, new GameobjectModelData(name, v1, v2, isWmo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,17 +234,20 @@ namespace Game.Collision
|
|||||||
float iScale;
|
float iScale;
|
||||||
WorldModel iModel;
|
WorldModel iModel;
|
||||||
GameObjectModelOwnerBase owner;
|
GameObjectModelOwnerBase owner;
|
||||||
|
bool isWmo;
|
||||||
}
|
}
|
||||||
public class GameobjectModelData
|
public class GameobjectModelData
|
||||||
{
|
{
|
||||||
public GameobjectModelData(string name_, AxisAlignedBox box)
|
public GameobjectModelData(string name_, Vector3 lowBound, Vector3 highBound, bool isWmo_)
|
||||||
{
|
{
|
||||||
bound = box;
|
bound = new AxisAlignedBox(lowBound, highBound);
|
||||||
name = name_;
|
name = name_;
|
||||||
|
isWmo = isWmo_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AxisAlignedBox bound;
|
public AxisAlignedBox bound;
|
||||||
public string name;
|
public string name;
|
||||||
|
public bool isWmo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,16 @@ namespace Game.Collision
|
|||||||
iCorner = corner;
|
iCorner = corner;
|
||||||
iType = type;
|
iType = type;
|
||||||
|
|
||||||
iHeight = new float[(width + 1) * (height + 1)];
|
if (width != 0 && height != 0)
|
||||||
iFlags = new byte[width * height];
|
{
|
||||||
|
iHeight = new float[(width + 1) * (height + 1)];
|
||||||
|
iFlags = new byte[width * height];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iHeight = new float[1];
|
||||||
|
iFlags = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public WmoLiquid(WmoLiquid other)
|
public WmoLiquid(WmoLiquid other)
|
||||||
{
|
{
|
||||||
@@ -77,6 +85,13 @@ namespace Game.Collision
|
|||||||
|
|
||||||
public bool GetLiquidHeight(Vector3 pos, out float liqHeight)
|
public bool GetLiquidHeight(Vector3 pos, out float liqHeight)
|
||||||
{
|
{
|
||||||
|
// simple case
|
||||||
|
if (iFlags == null)
|
||||||
|
{
|
||||||
|
liqHeight = iHeight[0];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
liqHeight = 0f;
|
liqHeight = 0f;
|
||||||
float tx_f = (pos.X - iCorner.X) / MapConst.LiquidTileSize;
|
float tx_f = (pos.X - iCorner.X) / MapConst.LiquidTileSize;
|
||||||
uint tx = (uint)tx_f;
|
uint tx = (uint)tx_f;
|
||||||
@@ -112,27 +127,6 @@ namespace Game.Collision
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeToFile(BinaryWriter writer)
|
|
||||||
{
|
|
||||||
writer.Write(iTilesX);
|
|
||||||
writer.Write(iTilesY);
|
|
||||||
|
|
||||||
writer.Write(iCorner.X);
|
|
||||||
writer.Write(iCorner.Y);
|
|
||||||
writer.Write(iCorner.Z);
|
|
||||||
writer.Write(iType);
|
|
||||||
|
|
||||||
uint size = (iTilesX + 1) * (iTilesY + 1);
|
|
||||||
for (var i = 0; i < size; i++)
|
|
||||||
writer.Write(iHeight[i]);
|
|
||||||
|
|
||||||
size = iTilesX * iTilesY;
|
|
||||||
for (var i = 0; i < size; i++)
|
|
||||||
writer.Write(iFlags[0]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WmoLiquid readFromFile(BinaryReader reader)
|
public static WmoLiquid readFromFile(BinaryReader reader)
|
||||||
{
|
{
|
||||||
WmoLiquid liquid = new WmoLiquid();
|
WmoLiquid liquid = new WmoLiquid();
|
||||||
@@ -142,15 +136,23 @@ namespace Game.Collision
|
|||||||
liquid.iCorner = reader.Read<Vector3>();
|
liquid.iCorner = reader.Read<Vector3>();
|
||||||
liquid.iType = reader.ReadUInt32();
|
liquid.iType = reader.ReadUInt32();
|
||||||
|
|
||||||
uint size = (liquid.iTilesX + 1) * (liquid.iTilesY + 1);
|
if (liquid.iTilesX != 0 && liquid.iTilesY != 0)
|
||||||
liquid.iHeight = new float[size];
|
{
|
||||||
for (var i = 0; i < size; i++)
|
uint size = (liquid.iTilesX + 1) * (liquid.iTilesY + 1);
|
||||||
liquid.iHeight[i] = reader.ReadSingle();
|
liquid.iHeight = new float[size];
|
||||||
|
for (var i = 0; i < size; i++)
|
||||||
|
liquid.iHeight[i] = reader.ReadSingle();
|
||||||
|
|
||||||
size = liquid.iTilesX * liquid.iTilesY;
|
size = liquid.iTilesX * liquid.iTilesY;
|
||||||
liquid.iFlags = new byte[size];
|
liquid.iFlags = new byte[size];
|
||||||
for (var i = 0; i < size; i++)
|
for (var i = 0; i < size; i++)
|
||||||
liquid.iFlags[i] = reader.ReadByte();
|
liquid.iFlags[i] = reader.ReadByte();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
liquid.iHeight = new float[1];
|
||||||
|
liquid.iHeight[0] = reader.ReadSingle();
|
||||||
|
}
|
||||||
|
|
||||||
return liquid;
|
return liquid;
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-29
@@ -187,7 +187,8 @@ namespace Game.Maps
|
|||||||
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
|
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
|
||||||
map_LiquidHeader liquidHeader = reader.ReadStruct<map_LiquidHeader>();
|
map_LiquidHeader liquidHeader = reader.ReadStruct<map_LiquidHeader>();
|
||||||
|
|
||||||
_liquidType = liquidHeader.liquidType;
|
_liquidGlobalEntry = liquidHeader.liquidType;
|
||||||
|
_liquidGlobalFlags = (byte)liquidHeader.liquidFlags;
|
||||||
_liquidOffX = liquidHeader.offsetX;
|
_liquidOffX = liquidHeader.offsetX;
|
||||||
_liquidOffY = liquidHeader.offsetY;
|
_liquidOffY = liquidHeader.offsetY;
|
||||||
_liquidWidth = liquidHeader.width;
|
_liquidWidth = liquidHeader.width;
|
||||||
@@ -506,7 +507,7 @@ namespace Game.Maps
|
|||||||
public ZLiquidStatus getLiquidStatus(float x, float y, float z, byte ReqLiquidType, LiquidData data)
|
public ZLiquidStatus getLiquidStatus(float x, float y, float z, byte ReqLiquidType, LiquidData data)
|
||||||
{
|
{
|
||||||
// Check water type (if no water return)
|
// Check water type (if no water return)
|
||||||
if (_liquidType == 0 && _liquidFlags == null)
|
if (_liquidGlobalFlags == 0 && _liquidFlags == null)
|
||||||
return ZLiquidStatus.NoWater;
|
return ZLiquidStatus.NoWater;
|
||||||
|
|
||||||
// Get cell
|
// Get cell
|
||||||
@@ -518,38 +519,34 @@ namespace Game.Maps
|
|||||||
|
|
||||||
// Check water type in cell
|
// Check water type in cell
|
||||||
int idx = (x_int >> 3) * 16 + (y_int >> 3);
|
int idx = (x_int >> 3) * 16 + (y_int >> 3);
|
||||||
byte type = _liquidFlags != null ? _liquidFlags[idx] : (byte)_liquidType;
|
byte type = _liquidFlags != null ? _liquidFlags[idx] : _liquidGlobalFlags;
|
||||||
uint entry = 0;
|
uint entry = _liquidEntry != null ? _liquidEntry[idx] : _liquidGlobalEntry;
|
||||||
if (_liquidEntry != null)
|
LiquidTypeRecord liquidEntry = CliDB.LiquidTypeStorage.LookupByKey(entry);
|
||||||
|
if (liquidEntry != null)
|
||||||
{
|
{
|
||||||
var liquidEntry = CliDB.LiquidTypeStorage.LookupByKey(_liquidEntry[idx]);
|
type &= MapConst.MapLiquidTypeDarkWater;
|
||||||
if (liquidEntry != null)
|
uint liqTypeIdx = liquidEntry.SoundBank;
|
||||||
|
if (entry < 21)
|
||||||
{
|
{
|
||||||
entry = liquidEntry.Id;
|
var area = CliDB.AreaTableStorage.LookupByKey(getArea(x, y));
|
||||||
type &= MapConst.MapLiquidTypeDarkWater;
|
if (area != null)
|
||||||
uint liqTypeIdx = liquidEntry.SoundBank;
|
|
||||||
if (entry < 21)
|
|
||||||
{
|
{
|
||||||
var area = CliDB.AreaTableStorage.LookupByKey(getArea(x, y));
|
uint overrideLiquid = area.LiquidTypeID[liquidEntry.SoundBank];
|
||||||
if (area != null)
|
if (overrideLiquid == 0 && area.ParentAreaID == 0)
|
||||||
{
|
{
|
||||||
uint overrideLiquid = area.LiquidTypeID[liquidEntry.SoundBank];
|
area = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
|
||||||
if (overrideLiquid == 0 && area.ParentAreaID == 0)
|
if (area != null)
|
||||||
{
|
overrideLiquid = area.LiquidTypeID[liquidEntry.SoundBank];
|
||||||
area = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
|
}
|
||||||
if (area != null)
|
var liq = CliDB.LiquidTypeStorage.LookupByKey(overrideLiquid);
|
||||||
overrideLiquid = area.LiquidTypeID[liquidEntry.SoundBank];
|
if (liq != null)
|
||||||
}
|
{
|
||||||
var liq = CliDB.LiquidTypeStorage.LookupByKey(overrideLiquid);
|
entry = overrideLiquid;
|
||||||
if (liq != null)
|
liqTypeIdx = liq.SoundBank;
|
||||||
{
|
|
||||||
entry = overrideLiquid;
|
|
||||||
liqTypeIdx = liq.SoundBank;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type |= (byte)(1 << (int)liqTypeIdx);
|
|
||||||
}
|
}
|
||||||
|
type |= (byte)(1 << (int)liqTypeIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == 0)
|
if (type == 0)
|
||||||
@@ -629,7 +626,8 @@ namespace Game.Maps
|
|||||||
byte[] _liquidFlags;
|
byte[] _liquidFlags;
|
||||||
float[] _liquidMap;
|
float[] _liquidMap;
|
||||||
ushort _gridArea;
|
ushort _gridArea;
|
||||||
ushort _liquidType;
|
ushort _liquidGlobalEntry;
|
||||||
|
byte _liquidGlobalFlags;
|
||||||
byte _liquidOffX;
|
byte _liquidOffX;
|
||||||
byte _liquidOffY;
|
byte _liquidOffY;
|
||||||
byte _liquidWidth;
|
byte _liquidWidth;
|
||||||
@@ -679,6 +677,7 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
public uint fourcc;
|
public uint fourcc;
|
||||||
public LiquidHeaderFlags flags;
|
public LiquidHeaderFlags flags;
|
||||||
|
public byte liquidFlags;
|
||||||
public ushort liquidType;
|
public ushort liquidType;
|
||||||
public byte offsetX;
|
public byte offsetX;
|
||||||
public byte offsetY;
|
public byte offsetY;
|
||||||
@@ -712,7 +711,7 @@ namespace Game.Maps
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum LiquidHeaderFlags : ushort
|
public enum LiquidHeaderFlags : byte
|
||||||
{
|
{
|
||||||
LiquidNoType = 0x0001,
|
LiquidNoType = 0x0001,
|
||||||
LiquidNoHeight = 0x0002
|
LiquidNoHeight = 0x0002
|
||||||
|
|||||||
Reference in New Issue
Block a user