mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
Prime update divisors
- Smooths out load when ticking too many instances
This commit is contained in:
parent
e5db27379e
commit
90173360f4
@ -212,10 +212,14 @@ public abstract class InstanceManager<T> implements MaterialManager.OriginShiftL
|
||||
return (frame % getUpdateDivisor(dX, dY, dZ)) == 0;
|
||||
}
|
||||
|
||||
// 1 followed by the prime numbers
|
||||
private static final int[] divisorSequence = new int[] { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
|
||||
protected int getUpdateDivisor(int dX, int dY, int dZ) {
|
||||
int dSq = dX * dX + dY * dY + dZ * dZ;
|
||||
|
||||
return (dSq / 1024) + 1;
|
||||
int i = (dSq / 2048);
|
||||
|
||||
return divisorSequence[Math.min(i, divisorSequence.length - 1)];
|
||||
}
|
||||
|
||||
protected void addInternal(T tile) {
|
||||
|
Loading…
Reference in New Issue
Block a user