zz
This commit is contained in:
24
GlobalShared/Plugin/GlobalInstance.cs
Normal file
24
GlobalShared/Plugin/GlobalInstance.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Global.Shared.Config;
|
||||
using Global.Shared.Logging;
|
||||
|
||||
namespace Global.Shared.Plugin
|
||||
{
|
||||
public static class GlobalInstance
|
||||
{
|
||||
public static IPluginLogger Log => Plugin.Log;
|
||||
public static IGlobalPlugin Plugin { get; private set; }
|
||||
public static IPluginConfig Config => Plugin.Config;
|
||||
|
||||
public static void SetPlugin(IGlobalPlugin plugin)
|
||||
{
|
||||
Plugin = plugin;
|
||||
GlobalStatic.OcTreeHandler.Init();
|
||||
}
|
||||
|
||||
public static void Run(Action action)
|
||||
{
|
||||
Plugin.Run(action);
|
||||
}
|
||||
}
|
||||
}
|
40
GlobalShared/Plugin/GlobalStatic.cs
Normal file
40
GlobalShared/Plugin/GlobalStatic.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
15
GlobalShared/Plugin/IGlobalPlugin.cs
Normal file
15
GlobalShared/Plugin/IGlobalPlugin.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using Global.Shared.Config;
|
||||
using Global.Shared.Logging;
|
||||
|
||||
namespace Global.Shared.Plugin
|
||||
{
|
||||
public interface IGlobalPlugin
|
||||
{
|
||||
IPluginLogger Log { get; }
|
||||
IPluginConfig Config { get; }
|
||||
long Tick { get; }
|
||||
bool Started { get; }
|
||||
void Run(Action action);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user