mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 16:06:28 +01:00
Prime update divisors
- Smooths out load when ticking too many instances
This commit is contained in:
parent
e5db27379e
commit
90173360f4
1 changed files with 5 additions and 1 deletions
|
@ -212,10 +212,14 @@ public abstract class InstanceManager<T> implements MaterialManager.OriginShiftL
|
||||||
return (frame % getUpdateDivisor(dX, dY, dZ)) == 0;
|
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) {
|
protected int getUpdateDivisor(int dX, int dY, int dZ) {
|
||||||
int dSq = dX * dX + dY * dY + dZ * 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) {
|
protected void addInternal(T tile) {
|
||||||
|
|
Loading…
Reference in a new issue