Exemple #1
0
        private void Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                Logger.Error("path file do not exit. {0}", fileName);
                return;
            }

            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            int        nSeek      = 0;

            //先从文件头读取地图的长和宽
            byte[] byteLen = new byte[Marshal.SizeOf(typeof(int))];
            fileStream.Seek(nSeek, SeekOrigin.Begin);
            fileStream.Read(byteLen, 0, byteLen.Length);
            Height = System.BitConverter.ToInt32(byteLen, 0);
            nSeek += byteLen.Length;

            byte[] byteWid = new byte[Marshal.SizeOf(typeof(int))];
            fileStream.Seek(nSeek, SeekOrigin.Begin);
            fileStream.Read(byteWid, 0, byteWid.Length);
            Width  = System.BitConverter.ToInt32(byteWid, 0);
            nSeek += byteWid.Length;

            int nReadLen = Marshal.SizeOf(typeof(ObstacleItem));

            byte[] read = new byte[nReadLen];

            mSearchGrid = new StaticGrid(Width * 2 + 1, Height * 2 + 1);

            byte[][] mat = new byte[Width * 2 + 1][];

            for (int i = 0; i < Width * 2 + 1; i++)
            {
                mat[i] = new byte[Height * 2 + 1];
            }

            for (int i = 0; i < (Height * 2 + 1) * (Width * 2 + 1); ++i)
            {
                fileStream.Seek(nSeek, SeekOrigin.Begin);
                fileStream.Read(read, 0, nReadLen);
                nSeek += nReadLen;
                ObstacleItem info = Byte2Struct(read);

                mat[(int)(info.Fx * 2)][(int)(info.Fy * 2)] = (byte)info.Value;
            }

            mSearchGrid.Reset(mat);

            mParam = new JumpPointParam(mSearchGrid, new GridPos(0, 0), new GridPos(0, 0), true, true, false,
                                        HeuristicMode.MANHATTAN);
        }