ace/Source/ACE.Server/Physics/Entity/BSPCache.cs
Mag-nus e2db0bdae6
Physics memory related additions (#1720)
* Reduce size of GfxObj

* Use capacity when creating the list in BSPNode

* /clearphysicscaches and /forcegc added

* clear other caches too

* Allow these commands in-game and at console

* Only populated if !PhysicsEngine.Instance.Server
2019-04-15 06:23:57 -05:00

55 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using ACE.Server.Physics.BSP;
namespace ACE.Server.Physics.Entity
{
public static class BSPCache
{
public static bool Enabled = false;
public static readonly HashSet<BSPTree> BSPTrees = new HashSet<BSPTree>();
public static int Requests;
public static int Hits;
public static int Count => BSPTrees.Count;
public static void Clear()
{
BSPTrees.Clear();
}
public static BSPTree Get(BSPTree bspTree)
{
if (!Enabled)
return bspTree;
Requests++;
//if (Requests % 1000 == 0)
//Console.WriteLine($"BSPCache: Requests={Requests}, Hits={Hits}");
if (BSPTrees.TryGetValue(bspTree, out var result))
{
Hits++;
return result;
}
// not cached, add it
BSPTrees.Add(bspTree);
return bspTree;
}
public static BSPTree Get(DatLoader.Entity.BSPTree _bspTree, Dictionary<ushort, DatLoader.Entity.Polygon> polys, DatLoader.Entity.CVertexArray vertexArray)
{
var bspTree = new BSPTree(_bspTree, polys, vertexArray);
if (!Enabled)
return bspTree;
return Get(bspTree);
}
}
}