Skip to content

Commit

Permalink
restore state only when reloading, not when flipping.
Browse files Browse the repository at this point in the history
fix restore state code to handle high voltage, not assume 5V.
  • Loading branch information
pfalstad committed Dec 9, 2024
1 parent 03914a5 commit 1dab1a7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/com/lushprojects/circuitjs1/client/GateElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public GateElm(int xa, int ya, int xb, int yb, int f,
lastOutput = lastOutputVoltage > highVoltage*.5;
setSize((f & FLAG_SMALL) != 0 ? 1 : 2);
allocNodes();
setupVolts();
}
boolean isInverting() { return false; }
int gsize, gwidth, gwidth2, gheight, hs2;
Expand Down Expand Up @@ -86,7 +87,6 @@ void setPoints() {
calcLeads(ww*2);
inPosts = new Point[inputCount];
inGates = new Point[inputCount];
allocNodes();
int i0 = -inputCount/2;
if (hasFlag(FLAG_INVERT_INPUTS))
icircles = new Point[inputCount];
Expand All @@ -100,14 +100,22 @@ void setPoints() {
inGates[i] = interpPoint(lead1, lead2, icircles != null ? -8/(ww*2.)+adj : adj, hs*i0);
if (icircles != null)
icircles[i] = interpPoint(lead1, lead2, -4/(ww*2.), hs*i0);
volts[i] = (lastOutput ^ isInverting()) ? 5 : 0;
}
hs2 = gwidth*(inputCount/2+1);
setBbox(point1, point2, hs2);
if (hasSchmittInputs())
schmittPoly = getSchmittPolygon(gsize, .47f);
}

// Restore state if loading from file or volts is reallocated.
void setupVolts() {
int i;
// We don't remember all the inputs, just the last output.
// Fill inputs with something that keeps output the same.
for (i = 0; i != inputCount; i++)
volts[i] = (lastOutput ^ isInverting()) ? highVoltage : 0;
}

double getLeadAdjustment(int ix) { return 0; }

void createEuroGatePolygon() {
Expand Down Expand Up @@ -227,6 +235,8 @@ public EditInfo getEditInfo(int n) {
public void setEditValue(int n, EditInfo ei) {
if (n == 0 && ei.value >= 1) {
inputCount = (int) ei.value;
allocNodes();
setupVolts();
setPoints();
}
if (n == 1)
Expand Down

0 comments on commit 1dab1a7

Please sign in to comment.