ID:265749
 
OK, I was made a DMP saver utility and now I need to make a DMP loader, I can imagine this isn't the easiest thing to do but I believe I can do it. I want this to be fast, very fast. So I am consulting you guys on the algorithm :) OK, heres what I have.

1. Clear the map

2. Create an associative list called atomdata

3. cycle through each key in the map and associate its value
key is something like "aa" and value is /turf/turfy{myvar=9;}

4. Make a proc that turns the value into a vars like list

5. Make some formula that gets the x y and z by the map data in the map where you have stuff like aaabbbddbaaabaa

6. loop through the map data, get the x y and z and create a new object, then add its vars


Is this a good way to do it or is there a better way, if there is please tell me.
Here's what I would do:

1. You'll want to record the length of each key. "a" will be one, "aa" will be two, etc... I assume that you know that they will all be the same size, seeing as how you've made a DMP saving utility.

2. I would generate the associative list of keys, associated with their atoms. You'd have to create the atom and set their variables while doing so. This would require that we read the key and use a procedure to return variable names associated with their values. You can use the atom.vars list to alter these variables. However, this may not be that efficient. Perhaps a pointer to the location or a list of traits for every key will be better than actually creating the atom.

3. Next, you will want to record the length of the map. You can record the maxx by taking the length of the first line and dividing it by the size of the key. If the number is not an integer, you've done something wrong. The y can be found by finding all of the linebreaks in the block containing one z level. This may not be as robust as you'd like, so maybe you'll just want to count the characters and (filtering out the linebreaks), divide by the actual length of one line (which is x * the character length, or just your recording of the length of a line before dividing it by the character length). The z level part is a little trickier, but with some fancy findtext() techniques (and a better understanding of the DMP format than I do), you can find this out easily. Adjust the map accordingly (world.maxx, world.maxy, world.maxz).

4. This is where we loop. Start at z level 1. I judge that the best place to start would be the top-left. Use a procedure that reads each line, starting at x=1 all the way to end of the line. Then, decrement the y variable and start on the second line. You'll know how to work this from here. If you've actually created new atoms within the list, you'll want to make a copy procedure on the atom and work it into the location you need it to be in. If you did not, you can simply use the variables and such you've recorded and make an atom right there. I think that would be the more efficient way, seeing as how you don't need to loop through every variable for copying and you don't create and delete objects in the list.
In response to CaptFalcon33035
That was very helpful, thanks a bunch :)