- Joined
- Sep 23, 2018
Breathing Simulator lives?!So for just a 256 grid with breathing air
If doing all this with arrays is proving too slow for you, have you considered linked lists? I remember having an issue with arrays being too slow back in the bad old days of Flash and learning about linked lists and being surprised that they worked so much faster, but YMMV with C#/Unity's internals.
The tl;dr is that you have a listHead variable which points to the first object in your list, and each object has a nextObject value which points to the next object in the list. Instead of for looping through an array, you while loop until nextObject is null. You can also have prevObject values if you need to go through the list backwards, or have the nextObject value point back to the first item in the list if you want to continuously loop through them. You can still add and remove items; in [A, B, C], you would remove B by simply setting A's nextObject to C. Then add D after A by setting A's nextObject to D and D's nextObject to C.
The downside is that it's not so simple to access the Nth item in the list arbitrarily, but if you're going to be looping more often than doing that, linked lists might help.