Better FPS + bug fixes

- Fix vanilla GPU memory leak
- Fix issue's with fog
- Fix issue's with chunks sometimes not rendering
- Fix "&e" on game over screen
- Fix lighting bug
- Port optifine's minimal entity updates
- Port optifine's fast math
This commit is contained in:
PeytonPlayz595 2025-04-06 22:44:27 -07:00
parent 1ed446c4cd
commit 853d2cd90c
9 changed files with 335 additions and 27 deletions

View File

@ -159,7 +159,12 @@ public class EntityLiving extends Entity {
}
public void onUpdate() {
super.onUpdate();
if(this.canSkipUpdate()) {
this.onUpdateMinimal();
} else {
super.onUpdate();
}
this.onLivingUpdate();
double var1 = this.posX - this.prevPosX;
double var3 = this.posZ - this.prevPosZ;
@ -450,6 +455,27 @@ public class EntityLiving extends Entity {
public boolean isEntityAlive() {
return !this.isDead && this.health > 0;
}
private void func_27021_X() {
Entity var1 = this.worldObj.getPlayerEntity();
if(var1 != null) {
double var2 = var1.posX - this.posX;
double var4 = var1.posY - this.posY;
double var6 = var1.posZ - this.posZ;
double var8 = var2 * var2 + var4 * var4 + var6 * var6;
if(var8 > 16384.0D) {
this.setEntityDead();
}
if(this.entityAge > 600 && this.rand.nextInt(800) == 0) {
if(var8 < 1024.0D) {
this.entityAge = 0;
} else {
this.setEntityDead();
}
}
}
}
public void onLivingUpdate() {
++this.entityAge;
@ -545,4 +571,38 @@ public class EntityLiving extends Entity {
protected void kill() {
this.attackEntityFrom((Entity)null, 4);
}
private boolean canSkipUpdate() {
if (this.hurtTime > 0) {
return false;
} else if (this.ticksExisted < 20) {
return false;
} else {
World world = this.worldObj;
if (world == null) {
return false;
} else {
Entity entity = (Entity)world.playerEntity;
double d0 = Math.max(Math.abs(this.posX - entity.posX) - 16.0D, 0.0D);
double d1 = Math.max(Math.abs(this.posZ - entity.posZ) - 16.0D, 0.0D);
double d2 = d0 * d0 + d1 * d1;
return !this.isInRangeToRenderDist(d2);
}
}
}
private void onUpdateMinimal() {
++this.entityAge;
if (this instanceof EntityMonster) {
float f = this.getEntityBrightness(1.0F);
if (f > 0.5F) {
this.entityAge += 2;
}
}
this.func_27021_X();
}
}

View File

@ -357,6 +357,7 @@ public class EntityRenderer {
this.mc.renderGlobal.clipRenderersByFrustrum(var12, var1);
this.mc.renderGlobal.updateRenderers(var2, false);
this.setupFog(0);
GL11.glEnable(GL11.GL_FOG);
GlStateManager.bindTexture(this.mc.renderEngine.getTexture("/terrain.png"));
RenderHelper.disableStandardItemLighting();
var3.sortAndRender(var2, 0, (double)var1);

View File

@ -1,7 +1,9 @@
package net.minecraft.src;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.lax1dude.eaglercraft.EagRuntime;
import net.lax1dude.eaglercraft.internal.buffer.ByteBuffer;
@ -10,22 +12,20 @@ import net.lax1dude.eaglercraft.internal.buffer.IntBuffer;
import net.lax1dude.eaglercraft.opengl.EaglercraftGPU;
public class GLAllocation {
private static final Map field_74531_a = new HashMap();
private static List<Integer> displayLists = new ArrayList<Integer>();
public static int generateDisplayLists(int var0) {
int var1 = EaglercraftGPU.glGenLists(var0);
displayLists.add(var1);
displayLists.add(var0);
field_74531_a.put(Integer.valueOf(var1), Integer.valueOf(var0));
return var1;
}
public static synchronized void deleteDisplayLists() {
for(int var0 = 0; var0 < displayLists.size(); var0 += 2) {
EaglercraftGPU.glDeleteLists(((Integer)displayLists.get(var0)).intValue(), ((Integer)displayLists.get(var0 + 1)).intValue());
}
displayLists.clear();
public static void deleteDisplayLists(int par0) {
EaglercraftGPU.glDeleteLists(par0, ((Integer) field_74531_a.remove(Integer.valueOf(par0))).intValue());
}
/**
* Creates and returns a direct byte buffer with the specified capacity. Applies
* native ordering to speed up access.

View File

@ -38,7 +38,7 @@ public class GuiGameOver extends GuiScreen {
GL11.glScalef(2.0F, 2.0F, 2.0F);
this.drawCenteredString(this.fontRenderer, "Game over!", this.width / 2 / 2, 30, 16777215);
GL11.glPopMatrix();
this.drawCenteredString(this.fontRenderer, "Score: &e" + this.mc.thePlayer.getScore(), this.width / 2, 100, 16777215);
this.drawCenteredString(this.fontRenderer, "Score: " + this.mc.thePlayer.getScore(), this.width / 2, 100, 16777215);
super.drawScreen(var1, var2, var3);
}

View File

@ -2,14 +2,14 @@ package net.minecraft.src;
public class MathHelper {
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION;
private static float[] SIN_TABLE = new float[65536];
private static float[] SIN_TABLE = new float[4096];
public static final float sin(float var0) {
return SIN_TABLE[(int)(var0 * 10430.378F) & '\uffff'];
return SIN_TABLE[(int) (var0 * 651.8986F) & 4095];
}
public static final float cos(float var0) {
return SIN_TABLE[(int)(var0 * 10430.378F + 16384.0F) & '\uffff'];
return SIN_TABLE[(int) ((var0 + ((float) Math.PI / 2F)) * 651.8986F) & 4095];
}
public static final float sqrt_float(float var0) {
@ -92,8 +92,12 @@ public class MathHelper {
}
static {
for(int var0 = 0; var0 < 65536; ++var0) {
SIN_TABLE[var0] = (float)Math.sin((double)var0 * Math.PI * 2.0D / 65536.0D);
for (int j = 0; j < 4096; ++j) {
SIN_TABLE[j] = (float) Math.sin((double) (((float) j + 0.5F) / 4096.0F * ((float) Math.PI * 2F)));
}
for (int l = 0; l < 360; l += 90) {
SIN_TABLE[(int) ((float) l * 11.377778F) & 4095] = (float) Math.sin((double) ((float) l * 0.017453292F));
}
MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[] { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27,

View File

@ -212,18 +212,18 @@ public class RenderGlobal implements IWorldAccess {
for(var4 = 0; var4 < this.renderChunksWide; ++var4) {
for(int var5 = 0; var5 < this.renderChunksTall; ++var5) {
for(int var6 = 0; var6 < this.renderChunksDeep; ++var6) {
if(this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4] != null) {
int index = (var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4;
if(this.worldRenderers[index] != null) {
this.tileEntities.removeAll(this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].tileEntityRenderers);
}
this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4] = new WorldRenderer(this.theWorld, this.tileEntities, var4 * 16, var5 * 16, var6 * 16, 16, this.glRenderListBase + var2);
this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].isWaitingOnOcclusionQuery = false;
this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].isVisible = true;
this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].isInFrustum = true;
this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].chunkIndex = var3++;
this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4].markDirty();
this.sortedWorldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4] = this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4];
this.worldRenderersToUpdate.add(this.worldRenderers[(var6 * this.renderChunksTall + var5) * this.renderChunksWide + var4]);
WorldRenderer wr = (this.worldRenderers[index] = new WorldRenderer(this.theWorld, this.tileEntities, var4 * 16, var5 * 16, var6 * 16, 16, this.glRenderListBase + var2));
wr.isWaitingOnOcclusionQuery = false;
wr.isVisible = true;
wr.isInFrustum = true;
wr.chunkIndex = var3++;
wr.markDirty();
this.sortedWorldRenderers[index] = wr;
this.worldRenderersToUpdate.add(wr);
var2 += 3;
}
}

View File

@ -3,8 +3,9 @@ package net.minecraft.src;
import net.lax1dude.eaglercraft.opengl.GlStateManager;
public class RenderHelper {
private static final Vec3D LIGHT0_POS = (new Vec3D(0.20000000298023224D, 1.0D, -0.699999988079071D)).normalize();
private static final Vec3D LIGHT1_POS = (new Vec3D(-0.20000000298023224D, 1.0D, 0.699999988079071D)).normalize();
private static final Vec3D_112 LIGHT0_POS = (new Vec3D_112(0.20000000298023224D, 1.0D, -0.699999988079071D)).normalize();
private static final Vec3D_112 LIGHT1_POS = (new Vec3D_112(-0.20000000298023224D, 1.0D, 0.699999988079071D)).normalize();
static boolean init = false;
public static void disableStandardItemLighting() {

View File

@ -0,0 +1,242 @@
package net.minecraft.src;
public class Vec3D_112 {
public static final Vec3D_112 ZERO = new Vec3D_112(0.0D, 0.0D, 0.0D);
/** X coordinate of Vec3D */
public final double xCoord;
/** Y coordinate of Vec3D */
public final double yCoord;
/** Z coordinate of Vec3D */
public final double zCoord;
public Vec3D_112(double x, double y, double z) {
if (x == -0.0D) {
x = 0.0D;
}
if (y == -0.0D) {
y = 0.0D;
}
if (z == -0.0D) {
z = 0.0D;
}
this.xCoord = x;
this.yCoord = y;
this.zCoord = z;
}
/**
* Returns a new vector with the result of the specified vector minus this.
*/
public Vec3D_112 subtractReverse(Vec3D_112 vec) {
return new Vec3D_112(vec.xCoord - this.xCoord, vec.yCoord - this.yCoord, vec.zCoord - this.zCoord);
}
/**
* Normalizes the vector to a length of 1 (except if it is the zero vector)
*/
public Vec3D_112 normalize() {
double d0 = (double) MathHelper
.sqrt_double(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord);
return d0 < 1.0E-4D ? ZERO : new Vec3D_112(this.xCoord / d0, this.yCoord / d0, this.zCoord / d0);
}
public double dotProduct(Vec3D_112 vec) {
return this.xCoord * vec.xCoord + this.yCoord * vec.yCoord + this.zCoord * vec.zCoord;
}
/**
* Returns a new vector with the result of this vector x the specified vector.
*/
public Vec3D_112 crossProduct(Vec3D_112 vec) {
return new Vec3D_112(this.yCoord * vec.zCoord - this.zCoord * vec.yCoord,
this.zCoord * vec.xCoord - this.xCoord * vec.zCoord,
this.xCoord * vec.yCoord - this.yCoord * vec.xCoord);
}
public Vec3D_112 subtract(Vec3D_112 vec) {
return this.subtract(vec.xCoord, vec.yCoord, vec.zCoord);
}
public Vec3D_112 subtract(double x, double y, double z) {
return this.addVector(-x, -y, -z);
}
public Vec3D_112 add(Vec3D_112 vec) {
return this.addVector(vec.xCoord, vec.yCoord, vec.zCoord);
}
/**
* Adds the specified x,y,z vector components to this vector and returns the
* resulting vector. Does not change this vector.
*/
public Vec3D_112 addVector(double x, double y, double z) {
return new Vec3D_112(this.xCoord + x, this.yCoord + y, this.zCoord + z);
}
/**
* Euclidean distance between this and the specified vector, returned as double.
*/
public double distanceTo(Vec3D_112 vec) {
double d0 = vec.xCoord - this.xCoord;
double d1 = vec.yCoord - this.yCoord;
double d2 = vec.zCoord - this.zCoord;
return (double) MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2);
}
/**
* The square of the Euclidean distance between this and the specified vector.
*/
public double squareDistanceTo(Vec3D_112 vec) {
double d0 = vec.xCoord - this.xCoord;
double d1 = vec.yCoord - this.yCoord;
double d2 = vec.zCoord - this.zCoord;
return d0 * d0 + d1 * d1 + d2 * d2;
}
public double squareDistanceTo(double xIn, double yIn, double zIn) {
double d0 = xIn - this.xCoord;
double d1 = yIn - this.yCoord;
double d2 = zIn - this.zCoord;
return d0 * d0 + d1 * d1 + d2 * d2;
}
public Vec3D_112 scale(double p_186678_1_) {
return new Vec3D_112(this.xCoord * p_186678_1_, this.yCoord * p_186678_1_, this.zCoord * p_186678_1_);
}
/**
* Returns the length of the vector.
*/
public double lengthVector() {
return (double) MathHelper
.sqrt_double(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord);
}
public double lengthSquared() {
return this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord;
}
/**
* Returns a new vector with x value equal to the second parameter, along the
* line between this vector and the passed in vector, or null if not possible.
*/
public Vec3D_112 getIntermediateWithXValue(Vec3D_112 vec, double x) {
double d0 = vec.xCoord - this.xCoord;
double d1 = vec.yCoord - this.yCoord;
double d2 = vec.zCoord - this.zCoord;
if (d0 * d0 < 1.0000000116860974E-7D) {
return null;
} else {
double d3 = (x - this.xCoord) / d0;
return d3 >= 0.0D && d3 <= 1.0D
? new Vec3D_112(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3)
: null;
}
}
/**
* Returns a new vector with y value equal to the second parameter, along the
* line between this vector and the passed in vector, or null if not possible.
*/
public Vec3D_112 getIntermediateWithYValue(Vec3D_112 vec, double y) {
double d0 = vec.xCoord - this.xCoord;
double d1 = vec.yCoord - this.yCoord;
double d2 = vec.zCoord - this.zCoord;
if (d1 * d1 < 1.0000000116860974E-7D) {
return null;
} else {
double d3 = (y - this.yCoord) / d1;
return d3 >= 0.0D && d3 <= 1.0D
? new Vec3D_112(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3)
: null;
}
}
/**
* Returns a new vector with z value equal to the second parameter, along the
* line between this vector and the passed in vector, or null if not possible.
*/
public Vec3D_112 getIntermediateWithZValue(Vec3D_112 vec, double z) {
double d0 = vec.xCoord - this.xCoord;
double d1 = vec.yCoord - this.yCoord;
double d2 = vec.zCoord - this.zCoord;
if (d2 * d2 < 1.0000000116860974E-7D) {
return null;
} else {
double d3 = (z - this.zCoord) / d2;
return d3 >= 0.0D && d3 <= 1.0D
? new Vec3D_112(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3)
: null;
}
}
public boolean equals(Object p_equals_1_) {
if (this == p_equals_1_) {
return true;
} else if (!(p_equals_1_ instanceof Vec3D_112)) {
return false;
} else {
Vec3D_112 vec3d = (Vec3D_112) p_equals_1_;
if (Double.compare(vec3d.xCoord, this.xCoord) != 0) {
return false;
} else if (Double.compare(vec3d.yCoord, this.yCoord) != 0) {
return false;
} else {
return Double.compare(vec3d.zCoord, this.zCoord) == 0;
}
}
}
public int hashCode() {
long j = Double.doubleToLongBits(this.xCoord);
int i = (int) (j ^ j >>> 32);
j = Double.doubleToLongBits(this.yCoord);
i = 31 * i + (int) (j ^ j >>> 32);
j = Double.doubleToLongBits(this.zCoord);
i = 31 * i + (int) (j ^ j >>> 32);
return i;
}
public String toString() {
return "(" + this.xCoord + ", " + this.yCoord + ", " + this.zCoord + ")";
}
public Vec3D_112 rotatePitch(float pitch) {
float f = MathHelper.cos(pitch);
float f1 = MathHelper.sin(pitch);
double d0 = this.xCoord;
double d1 = this.yCoord * (double) f + this.zCoord * (double) f1;
double d2 = this.zCoord * (double) f - this.yCoord * (double) f1;
return new Vec3D_112(d0, d1, d2);
}
public Vec3D_112 rotateYaw(float yaw) {
float f = MathHelper.cos(yaw);
float f1 = MathHelper.sin(yaw);
double d0 = this.xCoord * (double) f + this.zCoord * (double) f1;
double d1 = this.yCoord;
double d2 = this.zCoord * (double) f - this.xCoord * (double) f1;
return new Vec3D_112(d0, d1, d2);
}
/**
* returns a Vec3d from given pitch and yaw degrees
*/
public static Vec3D_112 fromPitchYaw(float p_189986_0_, float p_189986_1_) {
float f = MathHelper.cos(-p_189986_1_ * 0.017453292F - (float) Math.PI);
float f1 = MathHelper.sin(-p_189986_1_ * 0.017453292F - (float) Math.PI);
float f2 = -MathHelper.cos(-p_189986_0_ * 0.017453292F);
float f3 = MathHelper.sin(-p_189986_0_ * 0.017453292F);
return new Vec3D_112((double) (f1 * f2), (double) f3, (double) (f * f2));
}
}

View File

@ -210,7 +210,7 @@ public class WorldRenderer {
}
public boolean skipAllRenderPasses() {
return !this.isInitialized ? false : this.skipRenderPass[0] && this.skipRenderPass[1];
return !this.isInitialized ? false : this.skipRenderPass[0] && this.skipRenderPass[1] && !this.needsUpdate;
}
public void markDirty() {