FPS Boost, fix stuttering

This commit is contained in:
PeytonPlayz595 2024-01-23 17:10:35 +00:00
parent 51af5040eb
commit 3f9ff320b8
7 changed files with 9034 additions and 8969 deletions

8941
Indev.html

File diff suppressed because it is too large Load Diff

8941
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,40 +1,55 @@
package net.PeytonPlayz585.minecraft; package net.PeytonPlayz585.minecraft;
import java.nio.IntBuffer;
public class MinecraftImage { public class MinecraftImage {
public final int[] data; public final IntBuffer data;
public final int w; public final int w;
public final int h; public final int h;
public final boolean alpha; public final boolean alpha;
private final int wh;
public MinecraftImage(int pw, int ph, boolean palpha) { public MinecraftImage(int pw, int ph, boolean palpha) {
this.w = pw; this.w = pw;
this.h = ph; this.h = ph;
this.alpha = palpha; this.alpha = palpha;
this.data = new int[pw * ph]; this.data = IntBuffer.allocate(pw * ph);
this.wh = pw * ph;
} }
public MinecraftImage(int[] pdata, int pw, int ph, boolean palpha) { public MinecraftImage(IntBuffer pdata, int pw, int ph, boolean palpha) {
if (pdata.length != pw * ph) { if (pdata.capacity() != pw * ph) {
throw new IllegalArgumentException("array size does not equal image size"); throw new IllegalArgumentException("buffer capacity does not equal image size");
} }
this.w = pw; w = pw;
this.h = ph; h = ph;
this.alpha = palpha; alpha = palpha;
if (!palpha) { wh = pw * ph;
for (int i = 0; i < pdata.length; ++i) { if (!alpha) {
pdata[i] = pdata[i] | 0xFF000000; for (int i = 0; i < wh; ++i) {
pdata.put(i, pdata.get(i) | 0xFF000000);
} }
pdata.rewind();
} }
this.data = pdata; data = pdata;
} }
public MinecraftImage getSubImage(int x, int y, int pw, int ph) { public MinecraftImage getSubImage(int x, int y, int pw, int ph) {
int[] img = new int[pw * ph]; int start = y * w + x;
for (int i = 0; i < ph; ++i) { IntBuffer subBuffer = data.slice();
System.arraycopy(data, (i + y) * this.w + x, img, i * pw, pw); subBuffer.position(start);
} subBuffer.limit(start + pw * ph);
return new MinecraftImage(img, pw, ph, alpha); int[] temp = new int[pw * ph];
subBuffer.get(temp);
IntBuffer newBuffer = IntBuffer.wrap(temp);
return new MinecraftImage(newBuffer, pw, ph, alpha);
} }
public int[] data() {
int[] array = new int[wh];
data.rewind();
data.get(array);
return array;
}
} }

View File

