Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private float totalStrength = 0;
- public float activationThreshold;
- public float signalStrength;
- public bool showPackets = true;
- public bool showFullDebug = true;
- public Stack<float> signals = new Stack<float>();
- void Start ()
- {
- nodeGrowthThreshold = 60; //Just temporary arbitrary numeric values...
- activationThreshold = 20; //The default values if not set.
- path = GetComponent<Path>();
- }
- private void Update()
- {
- if (signalStrength > 0)
- {
- if (numRequests.Equals(nodeGrowthThreshold)) { StartCoroutine(NodeGrow()); StopCoroutine(NodeGrow()); }
- if (totalStrength >= activationThreshold)
- {
- StartCoroutine(AddToStack());
- StopCoroutine(AddToStack());
- signalStrength = 0;
- if (showPackets || showFullDebug) { StartCoroutine(ReadStack()); StopCoroutine(ReadStack()); }
- StartCoroutine(WriteStack());
- StopCoroutine(WriteStack());
- totalStrength -= activationThreshold;
- signalStrength = 0;
- signals.Clear();
- }
- else if (totalStrength < activationThreshold)
- {
- StartCoroutine(AddToStack());
- StopCoroutine(AddToStack());
- signalStrength = 0;
- }
- }
- if (showFullDebug) { print("Node receieved: " + numRequests + " requests."); }
- }
- private IEnumerator AddToStack()
- {
- if (!showFullDebug) { print("Node added signal: " + signalStrength + " to storage stack"); }
- signals.Push(signalStrength);
- numRequests++;
- totalStrength += signalStrength;
- yield return null;
- }
- private IEnumerator WriteStack()
- {
- if (showFullDebug) { print("Node is passing stack of stack size..." + signals.Count); }
- if (signals.Count > 0)
- {
- foreach (float signal in signals.ToArray()) { path.input = signal; if (showFullDebug) { print(signal); } print("Sending... " + signal); /**NOT CAPTURING DATA FAST ENOUGH. DATA IS SENDING FAST ENOUGH THOUGH.**/} }
- yield return null;
- }
- public class Out : MonoBehaviour
- {
- public float input = 0;
- private float savedOutput = 0;
- public bool showFullDebug = true;
- public List<float> savedInput = new List<float>();
- public Queue<float> output = new Queue<float>();
- private void Update()
- {
- if (input > 0) {
- //StartCoroutine(Save());
- //StopCoroutine(Save());
- Save();
- input = 0;
- }
- if (Input.GetKeyDown(KeyCode.A)) { print(savedOutput); }
- }
- private void Save()
- {
- savedInput.Add(input);
- output.Enqueue(input);
- foreach (float num in savedInput.ToArray()) { savedOutput += num; }
- //yield return null;
- }
- }
Add Comment
Please, Sign In to add comment