58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
#pragma warning disable IDE0130
|
|
#pragma warning disable CA1000
|
|
using Godot;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using Polonium.Attributes;
|
|
using Polonium;
|
|
using Polonium.Interfaces;
|
|
using System.Collections.Generic;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
public static partial class GlobalRegistry
|
|
{
|
|
public static void Start()
|
|
{
|
|
PoloniumRegistry.Prepare();
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
IEnumerable<Type> registerTypes = Utils.GetLoadableTypes(assembly);
|
|
registerTypes = registerTypes.Where(t => t.IsClass && t.GetCustomAttributes(typeof(AutoRegister), false).Any());
|
|
foreach (Type t in registerTypes)
|
|
{
|
|
MethodInfo registerMethod = t.GetMethod("Register", BindingFlags.Static | BindingFlags.Public);
|
|
if (registerMethod != null)
|
|
registerMethod.Invoke(null, null);
|
|
}
|
|
}
|
|
|
|
public static class Asset<T> where T : Node
|
|
{
|
|
private static readonly Queue<T> Pool = new();
|
|
// ReSharper disable once StaticMemberInGenericType
|
|
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
|
public static PackedScene Scene { get; set; }
|
|
private static T Instance => Scene.Instantiate<T>();
|
|
public static T Get() => Pool.Count > 0 ? Pool.Dequeue() : Instance;
|
|
|
|
public static void Return(T obj)
|
|
{
|
|
if(Pool.Count < 10)
|
|
Pool.Enqueue(obj);
|
|
else
|
|
obj.QueueFree();
|
|
}
|
|
}
|
|
public static PoloniumRegistry PoloniumRegistry => PoloniumRegistry.Instance;
|
|
public static bool Paused { get; set; }
|
|
public static HashSet<ITimeConsumer> TimeConsumers { get; } = [];
|
|
public static void Prepare() => PoloniumRegistry.Prepare();
|
|
|
|
// ReSharper disable once PartialTypeWithSinglePart
|
|
public static partial class TextureSets
|
|
{
|
|
}
|
|
}
|
|
#pragma warning restore IDE0130
|
|
#pragma warning restore CA1000
|