- delete[] tmp_data;
-
- // These have no compression
- if(version <= 3 || version == 5 || version == 6)
- {
- writeU8(os, is_underground);
- os.write((char*)*databuf_nodelist, databuf_nodelist.getSize());
- }
- else if(version <= 10)
- {
- /*
- With compression.
- Compress the materials and the params separately.
- */
-
- // First byte
- writeU8(os, is_underground);
-
- // Get and compress materials
- SharedBuffer<u8> materialdata(nodecount);
- for(u32 i=0; i<nodecount; i++)
- {
- materialdata[i] = databuf_nodelist[i*ser_length];
- }
- compress(materialdata, os, version);
-
- // Get and compress lights
- SharedBuffer<u8> lightdata(nodecount);
- for(u32 i=0; i<nodecount; i++)
- {
- lightdata[i] = databuf_nodelist[i*ser_length+1];
- }
- compress(lightdata, os, version);
-
- if(version >= 10)
- {
- // Get and compress param2
- SharedBuffer<u8> param2data(nodecount);
- for(u32 i=0; i<nodecount; i++)
- {
- param2data[i] = databuf_nodelist[i*ser_length+2];
- }
- compress(param2data, os, version);
- }
- }
- // All other versions (newest)
- else
- {
- // First byte
- u8 flags = 0;
- if(is_underground)
- flags |= 0x01;
- if(m_day_night_differs)
- flags |= 0x02;
- if(m_lighting_expired)
- flags |= 0x04;
- if(version >= 18)
- {
- if(m_generated == false)
- flags |= 0x08;
- }
- writeU8(os, flags);
-
- /*
- Get data
- */
-
- // Create buffer with different parameters sorted
- SharedBuffer<u8> databuf(nodecount*3);
- for(u32 i=0; i<nodecount; i++)
- {
- databuf[i] = databuf_nodelist[i*ser_length];
- databuf[i+nodecount] = databuf_nodelist[i*ser_length+1];
- databuf[i+nodecount*2] = databuf_nodelist[i*ser_length+2];
- }
-
- /*
- Compress data to output stream
- */