Loading/Saving land

Discussion in 'Plugin Development' started by SparrowMaxx, Jan 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    SparrowMaxx

    Since it's probably been done before, how would I go about saving/loading large amounts of land to memory? I want to take an area, allow it to be modifed, and the return it to "normal" on command. My best guess is to make a stupidly massive array of every block in the area and then just change the blocks back when I need to.
     
  2. Offline

    Zimp

    Saving and loading large sections of land is a surprisingly difficult problem. It is both intensive to compute and can quickly consume a lot of memory.

    Things I have learned in my own efforts:

    1. The biggest performance hit happens when the server needs to send large amounts of updated blocks to the clients. If you restore the state of a chunk of land but not many of them have changed then the performance hit is not as big as when you restore the state of a chunk where there have been huge changes.

    2. Restoring blocks as the world is updating introduces complications. For example, you cant load objects that are attached to something before you load the block they are supposed to be attached to. This introduces a need to sort the blocks in order of how you should load them, unless you can find some way to get the server to perform the update as one single operation rather than individual blocks.

    As for storing and processing the data I would stick to the general rule of thumb when it comes to programming:

    Do not prematurely optimize.

    Write the code in a way that makes sense, get it working and then identify the bottlenecks that need to be optimized.

    Outside of figuring out the things I mentioned previously the algorithm generally boils down to:

    1. Decide what area you want to save (use the players location as a starting point for example)
    2. Iterate through the blocks in that area. This is basically three nested loops to walk through a three dimensional area.
    3. For each block pick out the information that is meaningful to you and store it. Your approach can vary here. You could store the block reference itself. Wrap the critical information about the block in a custom class, or store the block info as raw bytes in an array.
    4. For restoring the area you would perform the reverse, taking precaution to address the issue mentioned in #2 at the top.

    That said, I don't know much about the internals of Bukkit and probably only have an intermediate level of expertise with the API. There may be other much more efficient/direct ways to grab the state of a chunk of the world and store/restore it.
     
  3. Offline

    SparrowMaxx

    I figured as much. Thanks for the detailed, informed reply. I'll take that into account.
     
Thread Status:
Not open for further replies.

Share This Page