3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00

Chunk fetching improvements

Dieser Commit ist enthalten in:
Tahg 2011-02-07 00:56:07 -05:00
Ursprung 172db788b3
Commit 3629580868
6 geänderte Dateien mit 2042 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -395,6 +395,7 @@ public class Chunk {
if (i != this.j || j != this.k) {
System.out.println("Wrong location! " + entity);
System.out.println("" + entity.locX + "," + entity.locZ + "(" + i + "," + j + ") vs " + this.j + "," + this.k);
Thread.dumpStack();
}

Datei anzeigen

@ -11,18 +11,17 @@ import java.util.Set;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.Event.Type;
import org.bukkit.event.world.ChunkLoadEvent;
// CraftBukkit end
public class ChunkProviderServer implements IChunkProvider {
private Set a = new HashSet();
private LongHashset a = new LongHashset();
private Chunk b;
private IChunkProvider c;
private IChunkLoader d;
private Map e = new HashMap();
private LongHashtable<Chunk> e = new LongHashtable<Chunk>();
private List f = new ArrayList();
private WorldServer g;
@ -47,9 +46,7 @@ public class ChunkProviderServer implements IChunkProvider {
// CraftBukkit end
public boolean a(int i, int j) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
return this.e.containsKey(chunkcoordinates);
return this.e.containsKey(i, j);
}
public void c(int i, int j) {
@ -58,15 +55,13 @@ public class ChunkProviderServer implements IChunkProvider {
short short1 = 128;
if (k < -short1 || k > short1 || l < -short1 || l > short1) {
this.a.add(new ChunkCoordinates(i, j));
this.a.add(i, j);
}
}
public Chunk d(int i, int j) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
this.a.remove(new ChunkCoordinates(i, j));
Chunk chunk = (Chunk) this.e.get(chunkcoordinates);
this.a.remove(i, j);
Chunk chunk = (Chunk) this.e.get(i, j);
if (chunk == null) {
chunk = this.e(i, j);
@ -78,7 +73,7 @@ public class ChunkProviderServer implements IChunkProvider {
}
}
this.e.put(chunkcoordinates, chunk);
this.e.put(i, j, chunk);
this.f.add(chunk);
if (chunk != null) {
chunk.c();
@ -118,8 +113,7 @@ public class ChunkProviderServer implements IChunkProvider {
}
public Chunk b(int i, int j) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
Chunk chunk = (Chunk) this.e.get(chunkcoordinates);
Chunk chunk = (Chunk) this.e.get(i, j);
return chunk == null ? (this.g.x ? this.d(i, j) : this.b) : chunk;
}
@ -211,13 +205,12 @@ public class ChunkProviderServer implements IChunkProvider {
if (!this.g.C) {
for (int i = 0; i < 100; ++i) {
if (!this.a.isEmpty()) {
ChunkCoordinates chunkcoordinates = (ChunkCoordinates) this.a.iterator().next();
Chunk chunk = this.b(chunkcoordinates.a, chunkcoordinates.b);
long chunkcoordinates = this.a.popFirst();
Chunk chunk = e.get(chunkcoordinates);
if(chunk == null) continue;
chunk.e();
this.b(chunk);
this.a(chunk);
this.a.remove(chunkcoordinates);
this.e.remove(chunkcoordinates);
this.f.remove(chunk);
}

Datei anzeigen

@ -0,0 +1,36 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.minecraft.server;
/**
*
* @author Nathan
*/
public abstract class LongHash<V> {
static long toLong(int msw, int lsw) {
return ((long)msw << 32) + lsw - Integer.MIN_VALUE;
}
static int msw(long l) {
return (int) (l >> 32);
}
static int lsw(long l) {
return (int) (l & 0xFFFFFFFF) + Integer.MIN_VALUE;
}
public boolean containsKey(int msw, int lsw) {
return containsKey(toLong(msw, lsw));
}
public void remove(int msw, int lsw) {
remove(toLong(msw, lsw));
}
public abstract boolean containsKey(long key);
public abstract void remove(long key);
}

Datei anzeigen

@ -0,0 +1,109 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.minecraft.server;
import java.util.ArrayList;
import java.util.Arrays;
/**
*
* @author Nathan
*/
public class LongHashset<V> extends LongHash<V> {
long values[][][] = new long[256][][];
int count = 0;
public boolean isEmpty() {
return count == 0;
}
public void add(long key, V value) {
int idx1 = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255);
long obj1[][] = values[idx1], obj2[];
if(obj1 == null) values[idx1] = obj1 = new long[256][];
obj2 = obj1[idx2];
if(obj2 == null) {
obj1[idx2] = obj2 = new long[1];
obj2[0] = key;
count++;
}
else {
int i;
for(i = 0; i < obj2.length; i++) {
if(obj2[i] == key) {
return;
}
}
obj2 = Arrays.copyOf(obj2, i+1);
obj2[i] = key;
count++;
}
}
public boolean containsKey(long key) {
int idx1 = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255);
long obj1[][] = values[idx1], obj2[];
if(obj1 == null) return false;
obj2 = obj1[idx2];
if(obj2 == null) return false;
else {
for(long entry : obj2) {
if(entry == key) return true;
}
return false;
}
}
public void remove(long key) {
int idx1 = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255);
long obj1[][] = values[idx1], obj2[];
if(obj1 == null) return;
obj2 = obj1[idx2];
if(obj2 == null) return;
else {
int max = obj2.length - 1;
for(int i = 0; i <= max; i++) {
if(obj2[i] == key) {
count--;
if(i != max) {
obj2[i] = obj2[max];
}
obj2 = Arrays.copyOf(obj2, max);
}
}
}
}
public long popFirst() {
for(long[][] outer : values) {
if(outer == null) continue;
for(long[] inner : outer) {
if(inner == null) continue;
long ret = inner[inner.length - 1];
inner = Arrays.copyOf(inner, inner.length - 1);
return ret;
}
}
return 0;
}
public long[] keys() {
int index = 0;
long ret[] = new long[count];
for(long[][] outer : values) {
if(outer == null) continue;
for(long[] inner : outer) {
if(inner == null) continue;
for(long entry : inner) {
ret[index++] = entry;
}
}
}
return ret;
}
}

Datei anzeigen

@ -0,0 +1,100 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.minecraft.server;
import java.util.ArrayList;
import java.util.Arrays;
/**
*
* @author Nathan
*/
public class LongHashtable<V> extends LongHash {
Object values[][][] = new Object[256][][];
Entry cache = null;
public void put(int msw, int lsw, V value) {
put(toLong(msw, lsw), value);
}
public V get(int msw, int lsw) {
return get(toLong(msw, lsw));
}
public void put(long key, V value) {
int idx1 = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255);
Object obj1[][] = values[idx1], obj2[];
if(obj1 == null) values[idx1] = obj1 = new Object[256][];
obj2 = obj1[idx2];
if(obj2 == null) {
obj1[idx2] = obj2 = new Object[5];
obj2[0] = cache = new Entry(key, value);
}
else {
int i;
for(i = 0; i < obj2.length; i++) {
if(obj2[i] == null || ((Entry)obj2[i]).key == key) {
obj2[i] = cache = new Entry(key, value);
return;
}
}
obj2 = Arrays.copyOf(obj2, i+i);
obj2[i] = new Entry(key, value);
}
}
public V get(long key) {
return containsKey(key) ? (V) cache.value : null;
}
public boolean containsKey(long key) {
if(cache != null && cache.key == key) return true;
int idx1 = (int) (key & 255);
int idx2 = (int) ((key >> 32) & 255);
Object obj1[][] = values[idx1], obj2[];
if(obj1 == null) return false;
obj2 = obj1[idx2];
if(obj2 == null) return false;
else {
for(int i = 0; i < obj2.length; i++) {
Entry e = (Entry)obj2[i];
if(e == null) return false;
else if(e.key == key) {
cache = e;
return true;
}
}
return false;
}
}
public void remove(long key) {
}
public ArrayList<V> values() {
ArrayList<V> ret = new ArrayList<V>();
for(Object[][] outer : values) {
if(outer == null) continue;
for(Object[] inner : outer) {
if(inner == null) continue;
for(Object entry : inner) {
if(entry == null) break;
ret.add((V)entry);
}
}
}
return ret;
}
private class Entry {
long key;
Object value;
Entry(long k, Object v) {
key = k;
value = v;
}
}
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden