ace/Source/ACE.Server/Physics/Entity/PolygonCache.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.2 KiB
C#

using System;
using System.Collections.Generic;
using ACE.DatLoader.Entity;
namespace ACE.Server.Physics.Entity
{
public static class PolygonCache
{
public static bool Enabled = false;
public static readonly HashSet<Polygon> Polygons = new HashSet<Polygon>();
public static int Requests;
public static int Hits;
public static int Count => Polygons.Count;
public static void Clear()
{
Polygons.Clear();
}
public static Polygon Get(Polygon p)
{
if (!Enabled)
return p;
Requests++;
//if (Requests % 10000 == 0)
//Console.WriteLine($"PolygonCache: Requests={Requests}, Hits={Hits}");
if (Polygons.TryGetValue(p, out var result))
{
Hits++;
return result;
}
// not cached, add it
Polygons.Add(p);
return p;
}
public static Polygon Get(DatLoader.Entity.Polygon p, CVertexArray v)
{
var polygon = new Polygon(p, v);
if (!Enabled)
return polygon;
return Get(polygon);
}
}
}