Skip to content

Commit 6707802

Browse files
committed
Found on twitter a new cool way to swap the buffers in the double buffer pattern with just one line of code, so I had to test it out. Also added a way to generate the same random numbers each time we run the script
1 parent 8fff8bf commit 6707802

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Assets/Patterns/7. Double Buffer/Cave/GameController.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void Start()
4040
bufferOld = new int[GRID_SIZE, GRID_SIZE];
4141
bufferNew = new int[GRID_SIZE, GRID_SIZE];
4242

43+
//To get the same random numbers each time we run the script
44+
Random.InitState(100);
45+
4346
//Init the old values so we can calculate the new values
4447
for (int x = 0; x < GRID_SIZE; x++)
4548
{
@@ -79,14 +82,12 @@ private IEnumerator SimulateCavePattern()
7982
GenerateAndDisplayTexture(bufferNew);
8083

8184
//Swap the pointers to the buffers
82-
int[,] temp = bufferOld;
83-
84-
bufferOld = bufferNew;
85-
86-
bufferNew = temp;
85+
(bufferOld, bufferNew) = (bufferNew, bufferOld);
8786

8887
yield return new WaitForSeconds(PAUSE_TIME);
8988
}
89+
90+
Debug.Log("Simulation completed!");
9091
}
9192

9293

0 commit comments

Comments
 (0)