Fixed #180 - Multimeter glitchy rendering
This commit is contained in:
parent
9acebbba76
commit
c7d4525a9c
3 changed files with 88 additions and 45 deletions
|
@ -1,6 +1,7 @@
|
|||
package resonantinduction.electrical.multimeter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import universalelectricity.api.net.IUpdate;
|
||||
|
@ -33,6 +34,11 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
private long queueGraphCapacity = 0;
|
||||
private boolean doUpdate = false;
|
||||
|
||||
/**
|
||||
* If the screen is not a perfect rectangle, don't render.
|
||||
*/
|
||||
public boolean isEnabled = true;
|
||||
|
||||
@Override
|
||||
public void addConnector(PartMultimeter connector)
|
||||
{
|
||||
|
@ -40,19 +46,6 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
upperBound = null;
|
||||
lowerBound = null;
|
||||
super.reconstruct();
|
||||
center = upperBound.midPoint(lowerBound);
|
||||
upperBound.subtract(center);
|
||||
lowerBound.subtract(center);
|
||||
size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z));
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
|
@ -88,6 +81,37 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
|||
return node.world() != null && node.tile() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
upperBound = null;
|
||||
lowerBound = null;
|
||||
super.reconstruct();
|
||||
center = upperBound.midPoint(lowerBound);
|
||||
|
||||
/**
|
||||
* Make bounds relative.
|
||||
*/
|
||||
upperBound.subtract(center);
|
||||
lowerBound.subtract(center);
|
||||
size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z));
|
||||
|
||||
double area = (size.x != 0 ? size.x : 1) * (size.y != 0 ? size.y : 1) * (size.z != 0 ? size.z : 1);
|
||||
isEnabled = area == getConnectors().size();
|
||||
|
||||
NetworkTickHandler.addNetwork(this);
|
||||
|
||||
Iterator<PartMultimeter> it = this.getConnectors().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
PartMultimeter connector = it.next();
|
||||
connector.updateDesc();
|
||||
}
|
||||
|
||||
doUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reconstructConnector(PartMultimeter node)
|
||||
{
|
||||
|
|
|
@ -113,10 +113,14 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
}
|
||||
|
||||
getNetwork().reconstruct();
|
||||
writeDesc(getWriteStream());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDesc()
|
||||
{
|
||||
writeDesc(getWriteStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldJoin()
|
||||
{
|
||||
|
@ -172,35 +176,35 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
|
||||
if (!world().isRemote)
|
||||
{
|
||||
long detectedEnergy = doGetDetectedEnergy();
|
||||
|
||||
boolean outputRedstone = false;
|
||||
|
||||
switch (detectMode)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case EQUAL:
|
||||
outputRedstone = detectedEnergy == redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
outputRedstone = detectedEnergy > redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy >= redstoneTriggerLimit;
|
||||
break;
|
||||
case LESS_THAN:
|
||||
outputRedstone = detectedEnergy < redstoneTriggerLimit;
|
||||
break;
|
||||
case LESS_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy <= redstoneTriggerLimit;
|
||||
break;
|
||||
}
|
||||
|
||||
getNetwork().updateGraph(detectedEnergy, 0);
|
||||
|
||||
if (ticks % 10 == 0)
|
||||
{
|
||||
long detectedEnergy = doGetDetectedEnergy();
|
||||
|
||||
boolean outputRedstone = false;
|
||||
|
||||
switch (detectMode)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case EQUAL:
|
||||
outputRedstone = detectedEnergy == redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
outputRedstone = detectedEnergy > redstoneTriggerLimit;
|
||||
break;
|
||||
case GREATER_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy >= redstoneTriggerLimit;
|
||||
break;
|
||||
case LESS_THAN:
|
||||
outputRedstone = detectedEnergy < redstoneTriggerLimit;
|
||||
break;
|
||||
case LESS_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy <= redstoneTriggerLimit;
|
||||
break;
|
||||
}
|
||||
|
||||
getNetwork().updateGraph(detectedEnergy, 0);
|
||||
|
||||
if (outputRedstone != redstoneOn)
|
||||
{
|
||||
redstoneOn = outputRedstone;
|
||||
|
@ -229,9 +233,9 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
packet.readByte();
|
||||
this.side = packet.readByte();
|
||||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
refresh();
|
||||
getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().isEnabled = packet.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,6 +246,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
packet.writeByte((byte) detectMode.ordinal());
|
||||
packet.writeNBTTagCompound(getNetwork().center.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeNBTTagCompound(getNetwork().size.writeToNBT(new NBTTagCompound()));
|
||||
packet.writeBoolean(getNetwork().isEnabled);
|
||||
}
|
||||
|
||||
public void writeGraph(MCDataOutput packet)
|
||||
|
@ -262,9 +267,10 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
{
|
||||
this.side = packet.readByte();
|
||||
detectMode = DetectMode.values()[packet.readByte()];
|
||||
refresh();
|
||||
getNetwork().center = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().size = new universalelectricity.api.vector.Vector3(packet.readNBTTagCompound());
|
||||
getNetwork().isEnabled = packet.readBoolean();
|
||||
refresh();
|
||||
}
|
||||
else if (packetID == 1)
|
||||
{
|
||||
|
@ -501,4 +507,17 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
|||
{
|
||||
return new universalelectricity.api.vector.Vector3(x(), y(), z());
|
||||
}
|
||||
|
||||
/**
|
||||
* Only one multimeter renders the text.
|
||||
*/
|
||||
public boolean isPrimaryRendering()
|
||||
{
|
||||
for (PartMultimeter m : getNetwork().getConnectors())
|
||||
{
|
||||
return m == this;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,14 +131,14 @@ public class RenderMultimeter
|
|||
* Only one block renders this text.
|
||||
* Render all the multimeter text
|
||||
*/
|
||||
if (part.getNetwork().center.distance(new Vector3(part.x(), part.y(), part.z()).translate(0.5)) < 1)
|
||||
if (part.getNetwork().isEnabled && part.isPrimaryRendering())
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
||||
Vector3 centerTranslation = part.getNetwork().center.clone().subtract(part.x(), part.y(), part.z()).add(-0.5);
|
||||
GL11.glTranslated(centerTranslation.x, centerTranslation.y, centerTranslation.z);
|
||||
RenderUtility.rotateFaceBlockToSideOutwards(part.getDirection().getOpposite());
|
||||
GL11.glTranslated(0, 0.07, 0);
|
||||
GL11.glTranslated(0, 0.05, 0);
|
||||
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue