From 3a429d84c0e38b4a33834400aa0213082b634d55 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Wed, 8 Jul 2020 23:15:20 +0930 Subject: 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. --- Gate.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'Gate.cpp') 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 "?"; } -- cgit v1.2.3