diff options
author | makamys <makamys@outlook.com> | 2021-05-10 22:55:31 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2021-05-10 22:55:31 +0200 |
commit | ec94ac14a74a52439c666fc494d4696c146aad95 (patch) | |
tree | 4b1271789a49e2568fd3e953603a33ad618a04e4 /src/main/java/makamys/lodmod/renderer | |
parent | 6741084ce1cee8648edb4af418a879321a7de4c0 (diff) | |
download | Neodymium-ec94ac14a74a52439c666fc494d4696c146aad95.tar.gz Neodymium-ec94ac14a74a52439c666fc494d4696c146aad95.tar.bz2 Neodymium-ec94ac14a74a52439c666fc494d4696c146aad95.zip |
Rewrite ChunkMesh#{readIntAt, readShortAt} to be faster hopefully
Sampling found it to be using a lot of CPU time
Diffstat (limited to 'src/main/java/makamys/lodmod/renderer')
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/ChunkMesh.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java index b6783f6..eef8ecd 100644 --- a/src/main/java/makamys/lodmod/renderer/ChunkMesh.java +++ b/src/main/java/makamys/lodmod/renderer/ChunkMesh.java @@ -116,8 +116,6 @@ public class ChunkMesh extends Mesh { int brightnessOffset = quadCount * (2 + 4 + 4 + 4 + 4 + 4); int colorOffset = quadCount * (2 + 4 + 4 + 4 + 4 + 4 + 4 + 4); - DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); - ByteBuffer buffer = BufferUtils.createByteBuffer(quadCount * 6 * getStride()); FloatBuffer floatBuffer = buffer.asFloatBuffer(); ShortBuffer shortBuffer = buffer.asShortBuffer(); @@ -125,7 +123,7 @@ public class ChunkMesh extends Mesh { try { for(int quadI = 0; quadI < quadCount; quadI++) { - short spriteIndex = readShortAt(in, quadI * 2); + short spriteIndex = readShortAt(data, quadI * 2); String spriteName = stringTable.get(spriteIndex); TextureAtlasSprite tas = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite(spriteName); @@ -157,7 +155,8 @@ public class ChunkMesh extends Mesh { intBuffer.position(shortBuffer.position() / 2); - intBuffer.put(readIntAt(in, colorOffset + 4 * 4 * quadI + 4 * vi)); // c + int integet = readIntAt(data, colorOffset + 4 * 4 * quadI + 4 * vi); + intBuffer.put(integet); // c floatBuffer.position(intBuffer.position()); } @@ -185,6 +184,10 @@ public class ChunkMesh extends Mesh { } } + public static short readShortAt(byte[] data, int offset) { + return (short)(Byte.toUnsignedInt(data[offset]) << 8 | Byte.toUnsignedInt(data[offset + 1])); + } + public static int readIntAt(DataInputStream in, int offset) { try { in.reset(); @@ -195,6 +198,10 @@ public class ChunkMesh extends Mesh { } } + public static int readIntAt(byte[] data, int offset) { + return (int)(Byte.toUnsignedLong(data[offset]) << 24 | Byte.toUnsignedLong(data[offset + 1]) << 16 | Byte.toUnsignedLong(data[offset + 2]) << 8 | Byte.toUnsignedLong(data[offset + 3])); + } + public int getStride() { return (3 * 4 + (flags.hasTexture ? 8 : 0) + (flags.hasBrightness ? 4 : 0) + (flags.hasColor ? 4 : 0) + (flags.hasNormals ? 4 : 0)); } |