Esempio n. 1
0
        public int FromBytes(byte[] array, int start)
        {
            magic      = BitConverter.ToInt32(array, start); start += sizeof(int);
            version    = BitConverter.ToInt32(array, start); start += sizeof(int);
            numTiles   = BitConverter.ToInt32(array, start); start += sizeof(int);
            meshParams = new Detour.dtNavMeshParams();
            meshParams.FromBytes(array, start); start += Detour.dtNavMeshParams.ByteSize();

            return(start);
        }
Esempio n. 2
0
        bool loadMapData(uint mapId)
        {
            // we already have this map loaded?
            if (loadedMMaps.ContainsKey(mapId) && loadedMMaps[mapId] != null)
            {
                return(true);
            }

            // load and init dtNavMesh - read parameters from file
            string filename = string.Format(MAP_FILE_NAME_FORMAT, Global.WorldMgr.GetDataPath(), mapId);

            if (!File.Exists(filename))
            {
                Log.outError(LogFilter.Maps, "Could not open mmap file {0}", filename);
                return(false);
            }

            using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read), Encoding.UTF8))
            {
                Detour.dtNavMeshParams Params = new Detour.dtNavMeshParams();
                Params.orig[0] = reader.ReadSingle();
                Params.orig[1] = reader.ReadSingle();
                Params.orig[2] = reader.ReadSingle();

                Params.tileWidth  = reader.ReadSingle();
                Params.tileHeight = reader.ReadSingle();
                Params.maxTiles   = reader.ReadInt32();
                Params.maxPolys   = reader.ReadInt32();

                Detour.dtNavMesh mesh = new Detour.dtNavMesh();
                if (Detour.dtStatusFailed(mesh.init(Params)))
                {
                    Log.outError(LogFilter.Maps, "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap {0:D4} from file {1}", mapId, filename);
                    return(false);
                }

                Log.outInfo(LogFilter.Maps, "MMAP:loadMapData: Loaded {0:D4}.mmap", mapId);

                // store inside our map list
                loadedMMaps[mapId] = new MMapData(mesh, mapId);
                return(true);
            }
        }