Esempio n. 1
0
        private void WriteHeights(string file, int w, int h)
        {
            byte[] hd = new byte[w * h * 17 + 8];
            int    i  = 0;

            BitConverter.GetBytes(w).CopyTo(hd, i); i += 4;
            BitConverter.GetBytes(h).CopyTo(hd, i); i += 4;
            Vector3I loc = Vector3I.Zero;
            LEVGR    vgr = new LEVGR();

            for (loc.Z = 0; loc.Z < h; loc.Z++)
            {
                for (loc.X = 0; loc.X < w; loc.X++)
                {
                    ColumnResult cr = MapParser.GetColumn(state.World, loc.X, loc.Z, w, h, vgr);
                    BitConverter.GetBytes(cr.Height.XNZN).CopyTo(hd, i); i += 4;
                    BitConverter.GetBytes(cr.Height.XPZN).CopyTo(hd, i); i += 4;
                    BitConverter.GetBytes(cr.Height.XNZP).CopyTo(hd, i); i += 4;
                    BitConverter.GetBytes(cr.Height.XPZP).CopyTo(hd, i); i += 4;
                    hd[i++] = cr.Walls;
                }
            }

            using (MemoryStream ms = new MemoryStream()) {
                var gs = new GZipStream(ms, CompressionMode.Compress, true);
                gs.Write(hd, 0, hd.Length);
                gs.Close();
                ms.Position = 0;
                using (var s = File.Create(file)) {
                    var bw = new BinaryWriter(s);
                    bw.Write(hd.Length);
                    bw.Flush();
                    ms.CopyTo(s);
                    s.Flush();
                }
            }
        }