I’m working on my Pathfinding in my game attempting to come up with my own version of A*, and I’ve found it massively less complicated to use a 2D array to gather data, and it seems plenty fast enough to suit my needs. But, a lot of other coders seem to want to cram the X/Y coordinates into a single array.
I was curious what your guy’s input is on these 2 methods of storing X/Y coordinate values, and if there’s any reason I shouldn’t just go with a 2D array? I can’t even find a real performance difference, and it’s a lot easier to code with an int[xCord][yCord] array.
Storing the daya in a small 2D array:
int[][] array = new int[mapHeight][mapWidth]; // or, [x][y] really
//then store data by:
array[x][y] = value;
Storing the same data in a large 1D array:
int[] array = new int[mapHeight * mapWidth];
//then store data by;
array[y + (x * mapWidth)] = value;
the 1D array is probably technically less memory intensive, but it’s a pain in the arse to work with. :o
Main reason I bring this up is I don’t want to get all the way into the final product of my pathfinding to find out there’s some legitimate serious flaw with using a 2D array.