I'm creating a playspace in Unity (which is only marginally relevant) in C#, which is ostensibly .NET since it's in Unity. The playspace is two-dimensional and is generated via cellular automata with refining methods which make the shape of the playspace "usable" for my intent.
Currently, data about the base playspace (alive cells or dead, open or closed, pathway or wall) is stored as a binary value in an int[,]
array. Eventually, additional data will be stored in the array as well, or potentially in a secondary collection mapped back to that int[,]
array.
The additional data will include information about things such as: has a player visited this cell, can the player see this cell currently (LoS), is there an enemy or object/item in this cell.
The LoS, hasVisited, and enemy data will be dynamic, obviously, as a player navigates and as enemies move along their paths.
I would like to design and develop this with performance in mind from the beginning as a misstep early on could cause performance bottlenecks later that might require significant refactoring - wasting precious development time as I near the end of the project.
My question is this:
Does updating an array or multiple arrays to track data become resource-expensive in a linear or exponential manner? In other words, if mapA is [80,80] and mapB is [160,160], is mapB going to consume roughly 4x the resources to maintain, or some greater or lesser amount? Are there benefits to using something like a Dictionary or custom collection if the size grows beyond some value of int[,]
?
My initial thought was to use something like Dictionary<int[,], Dictionary<string, string>>
. I use dictionaries pretty extensively in a utility I maintain for work, but performance is something I don't consider for that since it's internal and very use-specific, so I'm not incredibly familiar with the performance of Dictionary<>
in general. The benefit to the Dictionary over multiple arrays of the same grid with different data is that I can have keys that make sense rather than just having additional values that would need to be tracked. I suspect, however, that the array might simply be faster, while less readable in the long run.
Thanks!