コード例 #1
0
        public void SaveLevel(string name)
        {
            LastSaveName = name;

            using (FileStream fs = new FileStream(ArxPaths.GetDlfPath(name), FileMode.Create, FileAccess.Write))
                using (MemoryStream ms = new MemoryStream())
                {
                    dlf.WriteTo(ms);
                    using (var packedStream = DLF_IO.EnsurePacked(ms))
                    {
                        packedStream.CopyTo(fs);
                    }
                }

            using (FileStream fs = new FileStream(ArxPaths.GetLlfPath(name), FileMode.Create, FileAccess.Write))
                using (MemoryStream ms = new MemoryStream())
                {
                    llf.WriteTo(ms);
                    using (var packedStream = LLF_IO.EnsurePacked(ms))
                    {
                        packedStream.CopyTo(fs);
                    }
                }

            using (FileStream fs = new FileStream(ArxPaths.GetFtsPath(name), FileMode.Create, FileAccess.Write))
                using (MemoryStream ms = new MemoryStream())
                {
                    fts.WriteTo(ms);
                    using (var packedStream = FTS_IO.EnsurePacked(ms))
                    {
                        packedStream.CopyTo(fs);
                    }
                }
        }
コード例 #2
0
        public void SaveLevel(string name)
        {
            LastSaveName = name;

            using (MemoryStream ms = new MemoryStream())
            {
                dlf.WriteTo(ms);
                ms.Position = 0;
                using (var packedStream = DLF_IO.EnsurePacked(ms))
                    using (FileStream fs = new FileStream(ArxPaths.GetDlfPath(name), FileMode.Create, FileAccess.Write))
                    {
                        packedStream.CopyTo(fs);
                    }
            }

            using (MemoryStream ms = new MemoryStream())
            {
                llf.WriteTo(ms);
                ms.Position = 0;
                using (var packedStream = LLF_IO.EnsurePacked(ms))
                    using (FileStream fs = new FileStream(ArxPaths.GetLlfPath(name), FileMode.Create, FileAccess.Write))
                    {
                        packedStream.CopyTo(fs);
                    }
            }

            using (MemoryStream ms = new MemoryStream())
            {
                fts.header.uncompressedsize = fts.CalculateWrittenSize(true);

                fts.sceneHeader.nb_textures = fts.textureContainers.Length;
                fts.sceneHeader.nb_polys    = fts.CalculatePolyCount();
                fts.sceneHeader.nb_anchors  = fts.anchors.Length;
                fts.sceneHeader.nb_portals  = fts.portals.Length;
                fts.sceneHeader.nb_rooms    = fts.rooms.Length - 1;

                for (int i = 0; i < fts.rooms.Length; ++i)
                {
                    fts.rooms[i].data.nb_polys   = fts.rooms[i].polygons.Length;
                    fts.rooms[i].data.nb_portals = fts.rooms[i].portals.Length;
                }

                fts.WriteTo(ms);

                ms.Position = 0;
                using (var packedStream = FTS_IO.EnsurePacked(ms))
                    using (FileStream fs = new FileStream(ArxPaths.GetFtsPath(name), FileMode.Create, FileAccess.Write))
                    {
                        packedStream.CopyTo(fs);
                    }
            }
        }
コード例 #3
0
        public void TestIOReadWrite()
        {
            DirectoryInfo ftsDir    = new DirectoryInfo(@"F:\Program Files\Arx Libertatis\paks\game\graph\levels");
            DirectoryInfo dlfLlfDir = new DirectoryInfo(@"F:\Program Files\Arx Libertatis\paks\graph\levels");

            string name = levelName.text;

            var dlf = Path.Combine(dlfLlfDir.FullName, name, name + ".dlf");
            var llf = Path.Combine(dlfLlfDir.FullName, name, name + ".llf");
            var fts = Path.Combine(ftsDir.FullName, name, "fast.fts");

            //DEBUG: use unpacked versions of files for now
            dlf += ".unpacked";
            llf += ".unpacked";
            fts += ".unpacked";

            var DLF = new DLF_IO();

            byte[] dlfBytesIn;
            using (FileStream fs = new FileStream(dlf, FileMode.Open, FileAccess.Read))
            {
                dlfBytesIn = new byte[fs.Length];
                fs.Read(dlfBytesIn, 0, dlfBytesIn.Length);
                fs.Position = 0;
                DLF.LoadFrom(fs);
            }
            MemoryStream dlfOut = new MemoryStream();

            DLF.WriteTo(dlfOut);
            byte[] dlfBytesOut = dlfOut.ToArray();
            using (FileStream fs = new FileStream(dlf + ".out", FileMode.Create, FileAccess.Write))
            {
                dlfOut.Position = 0;
                dlfOut.CopyTo(fs);
            }

            var LLF = new LLF_IO();

            byte[] llfBytesIn;
            using (FileStream fs = new FileStream(llf, FileMode.Open, FileAccess.Read))
            {
                llfBytesIn = new byte[fs.Length];
                fs.Read(llfBytesIn, 0, llfBytesIn.Length);
                fs.Position = 0;
                LLF.LoadFrom(fs);
            }
            MemoryStream llfOut = new MemoryStream();

            LLF.WriteTo(llfOut);
            byte[] llfBytesOut = llfOut.ToArray();

            var FTS = new FTS_IO();

            byte[] ftsBytesIn;
            using (FileStream fs = new FileStream(fts, FileMode.Open, FileAccess.Read))
            {
                ftsBytesIn = new byte[fs.Length];
                fs.Read(ftsBytesIn, 0, ftsBytesIn.Length);
                fs.Position = 0;
                FTS.LoadFrom(fs);
            }
            MemoryStream ftsOut = new MemoryStream();

            FTS.WriteTo(ftsOut);
            byte[] ftsBytesOut = ftsOut.ToArray();
            using (FileStream fs = new FileStream(fts + ".out", FileMode.Create, FileAccess.Write))
            {
                ftsOut.Position = 0;
                ftsOut.CopyTo(fs);
            }

            //compare results
            compare("dlf", dlfBytesIn, dlfBytesOut);
            compare("llf", llfBytesIn, llfBytesOut);
            compare("fts", ftsBytesIn, ftsBytesOut);
        }