ace/Source/ACE.Server/Physics/Common/CellStruct.cs
Mag-nus 95a1fd08df Landblock async physics loading + some physics profiling improvements *NEEDS TESTING* (#1077)
* Physics Cache cleanup (Mostly cosmetic)

* Vertex/Polygon/BSP CacneEnabled flags added, default to false

Testing results:

Debug mode, loading 31,329 landblocks (x = 0x20-0xD0, y = 0x20-0xD0)

With Vertex, Polygon & BSP Cache:
2018-10-25 10:05:12,121 DEBUG: Loaded Landblocks in 120.39 seconds
2018-10-25 10:05:12,218 DEBUG: 13759 MB used

2018-10-25 10:08:00,330 DEBUG: Loaded Landblocks in 101.11 seconds
2018-10-25 10:08:00,427 DEBUG: 13667 MB used

2018-10-25 10:13:08,448 DEBUG: Loaded Landblocks in 104.36 seconds
2018-10-25 10:13:08,507 DEBUG: 13666 MB used

With Vertex, Polygon & BSP Cache Disabled:
2018-10-25 10:17:55,339 DEBUG: Loaded Landblocks in 100.63 seconds
2018-10-25 10:17:55,404 DEBUG: 14175 MB used

2018-10-25 10:21:11,596 DEBUG: Loaded Landblocks in 89.23 seconds
2018-10-25 10:21:11,666 DEBUG: 14220 MB used

2018-10-25 10:27:22,145 DEBUG: Loaded Landblocks in 93.74 seconds
2018-10-25 10:27:22,200 DEBUG: 14206 MB used

* PhysicsCaches, remove redundant null check

* Improved GfxObjCache model

* DBObj Boxing/Unboxing improvements

* Add thread safety to GfxObjCache

* Landblock phsyics loading async
2018-10-28 00:29:35 -04:00

75 lines
2.5 KiB
C#

using System.Collections.Generic;
using System.Numerics;
using ACE.Server.Physics.BSP;
using ACE.Server.Physics.Entity;
using ACE.Server.Physics.Collision;
namespace ACE.Server.Physics.Common
{
public class CellStruct
{
public int CellStructID;
public List<Vector3> VertexArray;
public Dictionary<ushort, Polygon> Polygons;
public Dictionary<ushort, Polygon> PhysicsPolygons;
public List<Polygon> Portals;
//public int NumSurfaceStrips;
//public List<SurfaceTriStrips> SurfaceStrips;
public BSPTree DrawingBSP;
public BSPTree PhysicsBSP;
public BSPTree CellBSP;
public CellStruct() { }
public CellStruct(DatLoader.Entity.CellStruct cellStruct)
{
Polygons = new Dictionary<ushort, Polygon>();
foreach (var poly in cellStruct.Polygons)
Polygons.Add(poly.Key, PolygonCache.Get(poly.Value, cellStruct.VertexArray));
Portals = new List<Polygon>();
foreach (var portal in cellStruct.Portals)
Portals.Add(Polygons[portal]);
PhysicsPolygons = new Dictionary<ushort, Polygon>();
foreach (var poly in cellStruct.PhysicsPolygons)
PhysicsPolygons.Add(poly.Key, PolygonCache.Get(poly.Value, cellStruct.VertexArray));
if (cellStruct.CellBSP != null)
CellBSP = BSPCache.Get(cellStruct.CellBSP, cellStruct.PhysicsPolygons, cellStruct.VertexArray);
if (cellStruct.DrawingBSP != null)
DrawingBSP = BSPCache.Get(cellStruct.DrawingBSP, cellStruct.Polygons, cellStruct.VertexArray);
if (cellStruct.PhysicsBSP != null)
PhysicsBSP = BSPCache.Get(cellStruct.PhysicsBSP, cellStruct.PhysicsPolygons, cellStruct.VertexArray);
}
public bool box_intersects_cell(BBox bbox)
{
return CellBSP.box_intersects_cell_bsp(bbox);
}
public Polygon get_portal(uint polyID)
{
Polygon portal = null;
foreach (var p in Portals)
{
if (polyID == portal.PolyID) continue;
portal = p;
}
return portal;
}
public BoundingType sphere_intersects_cell(Sphere sphere)
{
return CellBSP.sphere_intersects_cell_bsp(sphere);
}
public bool point_in_cell(Vector3 point)
{
return CellBSP.point_inside_cell_bsp(point);
}
}
}