Initial Commit

This commit is contained in:
2026-03-16 14:38:46 +02:00
commit b8f7327a21
2327 changed files with 253610 additions and 0 deletions
@@ -0,0 +1,54 @@
using System.Collections.Generic;
namespace Zenject
{
public class ArrayPool<T> : StaticMemoryPoolBaseBase<T[]>
{
readonly int _length;
public ArrayPool(int length)
: base(OnDespawned)
{
_length = length;
}
static void OnDespawned(T[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
arr[i] = default(T);
}
}
public T[] Spawn()
{
#if ZEN_MULTITHREADING
lock (_locker)
#endif
{
return SpawnInternal();
}
}
protected override T[] Alloc()
{
return new T[_length];
}
static readonly Dictionary<int, ArrayPool<T>> _pools =
new Dictionary<int, ArrayPool<T>>();
public static ArrayPool<T> GetPool(int length)
{
ArrayPool<T> pool;
if (!_pools.TryGetValue(length, out pool))
{
pool = new ArrayPool<T>(length);
_pools.Add(length, pool);
}
return pool;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 891d6e713fcfdfc4a95271fdee018e94
timeCreated: 1537870146
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using ModestTree;
namespace Zenject
{
public class DictionaryPool<TKey, TValue> : StaticMemoryPool<Dictionary<TKey, TValue>>
{
static DictionaryPool<TKey, TValue> _instance = new DictionaryPool<TKey, TValue>();
public DictionaryPool()
{
OnSpawnMethod = OnSpawned;
OnDespawnedMethod = OnDespawned;
}
public static DictionaryPool<TKey, TValue> Instance
{
get { return _instance; }
}
static void OnSpawned(Dictionary<TKey, TValue> items)
{
Assert.That(items.IsEmpty());
}
static void OnDespawned(Dictionary<TKey, TValue> items)
{
items.Clear();
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 031a0490d1684424e9e33b22106cb178
timeCreated: 1520670682
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using ModestTree;
namespace Zenject
{
public class HashSetPool<T> : StaticMemoryPool<HashSet<T>>
{
static HashSetPool<T> _instance = new HashSetPool<T>();
public HashSetPool()
{
OnSpawnMethod = OnSpawned;
OnDespawnedMethod = OnDespawned;
}
public static HashSetPool<T> Instance
{
get { return _instance; }
}
static void OnSpawned(HashSet<T> items)
{
Assert.That(items.IsEmpty());
}
static void OnDespawned(HashSet<T> items)
{
items.Clear();
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 89c66035001289a4199cb04e17d0bc28
timeCreated: 1520670682
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
using System.Collections.Generic;
namespace Zenject
{
public class ListPool<T> : StaticMemoryPool<List<T>>
{
static ListPool<T> _instance = new ListPool<T>();
public ListPool()
{
OnDespawnedMethod = OnDespawned;
}
public static ListPool<T> Instance
{
get { return _instance; }
}
void OnDespawned(List<T> list)
{
list.Clear();
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f30364d1ac067164ea56051cd000b49f
timeCreated: 1520670682
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ModestTree;
namespace Zenject
{
// If you want to ensure that all items are always returned to the pool, include the following
// in an installer
// Container.BindInterfacesTo<PoolCleanupChecker>().AsSingle()
public class PoolCleanupChecker : ILateDisposable
{
readonly List<IMemoryPool> _poolFactories;
readonly List<Type> _ignoredPools;
public PoolCleanupChecker(
[Inject(Optional = true, Source = InjectSources.Local)]
List<IMemoryPool> poolFactories,
[Inject(Source = InjectSources.Local)]
List<Type> ignoredPools)
{
_poolFactories = poolFactories;
_ignoredPools = ignoredPools;
Assert.That(ignoredPools.All(x => x.DerivesFrom<IMemoryPool>()));
}
public void LateDispose()
{
foreach (var pool in _poolFactories)
{
if (!_ignoredPools.Contains(pool.GetType()))
{
Assert.IsEqual(pool.NumActive, 0,
"Found active objects in pool '{0}' during dispose. Did you forget to despawn an object of type '{1}'?".Fmt(pool.GetType(), pool.ItemType));
}
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 69aee89274cd16b48aa790ddd5a061d2
timeCreated: 1520670682
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using ModestTree;
namespace Zenject
{
#if UNITY_EDITOR
public static class StaticMemoryPoolRegistry
{
public static event Action<IMemoryPool> PoolAdded = delegate {};
public static event Action<IMemoryPool> PoolRemoved = delegate {};
readonly static List<IMemoryPool> _pools = new List<IMemoryPool>();
public static IEnumerable<IMemoryPool> Pools
{
get { return _pools; }
}
public static void Add(IMemoryPool memoryPool)
{
_pools.Add(memoryPool);
PoolAdded(memoryPool);
}
public static void Remove(IMemoryPool memoryPool)
{
_pools.RemoveWithConfirm(memoryPool);
PoolRemoved(memoryPool);
}
}
#endif
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: cccc66ed95242b544bd7f501f0ecb89b
timeCreated: 1521390236
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: