-4

I am making a game like Minecraft and I have already chunks, but I currently store those chunks in a two-dimensional array. So chunks that I loaded stay loaded and when I go on a border I can't generate more chunks because I use an array.

So my question is how can I store my chunks to delete them when they are too far from me and load them when I am close to them?

Pikalek
  • 926
  • 7
  • 21
Nanored
  • 31
  • 7
  • To be clear: it sounds like you're asking about how to store the chunks *in memory* while they're loaded — not on disk when they're saved. Correct? – Wyzard May 20 '17 at 21:36

1 Answers1

1

Create a class that manages these in-memory chunks. Out of all the realized chunks, this class keeps track of how many have been loaded, which chunks they are and how recently they had to be accessed. This way when a new chunk needs to be loaded (by this class), you can save & evict the chunk that is least useful (by distance or access time).

This way you can add autosaves, predictively loading chuncks based on curren position & speed etc.

However, you probably just want an ArrayList.

Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40