Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by QuaintShanty · Jul 15, 2014 at 09:32 AM · mathsavingmapbytearrayschool

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fornoreason1000 · Jul 15, 2014 at 09:53 AM 0
Share

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...

http://social.msdn.microsoft.com/Forums/en-US/591545ab-50c7-4c06-954e-c1fb3e8c20fb/write-multidimensional-array-to-a-file-with-a-binarywriter

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need a bit of help with some math in regards to hex nodes 1 Answer

Local data saves on iOS (best practices) 1 Answer

Creating an UI GPS map 0 Answers

Assigning UV Map to model at runtime 0 Answers

Save array of GameObjects and their variables from an attached script under a parent 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges