Added renderer support for liquid meta, added liquid avarages to smooth liquid rendering, extracted some methods

This commit is contained in:
Krapht 2012-07-21 01:12:53 +02:00
parent 589f6ad4de
commit 888fdb459a
2 changed files with 133 additions and 83 deletions

View file

@ -62,7 +62,8 @@ public class RenderPipe extends TileEntitySpecialRenderer {
public int[] centerVertical = new int[displayLiquidStages]; public int[] centerVertical = new int[displayLiquidStages];
} }
private HashMap<Integer, DisplayLiquidList> displayLiquidLists = new HashMap<Integer, DisplayLiquidList>(); private HashMap<Integer, HashMap<Integer, DisplayLiquidList>> displayLiquidLists = new HashMap<Integer, HashMap<Integer, DisplayLiquidList>>();
private final int[] angleY = { 0, 0, 270, 90, 0, 180 }; private final int[] angleY = { 0, 0, 270, 90, 0, 180 };
private final int[] angleZ = { 90, 270, 0, 0, 0, 0 }; private final int[] angleZ = { 90, 270, 0, 0, 0, 0 };
@ -79,11 +80,18 @@ public class RenderPipe extends TileEntitySpecialRenderer {
} }
private DisplayLiquidList getDisplayLiquidLists(int liquidId, int meta, World world) { private DisplayLiquidList getDisplayLiquidLists(int liquidId, int meta, World world) {
if (displayLiquidLists.containsKey(liquidId)) if (displayLiquidLists.containsKey(liquidId)){
return displayLiquidLists.get(liquidId); HashMap<Integer, DisplayLiquidList> x = displayLiquidLists.get(liquidId);
if (x.containsKey(meta)){
return x.get(meta);
}
} else {
displayLiquidLists.put(liquidId, new HashMap<Integer, DisplayLiquidList>());
}
DisplayLiquidList d = new DisplayLiquidList(); DisplayLiquidList d = new DisplayLiquidList();
displayLiquidLists.put(liquidId, d); displayLiquidLists.get(liquidId).put(meta, d);
BlockInterface block = new BlockInterface(); BlockInterface block = new BlockInterface();
if (liquidId < Block.blocksList.length && Block.blocksList[liquidId] != null) if (liquidId < Block.blocksList.length && Block.blocksList[liquidId] != null)
@ -291,16 +299,19 @@ public class RenderPipe extends TileEntitySpecialRenderer {
boolean sides = false, above = false; boolean sides = false, above = false;
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
ILiquidTank tank = liq.getTanks()[i]; //ILiquidTank tank = liq.getTanks()[i];
LiquidStack liquid = tank.getLiquid(); //LiquidStack liquid = tank.getLiquid();
int amount = liquid != null ? liquid.amount : 0; LiquidStack liquid = liq.renderCache[i];
if ( amount > 0) { //int amount = liquid != null ? liquid.amount : 0;
//int amount = liquid != null ? liq.renderAmmount[i] : 0;
if ( liquid != null && liquid.amount > 0) {
DisplayLiquidList d = getListFromBuffer(liquid, pipe.worldObj); DisplayLiquidList d = getListFromBuffer(liquid, pipe.worldObj);
if (d == null) if (d == null)
continue; continue;
int stage = (int) ((float) amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1)); int stage = (int) ((float) liquid.amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
GL11.glPushMatrix(); GL11.glPushMatrix();
int list = 0; int list = 0;
@ -330,15 +341,18 @@ public class RenderPipe extends TileEntitySpecialRenderer {
} }
} }
// CENTER // CENTER
ILiquidTank tank = liq.getTanks()[Orientations.Unknown.ordinal()]; // ILiquidTank tank = liq.getTanks()[Orientations.Unknown.ordinal()];
LiquidStack liquid = tank.getLiquid(); // LiquidStack liquid = tank.getLiquid();
LiquidStack liquid = liq.renderCache[Orientations.Unknown.ordinal()];
int amount = liquid != null ? liquid.amount : 0; //int amount = liquid != null ? liquid.amount : 0;
if ( amount > 0) { //int amount = liquid != null ? liq.renderAmmount[Orientations.Unknown.ordinal()] : 0;
DisplayLiquidList d = getListFromBuffer(liq.getTanks()[Orientations.Unknown.ordinal()].getLiquid(), pipe.worldObj); if (liquid != null && liquid.amount > 0) {
//DisplayLiquidList d = getListFromBuffer(liq.getTanks()[Orientations.Unknown.ordinal()].getLiquid(), pipe.worldObj);
DisplayLiquidList d = getListFromBuffer(liquid, pipe.worldObj);
if (d != null) { if (d != null) {
int stage = (int) ((float) amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1)); int stage = (int) ((float) liquid.amount / (float) (PipeTransportLiquids.LIQUID_IN_PIPE) * (displayLiquidStages - 1));
if (above) if (above)
GL11.glCallList(d.centerVertical[stage]); GL11.glCallList(d.centerVertical[stage]);

View file

@ -37,6 +37,9 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
private final PipeSection[] internalTanks = new PipeSection[Orientations.values().length]; private final PipeSection[] internalTanks = new PipeSection[Orientations.values().length];
//public final short[] renderAmmount = new short[] {0,0,0,0,0,0,0};
public final LiquidStack[] renderCache = new LiquidStack[Orientations.values().length];
public class PipeSection extends LiquidTank { public class PipeSection extends LiquidTank {
private short currentTime = 0; private short currentTime = 0;
@ -77,6 +80,9 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
if (doDrain){ if (doDrain){
available -= drained.amount; available -= drained.amount;
if (this.getLiquid() == null){
int xxxx = 1+1;
}
} }
return drained; return drained;
@ -139,6 +145,28 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
return; return;
moveLiquids(); moveLiquids();
for (Orientations direction : Orientations.values()) {
LiquidStack liquid = internalTanks[direction.ordinal()].getLiquid();
if (liquid != null && renderCache[direction.ordinal()] != null){
liquid.itemID = renderCache[direction.ordinal()].itemID;
liquid.itemMeta = renderCache[direction.ordinal()].itemMeta;
}
if (renderCache[direction.ordinal()] != null){
renderCache[direction.ordinal()].amount = (short) ((renderCache[direction.ordinal()].amount * 39 + (liquid != null ? liquid.amount : 0)) / 40);
//renderCache[direction.ordinal()].amount = (liquid != null ? liquid.amount : 0);
}
if (renderCache[direction.ordinal()] == null && liquid != null){
renderCache[direction.ordinal()] = liquid.copy();
}
//renderCache[direction.ordinal()] = internalTanks[direction.ordinal()].getLiquid();
//renderAmmount[direction.ordinal()] = (short) ((renderAmmount[direction.ordinal()] * 39 + (liquid != null ? liquid.amount : 0)) / 40);
//renderAmmount[direction.ordinal()] = (short) (liquid != null ? liquid.amount : 0);
}
this.container.synchronizeIfDelay(1 * BuildCraftCore.updateFactor); this.container.synchronizeIfDelay(1 * BuildCraftCore.updateFactor);
} }
@ -212,6 +240,78 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
} }
moveFromPipe(outputCount);
moveToCenter();
moveFromCenter();
}
private void moveFromPipe(short outputCount) {
//Move liquid from the non-center to the connected output blocks
if (outputCount > 0){
for (Orientations o : Orientations.dirs()){
if (isOutput[o.ordinal()]){
TileEntity target = this.container.getTile(o);
if (!(target instanceof ITankContainer)) continue;
LiquidStack liquidToPush = internalTanks[o.ordinal()].drain(flowRate, false);
if (liquidToPush != null && liquidToPush.amount > 0) {
int filled = ((ITankContainer)target).fill(o.reverse(), liquidToPush, true);
internalTanks[o.ordinal()].drain(filled, true);
if (filled == 0){
for (Orientations direction : Orientations.dirs()){
if (bounceCount[direction.ordinal()]++ > 30){
bounceCount[direction.ordinal()] = 0;
isInput[direction.ordinal()] = true;
}
}
}
}
}
}
}
}
private void moveFromCenter() {
//Split liquids moving to output equally based on flowrate, how much each side can accept and available liquid
int[] maxOutput = new int[] {0,0,0,0,0,0};
int transferOutCount = 0;
LiquidStack pushStack = internalTanks[Orientations.Unknown.ordinal()].getLiquid();
int totalAvailable = internalTanks[Orientations.Unknown.ordinal()].getAvailable() / 2;
if (pushStack != null){
LiquidStack testStack = pushStack.copy();
testStack.amount = flowRate;
for (Orientations direction : Orientations.dirs()){
if (!isOutput[direction.ordinal()]) continue;
maxOutput[direction.ordinal()] = internalTanks[direction.ordinal()].fill(testStack, false);
if(maxOutput[direction.ordinal()] > 0){
transferOutCount++;
}
}
//Move liquid from the center to the output sides
for (Orientations direction : Orientations.dirs()) {
if (!container.pipe.outputOpen(direction)) continue;
if (isOutput[direction.ordinal()]) {
if (maxOutput[direction.ordinal()] == 0) continue;
int ammountToPush = (int) ((double) maxOutput[direction.ordinal()] / (double) flowRate / (double) transferOutCount * (double) Math.min(flowRate, totalAvailable));
if (ammountToPush < 1) ammountToPush++;
LiquidStack liquidToPush = internalTanks[Orientations.Unknown.ordinal()].drain(ammountToPush, false);
if (liquidToPush != null) {
int filled = internalTanks[direction.ordinal()].fill(liquidToPush, true);
internalTanks[Orientations.Unknown.ordinal()].drain(filled, true);
}
}
}
}
}
private void moveToCenter() {
int [] maxInput = new int[] {0,0,0,0,0,0}; int [] maxInput = new int[] {0,0,0,0,0,0};
int transferInCount = 0; int transferInCount = 0;
LiquidStack stackInCenter = internalTanks[Orientations.Unknown.ordinal()].drain(flowRate, false); LiquidStack stackInCenter = internalTanks[Orientations.Unknown.ordinal()].drain(flowRate, false);
@ -246,64 +346,6 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
} }
} }
} }
//Split liquids moving to output equally based on flowrate, how much each side can accept and available liquid
int[] maxOutput = new int[] {0,0,0,0,0,0};
int transferOutCount = 0;
LiquidStack pushStack = internalTanks[Orientations.Unknown.ordinal()].getLiquid();
int totalAvailable = internalTanks[Orientations.Unknown.ordinal()].getAvailable();
if (pushStack != null){
LiquidStack testStack = pushStack.copy();
testStack.amount = flowRate;
for (Orientations direction : Orientations.dirs()){
if (!isOutput[direction.ordinal()]) continue;
maxOutput[direction.ordinal()] = internalTanks[direction.ordinal()].fill(testStack, false);
if(maxOutput[direction.ordinal()] > 0){
transferOutCount++;
}
}
//Move liquid from the center to the output sides
for (Orientations direction : Orientations.dirs()) {
if (!container.pipe.outputOpen(direction)) continue;
if (isOutput[direction.ordinal()]) {
if (maxOutput[direction.ordinal()] == 0) continue;
int ammountToPush = (int) ((double) maxOutput[direction.ordinal()] / (double) flowRate / (double) transferOutCount * (double) Math.min(flowRate, totalAvailable));
if (ammountToPush < 1) ammountToPush++;
LiquidStack liquidToPush = internalTanks[Orientations.Unknown.ordinal()].drain(ammountToPush, false);
if (liquidToPush != null) {
int filled = internalTanks[direction.ordinal()].fill(liquidToPush, true);
internalTanks[Orientations.Unknown.ordinal()].drain(filled, true);
}
}
}
}
//Move liquid from the non-center to the connected output blocks
if (outputCount > 0){
for (Orientations o : Orientations.dirs()){
if (isOutput[o.ordinal()]){
TileEntity target = this.container.getTile(o);
if (!(target instanceof ITankContainer)) continue;
LiquidStack liquidToPush = internalTanks[o.ordinal()].drain(flowRate, false);
if (liquidToPush != null && liquidToPush.amount > 0) {
int filled = ((ITankContainer)target).fill(o.reverse(), liquidToPush, true);
internalTanks[o.ordinal()].drain(filled, true);
if (filled == 0){
for (Orientations direction : Orientations.dirs()){
if (bounceCount[direction.ordinal()]++ > 30){
bounceCount[direction.ordinal()] = 0;
isInput[direction.ordinal()] = true;
}
}
}
}
}
}
}
} }
private short computeOutputs() { private short computeOutputs() {
@ -326,6 +368,7 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
for (int i = 0; i < 6; ++i){ for (int i = 0; i < 6; ++i){
if (!Utils.checkPipesConnections(container.getTile(Orientations.values()[i]), container)) { if (!Utils.checkPipesConnections(container.getTile(Orientations.values()[i]), container)) {
internalTanks[i].reset(); internalTanks[i].reset();
renderCache[i] = null;
} }
} }
} }
@ -360,18 +403,11 @@ public class PipeTransportLiquids extends PipeTransport implements ITankContaine
@Override @Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) { public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
int filled = 0; isInput[tankIndex] = true;
if (this.container.pipe instanceof IPipeTransportLiquidsHook) if (this.container.pipe instanceof IPipeTransportLiquidsHook)
filled = ((IPipeTransportLiquidsHook) this.container.pipe).fill(Orientations.values()[tankIndex], resource, doFill); return ((IPipeTransportLiquidsHook) this.container.pipe).fill(Orientations.values()[tankIndex], resource, doFill);
else else
filled = internalTanks[tankIndex].fill(resource, doFill); return internalTanks[tankIndex].fill(resource, doFill);
if (filled > 0){
isInput[tankIndex] = true;
}
return filled;
} }
@Override @Override