Optimize Chunk Storage, made a slight FPS boost

This commit is contained in:
PeytonPlayz595 2023-10-12 23:46:17 -04:00
parent 3f03c09656
commit 458e47b0d5
5 changed files with 4231 additions and 4281 deletions

8375
js/app.js

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
package net.minecraft.src; package net.minecraft.src;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -23,14 +24,14 @@ public class ChunkLoader implements IChunkLoader {
int unsignedX = x + 30233088; int unsignedX = x + 30233088;
int unsignedZ = z + 30233088; int unsignedZ = z + 30233088;
int radix = CHUNK_CHARS.length(); int radix = CHUNK_CHARS.length();
char[] path = new char[10]; StringBuilder path = new StringBuilder(10);
for(int i = 0; i < 5; ++i) { for(int i = 0; i < 5; ++i) {
path[i * 2] = CHUNK_CHARS.charAt(unsignedX % radix); path.append(CHUNK_CHARS.charAt(unsignedX % radix));
unsignedX /= radix; unsignedX /= radix;
path[i * 2 + 1] = CHUNK_CHARS.charAt(unsignedZ % radix); path.append(CHUNK_CHARS.charAt(unsignedZ % radix));
unsignedZ /= radix; unsignedZ /= radix;
} }
return new String(path); return path.toString();
} }
public Chunk loadChunk(World var1, int x, int z) { public Chunk loadChunk(World var1, int x, int z) {
@ -67,14 +68,16 @@ public class ChunkLoader implements IChunkLoader {
NBTTagCompound toSave = new NBTTagCompound(); NBTTagCompound toSave = new NBTTagCompound();
storeChunkInCompound(var2, var1, toSave); storeChunkInCompound(var2, var1, toSave);
ByteArrayOutputStream bao = new ByteArrayOutputStream(131072); ByteArrayOutputStream bao = new ByteArrayOutputStream(131072);
try { try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(bao))) {
NBTBase.writeNamedTag(toSave, new DataOutputStream(bao)); NBTBase.writeNamedTag(toSave, dos);
dos.flush();
byte[] data = bao.toByteArray();
LWJGLMain.writeFile(saveDir + "/" + chunkFileForXZ(var2.xPosition, var2.zPosition), data);
} catch (IOException e) { } catch (IOException e) {
System.err.println("Failed to serialize chunk at [" + var2.xPosition + ", " + var2.zPosition + "] to byte array"); System.err.println("Failed to serialize chunk at [" + var2.xPosition + ", " + var2.zPosition + "] to byte array");
e.printStackTrace(); e.printStackTrace();
return; return;
} }
LWJGLMain.writeFile(saveDir + "/" + chunkFileForXZ(var2.xPosition, var2.zPosition), bao.toByteArray());
} }
public void storeChunkInCompound(Chunk var1, World var2, NBTTagCompound var3) { public void storeChunkInCompound(Chunk var1, World var2, NBTTagCompound var3) {

View File

@ -1,22 +1,28 @@
package net.minecraft.src; package net.minecraft.src;
public class Frustrum implements ICamera { public class Frustrum implements ICamera {
private ClippingHelper clippingHelper = ClippingHelperImplementation.getInstance(); private final ClippingHelper clippingHelper = ClippingHelperImplementation.getInstance();
private double xPosition; private double xPosition;
private double yPosition; private double yPosition;
private double zPosition; private double zPosition;
public void setPosition(double var1, double var3, double var5) { public void setPosition(double x, double y, double z) {
this.xPosition = var1; xPosition = x;
this.yPosition = var3; yPosition = y;
this.zPosition = var5; zPosition = z;
} }
public boolean isBoxInFrustum(double var1, double var3, double var5, double var7, double var9, double var11) { public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
return this.clippingHelper.isBoxInFrustum(var1 - this.xPosition, var3 - this.yPosition, var5 - this.zPosition, var7 - this.xPosition, var9 - this.yPosition, var11 - this.zPosition); 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) { public boolean isBoundingBoxInFrustum(AxisAlignedBB boundingBox) {
return this.isBoxInFrustum(var1.minX, var1.minY, var1.minZ, var1.maxX, var1.maxY, var1.maxZ); return isBoxInFrustum(boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ);
} }
} }

View File

@ -7,88 +7,25 @@ import org.teavm.jso.typedarrays.Int32Array;
public class Tessellator { public class Tessellator {
/** The byte buffer used for GL allocation. */
private Int32Array intBuffer; private Int32Array intBuffer;
private Float32Array floatBuffer; 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; private int vertexCount = 0;
/** The first coordinate to be used for the texture. */
private float textureU; private float textureU;
/** The second coordinate to be used for the texture. */
private float textureV; private float textureV;
/** The color (RGBA) value to be used for the following draw call. */
private int color; private int color;
/**
* Whether the current draw object for this tessellator has color values.
*/
private boolean hasColor = false; private boolean hasColor = false;
/**
* Whether the current draw object for this tessellator has texture coordinates.
*/
private boolean hasTexture = false; 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; 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; private int addedVertices = 0;
/** Disables all color information for the following draw call. */
private boolean isColorDisabled = false; private boolean isColorDisabled = false;
/** The draw mode currently being used by the tessellator. */
private int drawMode; private int drawMode;
/**
* An offset to be applied along the x-axis for all vertices in this draw call.
*/
private double xOffset; private double xOffset;
/**
* An offset to be applied along the y-axis for all vertices in this draw call.
*/
private double yOffset; private double yOffset;
/**
* An offset to be applied along the z-axis for all vertices in this draw call.
*/
private double zOffset; private double zOffset;
public static final Tessellator instance = new Tessellator(524288);
/** 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. */
private boolean isDrawing = false; 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) { private Tessellator(int par1) {
this.bufferSize = par1;
ArrayBuffer a = ArrayBuffer.create(par1 * 4); ArrayBuffer a = ArrayBuffer.create(par1 * 4);
this.intBuffer = Int32Array.create(a); this.intBuffer = Int32Array.create(a);
this.floatBuffer = Float32Array.create(a); this.floatBuffer = Float32Array.create(a);
@ -114,10 +51,6 @@ public class Tessellator {
GL11.glEnableVertexAttrib(GL11.GL_COLOR_ARRAY); 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)); GL11.glDrawArrays(this.drawMode, 0, this.vertexCount, Int32Array.create(intBuffer.getBuffer(), 0, this.vertexCount * 7));
if (this.hasTexture) { if (this.hasTexture) {
@ -127,10 +60,6 @@ public class Tessellator {
if (this.hasColor) { if (this.hasColor) {
GL11.glDisableVertexAttrib(GL11.GL_COLOR_ARRAY); GL11.glDisableVertexAttrib(GL11.GL_COLOR_ARRAY);
} }
if (this.hasNormals) {
GL11.glDisableVertexAttrib(GL11.GL_NORMAL_ARRAY);
}
} }
int var1 = this.rawBufferIndex * 4; int var1 = this.rawBufferIndex * 4;
@ -167,7 +96,6 @@ public class Tessellator {
this.isDrawing = true; this.isDrawing = true;
this.reset(); this.reset();
this.drawMode = par1; this.drawMode = par1;
this.hasNormals = false;
this.hasColor = false; this.hasColor = false;
this.hasTexture = false; this.hasTexture = false;
this.isColorDisabled = false; this.isColorDisabled = false;
@ -281,10 +209,6 @@ public class Tessellator {
intBuffer0.set(bufferIndex + 5, this.color); intBuffer0.set(bufferIndex + 5, this.color);
} }
if (this.hasNormals) {
intBuffer0.set(bufferIndex + 6, this.normal);
}
this.rawBufferIndex += 7; this.rawBufferIndex += 7;
} }