Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do video games efficiently store/retrieve large amounts of data?

Tags:

storage

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?

like image 797
John B Avatar asked Mar 30 '09 18:03

John B


People also ask

How do games store save data?

When a savegame is loaded, it is loaded completly into memory and from there on the game engine does its thing with the data. There are a handful of exceptions, such as MMORPGs which might work on a database, but single player games generally don't. How the data is actually stored depends on the game.

How do video games store data?

In the RTS gene, game data has been stored in files. The units and attributes have been stored in INI or XML files or other text-based formats, and the models have been a mix of binary or even text-based formats, and the textures and sounds and other media in mainstream formats.

How does a computer store data?

Data is copied from the computer's main memory (random-access memory or RAM), and then written to the hard disk. The drive is the mechanical device that writes the data to the disk.


1 Answers

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.

like image 72
MSalters Avatar answered Sep 16 '22 17:09

MSalters