DrawnBit DrawBitStepRecursive(Bit bit) { recursiveCall++; if (lastDrawnBits.ContainsKey(bit)) { return(lastDrawnBits[bit]); } if (bit.A != null) { DrawBitStepRecursive(bit.A); } if (bit.B != null) { DrawBitStepRecursive(bit.B); } int positionX = (int)bit.stepFromMessage; if (!depthStack.ContainsKey(positionX)) { depthStack.Add(positionX, 0); } else { depthStack[positionX]++; } DrawnBit drawnBit = new DrawnBit(bit, positionX, depthStack[positionX]); lastDrawnBits.Add(bit, drawnBit); return(drawnBit); }
public void ProcessDraw(List <Word> words) { int depth = 0; lastDrawnBits.Clear(); depthStack.Clear(); recursiveCall = 0; for (int i = 0; i < words.Count; i++) { Word w = words[i]; for (int k = w.bits.Count - 1; k >= 0; k--) { depthStack.Add(depth, 10); DrawnBit newDrawn = new DrawnBit(w[k], depth, 0); lastDrawnBits.Add(w[k], newDrawn); depth += 2; } } for (int i = 0; i < words.Count; i++) { Word w = words[i]; for (int k = w.bits.Count - 1; k >= 0; k--) { DrawBitChild(w[k]); } } Debug.Log("done draw with recursive : " + recursiveCall); int maxX = 0; int maxY = 0; foreach (KeyValuePair <int, int> kv in depthStack) { maxX = Mathf.Max(maxX, kv.Key); maxY = Mathf.Max(maxY, kv.Value); } Debug.Log("size " + maxX + "," + maxY); }
DrawnBit DrawBit(Bit bit) { recursiveCall++; if (lastDrawnBits.ContainsKey(bit)) { return(lastDrawnBits[bit]); } int positionX = 0; if (bit.A != null) { DrawnBit dA = DrawBit(bit.A); positionX = dA.pos.x; } if (bit.B != null) { DrawnBit dB = DrawBit(bit.B); positionX = Mathf.Max(dB.pos.x, positionX); } positionX++; if (!depthStack.ContainsKey(positionX)) { depthStack.Add(positionX, 10); } else { depthStack[positionX]++; } DrawnBit drawnBit = new DrawnBit(bit, positionX, depthStack[positionX]); lastDrawnBits.Add(bit, drawnBit); return(drawnBit); }
void Draw() { List <DrawnBit> actuallyDrawnBit = new List <DrawnBit>(); none_Line.Clear(); and_Line.Clear(); or_Line.Clear(); xor_Line.Clear(); not_Line.Clear(); if (depthStack.Count > 0) { int counter = 0; foreach (KeyValuePair <Bit, DrawnBit> kvp in lastDrawnBits) { counter++; if ((counter % drawOneOn) != 0) { continue; } if (kvp.Key.stepFromMessage == -1) { Debug.LogError("-1"); } Bit bit = kvp.Key; DrawnBit dBit = kvp.Value; if (drawStepCount != -1) { if (bit.stepFromMessage != drawStepCount) { continue; } actuallyDrawnBit.Add(dBit); } actuallyDrawnBit.Add(dBit); int childCount = bit.A != null ? 1 : 0; childCount += bit.B != null ? 1 : 0; if (childCount > 0) { Vector2 bitPos = new Vector2(dBit.pos.x, dBit.pos.y); if (childCount == 1) { Vector2 a = lastDrawnBits[bit.A].pos + new Vector2(0.4f, 0.0f); Vector2 b = dBit.pos + new Vector2(-0.4f, 0.0f); DrawLine(lastDrawnBits[bit.A].pos, a, bit.operation); DrawLine(a, b, bit.operation); DrawLine(b, dBit.pos, bit.operation); } else { Vector2 a = lastDrawnBits[bit.A].pos + new Vector2(0.4f, 0.0f); Vector2 b = dBit.pos + new Vector2(-0.4f, 0.04f); DrawLine(lastDrawnBits[bit.A].pos, a, bit.operation); DrawLine(a, b, bit.operation); DrawLine(b, dBit.pos, bit.operation); a = lastDrawnBits[bit.B].pos + new Vector2(0.4f, 0.0f); b = dBit.pos + new Vector2(-0.4f, -0.04f); DrawLine(lastDrawnBits[bit.B].pos, a, bit.operation); DrawLine(a, b, bit.operation); DrawLine(b, dBit.pos, bit.operation); } } } if (drawStepCount != -1 && sing) { MakeSounds(actuallyDrawnBit); } } }