ID:51087
 
Yesterday, on my snow day, I wrote my own custom map saving/loading system. Pretty good challenge, I think I might actually be over my fear/misunderstanding of the text procs! Either way, my system isn't exactly a .dmm reader/writer, although I did take the generic principles from it.

I will now divulge how I did this...

Saving:
1) Looped through everything of type W, X, Y, and Z (without modifying some things these are areas, turfs, objs, and mobs) and generated a key for them (four separate keys for every type, which can also keep down file size in some situations while increasing it in others).

2) Loop through all the tiles in the world, find something of said type with a combination of locate() and range(), (so I can grab areas and turfs, too, without typecasting, which I can't do here) and then turn it into text with the key.

3) Save the key, the world.maxx, world.maxy, world.maxz vars, and the strings of text obtained in step #2.

Loading:

1) Load the string and gather the key from it.

2) Grab the strings that contain the positions of the objects.

3) Set the dimensions of the map

4) Loop through every "word" in the string obtained in #2, then position the object with the algorithm below that could use improving. I wrote it at about 12:30 last night, and I'm still very tired from getting only a little bit of sleep last night, so if anyone could redo it for me it would be appreciated (I'm positive the modulus operator will be involved).

            y++
if(y>world.maxy)
x++
y = 1
if(x > world.maxx)
z++
x=1



Oh yeah, I'm not releasing it, by the way. It still needs some improvement before I would consider releasing it (I tried getting it to save a 50,000 tile map as a test, and it took over 300 CPU because of the map's size). It works excellently in small projects, though, which is why I'm going to be using it for Village Wars.
You could probably easily compress the map using something like run length encoding. I once put together a map saving system with RLE (although it only saved types and no other info) and it worked pretty well.
Hazman wrote:
You could probably easily compress the map using something like run length encoding. I once put together a map saving system with RLE (although it only saved types and no other info) and it worked pretty well.

Yeah, mine only saves types, too; that's why it should be a little faster than a DMM saver/loader in theory. I like the look of that article, though, I would just have to add a little extra parsing here and there to expand and shrink the string.
Hazman wrote:
You could probably easily compress the map using something like run length encoding. I once put together a map saving system with RLE (although it only saved types and no other info) and it worked pretty well.

I just used RLE on a 10x10 map, and it shrunk the file size by about 200 bytes! Thanks.