Rendering bug fixed (kinda)

This commit is contained in:
catfoolyou 2025-02-27 12:18:24 -05:00
parent 3d20bcd33d
commit c42ff423b8
4 changed files with 89 additions and 96 deletions

Binary file not shown.

Binary file not shown.

View File

@ -4,20 +4,24 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import net.lax1dude.eaglercraft.adapter.Tessellator;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.adapter.Tessellator;
public class WorldRenderer public class WorldRenderer {
{
/** Reference to the World object. */ /** Reference to the World object. */
public World worldObj; public World worldObj;
private int glRenderList = -1; private int glRenderList = -1;
private static Tessellator tessellator = Tessellator.instance; private static Tessellator tessellator = Tessellator.instance;
public static int chunksUpdated; public static int chunksUpdated = 0;
public static int chunksGeometryUpdated = 0;
public int posX; public int posX;
public int posY; public int posY;
public int posZ; public int posZ;
public int chunkX;
public int chunkY;
public int chunkZ;
/** Pos X minus */ /** Pos X minus */
public int posXMinus; public int posXMinus;
@ -35,7 +39,7 @@ public class WorldRenderer
/** Pos Z clipped */ /** Pos Z clipped */
public int posZClip; public int posZClip;
public boolean isInFrustum; public boolean isInFrustum = false;
/** Should this renderer skip this render pass */ /** Should this renderer skip this render pass */
public boolean[] skipRenderPass = new boolean[2]; public boolean[] skipRenderPass = new boolean[2];
@ -64,12 +68,9 @@ public class WorldRenderer
/** Is this renderer waiting on the result of the occlusion query */ /** Is this renderer waiting on the result of the occlusion query */
public boolean isWaitingOnOcclusionQuery; public boolean isWaitingOnOcclusionQuery;
/** OpenGL occlusion query */
public int glOcclusionQuery;
/** Is the chunk lit */ /** Is the chunk lit */
public boolean isChunkLit; public boolean isChunkLit;
private boolean isInitialized; private boolean isInitialized = false;
/** All the tile entities that have special rendering code for this chunk */ /** All the tile entities that have special rendering code for this chunk */
public List tileEntityRenderers = new ArrayList(); public List tileEntityRenderers = new ArrayList();
@ -78,8 +79,7 @@ public class WorldRenderer
/** Bytes sent to the GPU */ /** Bytes sent to the GPU */
private int bytesDrawn; private int bytesDrawn;
public WorldRenderer(World par1World, List par2List, int par3, int par4, int par5, int par6) public WorldRenderer(World par1World, List par2List, int par3, int par4, int par5, int par6) {
{
this.worldObj = par1World; this.worldObj = par1World;
this.tileEntities = par2List; this.tileEntities = par2List;
this.glRenderList = par6; this.glRenderList = par6;
@ -89,16 +89,18 @@ public class WorldRenderer
} }
/** /**
* Sets a new position for the renderer and setting it up so it can be reloaded with the new data for that position * Sets a new position for the renderer and setting it up so it can be reloaded
* with the new data for that position
*/ */
public void setPosition(int par1, int par2, int par3) public void setPosition(int par1, int par2, int par3) {
{ if (par1 != this.posX || par2 != this.posY || par3 != this.posZ) {
if (par1 != this.posX || par2 != this.posY || par3 != this.posZ)
{
this.setDontDraw(); this.setDontDraw();
this.posX = par1; this.posX = par1;
this.posY = par2; this.posY = par2;
this.posZ = par3; this.posZ = par3;
this.chunkX = par1 >> 4;
this.chunkY = par2 >> 4;
this.chunkZ = par3 >> 4;
this.posXPlus = par1 + 8; this.posXPlus = par1 + 8;
this.posYPlus = par2 + 8; this.posYPlus = par2 + 8;
this.posZPlus = par3 + 8; this.posZPlus = par3 + 8;
@ -108,27 +110,26 @@ public class WorldRenderer
this.posXMinus = par1 - this.posXClip; this.posXMinus = par1 - this.posXClip;
this.posYMinus = par2 - this.posYClip; this.posYMinus = par2 - this.posYClip;
this.posZMinus = par3 - this.posZClip; this.posZMinus = par3 - this.posZClip;
float var4 = 6.0F; float var4 = 0.0F;
this.rendererBoundingBox = AxisAlignedBB.getBoundingBox((double)((float)par1 - var4), (double)((float)par2 - var4), (double)((float)par3 - var4), (double)((float)(par1 + 16) + var4), (double)((float)(par2 + 16) + var4), (double)((float)(par3 + 16) + var4)); this.rendererBoundingBox = AxisAlignedBB.getBoundingBox((double) ((float) par1 - var4), (double) ((float) par2 - var4), (double) ((float) par3 - var4), (double) ((float) (par1 + 16) + var4),
(double) ((float) (par2 + 16) + var4), (double) ((float) (par3 + 16) + var4));
//EaglerAdapter.glNewList(this.glRenderList + 2, EaglerAdapter.GL_COMPILE); //EaglerAdapter.glNewList(this.glRenderList + 2, EaglerAdapter.GL_COMPILE);
//RenderItem.renderAABB(AxisAlignedBB.getAABBPool().getAABB((double)((float)this.posXClip - var4), (double)((float)this.posYClip - var4), (double)((float)this.posZClip - var4), (double)((float)(this.posXClip + 16) + var4), (double)((float)(this.posYClip + 16) + var4), (double)((float)(this.posZClip + 16) + var4))); //RenderItem.renderAABB(AxisAlignedBB.getAABBPool().getAABB((double) ((float) this.posXClip - var4), (double) ((float) this.posYClip - var4), (double) ((float) this.posZClip - var4), (double) ((float) (this.posXClip + 16) + var4),
// (double) ((float) (this.posYClip + 16) + var4), (double) ((float) (this.posZClip + 16) + var4)));
//EaglerAdapter.glEndList(); //EaglerAdapter.glEndList();
this.markDirty(); this.markDirty();
} }
} }
private void setupGLTranslation() private void setupGLTranslation() {
{ EaglerAdapter.glTranslatef((float) this.posXClip, (float) this.posYClip, (float) this.posZClip);
EaglerAdapter.glTranslatef((float)this.posXClip, (float)this.posYClip, (float)this.posZClip);
} }
/** /**
* Will update this chunk renderer * Will update this chunk renderer
*/ */
public void updateRenderer() public void updateRenderer() {
{ if (this.needsUpdate) {
if (this.needsUpdate)
{
this.needsUpdate = false; this.needsUpdate = false;
int var1 = this.posX; int var1 = this.posX;
int var2 = this.posY; int var2 = this.posY;
@ -137,8 +138,7 @@ public class WorldRenderer
int var5 = this.posY + 16; int var5 = this.posY + 16;
int var6 = this.posZ + 16; int var6 = this.posZ + 16;
for (int var7 = 0; var7 < 2; ++var7) for (int var7 = 0; var7 < 2; ++var7) {
{
this.skipRenderPass[var7] = true; this.skipRenderPass[var7] = true;
} }
@ -148,65 +148,52 @@ public class WorldRenderer
this.tileEntityRenderers.clear(); this.tileEntityRenderers.clear();
byte var8 = 1; byte var8 = 1;
ChunkCache var9 = new ChunkCache(this.worldObj, var1 - var8, var2 - var8, var3 - var8, var4 + var8, var5 + var8, var6 + var8, var8); ChunkCache var9 = new ChunkCache(this.worldObj, var1 - var8, var2 - var8, var3 - var8, var4 + var8, var5 + var8, var6 + var8, var8);
if (!var9.extendedLevelsInChunkCache()) {
if (!var9.extendedLevelsInChunkCache()) EaglerAdapter.hintAnisotropicFix(true);
{
++chunksUpdated; ++chunksUpdated;
RenderBlocks var10 = new RenderBlocks(var9); RenderBlocks var10 = new RenderBlocks(var9);
this.bytesDrawn = 0; this.bytesDrawn = 0;
for (int var11 = 0; var11 < 2; ++var11) for (int var11 = 0; var11 < 2; ++var11) {
{
boolean var12 = false; boolean var12 = false;
boolean var13 = false; boolean var13 = false;
boolean var14 = false; boolean var14 = false;
for (int var15 = var2; var15 < var5; ++var15) for (int var15 = var2; var15 < var5; ++var15) {
{ for (int var16 = var3; var16 < var6; ++var16) {
for (int var16 = var3; var16 < var6; ++var16) for (int var17 = var1; var17 < var4; ++var17) {
{
for (int var17 = var1; var17 < var4; ++var17)
{
int var18 = var9.getBlockId(var17, var15, var16); int var18 = var9.getBlockId(var17, var15, var16);
if (var18 > 0) if (var18 > 0) {
{ if (!var14) {
if (!var14)
{
var14 = true; var14 = true;
EaglerAdapter.glNewList(this.glRenderList + var11, EaglerAdapter.GL_COMPILE); EaglerAdapter.glNewList(this.glRenderList + var11, EaglerAdapter.GL_COMPILE);
/*EaglerAdapter.glPushMatrix(); //EaglerAdapter.glPushMatrix();
this.setupGLTranslation(); //this.setupGLTranslation();
float var19 = 1.000001F; //float var19 = 1.000001F;
EaglerAdapter.glTranslatef(-8.0F, -8.0F, -8.0F); //EaglerAdapter.glTranslatef(-8.0F, -8.0F, -8.0F);
EaglerAdapter.glScalef(var19, var19, var19); //EaglerAdapter.glScalef(var19, var19, var19);
EaglerAdapter.glTranslatef(8.0F, 8.0F, 8.0F);*/ //EaglerAdapter.glTranslatef(8.0F, 8.0F, 8.0F);
tessellator.startDrawingQuads(); tessellator.startDrawingQuads();
tessellator.setTranslation((double)(-this.posX), (double)(-this.posY), (double)(-this.posZ)); tessellator.setTranslation((double) (this.posXClip-this.posX), (double) (this.posYClip-this.posY), (double) (this.posZClip-this.posZ));
} }
Block var23 = Block.blocksList[var18]; Block var23 = Block.blocksList[var18];
if (var23 != null) if (var23 != null) {
{ if (var11 == 0 && var23.hasTileEntity()) {
if (var11 == 0 && var23.hasTileEntity())
{
TileEntity var20 = var9.getBlockTileEntity(var17, var15, var16); TileEntity var20 = var9.getBlockTileEntity(var17, var15, var16);
if (TileEntityRenderer.instance.hasSpecialRenderer(var20)) if (TileEntityRenderer.instance.hasSpecialRenderer(var20)) {
{
this.tileEntityRenderers.add(var20); this.tileEntityRenderers.add(var20);
} }
} }
int var24 = var23.getRenderBlockPass(); int var24 = var23.getRenderBlockPass();
if (var24 != var11) if (var24 != var11) {
{
var12 = true; var12 = true;
} } else if (var24 == var11) {
else if (var24 == var11)
{
var13 |= var10.renderBlockByRenderType(var23, var17, var15, var16); var13 |= var10.renderBlockByRenderType(var23, var17, var15, var16);
} }
} }
@ -215,28 +202,29 @@ public class WorldRenderer
} }
} }
if (var14) if (var14) {
{
this.bytesDrawn += tessellator.draw(); this.bytesDrawn += tessellator.draw();
//EaglerAdapter.glPopMatrix(); //EaglerAdapter.glPopMatrix();
EaglerAdapter.glEndList(); EaglerAdapter.glEndList();
tessellator.setTranslation(0.0D, 0.0D, 0.0D); tessellator.setTranslation(0.0D, 0.0D, 0.0D);
} } else {
else
{
var13 = false; var13 = false;
} }
if (var13) if (var13) {
{
this.skipRenderPass[var11] = false; this.skipRenderPass[var11] = false;
} }
if (!var12) if (!var12) {
{
break; break;
} }
} }
if(!(skipRenderPass[0] && skipRenderPass[1])) {
++chunksGeometryUpdated;
}
EaglerAdapter.hintAnisotropicFix(false);
} }
HashSet var22 = new HashSet(); HashSet var22 = new HashSet();
@ -247,37 +235,42 @@ public class WorldRenderer
this.tileEntities.removeAll(var21); this.tileEntities.removeAll(var21);
this.isChunkLit = Chunk.isLit; this.isChunkLit = Chunk.isLit;
this.isInitialized = true; this.isInitialized = true;
if(skipRenderPass[0]) {
EaglerAdapter.flushDisplayList(glRenderList);
}
if(skipRenderPass[1]) {
EaglerAdapter.flushDisplayList(glRenderList + 1);
}
} }
} }
/** /**
* Returns the distance of this chunk renderer to the entity without performing the final normalizing square root, * Returns the distance of this chunk renderer to the entity without performing
* for performance reasons. * the final normalizing square root, for performance reasons.
*/ */
public float distanceToEntitySquared(Entity par1Entity) public float distanceToEntitySquared(Entity par1Entity) {
{ float var2 = (float) (par1Entity.posX - (double) this.posXPlus);
float var2 = (float)(par1Entity.posX - (double)this.posXPlus); float var3 = (float) (par1Entity.posY - (double) this.posYPlus);
float var3 = (float)(par1Entity.posY - (double)this.posYPlus); float var4 = (float) (par1Entity.posZ - (double) this.posZPlus);
float var4 = (float)(par1Entity.posZ - (double)this.posZPlus);
return var2 * var2 + var3 * var3 + var4 * var4; return var2 * var2 + var3 * var3 + var4 * var4;
} }
/** /**
* When called this renderer won't draw anymore until its gets initialized again * When called this renderer won't draw anymore until its gets initialized again
*/ */
public void setDontDraw() public void setDontDraw() {
{ for (int var1 = 0; var1 < 2; ++var1) {
for (int var1 = 0; var1 < 2; ++var1)
{
this.skipRenderPass[var1] = true; this.skipRenderPass[var1] = true;
EaglerAdapter.flushDisplayList(glRenderList);
EaglerAdapter.flushDisplayList(glRenderList + 1);
} }
this.isInFrustum = false; this.isInFrustum = false;
this.isInitialized = false; this.isInitialized = false;
} }
public void stopRendering() public void stopRendering() {
{
this.setDontDraw(); this.setDontDraw();
this.worldObj = null; this.worldObj = null;
} }
@ -285,37 +278,37 @@ public class WorldRenderer
/** /**
* Takes in the pass the call list is being requested for. Args: renderPass * Takes in the pass the call list is being requested for. Args: renderPass
*/ */
public int getGLCallListForPass(int par1) public int getGLCallListForPass(int par1) {
{
return !this.isInFrustum ? -1 : (!this.skipRenderPass[par1] ? this.glRenderList + par1 : -1); return !this.isInFrustum ? -1 : (!this.skipRenderPass[par1] ? this.glRenderList + par1 : -1);
} }
public void updateInFrustum(ICamera par1ICamera) public void updateInFrustum(ICamera par1ICamera) {
{
this.isInFrustum = par1ICamera.isBoundingBoxInFrustum(this.rendererBoundingBox); this.isInFrustum = par1ICamera.isBoundingBoxInFrustum(this.rendererBoundingBox);
} }
/** /**
* Renders the occlusion query GL List * Renders the occlusion query GL List
*/ */
public void callOcclusionQueryList() public void callOcclusionQueryList() {
{
EaglerAdapter.glCallList(this.glRenderList + 2); EaglerAdapter.glCallList(this.glRenderList + 2);
} }
public boolean shouldTryOcclusionQuery() {
return !this.isInitialized ? true : !this.skipRenderPass[0] || !this.skipRenderPass[1];
}
/** /**
* Checks if all render passes are to be skipped. Returns false if the renderer is not initialized * Checks if all render passes are to be skipped. Returns false if the renderer
* is not initialized
*/ */
public boolean skipAllRenderPasses() public boolean skipAllRenderPasses() {
{
return !this.isInitialized ? false : this.skipRenderPass[0] && this.skipRenderPass[1]; return !this.isInitialized ? false : this.skipRenderPass[0] && this.skipRenderPass[1];
} }
/** /**
* Marks the current renderer data as dirty and needing to be updated. * Marks the current renderer data as dirty and needing to be updated.
*/ */
public void markDirty() public void markDirty() {
{
this.needsUpdate = true; this.needsUpdate = true;
} }
} }