Hi, I know this question is not really related to voxatron but in a way it is...
I noticed at the bottom of the PNG save files is some 1bit noise that is likely monster/event data.
I'm working on a program in PetitCom for Nintendo DS and have run into an issue where I have massive amounts of data I need to convert to an image in order to save and load it but I can't think of how to do this properly and have all the data save in the alloted space of the image (256x192x256).
To be in more detail, I am trying to save map data. For each map, there's 32x24 tiles. For each tile, there's a 3 digit pointer for the image, a pair of 2 digit pointers for colors of the tile to be used, and several other 1 digit pointers for various other tile properties. Take each of these and multiply it x2 minus the tile graphic and colors. So you're looking at approximately, if they were all put together in a single string, about 32 characters ('m just using 32 to make it easier to work with in the whole powers of 8 world).
Now what's the best way to convert this data into pixels? I'm racking my brain and can't seem to figure out how it's done, which is why I'm asking here because you seem to have figured it out on your own. I'm thinking, though that a lot of your data is binary to begin with whereas each piece of data I'm working with for the tile is arbitrary to the data itself...i.e. for the tiles I have CONVEYOR which has value of 0-5 and another property is HEIGHT which can be 0-9...
so can't quite figure out how to do this...any insight on converting this kind of thing into an image would be helpful. Ultimately, I'd like to stack all of that data into a single pixel since I have option for 256 colors instead of just black or white, but any advice I'll definitely take.
Thanks for the help!
Hahaha, nevermind, I think I got an idea of how to do it within the confines of the environment.
This probably doesn't apply to PetitCom, but for what it's worth, here's how I do it for Voxatron:
- Save the level to a simple raw binary file format (written to memory instead of to disk)
- Compress it using lodepng
- Convert the compressed data to ARGB format (one byte per colour channel) and construct the image
- Construct the larger image which also contains the level's thumbnail preview
- Save that image as a png (also using lodepng)
I think in your case the key point is how to convert your data to a nice binary format. Even if you are storing stuff in text, it is still binary! (i.e. one byte for each digit -- the ascii code for that character). More normally you would just represent numbers in their binary form (e.g. you can fit a value between 0..255 into one byte instead of a single digit)
Once you have a block of binary data, you can then just convert it to an image by setting the RGB values of the image to your binary values (or the palette index values if it's a 256-colour image).
It sounds like you might be able to pack each map tile data into 32 8-bit pixels, which you could then fit into a 256x96 image.@If it turns out you need to be more efficient for it to fit, you could start packing some values together into a single byte. Let me know if you'd like a howto for this.
I talked with another programmer and he said to start learning binary! So I took a look at it and saw how you can 'explode' decimal numbers into binary and pull out the numbers that were packed in there.
However, I had to make sure the values wouldn't go beyond 255.
So instead what I've done is do something likely programmers like yourself would hate me doing!
Basically, I have an array for the map data and each variable in the array is a string of many digits and for reading the map info when the player walks over and interacts with it, I simply count over into the string and extract the character(s) for the interaction checks and convert them to a value. Since I know the maximum value of these embedded variables, I was able to rearrange them into groups of 3 digits that can never exceed 255. This way when I go to save, I simply split the array string into groups of 3 characters, convert that to it's value then write the pixel. I was able to squash the map data into 2 images with each tile of the map having 15 pieces of info attached them.
I'm not quite comfortable enough yet with binary conversion so I think I could squash it down into one image using binary, but I'm afraid of accidentally going over 255 when packing the data up. In this way that I've done it, I know for sure I'll never get a save error.
Thanks for the info and help! goes back to programming with a stylus
[Please log in to post a comment]