- Home /
Saving a Triple Byte Array [,,]
My question is simple. I have a triple byte array, byte[,,] map, that needs to be saved in to a file in terms of chunks. If it gets confusing, read the last heading.
What work have you done so far?
Here's a method that I have been working on for quite a while now. I think it's about time I ask for some further assistance. For a 200,200,200 byte array, the file "Map_0" contains 0,0,0 through 0,0,100. "Map_1" contains 0,0,101 through 0,0,200. "Map_2" contains 0,1,0 through 0,1,100 and so on.
What's your issue then? This seems simple enough.
Not necessarily. Actually, the map array is edited in real time. When initializing the byte[,,] array, all values in it are set to 0. Because of that, if I were to create a 1000,1000,1000 array it would use up a lot of memory, dropping the FPS in return. As I have experienced already, sadly. Additionally, it gets confusing to find out what Map file you need to load from.
How are you using this map array then?
Well, 0 in the triple byte array would represent a spot that was never allocated. 1 would represent a certain texture. 2 would represent a different texture. 3 would represent a blank space, which wouldn't be rendered but is still needed. What I don't need is the massive zeroes in the array that do nothing but take up memory. I could always just load them individually from a file. But, that also brings up the issue of a limited hard drive space.
What are you looking to accomplish then, you dolt!?
While this is a very tricky task, since the byte[,,] array shouldn't been too large, and not too small either, what I need it to do is very simple. The map loads in chunks. If a player is in the center of the entire map, it'll only load the chunks within a certain radius of that individual. A simple feat. But, the chunks only load the byte[,,] when it is loaded and it accesses it by performing if(byte[x,y,z] = #) texturePosition = (...) where texturePosition would just be the corresponding coordinate on the texture sheet. As mentioned before; 0 is an untouched part while 1, 2, and 3 are the only used textures.
The most important information is that the byte[,,] array values that are 0 are only ever changed when the chunk tries to access it. It'll perform a PerlinNoise to randomly generate some values and set them to 1, 2, or 3.
The way things go in order is:
Map object holds the Map.cs --> Map.cs creates new byte[mapSizeX,mapSizeY,mapSizeZ] which is bad for memory when it gets too big --> Map.cs instantiates a Chunk prefab and passes the Map object to the Chunk prefab --> Chunk prefab accesses Map object's Map.cs for byte[,,] map --> if the byte[,,] map was not set, generate it --> apply the texture to the Chunk.
What it should be is:
Map object holds the Map.cs --> Map.cs instantiates a Chunk prefab and passes the map object to the Chunk prefab --> Chunk prefab accesses Map object for byte[,,] map --> Map object's Map.cs loads map file for specific chunk --> Map object's Map.cs returns the value to Chunk prefab to be rendered or changed.
Map files should be comprised of multiple chunks. In a 1000x1000x1000 world, there would be 100x100x100 chunks. Creating a map file for each chunk would be 1,000,000 files. Creating a map file for each 10 chunks would be 10x10x10, or 1000, files. Each 10 chunks could be called "Super Chunks".
This is confusing, can you explain it simpler?
Sure. Let's go back to grade school and give this question in a math assignment format. This'll bring back horrible memories for some of you. I used to love these.
You have a large package of chocolate bars. They are Hershey chocolate that have 10 pieces to break off to your friends in each. The men who packaged the chocolate put them in a large box. There are 1,000,000 chocolate bars, meaning there are 10,000,000 pieces to give to your friends for the rest of your life. Each large box contains 100 chocolate bars. There are 1000 boxes. Each chocolate bar has a few numbers on it as followed: 0,0,0 --> 0,0,1 --> 0,0,2... 0,0,999 --> 0,0,1000 --> 0,1,0 --> 0,1,1. Each by a comma ranges from 0 to 1000. How do you find the number 20,5,250?
Should the men who packaged these chocolate bars have packaged them differently? If so, how? And how would you find chocolate bar #20,5,250 with this new method?
Good Question!
anyway what you have is what we refer to as a multidimensional array. below is a link to guy who is trying to save the multidimensional array with the BinaryWriter...
Your answer