Files
QuartZ-dump/GlobalShared/Plugin/GlobalStatic.cs
2024-12-29 21:15:58 +01:00

40 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Diagnostics;
using Global.Shared.OcTree;
using Global.Shared.Patches;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using VRage.ModAPI;
namespace Global.Shared.Plugin
{
public static class GlobalStatic
{
public static OcTreeHandler OcTreeHandler = new OcTreeHandler();
internal static void Init()
{
MyAPIGateway.Entities.OnEntityAdd += Entities_OnEntityAdd;
var set = new HashSet<IMyEntity>();
var stopwatch = new Stopwatch();
stopwatch.Start();
MyAPIGateway.Entities.GetEntities(set);
foreach (var myEntity in set) Entities_OnEntityAdd(myEntity);
stopwatch.Stop();
GlobalInstance.Log.Info($"Collected all entities from startup. Took {stopwatch.ElapsedMilliseconds}ms");
}
internal static void Update()
{
TerminalSystemPatch.OwnerCache.Cleanup();
}
private static void Entities_OnEntityAdd(IMyEntity obj)
{
if (obj is MyCubeGrid grid)
OcTreeHandler.AddGrid(grid);
else if (obj is IMyControllableEntity controllableEntity)
OcTreeHandler.AddControllableEntity(controllableEntity);
}
}
}