Skip to content

calcLocalAdjacencies()

Jodoin, Nathan edited this page Nov 4, 2022 · 2 revisions

Local Adjacency Calculation

Local adjacency calculation is accomplished using X and Y offsets. While populating the adjacencies, out-of-bounds checking is conducted according to the location of the current zone and the size of the 2D array. The size of the 2D vector and the zones surrounding the current zone are accessed from the Map struct passed into the function.

For each zone in the current row of the map, the function uses X and Y offsets of -1, 0, and +1 to read the information about the zones surrounding the current zone in the map. Starting with the top left adjacent zone and moving in a clockwise fashion, a vector of size 8 is populated with pointers to the zone's surrounding neighbors.

While calculating adjacencies, if the adjacent zone is out of bounds, the pointer to that adjacency is stored as a null pointer, which is used later for out-of-bounds checking while traversing adjacencies in other functions.

The resulting vector of zone pointers is then passed to the local adjacency list mutator of the current zone by value.

Clone this wiki locally