fix EntitiesInRandomOrder
parent
5f0d694eb4
commit
4268762a0c
|
@ -15,7 +15,7 @@ namespace MoonTools.ECS
|
|||
}
|
||||
|
||||
public ReverseSpanEnumerator<Entity> Entities => FilterStorage.FilterEntities(Signature);
|
||||
public LinearCongruentialEnumerator EntitiesInRandomOrder => FilterStorage.FilterEntitiesRandom(Signature);
|
||||
public RandomEntityEnumerator EntitiesInRandomOrder => FilterStorage.FilterEntitiesRandom(Signature);
|
||||
public Entity RandomEntity => FilterStorage.FilterRandomEntity(Signature);
|
||||
|
||||
public int Count => FilterStorage.FilterCount(Signature);
|
||||
|
|
|
@ -54,9 +54,12 @@ namespace MoonTools.ECS
|
|||
return filterSignatureToEntityIDs[filterSignature].GetEnumerator();
|
||||
}
|
||||
|
||||
public LinearCongruentialEnumerator FilterEntitiesRandom(FilterSignature filterSignature)
|
||||
public RandomEntityEnumerator FilterEntitiesRandom(FilterSignature filterSignature)
|
||||
{
|
||||
return RandomGenerator.LinearCongruentialGenerator(FilterCount(filterSignature));
|
||||
return new RandomEntityEnumerator(
|
||||
this,
|
||||
filterSignature,
|
||||
RandomGenerator.LinearCongruentialGenerator(FilterCount(filterSignature)));
|
||||
}
|
||||
|
||||
public Entity FilterNthEntity(FilterSignature filterSignature, int index)
|
||||
|
@ -178,4 +181,26 @@ namespace MoonTools.ECS
|
|||
removeCallbacks.Add(filterSignature, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct RandomEntityEnumerator
|
||||
{
|
||||
public RandomEntityEnumerator GetEnumerator() => this;
|
||||
|
||||
private FilterStorage FilterStorage;
|
||||
private FilterSignature FilterSignature;
|
||||
private LinearCongruentialEnumerator LinearCongruentialEnumerator;
|
||||
|
||||
internal RandomEntityEnumerator(
|
||||
FilterStorage filterStorage,
|
||||
FilterSignature filterSignature,
|
||||
LinearCongruentialEnumerator linearCongruentialEnumerator)
|
||||
{
|
||||
FilterStorage = filterStorage;
|
||||
FilterSignature = filterSignature;
|
||||
LinearCongruentialEnumerator = linearCongruentialEnumerator;
|
||||
}
|
||||
|
||||
public bool MoveNext() => LinearCongruentialEnumerator.MoveNext();
|
||||
public Entity Current => FilterStorage.FilterNthEntity(FilterSignature, LinearCongruentialEnumerator.Current);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue