Добавил поддержку распараллеливания для рассчетов : )
Код
namespace Pixeye.Source
{
sealed class ProcessorTest : Processor, ITick
{
public Group<ComponentPosition> groupThreaded;
public ProcessorTest()
{
groupThreaded.MakeConcurrent(100000, Environment.ProcessorCount - 1, HandleCalculation);
}
public void Tick(float delta)
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
for (int i = 0; i < 500000; i++)
{
var e = Entity.Create();
e.Set<ComponentPosition>();
}
}
// One thread
if (Input.GetKeyDown(KeyCode.Alpha2))
{
for (int i = 0; i < groupThreaded.length; i++)
{
ref var entity = ref groupThreaded.entities[i];
ref var cPosition = ref entity.ComponentPosition();
for (int j = 0; j < 1000; j++)
{
cPosition.pos.x += 1 * delta;
}
}
}
// MultiThread
if (Input.GetKeyDown(KeyCode.Alpha3))
groupThreaded.Execute(delta);
}
static void HandleCalculation(SegmentGroup segment)
{
for (int i = segment.indexFrom; i < segment.indexTo; i++)
{
ref var entity = ref segment.source.entities[i];
ref var cPosition = ref entity.ComponentPosition();
for (int j = 0; j < 1000; j++)
{
cPosition.pos.x += 1 * segment.delta;
}
}
}
}
}
