1
\$\begingroup\$

I'm starting development of a 2d isometric (tiled, roguelike) game and I'm brainstorming which kind of data structure I would use to store runtime data like tiles and entities, but I don't want to use a 2D array (as the world will be huge). How could I handle the rendering in such a case?

\$\endgroup\$
8
\$\begingroup\$

If your argument against an array is "The world will be huge", then it's not about the data-structure, but rather about memory constraints. If your world is so large, that it doesn't fit into memory with a 2D array, then it won't fit into any other data-structure.

Instead you would have to implement a (file-)format, that allows loading chunks (or sectors) of the world. Then you simply load/unload the needed chunks into a data-structure. There's nothing wrong with a 2D array.

As for rendering: I assume you have some sort of camera/viewport. Then you simply render all tiles that are currently in the viewport.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

http://doryen.eptalys.net/articles/world-storage/ has a nice approach (at least I think so, I'm using it) to both 1. hierarchical storage of a world map comprised of smaller regional maps, and 2. sparse storage of upper floors/basements/... so you're not storing megabytes and megabytes of "empty air" or "solid rock".

It's designed to work with procedural generation, and personally I'm aiming to do the procedural gen of new regions in a second thread to cut down on stalling the main thread, but there's no reason you couldn't use it for storing a hand-generated world to disk.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.