views:

762

answers:

9

For example, in Fallout 3, a save game stores the state and location of every single object and NPC in the game, and only takes up a few MB's. How do they do that!?!?

And then, during game play, how is this data added/retrieved in/from memory such that it can be displayed to the player in real-time?

UPDATED: (I'm going to make you work for your answers :P)

Based on Kevin Crowell's answer... So I guess you would have a rendering distance that would apply to objects and NPC's, and you would "SELECT" the objects and NPC's within the given range. However, what type of data store would you use in order to get these objects?

In other words, you would you have a gigantic array of every object in the game, and constantly update a smaller list that holds the visible objects to render?

Also, per Chaos' answer... Would would happen if you eventually touched every object in the game? Would your save game get bigger and bigger? In the case of Fallout 3, I'm pretty sure there aren't "stages", where the past data could just be dropped. Everything is persisted when you leave/return to a location. So how do you think this specific case is implemented?

+6  A: 

It can simply be mapping objects, or NPCs, to an X,Y,Z coordinate plane. That information that be stored cheaply.

During gameplay, all of those objects are still mapped to a coordinate system at all times. They just need to read in the save information and start from there.

Kevin Crowell
+1 because your (at the time) points were '666'. ;-) Also, good answer!
dna123
+1 because your (at the time) points are 723
Click Upvote
Objects typically have more state that needs to be persisted than just their position, though...
snemarch
+3  A: 

If you think about the information you need to save it's really not that much;

E.g.

  • Position
  • Orientation
  • Inventory
  • Health
  • Objective-state

There are lots more of course, many of which dependend on both the type of game and how the save structure is organized.

Some games like Resident Evil only allow saves when you enter a new zone meaning you don't have to store all the information for entities in both zones. When you "load" a save their attributes come from the disc.

As to how this is data is retrieved/modofied, I'm not quite sure I understand. It's just data in the consoles memory. When the player saves it's written to the save device, and when they load it's restored.

Andrew Grant
+2  A: 

One major technique is differential saves: only saving state that's something other than its default. Compare and contrast "saving the state and location of every object in the game world" with "saving the state and location of every object in the game world that the player has moved or altered".

chaos
+6  A: 

I think you're overestimating the complexity of what's being stored/retrieved. You don't need to store the 3D models for the objects, or their textures, or any of the things that make up large parts of a game's size-on-disk.

First of all, as chaos mentioned, it's only necessary to store information about things that have been moved. Even then, you probably only need to store, for each of those, the new position and orientation (assuming there's not other variables involved, like "damaged"). So that's two vectors for each object, which will be around a grand total of 24 bytes per object. That means you can store the information for 40,000 objects per megabyte. That's an awful lot of objects to have moved around.

Restoring this data is no more complex than placing the objects in the first place. Every object has to have a default position/orientation defined for the game to put it somewhere, so all you're doing is replacing the default with the stored value in the save file. This is not complex, and doesn't require any significant additional processing.

Chad Birch
A: 

Echoing the other answers, the biggest savings comes from eliminating all unnecessary state data.

If you look at 8-bit side-scroller games, they will start discarding state as soon as things are offscreen, and oftentimes retain nothing, because their resources are too tight to keep around more than the minimum number of instances.

Doing it on the macro-level for a game like Fallout 3 is just a matter of increasing the scope of the problem. You start sectioning up the landscape by grid or other geometrical methods, and spawn/despawn stuff as the player moves from one section to the next. You ideally keep the size of each area small so that in-memory state is not high. You figure out the bare minimum of state needed to keep around NPC and item instances, and in the layout data you tag as much as possible to auto-respawn so that it doesn't need any state saved.

If you want to be pointed at a specific data structure, an example serialization format might be a linear stream indexed by a tree of pointers, where the organization of the tree corresponds to the map layout.

+4  A: 

With all the big hardisks nowaday, even developers seem to forget how many bytes there are in a megabyte. So to answer the question in the title: games store large amounts of data by creating savegames that are several megabyte large.

To illustrate how big a megabyte is, it's 8 million bits. That is sufficient to encode 2^8000000 = 10^2666666 states. In comparison, there are only 10^80 atoms in the universe. Now in a (save)game there are multiple subsystems with distinct states; e.g. in a RPG each NPC has its own state. But how much of a state is there, really? Their position in a town might be saved as 16 bits (do you remember their exact position if they're walking around anyway?). Their mood/disposition/etc as another 8 bits, and that allows for more emotions then some people have.

When it comes to storing this kind of data in-game, the typical datastructure is a QuadTree. This is a datastructure that allows you to determine objects in a certain X-Y region in O(log N). In some cases, game developers find it easier to pre-partition the world in zones. This reduces the amount of run-time calculations. A good example was Doom. Its maps had visibility pre-calculated; for each point one could determine quickly to which zone it belonged, and for each zone the amount of visible objects was pre-calculated. This reduced the amount of objects that needed runtime visibility checks.

MSalters
Dude... no down vote or anything but how on earth do you know the amount of atoms in the universe? (I'm not asking for a source I'm making the point that as far as I know they haven't figured out when it ends yet.) Did you mean in the galaxy? That would be a little more plausible.
Shraptnel
10^69 in our galaxy, actually. The exact boundaries do not matter that much, actually. There's plenty of error margin in that 10^80 estimate for a number of reasons.
MSalters
+1  A: 

On a related note, game engines often employ Zip compression, to keep the size of all that content down and also make some operations faster.

unwind
+1  A: 

Besides what everybody else said, i would like to add state doesn't necessarly imply just position and movement,but also properites for the respective state. Usually a Game Engine has a feature witch allows you to save the data of a certain class.

Say you have a Player class and you are well into the story, when you click save the possible data that can be stored is :

  • Where is the player located in the level/map
  • What are his attributes : health,mana,strenght, intelligence,etc
  • What skills does he have.
  • What level is he.

Globally we can also have:

  • How many references (names that allow the engine to pick up an object from a list) to objects are being stored in that specific level,in other words when you load what objects should be loaded along with it.
  • Are we using physics, if so who uses it.

And many more. Fallout 3 has one type of save, another game will have another. It really depends on the genre and the engine in use.

Cristina
+3  A: 

In Fallout 3 in particular, the map is divided in a grid fashion. You can only see your current square and the ones immediately next. The type of data store is not really important - can be a SQLite database, can be a tree serialized to disk, or can be something else entirely.

...you would you have a gigantic array of every object in the game, and constantly update a smaller list that holds the visible objects to render?

Generally yes, but the "gigantic array" doesn't need to be in memory. And there are more lists - objects in current and adjacent grid square (you can be attacked from behind - not in visible list), the visible list, the timer list...

Would would happen if you eventually touched every object in the game? Would your save game get bigger and bigger?

Could - if there is a default state table for everything, the save can contain only the differences. The save will then grow as you progress.

Everything is persisted when you leave/return to a location.

Nope. Items you drop outside of your house will eventually disappear. Bodies too, probably. Random monsters are respawned every once in a while. This is both convenient to game designers and consistent with the real world.

MaxVT