2012-08-05 04:06:17 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class AABBPool {
|
|
|
|
|
|
|
|
private final int a;
|
|
|
|
private final int b;
|
2012-10-25 05:53:23 +02:00
|
|
|
private final List pool = new ArrayList();
|
2012-08-05 04:06:17 +02:00
|
|
|
private int d = 0;
|
2012-10-25 05:53:23 +02:00
|
|
|
private int largestSize = 0;
|
|
|
|
private int resizeTime = 0;
|
2012-08-05 04:06:17 +02:00
|
|
|
|
|
|
|
public AABBPool(int i, int j) {
|
|
|
|
this.a = i;
|
|
|
|
this.b = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AxisAlignedBB a(double d0, double d1, double d2, double d3, double d4, double d5) {
|
2012-10-25 05:53:23 +02:00
|
|
|
// CraftBukkit - don't pool objects indefinitely if thread doesn't adhere to contract
|
|
|
|
if (this.resizeTime == 0) return new AxisAlignedBB(d0, d1, d2, d3, d4, d5);
|
2012-08-05 04:06:17 +02:00
|
|
|
AxisAlignedBB axisalignedbb;
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.d >= this.pool.size()) {
|
2012-08-05 04:06:17 +02:00
|
|
|
axisalignedbb = new AxisAlignedBB(d0, d1, d2, d3, d4, d5);
|
2012-10-25 05:53:23 +02:00
|
|
|
this.pool.add(axisalignedbb);
|
2012-08-05 04:06:17 +02:00
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
axisalignedbb = (AxisAlignedBB) this.pool.get(this.d);
|
2012-08-05 04:06:17 +02:00
|
|
|
axisalignedbb.b(d0, d1, d2, d3, d4, d5);
|
|
|
|
}
|
|
|
|
|
|
|
|
++this.d;
|
|
|
|
return axisalignedbb;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a() {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.d > this.largestSize) {
|
|
|
|
this.largestSize = this.d;
|
2012-08-05 04:06:17 +02:00
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Intelligent cache
|
2012-10-25 05:53:23 +02:00
|
|
|
if ((this.resizeTime++ & 0xff) == 0) {
|
|
|
|
int newSize = this.pool.size() - (this.pool.size() >> 3);
|
|
|
|
// newSize will be 87.5%, but if we were not in that range, we clear some of the cache
|
|
|
|
if (newSize > this.largestSize) {
|
|
|
|
// Work down from size() to prevent insane array copies
|
|
|
|
for (int i = this.pool.size() - 1; i > newSize; i--) {
|
|
|
|
this.pool.remove(i);
|
2012-08-05 04:11:28 +02:00
|
|
|
}
|
2012-08-05 04:06:17 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.largestSize = 0;
|
|
|
|
// this.resizeTime = 0; // We do not reset to zero; it doubles for a flag
|
2012-08-05 04:06:17 +02:00
|
|
|
}
|
2012-08-05 04:11:28 +02:00
|
|
|
// CraftBukkit end
|
2012-08-05 04:06:17 +02:00
|
|
|
|
|
|
|
this.d = 0;
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
public int c() {
|
|
|
|
return this.pool.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int d() {
|
|
|
|
return this.d;
|
|
|
|
}
|
2012-08-05 04:06:17 +02:00
|
|
|
}
|