Storage of large 2D games

I experimented with various ideas on how to store a 2D game world. I am interested in hearing methods of storing large numbers of objects, controlling the set visible (say, 100,000 square squares). Obviously, the methods may vary depending on how the game displays this space.

Suppose we are describing a scrolling world of a 2d game, not a screen, since you can pretty easily do screen-based rendering from this setting, while the reverse is a bit more messy.

We are looking for linguistic agnostic solutions here, so they are more useful for others.

Edit: I think a good answer here would be a general overview of the ideas that should be considered when thinking about it, as some of the respondents tried, but also begins to explain how the various solutions will apply to these scenarios. This is a somewhat tricky question, so I would expect a good answer to reflect that.

+7
data-structures spatial
source share
5 answers

Quadtrees is a fairly efficient solution for storing data about a large two-dimensional world and objects inside it.

+7
source share

You can get some ideas on how to implement this from some spatial data structures, such as range trees or kd.

However, the answer to this question will vary greatly depending on how your game works.

We are talking about a two-dimensional platformer with 10 enemies on the screen, another 20 off-screen, but “active”, and an unknown number is more “inactive”? If so, you can save your entire level as an array of “screens”, where you will manipulate those closest to you.

Or do you mean a real 2D game with a lot of up / down movement? You may need to be more careful.

The platform is also important. If you're using a simple desktop platformer, you probably won't have to worry about performance as much as you would on an embedded device. This is no reason to be naive about this, but you may not need to be terribly smart.

This is a somewhat interesting question that I think. Presumably, someone smarter than me, who has experience with platforming, was already thinking about it.

+2
source share

Break the world into smaller areas and deal with them. Any solution to this problem will come down to this concept (e.g., the quadrants mentioned in another answer). The differences are in how they divide the world.

How much data is stored on one tile? How fast can players move around the world? What is the behavior of NPCs etc. that are off screen? Do they just reset when the player returns (like the old Zelda games)? They just renew where they were? Do they make some kind of catch-up script?

How many different rendering data will be needed for different areas?

How much of the whole world can be seen at one time?

All these questions are going to secure your decision, as well as the capabilities of your platform. To come up with a common answer for them without having a reasonable understanding of these parameters will be a little difficult.

+2
source share

Assuming that your game will only update what is visible and the area around the visible, just break the world on the “screens” (the “screen” is a rectangular area on the tile that can fill the entire screen). Keep in memory the “screens” around the visible area (and a little more if you want to update objects close to the symbol - but there is no reason to update an object that is far away), and the rest on the cache disk to avoid loading / unloading of the most visited areas when moving. Some settings like:

+---+---+---+---+---+---+---+ |FFF|FFF|FFF|FFF|FFF|FFF|FFF| +---+---+---+---+---+---+---+ |FFF|NNN|NNN|NNN|NNN|NNN|FFF| +---+---+---+---+---+---+---+ |FFF|NNN|NNN|NNN|NNN|NNN|FFF| +---+---+---+---+---+---+---+ |FFF|NNN|NNN|VVV|NNN|NNN|FFF| +---+---+---+---+---+---+---+ |FFF|NNN|NNN|NNN|NNN|NNN|FFF| +---+---+---+---+---+---+---+ |FFF|NNN|NNN|NNN|NNN|NNN|FFF| +---+---+---+---+---+---+---+ |FFF|FFF|FFF|FFF|FFF|FFF|FFF| +---+---+---+---+---+---+---+ 

Where the “V” part is the “screen”, where the center is (the hero or something else), the “N” parts are those who are nearby and have active (updating) objects, are checked for collisions, etc. d. and the “F” parts are distant parts that can be updated infrequently and are subject to “replacement” (stored on disk). Of course, you can use more "N" screens than two :-).

Note that since 2D games usually do not contain large amounts of data instead of saving deleted parts to disk, you can simply save them in compressed memory.

0
source share

You probably want to use a single int or byte array that refers to block types. If you need additional optimization, you will need to reference more complex data structures, such as octal trees from your array. There is a good discussion on the Java forum here: http://www.javagaming.org/index.php/topic,20505.30.html text

Everything related to links becomes very expensive, because a pointer takes about 8 bytes depending on the language, so depending on how full your world is, it can become very expensive (8 pointers of 8 bytes each - 64 bytes per element, and an array of bytes - 1 byte per element). Therefore, if 1/64 of your world is empty, an array of bytes would be a much better option. You will also need to spend a lot of time iterating through the tree whenever you look at a collision or something else - an array of bytes will be an instant search.

Hope this is detailed enough for you. :-)

0
source share

All Articles