Update Project
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public interface IMemoryPool
|
||||
{
|
||||
int NumTotal { get; }
|
||||
int NumActive { get; }
|
||||
int NumInactive { get; }
|
||||
|
||||
Type ItemType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes pool size by creating new elements or destroying existing elements
|
||||
/// This bypasses the configured expansion method (OneAtATime or Doubling)
|
||||
/// </summary>
|
||||
void Resize(int desiredPoolSize);
|
||||
|
||||
void Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Expands the pool by the additional size.
|
||||
/// This bypasses the configured expansion method (OneAtATime or Doubling)
|
||||
/// </summary>
|
||||
/// <param name="numToAdd">The additional number of items to allocate in the pool</param>
|
||||
void ExpandBy(int numToAdd);
|
||||
|
||||
/// <summary>
|
||||
/// Shrinks the MemoryPool by removing a given number of elements
|
||||
/// This bypasses the configured expansion method (OneAtATime or Doubling)
|
||||
/// </summary>
|
||||
/// <param name="numToRemove">The amount of items to remove from the pool</param>
|
||||
void ShrinkBy(int numToRemove);
|
||||
|
||||
void Despawn(object obj);
|
||||
}
|
||||
|
||||
public interface IDespawnableMemoryPool<TValue> : IMemoryPool
|
||||
{
|
||||
void Despawn(TValue item);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn();
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, in TParam3, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, in TParam3, in TParam4, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, in TParam3, in TParam4, in TParam5, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, in TParam3, in TParam4, in TParam5, in TParam6, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5, TParam6 param6);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, in TParam3, in TParam4, in TParam5, in TParam6, in TParam7, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5, TParam6 param6, TParam7 param7);
|
||||
}
|
||||
|
||||
public interface IMemoryPool<in TParam1, in TParam2, in TParam3, in TParam4, in TParam5, in TParam6, in TParam7, in TParam8, TValue> : IDespawnableMemoryPool<TValue>
|
||||
{
|
||||
TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5, TParam6 param6, TParam7 param7, TParam8 param8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13b8377ec575a1a44a1028ee324ba17a
|
||||
timeCreated: 1485699960
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,316 @@
|
||||
namespace Zenject
|
||||
{
|
||||
// Zero parameters
|
||||
public class MemoryPool<TValue> : MemoryPoolBase<TValue>, IMemoryPool<TValue>, IFactory<TValue>
|
||||
{
|
||||
public TValue Spawn()
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TValue>.Create()
|
||||
{
|
||||
return Spawn();
|
||||
}
|
||||
}
|
||||
|
||||
// One parameter
|
||||
public class MemoryPool<TParam1, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TValue>, IFactory<TParam1, TValue>
|
||||
{
|
||||
public TValue Spawn(TParam1 param)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param, item);
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TValue>.Create(TParam1 p1)
|
||||
{
|
||||
return Spawn(p1);
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
public class MemoryPool<TParam1, TParam2, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TValue>, IFactory<TParam1, TParam2, TValue>
|
||||
{
|
||||
public TValue Spawn(TParam1 param1, TParam2 param2)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, item);
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TValue>.Create(TParam1 p1, TParam2 p2)
|
||||
{
|
||||
return Spawn(p1, p2);
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
public class MemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TValue>, IFactory<TParam1, TParam2, TParam3, TValue>
|
||||
{
|
||||
public TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, param3, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TParam3, TValue>.Create(TParam1 p1, TParam2 p2, TParam3 p3)
|
||||
{
|
||||
return Spawn(p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
public class MemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>, IFactory<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
{
|
||||
public TValue Spawn(TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, param3, param4, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TParam3, TParam4, TValue>.Create(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4)
|
||||
{
|
||||
return Spawn(p1, p2, p3, p4);
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
public class MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>, IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
{
|
||||
public TValue Spawn(
|
||||
TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5)
|
||||
{
|
||||
var item = GetInternal();
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, param3, param4, param5, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>.Create(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5)
|
||||
{
|
||||
return Spawn(p1, p2, p3, p4, p5);
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
public class MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>,
|
||||
IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
{
|
||||
public TValue Spawn(
|
||||
TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5, TParam6 param6)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, param3, param4, param5, param6, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>.Create(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6)
|
||||
{
|
||||
return Spawn(p1, p2, p3, p4, p5, p6);
|
||||
}
|
||||
}
|
||||
|
||||
// Seven parameters
|
||||
public class MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>,
|
||||
IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
{
|
||||
public TValue Spawn(
|
||||
TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5, TParam6 param6, TParam7 param7)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, param3, param4, param5, param6, param7, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>.Create(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7)
|
||||
{
|
||||
return Spawn(p1, p2, p3, p4, p5, p6, p7);
|
||||
}
|
||||
}
|
||||
|
||||
// Eight parameters
|
||||
public class MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>
|
||||
: MemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>,
|
||||
IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>
|
||||
{
|
||||
public TValue Spawn(
|
||||
TParam1 param1, TParam2 param2, TParam3 param3, TParam4 param4, TParam5 param5, TParam6 param6, TParam7 param7, TParam8 param8)
|
||||
{
|
||||
var item = GetInternal();
|
||||
|
||||
if (!Container.IsValidating)
|
||||
{
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.Reinitialize", GetType()))
|
||||
#endif
|
||||
{
|
||||
Reinitialize(param1, param2, param3, param4, param5, param6, param7, param8, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
protected virtual void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TParam8 p8, TValue item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
TValue IFactory<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>.Create(
|
||||
TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TParam8 p8)
|
||||
{
|
||||
return Spawn(p1, p2, p3, p4, p5, p6, p7, p8);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 305d88c8b2af3f2479cb45ffb6f2923c
|
||||
timeCreated: 1485699960
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public class PoolExceededFixedSizeException : Exception
|
||||
{
|
||||
public PoolExceededFixedSizeException(string errorMessage)
|
||||
: base(errorMessage)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MemoryPoolSettings
|
||||
{
|
||||
public int InitialSize;
|
||||
public int MaxSize;
|
||||
public PoolExpandMethods ExpandMethod;
|
||||
|
||||
public MemoryPoolSettings()
|
||||
{
|
||||
InitialSize = 0;
|
||||
MaxSize = int.MaxValue;
|
||||
ExpandMethod = PoolExpandMethods.OneAtATime;
|
||||
}
|
||||
|
||||
public MemoryPoolSettings(int initialSize, int maxSize, PoolExpandMethods expandMethod)
|
||||
{
|
||||
InitialSize = initialSize;
|
||||
MaxSize = maxSize;
|
||||
ExpandMethod = expandMethod;
|
||||
}
|
||||
|
||||
public static readonly MemoryPoolSettings Default = new MemoryPoolSettings();
|
||||
}
|
||||
|
||||
[ZenjectAllowDuringValidation]
|
||||
public class MemoryPoolBase<TContract> : IValidatable, IMemoryPool, IDisposable
|
||||
{
|
||||
Stack<TContract> _inactiveItems;
|
||||
IFactory<TContract> _factory;
|
||||
MemoryPoolSettings _settings;
|
||||
DiContainer _container;
|
||||
|
||||
int _activeCount;
|
||||
|
||||
[Inject]
|
||||
void Construct(
|
||||
IFactory<TContract> factory,
|
||||
DiContainer container,
|
||||
[InjectOptional]
|
||||
MemoryPoolSettings settings)
|
||||
{
|
||||
_settings = settings ?? MemoryPoolSettings.Default;
|
||||
_factory = factory;
|
||||
_container = container;
|
||||
|
||||
_inactiveItems = new Stack<TContract>(_settings.InitialSize);
|
||||
|
||||
if (!container.IsValidating)
|
||||
{
|
||||
for (int i = 0; i < _settings.InitialSize; i++)
|
||||
{
|
||||
_inactiveItems.Push(AllocNew());
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
StaticMemoryPoolRegistry.Add(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected DiContainer Container
|
||||
{
|
||||
get { return _container; }
|
||||
}
|
||||
|
||||
public IEnumerable<TContract> InactiveItems
|
||||
{
|
||||
get { return _inactiveItems; }
|
||||
}
|
||||
|
||||
public int NumTotal
|
||||
{
|
||||
get { return NumInactive + NumActive; }
|
||||
}
|
||||
|
||||
public int NumInactive
|
||||
{
|
||||
get { return _inactiveItems.Count; }
|
||||
}
|
||||
|
||||
public int NumActive
|
||||
{
|
||||
get { return _activeCount; }
|
||||
}
|
||||
|
||||
public Type ItemType
|
||||
{
|
||||
get { return typeof(TContract); }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
StaticMemoryPoolRegistry.Remove(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IMemoryPool.Despawn(object item)
|
||||
{
|
||||
Despawn((TContract)item);
|
||||
}
|
||||
|
||||
public void Despawn(TContract item)
|
||||
{
|
||||
Assert.That(!_inactiveItems.Contains(item),
|
||||
"Tried to return an item to pool {0} twice", GetType());
|
||||
|
||||
_activeCount--;
|
||||
|
||||
_inactiveItems.Push(item);
|
||||
|
||||
#if ZEN_INTERNAL_PROFILING
|
||||
using (ProfileTimers.CreateTimedBlock("User Code"))
|
||||
#endif
|
||||
#if UNITY_EDITOR
|
||||
using (ProfileBlock.Start("{0}.OnDespawned", GetType()))
|
||||
#endif
|
||||
{
|
||||
OnDespawned(item);
|
||||
}
|
||||
|
||||
if (_inactiveItems.Count > _settings.MaxSize)
|
||||
{
|
||||
Resize(_settings.MaxSize);
|
||||
}
|
||||
}
|
||||
|
||||
TContract AllocNew()
|
||||
{
|
||||
try
|
||||
{
|
||||
var item = _factory.Create();
|
||||
|
||||
if (!_container.IsValidating)
|
||||
{
|
||||
Assert.IsNotNull(item, "Factory '{0}' returned null value when creating via {1}!", _factory.GetType(), GetType());
|
||||
OnCreated(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ZenjectException(
|
||||
"Error during construction of type '{0}' via {1}.Create method!".Fmt(
|
||||
typeof(TContract), GetType()), e);
|
||||
}
|
||||
}
|
||||
|
||||
void IValidatable.Validate()
|
||||
{
|
||||
try
|
||||
{
|
||||
_factory.Create();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ZenjectException(
|
||||
"Validation for factory '{0}' failed".Fmt(GetType()), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Resize(0);
|
||||
}
|
||||
|
||||
public void ShrinkBy(int numToRemove)
|
||||
{
|
||||
Resize(_inactiveItems.Count - numToRemove);
|
||||
}
|
||||
|
||||
public void ExpandBy(int numToAdd)
|
||||
{
|
||||
Resize(_inactiveItems.Count + numToAdd);
|
||||
}
|
||||
|
||||
protected TContract GetInternal()
|
||||
{
|
||||
if (_inactiveItems.Count == 0)
|
||||
{
|
||||
ExpandPool();
|
||||
Assert.That(!_inactiveItems.IsEmpty());
|
||||
}
|
||||
|
||||
var item = _inactiveItems.Pop();
|
||||
_activeCount++;
|
||||
OnSpawned(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void Resize(int desiredPoolSize)
|
||||
{
|
||||
if (_inactiveItems.Count == desiredPoolSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_settings.ExpandMethod == PoolExpandMethods.Disabled)
|
||||
{
|
||||
throw new PoolExceededFixedSizeException(
|
||||
"Pool factory '{0}' attempted resize but pool set to fixed size of '{1}'!"
|
||||
.Fmt(GetType(), _inactiveItems.Count));
|
||||
}
|
||||
|
||||
Assert.That(desiredPoolSize >= 0, "Attempted to resize the pool to a negative amount");
|
||||
|
||||
while (_inactiveItems.Count > desiredPoolSize)
|
||||
{
|
||||
OnDestroyed(_inactiveItems.Pop());
|
||||
}
|
||||
|
||||
while (desiredPoolSize > _inactiveItems.Count)
|
||||
{
|
||||
_inactiveItems.Push(AllocNew());
|
||||
}
|
||||
|
||||
Assert.IsEqual(_inactiveItems.Count, desiredPoolSize);
|
||||
}
|
||||
|
||||
void ExpandPool()
|
||||
{
|
||||
switch (_settings.ExpandMethod)
|
||||
{
|
||||
case PoolExpandMethods.Disabled:
|
||||
{
|
||||
throw new PoolExceededFixedSizeException(
|
||||
"Pool factory '{0}' exceeded its fixed size of '{1}'!"
|
||||
.Fmt(GetType(), _inactiveItems.Count));
|
||||
}
|
||||
case PoolExpandMethods.OneAtATime:
|
||||
{
|
||||
ExpandBy(1);
|
||||
break;
|
||||
}
|
||||
case PoolExpandMethods.Double:
|
||||
{
|
||||
if (NumTotal == 0)
|
||||
{
|
||||
ExpandBy(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ExpandBy(NumTotal);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Assert.CreateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDespawned(TContract item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
protected virtual void OnSpawned(TContract item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
protected virtual void OnCreated(TContract item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
|
||||
protected virtual void OnDestroyed(TContract item)
|
||||
{
|
||||
// Optional
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba9d727a5d866fb46a576ab76012b727
|
||||
timeCreated: 1485703991
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,254 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Zero parameters
|
||||
// NOTE: For this to work, the given component must be at the root game object of the thing
|
||||
// you want to use in a pool
|
||||
public class MonoMemoryPool<TValue> : MemoryPool<TValue>
|
||||
where TValue : Component
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
// Record the original parent which will be set to whatever is used in the UnderTransform method
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnSpawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One parameter
|
||||
// NOTE: For this to work, the given component must be at the root game object of the thing
|
||||
// you want to use in a pool
|
||||
public class MonoMemoryPool<TParam1, TValue> : MemoryPool<TParam1, TValue>
|
||||
where TValue : Component
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
// Record the original parent which will be set to whatever is used in the UnderTransform method
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnSpawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
// NOTE: For this to work, the given component must be at the root game object of the thing
|
||||
// you want to use in a pool
|
||||
public class MonoMemoryPool<TParam1, TParam2, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TValue>
|
||||
where TValue : Component
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
// Record the original parent which will be set to whatever is used in the UnderTransform method
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnSpawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
// NOTE: For this to work, the given component must be at the root game object of the thing
|
||||
// you want to use in a pool
|
||||
public class MonoMemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
where TValue : Component
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
// Record the original parent which will be set to whatever is used in the UnderTransform method
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnSpawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
// NOTE: For this to work, the given component must be at the root game object of the thing
|
||||
// you want to use in a pool
|
||||
public class MonoMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
where TValue : Component
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
// Record the original parent which will be set to whatever is used in the UnderTransform method
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnSpawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
// NOTE: For this to work, the given component must be at the root game object of the thing
|
||||
// you want to use in a pool
|
||||
public class MonoMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
where TValue : Component
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
// Record the original parent which will be set to whatever is used in the UnderTransform method
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnSpawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1334aecb808e6c145a993cb441f43bdb
|
||||
timeCreated: 1485703991
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,372 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Zero parameters
|
||||
public class MonoPoolableMemoryPool<TValue> : MemoryPool<TValue>
|
||||
where TValue : Component, IPoolable
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned();
|
||||
}
|
||||
}
|
||||
|
||||
// One parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TValue>
|
||||
: MemoryPool<TParam1, TValue>
|
||||
where TValue : Component, IPoolable<TParam1>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1);
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2);
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2, TParam3>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2, TParam3, TParam4>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2, p3, p4);
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2, p3, p4, p5);
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2, p3, p4, p5, p6);
|
||||
}
|
||||
}
|
||||
|
||||
// Seven parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2, p3, p4, p5, p6, p7);
|
||||
}
|
||||
}
|
||||
|
||||
// Eight parameters
|
||||
public class MonoPoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>
|
||||
where TValue : Component, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8>
|
||||
{
|
||||
Transform _originalParent;
|
||||
|
||||
[Inject]
|
||||
public MonoPoolableMemoryPool()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnCreated(TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_originalParent = item.transform.parent;
|
||||
}
|
||||
|
||||
protected override void OnDestroyed(TValue item)
|
||||
{
|
||||
GameObject.Destroy(item.gameObject);
|
||||
}
|
||||
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
item.gameObject.SetActive(false);
|
||||
|
||||
if (item.transform.parent != _originalParent)
|
||||
{
|
||||
item.transform.SetParent(_originalParent, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TParam8 p8, TValue item)
|
||||
{
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnSpawned(p1, p2, p3, p4, p5, p6, p7, p8);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5475433f41ca61c4a9095affbf60b848
|
||||
timeCreated: 1528535898
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Here we assume that each spawned object does the work of returning itself to the pool
|
||||
// in its own Dispose method
|
||||
public class PoolWrapperFactory<T> : IFactory<T>
|
||||
where T : IDisposable
|
||||
{
|
||||
readonly IMemoryPool<T> _pool;
|
||||
|
||||
public PoolWrapperFactory(IMemoryPool<T> pool)
|
||||
{
|
||||
_pool = pool;
|
||||
}
|
||||
|
||||
public T Create()
|
||||
{
|
||||
return _pool.Spawn();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolWrapperFactory<TParam1, TValue> : IFactory<TParam1, TValue>
|
||||
where TValue : IDisposable
|
||||
{
|
||||
readonly IMemoryPool<TParam1, TValue> _pool;
|
||||
|
||||
public PoolWrapperFactory(IMemoryPool<TParam1, TValue> pool)
|
||||
{
|
||||
_pool = pool;
|
||||
}
|
||||
|
||||
public TValue Create(TParam1 arg)
|
||||
{
|
||||
return _pool.Spawn(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 125bde4ab63a4984484c450640ee1702
|
||||
timeCreated: 1518946218
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,147 @@
|
||||
namespace Zenject
|
||||
{
|
||||
// Zero parameters
|
||||
public class PoolableMemoryPool<TValue>
|
||||
: MemoryPool<TValue>
|
||||
where TValue : IPoolable
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TValue item)
|
||||
{
|
||||
item.OnSpawned();
|
||||
}
|
||||
}
|
||||
|
||||
// One parameters
|
||||
public class PoolableMemoryPool<TParam1, TValue>
|
||||
: MemoryPool<TParam1, TValue>
|
||||
where TValue : IPoolable<TParam1>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1);
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2);
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2, TParam3>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2, p3);
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2, TParam3, TParam4>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2, p3, p4);
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2, p3, p4, p5);
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2, p3, p4, p5, p6);
|
||||
}
|
||||
}
|
||||
|
||||
// Seven parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2, p3, p4, p5, p6, p7);
|
||||
}
|
||||
}
|
||||
|
||||
// Eight parameters
|
||||
public class PoolableMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>
|
||||
: MemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TValue>
|
||||
where TValue : IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8>
|
||||
{
|
||||
protected override void OnDespawned(TValue item)
|
||||
{
|
||||
item.OnDespawned();
|
||||
}
|
||||
|
||||
protected override void Reinitialize(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TParam8 p8, TValue item)
|
||||
{
|
||||
item.OnSpawned(p1, p2, p3, p4, p5, p6, p7, p8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fa0c435e1800a048ac5f7c53e03472d
|
||||
timeCreated: 1517205083
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28d06bc0b4cdf374ca41d78b0ec5dc0a
|
||||
folderAsset: yes
|
||||
timeCreated: 1515014902
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,154 @@
|
||||
namespace Zenject
|
||||
{
|
||||
public class PoolableStaticMemoryPool<TValue> : StaticMemoryPool<TValue>
|
||||
where TValue : class, IPoolable, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TValue value)
|
||||
{
|
||||
value.OnSpawned();
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TValue> : StaticMemoryPool<TParam1, TValue>
|
||||
where TValue : class, IPoolable<TParam1>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TParam2, TValue> : StaticMemoryPool<TParam1, TParam2, TValue>
|
||||
where TValue : class, IPoolable<TParam1, TParam2>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TParam2 p2, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1, p2);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TParam2, TParam3, TValue> : StaticMemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
where TValue : class, IPoolable<TParam1, TParam2, TParam3>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TParam2 p2, TParam3 p3, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1, p2, p3);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue> : StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
where TValue : class, IPoolable<TParam1, TParam2, TParam3, TParam4>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1, p2, p3, p4);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue> : StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
where TValue : class, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1, p2, p3, p4, p5);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> : StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
where TValue : class, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1, p2, p3, p4, p5, p6);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolableStaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue> : StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
where TValue : class, IPoolable<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7>, new()
|
||||
{
|
||||
public PoolableStaticMemoryPool()
|
||||
: base(OnSpawned, OnDespawned)
|
||||
{
|
||||
}
|
||||
|
||||
static void OnSpawned(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7, TValue value)
|
||||
{
|
||||
value.OnSpawned(p1, p2, p3, p4, p5, p6, p7);
|
||||
}
|
||||
|
||||
static void OnDespawned(TValue value)
|
||||
{
|
||||
value.OnDespawned();
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bf78918a4d09d44695230ef305b6e1a
|
||||
timeCreated: 1528618262
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,557 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
[NoReflectionBaking]
|
||||
public abstract class StaticMemoryPoolBaseBase<TValue> : IDespawnableMemoryPool<TValue>, IDisposable
|
||||
where TValue : class
|
||||
{
|
||||
// I also tried using ConcurrentBag instead of Stack + lock here but that performed much much worse
|
||||
readonly Stack<TValue> _stack = new Stack<TValue>();
|
||||
|
||||
Action<TValue> _onDespawnedMethod;
|
||||
int _activeCount;
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
protected readonly object _locker = new object();
|
||||
#endif
|
||||
|
||||
public StaticMemoryPoolBaseBase(Action<TValue> onDespawnedMethod)
|
||||
{
|
||||
_onDespawnedMethod = onDespawnedMethod;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
StaticMemoryPoolRegistry.Add(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public Action<TValue> OnDespawnedMethod
|
||||
{
|
||||
set { _onDespawnedMethod = value; }
|
||||
}
|
||||
|
||||
public int NumTotal
|
||||
{
|
||||
get { return NumInactive + NumActive; }
|
||||
}
|
||||
|
||||
public int NumActive
|
||||
{
|
||||
get
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
return _activeCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int NumInactive
|
||||
{
|
||||
get
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
return _stack.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Type ItemType
|
||||
{
|
||||
get { return typeof(TValue); }
|
||||
}
|
||||
|
||||
public void Resize(int desiredPoolSize)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
ResizeInternal(desiredPoolSize);
|
||||
}
|
||||
}
|
||||
|
||||
// We assume here that we're in a lock
|
||||
void ResizeInternal(int desiredPoolSize)
|
||||
{
|
||||
Assert.That(desiredPoolSize >= 0, "Attempted to resize the pool to a negative amount");
|
||||
|
||||
while (_stack.Count > desiredPoolSize)
|
||||
{
|
||||
_stack.Pop();
|
||||
}
|
||||
|
||||
while (desiredPoolSize > _stack.Count)
|
||||
{
|
||||
_stack.Push(Alloc());
|
||||
}
|
||||
|
||||
Assert.IsEqual(_stack.Count, desiredPoolSize);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
StaticMemoryPoolRegistry.Remove(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ClearActiveCount()
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
_activeCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Resize(0);
|
||||
}
|
||||
|
||||
public void ShrinkBy(int numToRemove)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
ResizeInternal(_stack.Count - numToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
public void ExpandBy(int numToAdd)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
ResizeInternal(_stack.Count + numToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
// We assume here that we're in a lock
|
||||
protected TValue SpawnInternal()
|
||||
{
|
||||
TValue element;
|
||||
|
||||
if (_stack.Count == 0)
|
||||
{
|
||||
element = Alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
element = _stack.Pop();
|
||||
}
|
||||
|
||||
_activeCount++;
|
||||
return element;
|
||||
}
|
||||
|
||||
void IMemoryPool.Despawn(object item)
|
||||
{
|
||||
Despawn((TValue)item);
|
||||
}
|
||||
|
||||
public void Despawn(TValue element)
|
||||
{
|
||||
if (_onDespawnedMethod != null)
|
||||
{
|
||||
_onDespawnedMethod(element);
|
||||
}
|
||||
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
Assert.That(!_stack.Contains(element), "Attempted to despawn element twice!");
|
||||
|
||||
_activeCount--;
|
||||
_stack.Push(element);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract TValue Alloc();
|
||||
}
|
||||
|
||||
[NoReflectionBaking]
|
||||
public abstract class StaticMemoryPoolBase<TValue> : StaticMemoryPoolBaseBase<TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
public StaticMemoryPoolBase(Action<TValue> onDespawnedMethod)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TValue Alloc()
|
||||
{
|
||||
return new TValue();
|
||||
}
|
||||
}
|
||||
|
||||
// Zero parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
Action<TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
Action<TValue> onSpawnMethod = null, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public Action<TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn()
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One parameter
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
Action<TParam1, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
Action<TParam1, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public Action<TParam1, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 param)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(param, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Two parameter
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TParam2, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
Action<TParam1, TParam2, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
Action<TParam1, TParam2, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public Action<TParam1, TParam2, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 p1, TParam2 p2)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(p1, p2, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Three parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TParam2, TParam3, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
Action<TParam1, TParam2, TParam3, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
Action<TParam1, TParam2, TParam3, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public Action<TParam1, TParam2, TParam3, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 p1, TParam2 p2, TParam3 p3)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(p1, p2, p3, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Four parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(p1, p2, p3, p4, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Five parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(p1, p2, p3, p4, p5, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Six parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(p1, p2, p3, p4, p5, p6, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Seven parameters
|
||||
|
||||
[NoReflectionBaking]
|
||||
public class StaticMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue> : StaticMemoryPoolBase<TValue>, IMemoryPool<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue>
|
||||
where TValue : class, new()
|
||||
{
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue> _onSpawnMethod;
|
||||
|
||||
public StaticMemoryPool(
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue> onSpawnMethod, Action<TValue> onDespawnedMethod = null)
|
||||
: base(onDespawnedMethod)
|
||||
{
|
||||
// What's the point of having a param otherwise?
|
||||
Assert.IsNotNull(onSpawnMethod);
|
||||
_onSpawnMethod = onSpawnMethod;
|
||||
}
|
||||
|
||||
public
|
||||
#if !NET_4_6
|
||||
ModestTree.Util.
|
||||
#endif
|
||||
Action<TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TValue> OnSpawnMethod
|
||||
{
|
||||
set { _onSpawnMethod = value; }
|
||||
}
|
||||
|
||||
public TValue Spawn(TParam1 p1, TParam2 p2, TParam3 p3, TParam4 p4, TParam5 p5, TParam6 p6, TParam7 p7)
|
||||
{
|
||||
#if ZEN_MULTITHREADING
|
||||
lock (_locker)
|
||||
#endif
|
||||
{
|
||||
var item = SpawnInternal();
|
||||
|
||||
if (_onSpawnMethod != null)
|
||||
{
|
||||
_onSpawnMethod(p1, p2, p3, p4, p5, p6, p7, item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56b2eb81b3385fd47a0500abeac7b60e
|
||||
timeCreated: 1528024394
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6214acccd2e0c2044921cc068fb3d0a6
|
||||
folderAsset: yes
|
||||
timeCreated: 1520607639
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
Reference in New Issue
Block a user