on-internet
← Community

How to cache neighbouring variables in a 2D array?

Stack Overflow ·

I'm making a grid based game in c++ with SDL3. My rooms are a 2D array of Tile objects stored in an array in DungeonCrawler (think of dungeoncrawler as my game settings .cpp and .h). I have a GetNeighbour() function that returns a pointer to a tile's neigbour depending on its direction (an enum of north, south, east and west, or null if it's at the edge of the room). Instead of calling GetNeighbour() every time I need a tile to know its neighbour, I want to loop over all the tiles once and cache their neighbours so an individual tile can later easily access its neighbour. I've started the cach

Comments

Sign in or sign up to comment and upvote.

No comments yet.