mirror of
https://github.com/DCFApixels/DragonECS-ClassicThreads.git
synced 2025-09-17 19:24:37 +08:00
even split
This commit is contained in:
parent
4748c43eaf
commit
8fa27157b7
@ -76,14 +76,20 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
if (threadsCount > 1)
|
if (threadsCount > 1)
|
||||||
{
|
{
|
||||||
int spanSize = entitiesCount / (threadsCount - 1);
|
int remainder = entitiesCount % threadsCount;
|
||||||
for (int i = 0; i < threadsCount; i++)
|
int quotient = entitiesCount / threadsCount;
|
||||||
|
for (int i = 0, start = 0; i < threadsCount; i++)
|
||||||
{
|
{
|
||||||
ref var thread = ref _threads[i];
|
ref var thread = ref _threads[i];
|
||||||
thread.start = i * spanSize;
|
thread.start = start;
|
||||||
thread.size = spanSize;
|
thread.size = quotient;
|
||||||
|
if (remainder > 0)
|
||||||
|
{
|
||||||
|
thread.size++;
|
||||||
|
remainder--;
|
||||||
|
}
|
||||||
|
start += thread.size;
|
||||||
}
|
}
|
||||||
_threads[threadsCount - 1].size = entities.Count % (threadsCount - 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user