2012-08-06 04:36:09 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class Vec3DPool {
|
|
|
|
|
|
|
|
private final int a;
|
|
|
|
private final int b;
|
2012-08-12 00:27:27 +02:00
|
|
|
// CraftBukkit start
|
2012-10-25 05:53:23 +02:00
|
|
|
// private final List pool = new ArrayList();
|
2012-08-12 00:27:27 +02:00
|
|
|
private Vec3D freelist = null;
|
|
|
|
private Vec3D alloclist = null;
|
|
|
|
private Vec3D freelisthead = null;
|
|
|
|
private Vec3D alloclisthead = null;
|
|
|
|
private int total_size = 0;
|
|
|
|
// CraftBukkit end
|
2013-07-01 13:03:00 +02:00
|
|
|
private int position;
|
|
|
|
private int largestSize;
|
|
|
|
private int resizeTime;
|
2012-08-06 04:36:09 +02:00
|
|
|
|
|
|
|
public Vec3DPool(int i, int j) {
|
|
|
|
this.a = i;
|
|
|
|
this.b = j;
|
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
public final Vec3D create(double d0, double d1, double d2) { // CraftBukkit - Add final
|
|
|
|
if (this.resizeTime == 0) return Vec3D.a(d0, d1, d2); // CraftBukkit - Don't pool objects indefinitely if thread doesn't adhere to contract
|
2012-08-06 04:36:09 +02:00
|
|
|
Vec3D vec3d;
|
|
|
|
|
2012-08-12 00:27:27 +02:00
|
|
|
if (this.freelist == null) { // CraftBukkit
|
2012-10-25 05:53:23 +02:00
|
|
|
vec3d = new Vec3D(this, d0, d1, d2);
|
2012-08-12 00:27:27 +02:00
|
|
|
this.total_size++; // CraftBukkit
|
2012-08-06 04:36:09 +02:00
|
|
|
} else {
|
2012-08-12 00:27:27 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
vec3d = this.freelist;
|
|
|
|
this.freelist = vec3d.next;
|
|
|
|
// CraftBukkit end
|
2012-08-06 04:36:09 +02:00
|
|
|
vec3d.b(d0, d1, d2);
|
|
|
|
}
|
|
|
|
|
2012-08-12 00:27:27 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
if (this.alloclist == null) {
|
|
|
|
this.alloclisthead = vec3d;
|
|
|
|
}
|
2013-03-25 05:22:32 +01:00
|
|
|
vec3d.next = this.alloclist; // Add to allocated list
|
2012-08-12 00:27:27 +02:00
|
|
|
this.alloclist = vec3d;
|
|
|
|
// CraftBukkit end
|
2012-10-25 05:53:23 +02:00
|
|
|
++this.position;
|
2012-08-06 04:36:09 +02:00
|
|
|
return vec3d;
|
|
|
|
}
|
2012-09-14 07:03:47 +02:00
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Offer back vector (can save LOTS of unneeded bloat) - works about 90% of the time
|
2012-08-12 00:27:27 +02:00
|
|
|
public void release(Vec3D v) {
|
|
|
|
if (this.alloclist == v) {
|
|
|
|
this.alloclist = v.next; // Pop off alloc list
|
|
|
|
// Push on to free list
|
|
|
|
if (this.freelist == null) this.freelisthead = v;
|
|
|
|
v.next = this.freelist;
|
|
|
|
this.freelist = v;
|
2012-10-25 05:53:23 +02:00
|
|
|
this.position--;
|
2012-08-12 00:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-08-06 04:36:09 +02:00
|
|
|
|
|
|
|
public void a() {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.position > this.largestSize) {
|
|
|
|
this.largestSize = this.position;
|
2012-08-06 04:36:09 +02:00
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Intelligent cache
|
2012-08-12 00:27:27 +02:00
|
|
|
// Take any allocated blocks and put them on free list
|
|
|
|
if (this.alloclist != null) {
|
|
|
|
if (this.freelist == null) {
|
|
|
|
this.freelist = this.alloclist;
|
|
|
|
this.freelisthead = this.alloclisthead;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.alloclisthead.next = this.freelist;
|
|
|
|
this.freelist = this.alloclist;
|
|
|
|
this.freelisthead = this.alloclisthead;
|
|
|
|
}
|
|
|
|
this.alloclist = null;
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
if ((this.resizeTime++ & 0xff) == 0) {
|
2012-08-12 00:27:27 +02:00
|
|
|
int newSize = total_size - (total_size >> 3);
|
2012-10-25 05:53:23 +02:00
|
|
|
if (newSize > this.largestSize) { // newSize will be 87.5%, but if we were not in that range, we clear some of the cache
|
2012-08-12 00:27:27 +02:00
|
|
|
for (int i = total_size; i > newSize; i--) {
|
|
|
|
freelist = freelist.next;
|
2012-08-06 04:36:25 +02:00
|
|
|
}
|
2012-08-12 00:27:27 +02:00
|
|
|
total_size = newSize;
|
2012-08-06 04:36:09 +02:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
this.largestSize = 0;
|
2012-08-06 04:36:25 +02:00
|
|
|
// this.f = 0; // We do not reset to zero; it doubles for a flag
|
2012-08-06 04:36:09 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.position = 0;
|
2013-07-01 13:03:00 +02:00
|
|
|
// CraftBukkit end
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int c() {
|
|
|
|
return this.total_size; // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
public int d() {
|
|
|
|
return this.position;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean e() {
|
|
|
|
return this.b < 0 || this.a < 0;
|
2012-08-06 04:36:09 +02:00
|
|
|
}
|
|
|
|
}
|