summaryrefslogtreecommitdiff
path: root/Gate.cpp
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-07-08 23:15:20 +0930
committerDaniel Jones <admin@danieljon.es>2020-07-08 23:15:20 +0930
commit3a429d84c0e38b4a33834400aa0213082b634d55 (patch)
treee897390f88b0893e181c191d8cec1ebef547dfad /Gate.cpp
parent848e32a6983cd2d61e3c1e9a489ca6563536099f (diff)
downloadfoxlogicgates-3a429d84c0e38b4a33834400aa0213082b634d55.tar.gz
foxlogicgates-3a429d84c0e38b4a33834400aa0213082b634d55.zip
Made gate updating work on separate thread, added 3 way NAND gate
Becuase of a recursion and stack overflow problem when looping objects i've moved the object updating to a separate thread, and it no longer does recursion. I also added a 3 input NAND gate and paved the work to add more 3 input gates.
Diffstat (limited to 'Gate.cpp')
-rw-r--r--Gate.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/Gate.cpp b/Gate.cpp
index 0e206d0..33313f3 100644
--- a/Gate.cpp
+++ b/Gate.cpp
@@ -23,6 +23,7 @@ Gate::Gate(GATE_TYPE type, int x, int y, int width, int height, int loaded_id)
this->gate_type = type;
this->input_gate1 = nullptr;
this->input_gate2 = nullptr;
+ this->input_gate3 = nullptr;
//this->output_gate = nullptr;
/* special handing of id - if the gate is loaded from file the loaded_id will be set and we use that */
@@ -53,6 +54,13 @@ Gate::remove_input_object(int id)
if (input_gate2->get_id() == id)
input_gate2 = nullptr;
}
+
+ if (input_gate3)
+ {
+ if (input_gate3->get_id() == id)
+ input_gate3 = nullptr;
+ }
+
}
void Gate::update_state()
@@ -110,6 +118,12 @@ void Gate::update_state()
break;
}
+ case NAND3:
+ {
+ if (!input_gate1 || !input_gate2 || !input_gate3) { output_state = false; return; }
+ output_state = !(input_gate1->get_output_state() && input_gate2->get_output_state() && input_gate3->get_output_state());
+ break;
+ }
case NOR:
{
@@ -149,53 +163,42 @@ Gate::get_output_type_text()
{
return "INPUT";
}
-
case OUTPUT:
{
return "OUTPUT";
}
-
case AND:
{
return "AND";
}
-
-
case OR:
{
return "OR";
}
-
-
case NOT:
{
return "NOT";
}
-
-
case NAND:
{
return "NAND";
}
-
-
+ case NAND3:
+ {
+ return "3NAND";
+ }
case NOR:
{
return "NOR";
}
-
-
case XOR:
{
return "XOR";
}
-
-
case XNOR:
{
return "XNOR";
}
-
default:
return "?";
}