mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
optimize CreatePool
This commit is contained in:
parent
4c183bd126
commit
d7b40e33b1
@ -1,6 +1,5 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
@ -106,8 +105,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
Throw.World_PoolAlreadyCreated();
|
Throw.World_PoolAlreadyCreated();
|
||||||
}
|
}
|
||||||
|
TPool newPool = new TPool();
|
||||||
|
|
||||||
Type componentType = typeof(TPool).GetInterfaces().First(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEcsPoolImplementation<>)).GetGenericArguments()[0];
|
Type componentType = newPool.ComponentType;
|
||||||
int componentTypeCode = EcsTypeCode.Get(componentType);
|
int componentTypeCode = EcsTypeCode.Get(componentType);
|
||||||
|
|
||||||
if (_componentTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int componentTypeID))
|
if (_componentTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int componentTypeID))
|
||||||
@ -134,13 +134,14 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pools[componentTypeID] == _nullPool)
|
if (_pools[componentTypeID] != _nullPool)
|
||||||
{
|
{
|
||||||
var pool = new TPool();
|
Throw.UndefinedException();
|
||||||
_pools[componentTypeID] = pool;
|
|
||||||
pool.OnInit(this, _poolsMediator, componentTypeID);
|
|
||||||
}
|
}
|
||||||
return (TPool)_pools[componentTypeID];
|
|
||||||
|
_pools[componentTypeID] = newPool;
|
||||||
|
newPool.OnInit(this, _poolsMediator, componentTypeID);
|
||||||
|
return newPool;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user