This commit is contained in:
/
2024-12-29 21:15:58 +01:00
commit 547655c326
77 changed files with 7313 additions and 0 deletions

View 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);
}
}
}

View 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);
}
}
}

View 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);
}
}