@ -18,7 +18,7 @@ public class FontRenderer {
MinecraftImage bufferedimage = GL11.loadPNG(GL11.loadResourceBytes(s)); MinecraftImage bufferedimage = GL11.loadPNG(GL11.loadResourceBytes(s));
int i = bufferedimage.w; int i = bufferedimage.w;
int j = bufferedimage.h; int j = bufferedimage.h;
int ai[] = bufferedimage.data; int ai[] = bufferedimage.data();
for (int k = 0; k < 256; k++) { for (int k = 0; k < 256; k++) {
int l = k % 16; int l = k % 16;
int k1 = k / 16; int k1 = k / 16;

View File

@ -23,6 +23,7 @@ public class RenderEngine {
textureNameToImageMap = new HashMap<Integer, MinecraftImage>(); textureNameToImageMap = new HashMap<Integer, MinecraftImage>();
singleIntBuffer = BufferUtils.createIntBuffer(1); singleIntBuffer = BufferUtils.createIntBuffer(1);
imageDataB1 = BufferUtils.createByteBuffer(0x100000); imageDataB1 = BufferUtils.createByteBuffer(0x100000);
imageDataB2 = BufferUtils.createByteBuffer(0x100000);
clampTexture = false; clampTexture = false;
blurTexture = false; blurTexture = false;
options = gamesettings; options = gamesettings;
@ -81,8 +82,9 @@ public class RenderEngine {
public void setupTexture(MinecraftImage bufferedimage, int i) { public void setupTexture(MinecraftImage bufferedimage, int i) {
bindTexture(i); bindTexture(i);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, GL11.GL_NEAREST_MIPMAP_LINEAR);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, GL11.GL_NEAREST /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, GL11.GL_TEXTURE_MAX_LEVEL, 4);
if (blurTexture) { if (blurTexture) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9729 /* GL_LINEAR */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9729 /* GL_LINEAR */);
@ -96,7 +98,7 @@ public class RenderEngine {
} }
int j = bufferedimage.w; int j = bufferedimage.w;
int k = bufferedimage.h; int k = bufferedimage.h;
int ai[] = bufferedimage.data; int ai[] = bufferedimage.data();
byte abyte0[] = new byte[j * k * 4]; byte abyte0[] = new byte[j * k * 4];
for (int l = 0; l < ai.length; l++) { for (int l = 0; l < ai.length; l++) {
int j1 = ai[l] >> 24 & 0xff; int j1 = ai[l] >> 24 & 0xff;
@ -121,6 +123,28 @@ public class RenderEngine {
imageDataB1.position(0).limit(abyte0.length); imageDataB1.position(0).limit(abyte0.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, j, k, 0, 6408 /* GL_RGBA */, GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, j, k, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB1); 5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
for (int i1 = 1; i1 <= 4; i1++) {
int k1 = j >> i1 - 1;
int i2 = j >> i1;
int k2 = k >> i1;
imageDataB2.clear();
for (int i3 = 0; i3 < i2; i3++) {
for (int k3 = 0; k3 < k2; k3++) {
int i4 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 0) * k1) * 4);
int k4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 0) * k1) * 4);
int l4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 1) * k1) * 4);
int i5 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 1) * k1) * 4);
int j5 = averageColor(averageColor(i4, k4), averageColor(l4, i5));
imageDataB2.putInt((i3 + k3 * i2) * 4, j5);
}
}
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, i1, 6408 /* GL_RGBA */, i2, k2, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB2);
ByteBuffer tmp = imageDataB1;
imageDataB1 = imageDataB2;
imageDataB2 = tmp;
}
} }
public void deleteTexture(int i) { public void deleteTexture(int i) {
@ -135,6 +159,12 @@ public class RenderEngine {
return GL11.loadPNG(inputstream); return GL11.loadPNG(inputstream);
} }
private int averageColor(int i, int j) {
int k = (i & 0xff000000) >> 24 & 0xff;
int l = (j & 0xff000000) >> 24 & 0xff;
return ((k + l >> 1) << 24) + ((i & 0xfefefe) + (j & 0xfefefe) >> 1);
}
public static void bindTexture(int i) { public static void bindTexture(int i) {
Minecraft.getMinecraft().setLighting(true); Minecraft.getMinecraft().setLighting(true);
if (i < 0) { if (i < 0) {
@ -150,6 +180,7 @@ public class RenderEngine {
private HashMap<Integer, MinecraftImage> textureNameToImageMap; private HashMap<Integer, MinecraftImage> textureNameToImageMap;
private IntBuffer singleIntBuffer; private IntBuffer singleIntBuffer;
private ByteBuffer imageDataB1; private ByteBuffer imageDataB1;
private ByteBuffer imageDataB2;
private GameSettings options; private GameSettings options;
private boolean clampTexture; private boolean clampTexture;
private boolean blurTexture; private boolean blurTexture;

View File

@ -937,7 +937,8 @@ public class WebGL {
for(int i = 0; i < pixels.length; ++i) { for(int i = 0; i < pixels.length; ++i) {
pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24); pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24);
} }
ret.complete(new MinecraftImage(pixels, pxlsDat.getWidth(), pxlsDat.getHeight(), true)); IntBuffer buffer = IntBuffer.wrap(pixels);
ret.complete(new MinecraftImage(buffer, pxlsDat.getWidth(), pxlsDat.getHeight(), true));
} }
}); });
toLoad.addEventListener("error", new EventListener<Event>() { toLoad.addEventListener("error", new EventListener<Event>() {