Help understandnig the world format

ptvirgo
Member
 
Posts: 18
Joined: Thu May 26, 2016 22:18
GitHub: ptvirgo

Help understandnig the world format

by ptvirgo » Mon May 30, 2016 23:18

I'm trying to parse the minetest map.sqlite format, mostly relying on the world.txt documentation. I'm a bit stuck on this bit:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
zlib-compressed node data:
if content_width == 1:
    - content:
      u8[4096]: param0 fields
      u8[4096]: param1 fields
      u8[4096]: param2 fields
if content_width == 2:
    - content:
      u16[4096]: param0 fields
      u8[4096]: param1 fields
      u8[4096]: param2 fields
- The location of a node in each of those arrays is (z*16*16 + y*16 + x).


What do "u16[4096]" and "u8[4096]" mean in this context?
 

sofar
Member
 
Posts: 781
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Help understandnig the world format

by sofar » Mon May 30, 2016 23:56

each block contains 4096 nodes (16*16*16), and for each node, the param0 values are the node types, the param1 values are the param1 value (usually light) and param2 values are param2 (usually rotation).

u8 is a C type, it's basically a byte (unsigned 8-bit integer). u16 is a 16-bit unsigned integer, also known as a "word"

See https://en.wikipedia.org/wiki/Units_of_information for more information
 

ptvirgo
Member
 
Posts: 18
Joined: Thu May 26, 2016 22:18
GitHub: ptvirgo

Re: Help understandnig the world format

by ptvirgo » Sun Jun 05, 2016 20:56

Thanks, that helped me make a bunch of progress. Unfortunately I'm still missing a step...

Here's what I've been able to gather:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
  - map-version: 25
  - flags: 1 (appears that per-bit operators would be needed to parse these,
    might come back to that.)
  - content-width: 2
  - parameters-width: 2
  - Unknown u8: 120
  - Unknown u8: 156


If I pull those two bytes from the data (I don't see them documented) I can run a gzip-based decompressor on the next chunk of the stream, and get:

- param0: A list of 16 bit 0's containing 4096 elements. I'm guessing those mean "air node."
- param1: A list of 8 bit 15's containing 4096 elements. I'm guessing that those mean 15 is the highest possible light level.
- param2: A list of 8 bit 0's containing 4096 elements. I'm guessing those mean that air nodes have no extra parameters.

After that, the world format says I should expect:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    zlib-compressed node metadata list
    - content:
    if map format version <= 22:
      ....
    if map format version >= 23:
      u8 version (=1) -- Note the type is u8, while for map format version <= 22
    it's u16
      u16 count of metadata
      foreach count:
        u16 position (p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X)
        u32 num_vars
        foreach num_vars:
          u16 key_len
          u8[key_len] key
          u32 val_len
          u8[val_len] value
        serialized inventory


Unfortunately, trying to decompress the remaining bytes generates an error, and I can't seem to match what's left with the description. I've also tried looking at the C++ code in node_metadata.cpp, but it's my first look at C++ and there's a fair bit that is beyond me.

Any tips on how to parse out the remaining bytes? If I spit them out from my REPL I get:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 \t\236\360\1x\234c\0\0\0\1\0\1\0\0\0\0\0\2\266\0\0\1\0\0\0\3air\n\0\0
 


Return to Minetest-Related

Who is online

Users browsing this forum: No registered users and 28 guests

cron