More simplifications from Brian

This commit is contained in:
Barry Silverman 2010-10-15 08:11:43 -04:00
parent 5a4c574765
commit df6aaa392c
2 changed files with 24 additions and 35 deletions

View File

@ -56,20 +56,18 @@ function recalcNodeList(list){
function recalcNode(node){ function recalcNode(node){
if(node==ngnd) return; if(node==ngnd) return;
if(node==npwr) return; if(node==npwr) return;
group = getNodeGroup(node); getNodeGroup(node);
var newState = getNodeValue(group); var newState = getNodeValue();
if(ctrace && (traceTheseNodes.indexOf(node)!=-1)) if(ctrace && (traceTheseNodes.indexOf(node)!=-1))
console.log('recalc', node, group); console.log('recalc', node, group);
for(var i in group){ group.forEach(function(i){
var n = nodes[group[i]]; var n = nodes[i];
if(n.state==newState)continue; /******Performance********/ if(n.state==newState) return;
n.state = newState; n.state = newState;
if(n.state){ n.gates.forEach(function(t){
n.gates.forEach(turnTransistorOn); if(n.state) turnTransistorOn(t);
} else { else turnTransistorOff(t);});
n.gates.forEach(turnTransistorOff); });
}
}
} }
function turnTransistorOn(t){ function turnTransistorOn(t){
@ -78,7 +76,6 @@ function turnTransistorOn(t){
console.log(t.name, 'on', t.gate, t.c1, t.c2); console.log(t.name, 'on', t.gate, t.c1, t.c2);
t.on = true; t.on = true;
addRecalcNode(t.c1); addRecalcNode(t.c1);
addRecalcNode(t.c2);
} }
function turnTransistorOff(t){ function turnTransistorOff(t){
@ -101,7 +98,6 @@ function addRecalcNode(nn){
function getNodeGroup(i){ function getNodeGroup(i){
group = new Array(); group = new Array();
addNodeToGroup(i); addNodeToGroup(i);
return group;
} }
function addNodeToGroup(i){ function addNodeToGroup(i){
@ -109,35 +105,26 @@ function addNodeToGroup(i){
group.push(i); group.push(i);
if(i==ngnd) return; if(i==ngnd) return;
if(i==npwr) return; if(i==npwr) return;
addNodeToGroup1(i); nodes[i].c1c2s.forEach(
}
function addNodeToGroup1(i){
var output=nodes[i].c1c2s;
output.forEach(
function(t){ function(t){
if(t.on)addNodeTransistor(i,t); if(!t.on) return;
}); var other;
} if(t.c1==i) other=t.c2;
if(t.c2==i) other=t.c1;
function addNodeTransistor(node, tr){ addNodeToGroup(other);});
var other;
if(tr.c1==node) other=tr.c2;
if(tr.c2==node) other=tr.c1;
addNodeToGroup(other);
} }
function getNodeValue(){ function getNodeValue(){
if(arrayContains(group, ngnd)) return false; if(arrayContains(group, ngnd)) return false;
if(arrayContains(group, npwr)) return true; if(arrayContains(group, npwr)) return true;
for(var i in group){ for(var i in group){
var nn = group[i]; var nn = group[i];
var n = nodes[nn]; var n = nodes[nn];
if(n.pullup) return true; if(n.pullup) return true;
if(n.pulldown) return false; if(n.pulldown) return false;
if(n.state) return true; if(n.state) return true;
} }
return false; return false;
} }

View File

@ -50,6 +50,8 @@ function setupTransistors(){
var gate = tdef[1]; var gate = tdef[1];
var c1 = tdef[2]; var c1 = tdef[2];
var c2 = tdef[3]; var c2 = tdef[3];
if(c1==ngnd) {c1=c2;c2=ngnd;}
if(c1==npwr) {c1=c2;c2=npwr;}
var trans = {name: name, on: false, gate: gate, c1: c1, c2: c2}; var trans = {name: name, on: false, gate: gate, c1: c1, c2: c2};
nodes[gate].gates.push(trans); nodes[gate].gates.push(trans);
nodes[c1].c1c2s.push(trans); nodes[c1].c1c2s.push(trans);