public void Load(string filename) { if (!FileReaderProxy.Exists(filename)) { return; } try { using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename)) { using (BinaryReader br = new BinaryReader(ms)) { while (ms.Position <= ms.Length - c_RecordSize) { short row = br.ReadInt16(); short col = br.ReadInt16(); byte obstacle = br.ReadByte(); byte oldObstacle = br.ReadByte(); Update(row, col, obstacle, oldObstacle); } br.Close(); } ms.Close(); } } catch (Exception ex) { LogUtil.Error("{0}\n{1}", ex.Message, ex.StackTrace); } }
void InitDefault(string filename) { using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename)) { using (BinaryReader br = new BinaryReader(ms)) { map_width_ = (float)br.ReadDouble(); map_height_ = (float)br.ReadDouble(); cell_width_ = (float)br.ReadDouble(); GetCell(new Vector3(map_width_, 0, map_height_), out max_row_, out max_col_); max_row_++; max_col_++; if (max_col_ % 2 == 0) { max_row_++; } cells_arr_ = new byte[max_row_, max_col_]; int row = 0; int col = 0; while (ms.Position < ms.Length && row < max_row_) { cells_arr_[row, col] = br.ReadByte(); if (++col >= max_col_) { col = 0; ++row; } } br.Close(); } } }
public bool ParseTiledData(string xml_file, float width, float height) { map_width_ = width; map_height_ = height; XmlDocument xmldoc = new XmlDocument(); System.IO.Stream ms = null; try { ms = FileReaderProxy.ReadFileAsMemoryStream(xml_file); if (ms == null) { return(false); } xmldoc.Load(ms); } catch (System.IO.FileNotFoundException ex) { LogUtil.Error("config xml file {0} not find!\n{1}", xml_file, ex.Message); return(false); } catch (Exception ex) { LogUtil.Error("parse xml file {0} error!\n{1}", xml_file, ex.Message); return(false); } finally { if (ms != null) { ms.Close(); } } XmlNode root = xmldoc.SelectSingleNode("map"); XmlNodeList objgroups = root.SelectNodes("objectgroup"); foreach (XmlNode objgroup in objgroups) { string groupName = objgroup.Attributes["name"].Value; foreach (XmlNode obj in objgroup.ChildNodes) { if (groupName == "walktriangle") { ParseObject(obj, walk_triangle_list_, null); } else if (groupName == "obstacle") { ParseObject(obj, obstacle_area_list_, obstacle_line_list_); } else { ParseObject(obj, walk_area_list_, null); } } } return(true); }
public bool ParseTiledData(string xml_file, float mapwidth, float mapheight, float scale, out string txt) { txt = ""; XmlDocument xmldoc = new XmlDocument(); System.IO.Stream ms = null; try { ms = FileReaderProxy.ReadFileAsMemoryStream(xml_file); if (ms == null) { return(false); } xmldoc.Load(ms); } catch (System.IO.FileNotFoundException ex) { LogSystem.Error("config xml file {0} not find!\n{1}", xml_file, ex.Message); return(false); } catch (Exception ex) { LogSystem.Error("parse xml file {0} error!\n{1}", xml_file, ex.Message); return(false); } finally { if (ms != null) { ms.Close(); } } XmlNode root = xmldoc.SelectSingleNode("map"); XmlNodeList objgroups = root.SelectNodes("objectgroup"); StringBuilder sb = new StringBuilder(); sb.AppendLine("类型\t名称\t是否多边形\t点XZ列表"); foreach (XmlNode objgroup in objgroups) { string groupName = objgroup.Attributes["name"].Value; foreach (XmlNode obj in objgroup.ChildNodes) { string objName = obj.Attributes["name"].Value; sb.Append(groupName).Append("\t").Append(objName).Append("\t"); TiledData td = new TiledData(mapwidth * scale, mapheight * scale); if (td.CollectDataFromXml(obj)) { sb.Append(td.IsPolygon).Append("\t"); AppendPointList(td.GetPoints(), scale, sb); sb.AppendLine(); } } } txt = sb.ToString(); return(true); }
// 从文件读取 public bool Init(string filename) { if (!FileReaderProxy.Exists(filename)) { return(false); } try { using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename)) { using (BinaryReader br = new BinaryReader(ms)) { map_width_ = (float)br.ReadDouble(); map_height_ = (float)br.ReadDouble(); cell_width_ = (float)br.ReadDouble(); GetCell(new Vector3(map_width_, 0, map_height_), out max_row_, out max_col_); max_row_++; max_col_++; if (max_col_ % 2 == 0) { max_row_++; } cells_arr_ = new byte[max_row_, max_col_]; int row = 0; int col = 0; while (ms.Position < ms.Length && row < max_row_) { cells_arr_[row, col] = br.ReadByte(); if (++col >= max_col_) { col = 0; ++row; } } br.Close(); } } } catch (Exception e) { LogUtil.Error("{0}\n{1}", e.Message, e.StackTrace); return(false); } return(true); }
public bool Initial(string filename) { bool result = false; using (MemoryStream ms = FileReaderProxy.ReadFileAsMemoryStream(filename)) { using (BinaryReader br = new BinaryReader(ms)) { float unclampedGridSizeX = br.ReadSingle(); float unclampedGridSizeY = br.ReadSingle(); unclampedGridSize = new Vector2(unclampedGridSizeX, unclampedGridSizeY); float gridCoordinateCenterX = br.ReadSingle(); float gridCoordinateCenterY = br.ReadSingle(); float gridCoordinateCenterZ = br.ReadSingle(); gridCoordinateCenter = new Vector3(gridCoordinateCenterX, gridCoordinateCenterY, gridCoordinateCenterZ); nodeSize = br.ReadSingle(); maxNodeNumInWidth = br.ReadInt32(); maxNodeNumInDepth = br.ReadInt32(); m_NodeSizeSelfAdaption = br.ReadBoolean(); result = GenerateMatrix(); if (result) { m_Nodes = new byte[nodeNumInWidth * nodeNumInDepth]; for (int z = 0; z < nodeNumInDepth; z++) { for (int x = 0; x < nodeNumInWidth; x++) { byte walkable = br.ReadByte(); m_Nodes[z * nodeNumInWidth + x] = walkable; } } } br.Close(); } } return(result); }