I don't know if it'll fit in your design, but here's how I'd do something like that.
- that the default colour for your not-yet-visited tiles are pink and your visited tiles are white (as per in your question).
- that the radius the player can see is 3 tiles, excluding the one on which he is standing, so it results in a 7 by 7 square.
I would keep track only of the things that the player has modified.
For example, if your player starts at position
[0, 0], you know how to generate the radius around him, so, for instance, tiles
[-3, -3] through
[3, 3] are generated as pink tiles and displayed. Now, since the player only went on tile
[0, 0], you make it as a white tile and keep only this information in a data container (for instance a
map or a
set). If he places an item, you also keep that information in another container. (Or you could have your data able to keep track of both.)
Then, as your player travels, you add your data about the tiles he travelled. At the same time, when you "create" a new row or a new column, in fact, you just show temporary information that is easy to generate "on the fly" (the pink tiles), and then you query your data containers to check if he's already been into the "generated" tiles, and modify them accordingly.
For instance, your player goes from tile
[0, 0] to tile
[4, 0]. This creates 4 white tiles in your data container. When he steps back on tile
[3, 0], the column 0 has to be re-generated. Which you do: all the generated tiles will be white tiles, but since you know you'll display tiles
[0, 3] through
[0, -3] (the whole column the player can now see), you'll query your data container and see that you have to put the tile at
[0, 0] as a white tile. You'll also query you items container to see if he placed an item on one of these tiles.
Here is why I'd do it like that:
- You don't need to keep track of stuff you don't need (if you had to keep your infinite map in memory, it would end up taking a lot of memory).
- If your map becomes very large, you can easily partition your data into smaller containers.