Skip to content

Commit

Permalink
Merge pull request #143 from evg-zhabotinsky/zerotick
Browse files Browse the repository at this point in the history
Made output updates synchronized. Fixed #135
  • Loading branch information
Victorious3 committed Aug 8, 2015
2 parents 3f94699 + a926e02 commit 0fc19a6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void drawButton(Minecraft mc, int x, int y) {

ForgeDirection dir = MiscUtils.getDirection(side);
isActive = te.getCircuitData().getProperties().getModeAtSide(side) != EnumConnectionType.SIMPLE || color == 0;
boolean isPowered = isActive && te.getInputFromSide(dir, color) || te.getOutputToSide(dir, color);
boolean isPowered = isActive && te.getExternalInputFromSide(dir, color) || te.getOutputToSide(dir, color);

if (isActive) {
if (isPowered)
Expand Down Expand Up @@ -85,7 +85,7 @@ public boolean mousePressed(Minecraft mc, int par1, int par2) {
boolean b = super.mousePressed(mc, par1, par2) && !parent.blockMouseInput;
if (b) {
ForgeDirection dir = MiscUtils.getDirection(side);
te.setInputFromSide(dir, color, !te.getInputFromSide(dir, color));
te.setExternalInputFromSide(dir, color, !te.getExternalInputFromSide(dir, color));
}
return b;
}
Expand All @@ -101,7 +101,7 @@ public List<String> getHoverInformation() {
if (isActive) {
text.add("I: "
+ I18n.format("gui.integratedcircuits.cad.mode."
+ (te.getInputFromSide(dir, color) ? "high" : "low")));
+ (te.getExternalInputFromSide(dir, color) ? "high" : "low")));
text.add("O: "
+ I18n.format("gui.integratedcircuits.cad.mode."
+ (te.getOutputToSide(dir, color) ? "high" : "low")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ public void updateOutput() {
PartIOBit io3 = (PartIOBit) getPart(pos3);
PartIOBit io4 = (PartIOBit) getPart(pos4);

io1.onInputChange(pos1, parent);
io2.onInputChange(pos2, parent);
io3.onInputChange(pos3, parent);
io4.onInputChange(pos4, parent);
io1.updateExternalOutput(pos1, parent);
io2.updateExternalOutput(pos2, parent);
io3.updateExternalOutput(pos3, parent);
io4.updateExternalOutput(pos4, parent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,29 @@ public final void setFrequency(Vec2 pos, ICircuit parent, int frequency) {
setProperty(pos, parent, PROP_FREQUENCY, frequency);
}

public final void updateExternalOutput(Vec2 pos, ICircuit parent) {
ForgeDirection dir = MiscUtils.getDirection(getRotation(pos, parent));
parent.setOutputToSide(dir, getFrequency(pos, parent),
getInputFromSide(pos, parent, dir.getOpposite()));
}

public boolean canConnectToSide(Vec2 pos, ICircuit parent, ForgeDirection side) {
ForgeDirection dir = MiscUtils.getDirection(getRotation(pos, parent));
return side == dir.getOpposite();
}

@Override
public void onInputChange(Vec2 pos, ICircuit parent) {
ForgeDirection dir = MiscUtils.getDirection(getRotation(pos, parent));
parent.setOutputToSide(dir, getFrequency(pos, parent),
getInputFromSide(pos, parent, dir.getOpposite()));
scheduleTick(pos, parent);
notifyNeighbours(pos, parent);
}

@Override
public void onScheduledTick(Vec2 pos, ICircuit parent) {
updateExternalOutput(pos, parent);
notifyNeighbours(pos, parent); // Implicit updateExternalInput
}

@Override
public boolean getOutputToSide(Vec2 pos, ICircuit parent, ForgeDirection side) {
ForgeDirection dir = MiscUtils.getDirection(getRotation(pos, parent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,21 @@ public void writeToNBT(NBTTagCompound compound) {
compound.setTag("floppyStack", stackCompound);
}

public final boolean getExternalInputFromSide(ForgeDirection dir, int frequency) {
return (in[MiscUtils.getSide(dir)] & 1 << frequency) != 0;
}

@Override
public boolean getInputFromSide(ForgeDirection dir, int frequency) {
return (in[MiscUtils.getSide(dir)] & 1 << frequency) != 0;
return getExternalInputFromSide(dir, frequency) && !getOutputToSide(dir, frequency);
}

public boolean getOutputToSide(ForgeDirection dir, int frequency) {
return (out[MiscUtils.getSide(dir)] & 1 << frequency) != 0;
}

@SideOnly(Side.CLIENT)
public void setInputFromSide(ForgeDirection dir, int frequency, boolean output) {
public final void setExternalInputFromSide(ForgeDirection dir, int frequency, boolean output) {
EnumConnectionType mode = circuitData.getProperties().getModeAtSide(MiscUtils.getSide(dir));
if (mode != EnumConnectionType.SIMPLE || frequency == 0) {
int[] i = this.in.clone();
Expand Down

0 comments on commit 0fc19a6

Please sign in to comment.