Optimize Chunk Storage, made a slight FPS boost
This commit is contained in:
parent
3f03c09656
commit
458e47b0d5
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,6 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
@ -23,14 +24,14 @@ public class ChunkLoader implements IChunkLoader {
|
|||
int unsignedX = x + 30233088;
|
||||
int unsignedZ = z + 30233088;
|
||||
int radix = CHUNK_CHARS.length();
|
||||
char[] path = new char[10];
|
||||
StringBuilder path = new StringBuilder(10);
|
||||
for(int i = 0; i < 5; ++i) {
|
||||
path[i * 2] = CHUNK_CHARS.charAt(unsignedX % radix);
|
||||
path.append(CHUNK_CHARS.charAt(unsignedX % radix));
|
||||
unsignedX /= radix;
|
||||
path[i * 2 + 1] = CHUNK_CHARS.charAt(unsignedZ % radix);
|
||||
path.append(CHUNK_CHARS.charAt(unsignedZ % radix));
|
||||
unsignedZ /= radix;
|
||||
}
|
||||
return new String(path);
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
public Chunk loadChunk(World var1, int x, int z) {
|
||||
|
@ -67,14 +68,16 @@ public class ChunkLoader implements IChunkLoader {
|
|||
NBTTagCompound toSave = new NBTTagCompound();
|
||||
storeChunkInCompound(var2, var1, toSave);
|
||||
ByteArrayOutputStream bao = new ByteArrayOutputStream(131072);
|
||||
try {
|
||||
NBTBase.writeNamedTag(toSave, new DataOutputStream(bao));
|
||||
try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(bao))) {
|
||||
NBTBase.writeNamedTag(toSave, dos);
|
||||
dos.flush();
|
||||
byte[] data = bao.toByteArray();
|
||||
LWJGLMain.writeFile(saveDir + "/" + chunkFileForXZ(var2.xPosition, var2.zPosition), data);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to serialize chunk at [" + var2.xPosition + ", " + var2.zPosition + "] to byte array");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
LWJGLMain.writeFile(saveDir + "/" + chunkFileForXZ(var2.xPosition, var2.zPosition), bao.toByteArray());
|
||||
}
|
||||
|
||||
public void storeChunkInCompound(Chunk var1, World var2, NBTTagCompound var3) {
|
||||
|
|
|
@ -1,22 +1,28 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
public class Frustrum implements ICamera {
|
||||
private ClippingHelper clippingHelper = ClippingHelperImplementation.getInstance();
|
||||
private double xPosition;
|
||||
private double yPosition;
|
||||
private double zPosition;
|
||||
private final ClippingHelper clippingHelper = ClippingHelperImplementation.getInstance();
|
||||
private double xPosition;
|
||||
private double yPosition;
|
||||
private double zPosition;
|
||||
|
||||
public void setPosition(double var1, double var3, double var5) {
|
||||
this.xPosition = var1;
|
||||
this.yPosition = var3;
|
||||
this.zPosition = var5;
|
||||
}
|
||||
public void setPosition(double x, double y, double z) {
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
zPosition = z;
|
||||
}
|
||||
|
||||
public boolean isBoxInFrustum(double var1, double var3, double var5, double var7, double var9, double var11) {
|
||||
return this.clippingHelper.isBoxInFrustum(var1 - this.xPosition, var3 - this.yPosition, var5 - this.zPosition, var7 - this.xPosition, var9 - this.yPosition, var11 - this.zPosition);
|
||||
}
|
||||
public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
minX -= xPosition;
|
||||
minY -= yPosition;
|
||||
minZ -= zPosition;
|
||||
maxX -= xPosition;
|
||||
maxY -= yPosition;
|
||||
maxZ -= zPosition;
|
||||
return clippingHelper.isBoxInFrustum(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public boolean isBoundingBoxInFrustum(AxisAlignedBB var1) {
|
||||
return this.isBoxInFrustum(var1.minX, var1.minY, var1.minZ, var1.maxX, var1.maxY, var1.maxZ);
|
||||
}
|
||||
public boolean isBoundingBoxInFrustum(AxisAlignedBB boundingBox) {
|
||||
return isBoxInFrustum(boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ);
|
||||
}
|
||||
}
|
|
@ -7,88 +7,25 @@ import org.teavm.jso.typedarrays.Int32Array;
|
|||
|
||||
public class Tessellator {
|
||||
|
||||
/** The byte buffer used for GL allocation. */
|
||||
private Int32Array intBuffer;
|
||||
private Float32Array floatBuffer;
|
||||
|
||||
/**
|
||||
* The number of vertices to be drawn in the next draw call. Reset to 0 between
|
||||
* draw calls.
|
||||
*/
|
||||
private int vertexCount = 0;
|
||||
|
||||
/** The first coordinate to be used for the texture. */
|
||||
private float textureU;
|
||||
|
||||
/** The second coordinate to be used for the texture. */
|
||||
private float textureV;
|
||||
|
||||
/** The color (RGBA) value to be used for the following draw call. */
|
||||
private int color;
|
||||
|
||||
/**
|
||||
* Whether the current draw object for this tessellator has color values.
|
||||
*/
|
||||
private boolean hasColor = false;
|
||||
|
||||
/**
|
||||
* Whether the current draw object for this tessellator has texture coordinates.
|
||||
*/
|
||||
private boolean hasTexture = false;
|
||||
|
||||
/**
|
||||
* Whether the current draw object for this tessellator has normal values.
|
||||
*/
|
||||
private boolean hasNormals = false;
|
||||
|
||||
/** The index into the raw buffer to be used for the next data. */
|
||||
private int rawBufferIndex = 0;
|
||||
|
||||
/**
|
||||
* The number of vertices manually added to the given draw call. This differs
|
||||
* from vertexCount because it adds extra vertices when converting quads to
|
||||
* triangles.
|
||||
*/
|
||||
private int addedVertices = 0;
|
||||
|
||||
/** Disables all color information for the following draw call. */
|
||||
private boolean isColorDisabled = false;
|
||||
|
||||
/** The draw mode currently being used by the tessellator. */
|
||||
private int drawMode;
|
||||
|
||||
/**
|
||||
* An offset to be applied along the x-axis for all vertices in this draw call.
|
||||
*/
|
||||
private double xOffset;
|
||||
|
||||
/**
|
||||
* An offset to be applied along the y-axis for all vertices in this draw call.
|
||||
*/
|
||||
private double yOffset;
|
||||
|
||||
/**
|
||||
* An offset to be applied along the z-axis for all vertices in this draw call.
|
||||
*/
|
||||
private double zOffset;
|
||||
|
||||
/** The normal to be applied to the face being drawn. */
|
||||
private int normal;
|
||||
|
||||
/** The static instance of the Tessellator. */
|
||||
public static final Tessellator instance = new Tessellator(525000);
|
||||
|
||||
/** Whether this tessellator is currently in draw mode. */
|
||||
public static final Tessellator instance = new Tessellator(524288);
|
||||
private boolean isDrawing = false;
|
||||
|
||||
/** Whether we are currently using VBO or not. */
|
||||
private boolean useVBO = false;
|
||||
|
||||
/** The size of the buffers used (in integers). */
|
||||
private int bufferSize;
|
||||
|
||||
private Tessellator(int par1) {
|
||||
this.bufferSize = par1;
|
||||
ArrayBuffer a = ArrayBuffer.create(par1 * 4);
|
||||
this.intBuffer = Int32Array.create(a);
|
||||
this.floatBuffer = Float32Array.create(a);
|
||||
|
@ -114,10 +51,6 @@ public class Tessellator {
|
|||
GL11.glEnableVertexAttrib(GL11.GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
if (this.hasNormals) {
|
||||
GL11.glEnableVertexAttrib(GL11.GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
GL11.glDrawArrays(this.drawMode, 0, this.vertexCount, Int32Array.create(intBuffer.getBuffer(), 0, this.vertexCount * 7));
|
||||
|
||||
if (this.hasTexture) {
|
||||
|
@ -127,10 +60,6 @@ public class Tessellator {
|
|||
if (this.hasColor) {
|
||||
GL11.glDisableVertexAttrib(GL11.GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
if (this.hasNormals) {
|
||||
GL11.glDisableVertexAttrib(GL11.GL_NORMAL_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
int var1 = this.rawBufferIndex * 4;
|
||||
|
@ -167,7 +96,6 @@ public class Tessellator {
|
|||
this.isDrawing = true;
|
||||
this.reset();
|
||||
this.drawMode = par1;
|
||||
this.hasNormals = false;
|
||||
this.hasColor = false;
|
||||
this.hasTexture = false;
|
||||
this.isColorDisabled = false;
|
||||
|
@ -281,10 +209,6 @@ public class Tessellator {
|
|||
intBuffer0.set(bufferIndex + 5, this.color);
|
||||
}
|
||||
|
||||
if (this.hasNormals) {
|
||||
intBuffer0.set(bufferIndex + 6, this.normal);
|
||||
}
|
||||
|
||||
this.rawBufferIndex += 7;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user