Guest User

Untitled

a guest
Nov 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. private float totalStrength = 0;
  2. public float activationThreshold;
  3. public float signalStrength;
  4. public bool showPackets = true;
  5. public bool showFullDebug = true;
  6. public Stack<float> signals = new Stack<float>();
  7.  
  8.  
  9. void Start ()
  10. {
  11. nodeGrowthThreshold = 60; //Just temporary arbitrary numeric values...
  12. activationThreshold = 20; //The default values if not set.
  13. path = GetComponent<Path>();
  14. }
  15.  
  16. private void Update()
  17. {
  18. if (signalStrength > 0)
  19. {
  20. if (numRequests.Equals(nodeGrowthThreshold)) { StartCoroutine(NodeGrow()); StopCoroutine(NodeGrow()); }
  21.  
  22. if (totalStrength >= activationThreshold)
  23. {
  24. StartCoroutine(AddToStack());
  25. StopCoroutine(AddToStack());
  26. signalStrength = 0;
  27. if (showPackets || showFullDebug) { StartCoroutine(ReadStack()); StopCoroutine(ReadStack()); }
  28. StartCoroutine(WriteStack());
  29. StopCoroutine(WriteStack());
  30.  
  31. totalStrength -= activationThreshold;
  32. signalStrength = 0;
  33. signals.Clear();
  34. }
  35. else if (totalStrength < activationThreshold)
  36. {
  37. StartCoroutine(AddToStack());
  38. StopCoroutine(AddToStack());
  39. signalStrength = 0;
  40. }
  41.  
  42.  
  43. }
  44. if (showFullDebug) { print("Node receieved: " + numRequests + " requests."); }
  45. }
  46.  
  47. private IEnumerator AddToStack()
  48. {
  49. if (!showFullDebug) { print("Node added signal: " + signalStrength + " to storage stack"); }
  50. signals.Push(signalStrength);
  51. numRequests++;
  52. totalStrength += signalStrength;
  53. yield return null;
  54. }
  55.  
  56.  
  57.  
  58. private IEnumerator WriteStack()
  59. {
  60. if (showFullDebug) { print("Node is passing stack of stack size..." + signals.Count); }
  61. if (signals.Count > 0)
  62. {
  63. 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.**/} }
  64. yield return null;
  65. }
  66.  
  67. public class Out : MonoBehaviour
  68. {
  69. public float input = 0;
  70. private float savedOutput = 0;
  71. public bool showFullDebug = true;
  72. public List<float> savedInput = new List<float>();
  73. public Queue<float> output = new Queue<float>();
  74.  
  75. private void Update()
  76. {
  77. if (input > 0) {
  78. //StartCoroutine(Save());
  79. //StopCoroutine(Save());
  80. Save();
  81. input = 0;
  82. }
  83. if (Input.GetKeyDown(KeyCode.A)) { print(savedOutput); }
  84. }
  85.  
  86. private void Save()
  87. {
  88. savedInput.Add(input);
  89. output.Enqueue(input);
  90. foreach (float num in savedInput.ToArray()) { savedOutput += num; }
  91. //yield return null;
  92. }
  93. }
Add Comment
Please, Sign In to add comment