mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-15 11:49:27 +01:00
sim: split the most basic crappy solver into separate file
This commit is contained in:
@@ -44,51 +44,6 @@ void CSimulation::drawSim() {
|
||||
for (int i = 0; i < wires.size(); i++) {
|
||||
wires[i]->drawWire();
|
||||
}
|
||||
// sim
|
||||
for (int i = 0; i < junctions.size(); i++) {
|
||||
CJunction *ju = junctions[i];
|
||||
if (ju->isCurrentSource() == false) {
|
||||
ju->setVoltage(-1);
|
||||
}
|
||||
ju->setVisitCount(0);
|
||||
}
|
||||
for (int i = 0; i < junctions.size(); i++) {
|
||||
CJunction *ju = junctions[i];
|
||||
if (ju->hasName("VDD")) {
|
||||
floodJunctions(ju,3.3f);
|
||||
}
|
||||
else if (ju->hasName("GND")) {
|
||||
floodJunctions(ju, 0);
|
||||
}
|
||||
else if (ju->isCurrentSource()) {
|
||||
floodJunctions(ju, ju->getVoltage());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Idea: count steps to VDD/GND and use it to support multiple objects on line?
|
||||
void CSimulation::floodJunctions(CJunction *ju, float voltage) {
|
||||
if (ju == 0)
|
||||
return;
|
||||
if (ju->getVisitCount() != 0)
|
||||
return;
|
||||
ju->setVisitCount(1);
|
||||
ju->setVoltage(voltage);
|
||||
for (int i = 0; i < ju->getLinksCount(); i++) {
|
||||
CJunction *other = ju->getLink(i);
|
||||
floodJunctions(other, voltage);
|
||||
}
|
||||
for (int i = 0; i < ju->getEdgesCount(); i++) {
|
||||
CEdge *e = ju->getEdge(i);
|
||||
CJunction *o = e->getOther(ju);
|
||||
floodJunctions(o, voltage);
|
||||
}
|
||||
CControllerBase *cntr = ju->findOwnerController_r();
|
||||
if (cntr != 0) {
|
||||
CJunction *other = cntr->findOtherJunctionIfPassable(ju);
|
||||
if (other) {
|
||||
floodJunctions(other, voltage);
|
||||
}
|
||||
}
|
||||
}
|
||||
class CShape *CSimulation::findShapeByBoundsPoint(const class Coord &p) {
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user