mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
GetProcesses optimization
This commit is contained in:
parent
0c3cb79119
commit
ba3ce72029
@ -99,11 +99,38 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = _allSystems.OfType<T>().ToArray();
|
result = CreateProcess<T>();
|
||||||
_processes.Add(type, result);
|
_processes.Add(type, result);
|
||||||
}
|
}
|
||||||
return new EcsProcess<T>(result);
|
return new EcsProcess<T>(result);
|
||||||
}
|
}
|
||||||
|
[ThreadStatic]
|
||||||
|
private static IEcsProcess[] _buffer;
|
||||||
|
private T[] CreateProcess<T>() where T : IEcsProcess
|
||||||
|
{
|
||||||
|
if(_buffer == null || _buffer.Length < _allSystems.Length)
|
||||||
|
{
|
||||||
|
if(_buffer == null)
|
||||||
|
{
|
||||||
|
_buffer = new IEcsProcess[_allSystems.Length];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Array.Resize(ref _buffer, _allSystems.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int l = 0;
|
||||||
|
for (int i = 0, iMax = _allSystems.Length; i < iMax; i++)
|
||||||
|
{
|
||||||
|
if (_allSystems[i] is T)
|
||||||
|
{
|
||||||
|
_buffer[l++] = _allSystems[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
T[] result = new T[l];
|
||||||
|
Array.Copy(_buffer, result, l);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetRunner
|
#region GetRunner
|
||||||
|
Loading…
Reference in New Issue
Block a user