Advertisement
vikinghelmet99

Recursive World Build, 2.5.2018

Feb 4th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1.     void BuildRecursively(IntCoordinates c) {
  2.  
  3.         MECCoroutineQueue instance = MECCoroutineQueue.Instance;
  4.  
  5.         Queue<IntCoordinates> ToBeChecked = new Queue<IntCoordinates> ();
  6.         ToBeChecked.Enqueue (c);
  7.  
  8.         while (ToBeChecked.Count != 0) {
  9.             IntCoordinates home = ToBeChecked.Dequeue ();
  10.  
  11.             //function to check whether a provided coordinate set needs to be built
  12.             Func<IntCoordinates, bool> Unbuilt = (o) => !generator.chunks.ContainsKey (o);
  13.             Func<IntCoordinates, bool> CloseEnough = (o) => CheckRadius (o);
  14.  
  15.             //list of all coordinates for which we will be building
  16.             int step = MakeChunk_5.Step;
  17.             IntCoordinates[] coords = new IntCoordinates[] {
  18.                 home + new IntCoordinates (-step, 0, 0),
  19.                 home + new IntCoordinates (+step, 0, 0),
  20.                 home + new IntCoordinates (0, -step, 0),
  21.                 home + new IntCoordinates (0, +step, 0),
  22.                 home + new IntCoordinates (0, 0, -step),
  23.                 home + new IntCoordinates (0, 0, +step)
  24.             };
  25.  
  26.             //for each coordinate set in the list, check to see if it should be built, and if so, build it
  27.             for (int i = 0; i < coords.Length; i++) {
  28.                 if (CloseEnough (coords [i])) {
  29.                     if (!worked.Contains (coords [i])) {
  30.                         worked.Add (coords [i]);
  31.                         ToBeChecked.Enqueue (coords [i]);
  32.                     }
  33.                     if (Unbuilt (coords [i])) {
  34.                         instance.Run (chunkMaker.Make (coords [i]));
  35.                     }
  36.                 }
  37.             }
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement