ID:159995
 
As you might have read from a couple other posts, I use a simple map saving technique that involves looping through
the world, adding objects to a list, and saving the list. The problem is, in the game, there's going to be a very
large number of trees and deposits that can be depleted after chopping/mining for a while. As you can imagine,
saving all of these things and loading them takes a very long time. My problem is, what is an efficient way to save
massive amounts of objects?
Save the contents of every area. That's the only really efficient way.
In response to Jeff8500
Is there a difference? There's only one area in the world, containing everything.
Kaiochao wrote:
As you might have read from a couple other posts, I use a simple map saving technique that involves looping through
the world, adding objects to a list, and saving the list. The problem is, in the game, there's going to be a very
large number of trees and deposits that can be depleted after chopping/mining for a while. As you can imagine,
saving all of these things and loading them takes a very long time. My problem is, what is an efficient way to save
massive amounts of objects?

One thing is to only save things that need to be saved. This isn't possible if the maps in the game are some how generated when the game starts, but if they are not then simply only save/load objects that have been changed during the game.

Another thing to do is not save the object, but only save the information needed about it.
For an ore deposit simply save it's location (x, y and z), then save what type of ore it is (if needed), and how close it is to being depleted. When these are loaded you would simply create the object of the type saved, at the location saved, then set how depleted it is to the value saved.
Since this method would save a lot less info I would imagine it would be quicker at saving/loading.
In response to The Magic Man
The deposits are there on the map, and may get deleted while the game is playing. There's no need for creating, but deleting if needed, and I don't know an efficient way of doing this.
Of course, players can also build and create new objects on the map which need saving.
The method I've employed for labs in console is to use area.Write() but for large areas it'll probably freeze your game instead of actually working since it would result in one massive savefile.

To counteract this I gave each lab its own unique area and saved them individually, which works pretty quickly and saves everything in it. One thing you'd want to do is prevent it from saving mobs and any variables that may be a reference to a mob, since that could lead to 'rollback' bugs.
In response to Kaiochao
As you seem to be going for speed together with slim savefiles you could combine the suggested methods and include lists.
  • Divide your map into smaller areas
  • Create a list for each area
  • Whenever an object is created or altered, insert it (if not in list)
  • Make sure to remove objects upon destruction
  • When saving loop through the list after checking it's length

That way you have a small list of objects that have been changed/created, which you can save/load rather fast, instead of going through everything in the world and saving it.
In response to Kaiochao
Look at this, and tell me what looks more efficient.

proc/Bad_Save()
var/list/L = new
for(var/atom/X in world) L += X //notice how we probably have thousands,
//maybe even millions more iterations
var/savefile/F = new("Save")
F << L

proc/Good_Save()
var/list/L = new
for(var/area/A in world) //you probably only have a few areas in the world, so maybe only 3 to 20 iterations
L += A.contents+A
var/savefile/F = new("Save")
F << L
In response to Jeff8500
Don't forget to take out any mobs from A's contents since we don't want possible roll-backs ^_^
In response to GhostAnime
But only ones with clients :P