Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6707802

Browse filesBrowse 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
Copy full SHA for 6707802

File tree

Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed

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

Copy file name to clipboardExpand all lines: Assets/Patterns/7. Double Buffer/Cave/GameController.cs
+6-5Lines changed: 6 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.