Core/Vmaps: Reduce memory used by vmaps (and their size, slightly)
Port From (https://github.com/TrinityCore/TrinityCore/commit/bb8f22ed2013f8cb6b9d61c738f2ebd96b83722f)
This commit is contained in:
@@ -292,19 +292,15 @@ namespace Game.Collision
|
|||||||
var model = iLoadedModelFiles.LookupByKey(filename);
|
var model = iLoadedModelFiles.LookupByKey(filename);
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
WorldModel worldmodel = new();
|
model = new ManagedModel();
|
||||||
if (!worldmodel.ReadFile(VMapPath + filename))
|
if (!model.GetModel().ReadFile(VMapPath + filename))
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Server, "VMapManager: could not load '{0}'", filename);
|
Log.outError(LogFilter.Server, "VMapManager: could not load '{0}'", filename);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.outDebug(LogFilter.Maps, "VMapManager: loading file '{0}'", filename);
|
Log.outDebug(LogFilter.Maps, "VMapManager: loading file '{0}'", filename);
|
||||||
|
model.GetModel().Flags = flags;
|
||||||
worldmodel.Flags = flags;
|
|
||||||
|
|
||||||
model = new ManagedModel();
|
|
||||||
model.SetModel(worldmodel);
|
|
||||||
|
|
||||||
iLoadedModelFiles.Add(filename, model);
|
iLoadedModelFiles.Add(filename, model);
|
||||||
}
|
}
|
||||||
@@ -382,7 +378,7 @@ namespace Game.Collision
|
|||||||
{
|
{
|
||||||
public ManagedModel()
|
public ManagedModel()
|
||||||
{
|
{
|
||||||
iModel = null;
|
iModel = new();
|
||||||
iRefCount = 0;
|
iRefCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ namespace Game.Collision
|
|||||||
if (iModel == null)
|
if (iModel == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
name = modelData.name;
|
|
||||||
iPos = modelOwner.GetPosition();
|
iPos = modelOwner.GetPosition();
|
||||||
iScale = modelOwner.GetScale();
|
iScale = modelOwner.GetScale();
|
||||||
iInvScale = 1.0f / iScale;
|
iInvScale = 1.0f / iScale;
|
||||||
@@ -224,7 +223,6 @@ namespace Game.Collision
|
|||||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} GameObject models in {1} ms", StaticModelList.models.Count, Time.GetMSTimeDiffToNow(oldMSTime));
|
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} GameObject models in {1} ms", StaticModelList.models.Count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
string name;
|
|
||||||
bool _collisionEnabled;
|
bool _collisionEnabled;
|
||||||
AxisAlignedBox iBound;
|
AxisAlignedBox iBound;
|
||||||
Matrix3 iInvRot;
|
Matrix3 iInvRot;
|
||||||
|
|||||||
@@ -29,9 +29,23 @@ namespace Game.Collision
|
|||||||
ParentSpawn = 1 << 2
|
ParentSpawn = 1 << 2
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModelSpawn
|
public class ModelMinimalData
|
||||||
{
|
{
|
||||||
|
public byte flags;
|
||||||
|
public byte adtId;
|
||||||
|
public uint Id;
|
||||||
|
public Vector3 iPos;
|
||||||
|
public float iScale;
|
||||||
|
public AxisAlignedBox iBound;
|
||||||
|
public string name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ModelSpawn : ModelMinimalData
|
||||||
|
{
|
||||||
|
public Vector3 iRot;
|
||||||
|
|
||||||
public ModelSpawn() { }
|
public ModelSpawn() { }
|
||||||
|
|
||||||
public ModelSpawn(ModelSpawn spawn)
|
public ModelSpawn(ModelSpawn spawn)
|
||||||
{
|
{
|
||||||
flags = spawn.flags;
|
flags = spawn.flags;
|
||||||
@@ -48,8 +62,8 @@ namespace Game.Collision
|
|||||||
{
|
{
|
||||||
spawn = new ModelSpawn();
|
spawn = new ModelSpawn();
|
||||||
|
|
||||||
spawn.flags = reader.ReadUInt32();
|
spawn.flags = reader.ReadByte();
|
||||||
spawn.adtId = reader.ReadUInt16();
|
spawn.adtId = reader.ReadByte();
|
||||||
spawn.Id = reader.ReadUInt32();
|
spawn.Id = reader.ReadUInt32();
|
||||||
spawn.iPos = reader.Read<Vector3>();
|
spawn.iPos = reader.Read<Vector3>();
|
||||||
spawn.iRot = reader.Read<Vector3>();
|
spawn.iRot = reader.Read<Vector3>();
|
||||||
@@ -67,30 +81,33 @@ namespace Game.Collision
|
|||||||
spawn.name = reader.ReadString((int)nameLen);
|
spawn.name = reader.ReadString((int)nameLen);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint flags;
|
|
||||||
public ushort adtId;
|
|
||||||
public uint Id;
|
|
||||||
public Vector3 iPos;
|
|
||||||
public Vector3 iRot;
|
|
||||||
public float iScale;
|
|
||||||
public AxisAlignedBox iBound;
|
|
||||||
public string name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModelInstance : ModelSpawn
|
public class ModelInstance : ModelMinimalData
|
||||||
{
|
{
|
||||||
|
Matrix3 iInvRot;
|
||||||
|
float iInvScale;
|
||||||
|
WorldModel iModel;
|
||||||
|
|
||||||
public ModelInstance()
|
public ModelInstance()
|
||||||
{
|
{
|
||||||
iInvScale = 0.0f;
|
iInvScale = 0.0f;
|
||||||
iModel = null;
|
iModel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModelInstance(ModelSpawn spawn, WorldModel model)
|
public ModelInstance(ModelSpawn spawn, WorldModel model)
|
||||||
: base(spawn)
|
|
||||||
{
|
{
|
||||||
|
flags = spawn.flags;
|
||||||
|
adtId = spawn.adtId;
|
||||||
|
Id = spawn.Id;
|
||||||
|
iPos = spawn.iPos;
|
||||||
|
iScale = spawn.iScale;
|
||||||
|
iBound = spawn.iBound;
|
||||||
|
name = spawn.name;
|
||||||
|
|
||||||
iModel = model;
|
iModel = model;
|
||||||
|
|
||||||
iInvRot = Matrix3.fromEulerAnglesZYX(MathFunctions.PI * iRot.Y / 180.0f, MathFunctions.PI * iRot.X / 180.0f, MathFunctions.PI * iRot.Z / 180.0f).inverse();
|
iInvRot = Matrix3.fromEulerAnglesZYX(MathFunctions.PI * spawn.iRot.Y / 180.0f, MathFunctions.PI * spawn.iRot.X / 180.0f, MathFunctions.PI * spawn.iRot.Z / 180.0f).inverse();
|
||||||
iInvScale = 1.0f / iScale;
|
iInvScale = 1.0f / iScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,9 +210,5 @@ namespace Game.Collision
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetUnloaded() { iModel = null; }
|
public void SetUnloaded() { iModel = null; }
|
||||||
|
|
||||||
Matrix3 iInvRot;
|
|
||||||
float iInvScale;
|
|
||||||
WorldModel iModel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,21 +25,29 @@ namespace Game.Collision
|
|||||||
{
|
{
|
||||||
public struct MeshTriangle
|
public struct MeshTriangle
|
||||||
{
|
{
|
||||||
|
public uint idx0;
|
||||||
|
public uint idx1;
|
||||||
|
public uint idx2;
|
||||||
|
|
||||||
public MeshTriangle(uint na, uint nb, uint nc)
|
public MeshTriangle(uint na, uint nb, uint nc)
|
||||||
{
|
{
|
||||||
idx0 = na;
|
idx0 = na;
|
||||||
idx1 = nb;
|
idx1 = nb;
|
||||||
idx2 = nc;
|
idx2 = nc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint idx0;
|
|
||||||
public uint idx1;
|
|
||||||
public uint idx2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WmoLiquid
|
public class WmoLiquid
|
||||||
{
|
{
|
||||||
|
uint iTilesX;
|
||||||
|
uint iTilesY;
|
||||||
|
Vector3 iCorner;
|
||||||
|
uint iType;
|
||||||
|
float[] iHeight;
|
||||||
|
byte[] iFlags;
|
||||||
|
|
||||||
public WmoLiquid() { }
|
public WmoLiquid() { }
|
||||||
|
|
||||||
public WmoLiquid(uint width, uint height, Vector3 corner, uint type)
|
public WmoLiquid(uint width, uint height, Vector3 corner, uint type)
|
||||||
{
|
{
|
||||||
iTilesX = width;
|
iTilesX = width;
|
||||||
@@ -58,6 +66,7 @@ namespace Game.Collision
|
|||||||
iFlags = null;
|
iFlags = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WmoLiquid(WmoLiquid other)
|
public WmoLiquid(WmoLiquid other)
|
||||||
{
|
{
|
||||||
if (this == other)
|
if (this == other)
|
||||||
@@ -155,23 +164,23 @@ namespace Game.Collision
|
|||||||
}
|
}
|
||||||
|
|
||||||
public uint GetLiquidType() { return iType; }
|
public uint GetLiquidType() { return iType; }
|
||||||
float[] GetHeightStorage() { return iHeight; }
|
|
||||||
byte[] GetFlagsStorage() { return iFlags; }
|
|
||||||
|
|
||||||
uint iTilesX;
|
|
||||||
uint iTilesY;
|
|
||||||
Vector3 iCorner;
|
|
||||||
uint iType;
|
|
||||||
float[] iHeight;
|
|
||||||
byte[] iFlags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GroupModel : IModel
|
public class GroupModel : IModel
|
||||||
{
|
{
|
||||||
|
AxisAlignedBox iBound;
|
||||||
|
uint iMogpFlags;
|
||||||
|
uint iGroupWMOID;
|
||||||
|
List<Vector3> vertices = new();
|
||||||
|
List<MeshTriangle> triangles = new();
|
||||||
|
BIH meshTree = new();
|
||||||
|
WmoLiquid iLiquid;
|
||||||
|
|
||||||
public GroupModel()
|
public GroupModel()
|
||||||
{
|
{
|
||||||
iLiquid = null;
|
iLiquid = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupModel(GroupModel other)
|
public GroupModel(GroupModel other)
|
||||||
{
|
{
|
||||||
iBound = other.iBound;
|
iBound = other.iBound;
|
||||||
@@ -185,6 +194,7 @@ namespace Game.Collision
|
|||||||
if (other.iLiquid != null)
|
if (other.iLiquid != null)
|
||||||
iLiquid = new WmoLiquid(other.iLiquid);
|
iLiquid = new WmoLiquid(other.iLiquid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupModel(uint mogpFlags, uint groupWMOID, AxisAlignedBox bound)
|
public GroupModel(uint mogpFlags, uint groupWMOID, AxisAlignedBox bound)
|
||||||
{
|
{
|
||||||
iBound = bound;
|
iBound = bound;
|
||||||
@@ -193,11 +203,6 @@ namespace Game.Collision
|
|||||||
iLiquid = null;
|
iLiquid = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLiquidData(WmoLiquid liquid)
|
|
||||||
{
|
|
||||||
iLiquid = liquid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ReadFromFile(BinaryReader reader)
|
public bool ReadFromFile(BinaryReader reader)
|
||||||
{
|
{
|
||||||
triangles.Clear();
|
triangles.Clear();
|
||||||
@@ -294,22 +299,15 @@ namespace Game.Collision
|
|||||||
public uint GetMogpFlags() { return iMogpFlags; }
|
public uint GetMogpFlags() { return iMogpFlags; }
|
||||||
|
|
||||||
public uint GetWmoID() { return iGroupWMOID; }
|
public uint GetWmoID() { return iGroupWMOID; }
|
||||||
|
|
||||||
AxisAlignedBox iBound;
|
|
||||||
uint iMogpFlags;
|
|
||||||
uint iGroupWMOID;
|
|
||||||
List<Vector3> vertices = new();
|
|
||||||
List<MeshTriangle> triangles = new();
|
|
||||||
BIH meshTree = new();
|
|
||||||
WmoLiquid iLiquid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WorldModel : IModel
|
public class WorldModel : IModel
|
||||||
{
|
{
|
||||||
public WorldModel()
|
public uint Flags;
|
||||||
{
|
|
||||||
RootWMOID = 0;
|
uint RootWMOID;
|
||||||
}
|
List<GroupModel> groupModels = new();
|
||||||
|
BIH groupTree = new();
|
||||||
|
|
||||||
public override bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags)
|
public override bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags)
|
||||||
{
|
{
|
||||||
@@ -408,10 +406,5 @@ namespace Game.Collision
|
|||||||
return groupTree.ReadFromFile(reader);
|
return groupTree.ReadFromFile(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<GroupModel> groupModels = new();
|
|
||||||
BIH groupTree = new();
|
|
||||||
uint RootWMOID;
|
|
||||||
public uint Flags;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user