Created
January 15, 2012 20:36
-
-
Save Corosauce/1617115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.minecraft.src; | |
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import net.minecraft.src.AxisAlignedBB; | |
import net.minecraft.src.Block; | |
import net.minecraft.src.Chunk; | |
import net.minecraft.src.ChunkCache; | |
import net.minecraft.src.Config; | |
import net.minecraft.src.Entity; | |
import net.minecraft.src.ICamera; | |
import net.minecraft.src.MathHelper; | |
import net.minecraft.src.Reflector; | |
import net.minecraft.src.RenderBlocks; | |
import net.minecraft.src.RenderItem; | |
import net.minecraft.src.Tessellator; | |
import net.minecraft.src.TileEntity; | |
import net.minecraft.src.TileEntityRenderer; | |
import net.minecraft.src.World; | |
import org.lwjgl.opengl.GL11; | |
public class WorldRenderer { | |
public World worldObj; | |
private int glRenderList = -1; | |
public static int chunksUpdated = 0; | |
public int posX; | |
public int posY; | |
public int posZ; | |
public int sizeWidth; | |
public int sizeHeight; | |
public int sizeDepth; | |
public int posXMinus; | |
public int posYMinus; | |
public int posZMinus; | |
public int posXClip; | |
public int posYClip; | |
public int posZClip; | |
public boolean isInFrustum = false; | |
public boolean[] skipRenderPass = new boolean[2]; | |
public int posXPlus; | |
public int posYPlus; | |
public int posZPlus; | |
public float rendererRadius; | |
public boolean needsUpdate; | |
public AxisAlignedBB rendererBoundingBox; | |
public int chunkIndex; | |
public boolean isVisible = true; | |
public boolean isWaitingOnOcclusionQuery; | |
public int glOcclusionQuery; | |
public boolean isChunkLit; | |
private boolean isInitialized = false; | |
public List tileEntityRenderers = new ArrayList(); | |
private List tileEntities; | |
private int bytesDrawn; | |
public boolean isVisibleFromPosition = false; | |
public double visibleFromX; | |
public double visibleFromY; | |
public double visibleFromZ; | |
private boolean needsBoxUpdate = false; | |
public boolean isInFrustrumFully = false; | |
public WorldRenderer(World var1, List var2, int var3, int var4, int var5, int var6, int var7) { | |
this.worldObj = var1; | |
this.tileEntities = var2; | |
this.sizeWidth = this.sizeHeight = this.sizeDepth = var6; | |
this.rendererRadius = MathHelper.sqrt_float((float)(this.sizeWidth * this.sizeWidth + this.sizeHeight * this.sizeHeight + this.sizeDepth * this.sizeDepth)) / 2.0F; | |
this.glRenderList = var7; | |
this.posX = -999; | |
this.setPosition(var3, var4, var5); | |
this.needsUpdate = false; | |
} | |
public void setPosition(int var1, int var2, int var3) { | |
if(var1 != this.posX || var2 != this.posY || var3 != this.posZ) { | |
this.setDontDraw(); | |
this.posX = var1; | |
this.posY = var2; | |
this.posZ = var3; | |
this.posXPlus = var1 + this.sizeWidth / 2; | |
this.posYPlus = var2 + this.sizeHeight / 2; | |
this.posZPlus = var3 + this.sizeDepth / 2; | |
this.posXClip = var1 & 1023; | |
this.posYClip = var2; | |
this.posZClip = var3 & 1023; | |
this.posXMinus = var1 - this.posXClip; | |
this.posYMinus = var2 - this.posYClip; | |
this.posZMinus = var3 - this.posZClip; | |
float var4 = 0.0F; | |
this.rendererBoundingBox = AxisAlignedBB.getBoundingBox((double)((float)var1 - var4), (double)((float)var2 - var4), (double)((float)var3 - var4), (double)((float)(var1 + this.sizeWidth) + var4), (double)((float)(var2 + this.sizeHeight) + var4), (double)((float)(var3 + this.sizeDepth) + var4)); | |
this.needsBoxUpdate = true; | |
this.markDirty(); | |
this.isVisibleFromPosition = false; | |
} | |
} | |
private void setupGLTranslation() { | |
GL11.glTranslatef((float)this.posXClip, (float)this.posYClip, (float)this.posZClip); | |
} | |
public void updateRenderer() { | |
if(this.needsUpdate) { | |
++chunksUpdated; | |
if(this.needsBoxUpdate) { | |
float var1 = 0.0F; | |
GL11.glNewList(this.glRenderList + 2, 4864 /*GL_COMPILE*/); | |
RenderItem.renderAABB(AxisAlignedBB.getBoundingBoxFromPool((double)((float)this.posXClip - var1), (double)((float)this.posYClip - var1), (double)((float)this.posZClip - var1), (double)((float)(this.posXClip + this.sizeWidth) + var1), (double)((float)(this.posYClip + this.sizeHeight) + var1), (double)((float)(this.posZClip + this.sizeDepth) + var1))); | |
GL11.glEndList(); | |
this.needsBoxUpdate = false; | |
} | |
this.isVisible = true; | |
this.isVisibleFromPosition = false; | |
int var24 = this.posX; | |
int var2 = this.posY; | |
int var3 = this.posZ; | |
int var4 = this.posX + this.sizeWidth; | |
int var5 = this.posY + this.sizeHeight; | |
int var6 = this.posZ + this.sizeDepth; | |
for(int var7 = 0; var7 < 2; ++var7) { | |
this.skipRenderPass[var7] = true; | |
} | |
if(Reflector.hasClass(3)) { | |
Object var26 = Reflector.getFieldValue(30); | |
Reflector.callVoid(var26, 30, new Object[0]); | |
Reflector.callVoid(40, new Object[0]); | |
} | |
Chunk.isLit = false; | |
HashSet var25 = new HashSet(); | |
var25.addAll(this.tileEntityRenderers); | |
this.tileEntityRenderers.clear(); | |
byte var8 = 1; | |
ChunkCache var9 = new ChunkCache(this.worldObj, var24 - var8, var2 - var8, var3 - var8, var4 + var8, var5 + var8, var6 + var8); | |
RenderBlocks var10 = new RenderBlocks(var9); | |
this.bytesDrawn = 0; | |
Tessellator var11 = Tessellator.instance; | |
boolean var12 = Reflector.hasClass(1); | |
for(int var13 = 0; var13 < 2; ++var13) { | |
boolean var14 = false; | |
boolean var15 = false; | |
boolean var16 = false; | |
for(int var17 = var2; var17 < var5; ++var17) { | |
for(int var18 = var3; var18 < var6; ++var18) { | |
for(int var19 = var24; var19 < var4; ++var19) { | |
int var20 = var9.getBlockId(var19, var17, var18); | |
if(var20 > 0) { | |
if(!var16) { | |
var16 = true; | |
GL11.glNewList(this.glRenderList + var13, 4864 /*GL_COMPILE*/); | |
var11.setRenderingChunk(true); | |
if(var12) { | |
Reflector.callVoid(13, new Object[] {Integer.valueOf(var13)}); | |
} | |
var11.startDrawingQuads(); | |
} | |
if(var13 == 0 && Block.isBlockContainer[var20]) { | |
TileEntity var21 = var9.getBlockTileEntity(var19, var17, var18); | |
if(TileEntityRenderer.instance.hasSpecialRenderer(var21)) { | |
this.tileEntityRenderers.add(var21); | |
} | |
} | |
Block var28 = Block.blocksList[var20]; | |
int var22 = var28.getRenderBlockPass(); | |
if(var13 == 0 && var10.renderLightOnBlock(var19, var17, var18, var13)) { | |
var15 = true; | |
} | |
boolean var23 = true; | |
if(var22 != var13) { | |
var14 = true; | |
var23 = false; | |
} | |
if(var12) { | |
var23 = Reflector.callBoolean(11, new Object[] {var28, Integer.valueOf(var13)}); | |
} | |
if(var23) { | |
if(var12) { | |
Reflector.callVoid(15, new Object[] {var28, var10}); | |
} | |
var15 |= var10.renderBlockByRenderType(var28, var19, var17, var18); | |
if(var12) { | |
Reflector.callVoid(16, new Object[] {var28, var10}); | |
} | |
} | |
} | |
} | |
} | |
} | |
if(var16) { | |
if(var12) { | |
Reflector.callVoid(14, new Object[] {Integer.valueOf(var13)}); | |
} | |
this.bytesDrawn += var11.draw(); | |
GL11.glEndList(); | |
var11.setRenderingChunk(false); | |
} else { | |
var15 = false; | |
} | |
if(var15) { | |
this.skipRenderPass[var13] = false; | |
} | |
if(!var14) { | |
break; | |
} | |
} | |
HashSet var27 = new HashSet(); | |
var27.addAll(this.tileEntityRenderers); | |
var27.removeAll(var25); | |
this.tileEntities.addAll(var27); | |
var25.removeAll(this.tileEntityRenderers); | |
this.tileEntities.removeAll(var25); | |
this.isChunkLit = Chunk.isLit; | |
this.isInitialized = true; | |
} | |
} | |
public float distanceToEntitySquared(Entity var1) { | |
float var2 = (float)(var1.posX - (double)this.posXPlus); | |
float var3 = (float)(var1.posY - (double)this.posYPlus); | |
float var4 = (float)(var1.posZ - (double)this.posZPlus); | |
return var2 * var2 + var3 * var3 + var4 * var4; | |
} | |
public void setDontDraw() { | |
for(int var1 = 0; var1 < 2; ++var1) { | |
this.skipRenderPass[var1] = true; | |
} | |
this.isInFrustum = false; | |
this.isInitialized = false; | |
} | |
public void stopRendering() { | |
this.setDontDraw(); | |
this.worldObj = null; | |
} | |
public int getGLCallListForPass(int var1) { | |
return !this.isInFrustum?-1:(!this.skipRenderPass[var1]?this.glRenderList + var1:-1); | |
} | |
public void updateInFrustrum(ICamera var1) { | |
this.isInFrustum = var1.isBoundingBoxInFrustum(this.rendererBoundingBox); | |
if(this.isInFrustum && Config.isOcclusionEnabled() && Config.isOcclusionFancy()) { | |
this.isInFrustrumFully = var1.isBoundingBoxInFrustumFully(this.rendererBoundingBox); | |
} else { | |
this.isInFrustrumFully = false; | |
} | |
} | |
public void callOcclusionQueryList() { | |
GL11.glCallList(this.glRenderList + 2); | |
} | |
public boolean skipAllRenderPasses() { | |
return !this.isInitialized?false:this.skipRenderPass[0] && this.skipRenderPass[1]; | |
} | |
public void markDirty() { | |
this.needsUpdate = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment