I’m making a 2D Minecraft or Terraria style game and I’ve started to make a terrain generation script. If your not aware Minecraft uses blocks as it’s level geometry. My problem is that when saving out each of my blocks to an XML file it take sooooooo long! All I’m doing is writing three things to the file: posX, posY and blockType. If I save a world this big then it takes 20 seconds! Now that world was about 640 blocks and obviously way to small for an actual world. It was only 20 blocks across and 32 down.
Now I thought about what the problems could be like maybe it’s because I’m instantiating so many blocks at one time and that could have an effect on the time it takes for the world the save out. However that is not the case, I ran the same test with the same amount of blocks only this time didn’t instantiate anything just wrote to the file. The time it took was the exact same. I don’t think that instantiating so many blocks even really is that hard on the engine considering that I can generate a world this big (without saving of course) without any problems. That world was about 12,800 blocks (400 x 32). God knows how long it would take to save that world at my current rate!
So whats the problem here? Why does it take so long to save a world by writing to a XML file? I’m I going about this wrong? Please help me out!
EDIT: Here is a screen shot of my XML file for the 640 block world in case you were curious on how I’m structuring it.