public bool ReadFromMemory(byte[] filebuffer, bool skipId0 = false) { _regionOrderList.Clear(); _regionMap.Clear(); try { byte[] bytes; using (MemoryStream fs = new MemoryStream(filebuffer)) { using (BinaryReader br = new BinaryReader(fs)) { bytes = br.ReadBytes(Marshal.SizeOf(typeof(SMapRegionHeader))); Header = (SMapRegionHeader)RegionUtility.ByteToStruct(bytes, typeof(SMapRegionHeader)); for (int i = 0; i < Header.iNumRegion; ++i) { int id = br.ReadInt32(); int nGridNum = br.ReadInt32(); if (id == 0 && skipId0) //跳过id0 { //跳过读取数据 br.ReadBytes(nGridNum * Marshal.SizeOf(typeof(uint))); continue; } //Vector2 mins = new Vector2(99999.0f, 99999.0f); //Vector2 maxs = new Vector2(-99999.0f, -99999.0f); HashSet <uint> gridSet = new HashSet <uint>(); for (int k = 0; k < nGridNum; ++k) { uint data = br.ReadUInt32(); gridSet.Add(data); } FileRegion fileRegion = new FileRegion(); fileRegion.Id = id; fileRegion.GridNum = nGridNum; fileRegion.RegionGridSet = gridSet; //添加region _regionMap.Add(fileRegion.Id, fileRegion); _regionOrderList.Add(fileRegion); } } } } catch (IOException) { return(false); } _regionOrderList.Sort(CompareFileRegion); _fInvGridSize = 1.0f / Header.fGridSize; _fLeft = -Header.fWorldWid * 0.5f; _fTop = Header.fWorldLen * 0.5f; return(true); }
public FileMapRegion() { Header = new SMapRegionHeader(); _regionOrderList = new List <FileRegion>(); _regionMap = new Dictionary <int, FileRegion>(); _PtToRegionSetMap = new Dictionary <int, Dictionary <uint, int> >(); //_fileRegionMaxRectList = new List<FileRegionMaxRect>(); }
public bool ReadFile(string filename) { _regionOrderList.Clear(); _regionMap.Clear(); if (!File.Exists(filename)) { return(false); } try { byte[] bytes; using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs)) { bytes = br.ReadBytes(Marshal.SizeOf(typeof(SMapRegionHeader))); Header = (SMapRegionHeader)RegionUtility.ByteToStruct(bytes, typeof(SMapRegionHeader)); for (int i = 0; i < Header.iNumRegion; ++i) { FileRegion fileRegion = new FileRegion(); fileRegion.Id = br.ReadInt32(); fileRegion.GridNum = br.ReadInt32(); HashSet <uint> gridSet = new HashSet <uint>(); for (int k = 0; k < fileRegion.GridNum; ++k) { uint data = br.ReadUInt32(); gridSet.Add(data); } fileRegion.RegionGridSet = gridSet; //添加region _regionMap.Add(fileRegion.Id, fileRegion); _regionOrderList.Add(fileRegion); } } } } catch (Exception ex) { return(false); } _regionOrderList.Sort(CompareFileRegion); _fInvGridSize = 1.0f / Header.fGridSize; _fLeft = -Header.fWorldWid * 0.5f; _fTop = Header.fWorldLen * 0.5f; return(true); }