public QuadTree(int x, int y, int width, int height, List<NodeObject> listObject, int minSize) { _root = new QuadNode(x, y, width, height, 0); _root._listNodeObject = new List<NodeObject>(listObject); _minSize = minSize; initTreeWithMinSize(_root); }
public Tile(QuadNode<Tile> node, PlaceableObject placeableObject, Vec2Int v) { _node = node; _node.data(this); _object = placeableObject; _pos = v; }
public static void createTile(QuadNode<Tile> node, Utilities.Vec2Int pos) { if (_defaultFloorTex == null) _defaultFloorTex = Resources.Load<Texture2D>("Textures/Game Environment/Tile"); Tile tile = new Tile(node, null, pos); tile.setFloorTexture(_defaultFloorTex); }
private void SaveDynamic(string path, string name, bool saveObject) { QuadNode root = AutoBuild((int)Type.Dynamic, out List <CObject> objs); string file = Path.Combine(path, name + "_dynamic.txt"); string fileObject = Path.Combine(path, name + ".txt"); if (saveObject) { SaveObject(objs, fileObject); } if (checkBoxInclude.Checked) { SaveQuadTree(root, file); } }
private void CreateQuadNodeSub() { Size center = GetCenter(region); if (center.Width < minSize.Width || center.Height < minSize.Height || objects.Count < 2 || level > depth) { return; } else { this.leftTop = new QuadNode(id * 10 + 1, level + 1, new Rectangle(region.Location, center)); this.rightTop = new QuadNode(id * 10 + 2, level + 1, new Rectangle(new Point(center.Width + region.X, region.Y), center)); this.leftBottom = new QuadNode(id * 10 + 3, level + 1, new Rectangle(new Point(region.X, region.Y + center.Height), center)); this.rightBottom = new QuadNode(id * 10 + 4, level + 1, new Rectangle(new Point(region.X + center.Width, region.Y + center.Height), center)); } }
public void CreateSubNode() { int halfWidth = rec.Width / 2; int halfHeight = rec.Height / 2; if (halfWidth < 136 || listObj.Count == 0) { LeftBot = null; LeftTop = null; RightBot = null; RightTop = null; return; } LeftTop = new QuadNode(this.id + "0", new Rectangle(rec.Location, new Size(halfWidth, halfHeight))); RightTop = new QuadNode(this.id + "1", new Rectangle(new Point(rec.Left + halfWidth, rec.Top), new Size(halfWidth, halfHeight))); LeftBot = new QuadNode(this.id + "2", new Rectangle(new Point(rec.Left, rec.Top + halfHeight), new Size(halfWidth, halfHeight))); RightBot = new QuadNode(this.id + "3", new Rectangle(new Point(rec.Left + halfWidth, rec.Top + halfHeight), new Size(halfWidth, halfHeight))); }
private void SaveAll(string path, string name) { string fileObject = Path.Combine(path, name + ".txt"); if (!checkBoxOnly.Checked) { SaveObject(objects.Values.ToList(), fileObject); SaveDynamic(path, name, false); SaveStatic(path, name, false); return; } QuadNode root = AutoBuild((int)Type.All, out List <CObject> objs); string file = Path.Combine(path, name + "_all.txt"); SaveObject(objs, fileObject); if (checkBoxInclude.Checked) { SaveQuadTree(root, file); } }
private void btn_Open_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); try { fileDirectory = Path.GetDirectoryName(openFileDialog1.FileName); fileName = Path.GetFileName(openFileDialog1.FileName).Substring(0, Path.GetFileName(openFileDialog1.FileName).LastIndexOf(".")); pictureBox2.BackgroundImage = Image.FromFile(openFileDialog1.FileName); pictureBox2.Width = pictureBox2.BackgroundImage.Width; pictureBox2.Height = pictureBox2.BackgroundImage.Height; readMatrix = File.ReadAllText(Path.Combine(fileDirectory, fileName + ".txt")); countRow = pictureBox2.Height / 32; countCol = pictureBox2.Width / 32; matTile = new int[countRow, countCol]; Cut(pictureBox2.BackgroundImage); decodeMatrix(); // FileStream fileStream = new FileStream("") String readObj = File.ReadAllText(Path.Combine(fileDirectory, fileName + "OBJ.txt")); decodeObj(readObj); buildBackground(); //pictureBox1.Width = pictureBox1.BackgroundImage.Width; //pictureBox1.Height = pictureBox1.BackgroundImage.Height; //pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height); String readQuadTree = File.ReadAllText(Path.Combine(fileDirectory, fileName + "QuadTree.txt")); rootNode = new QuadNode("0", new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height)); rootNode.LoadNode(readQuadTree, listobjmap); DrawDash(countMatrixRow, countMatrixCol); } catch { } }
public QuadTree(int x, int y, int width, int height, List<NodeObject> listObject) { _root = new QuadNode(x, y, width, height, 0); _root._listNodeObject = new List<NodeObject>(listObject); initTreeWithMaximumObject(_root); }
private void traverseTree4Writring(XmlWriter writer, QuadNode node) { if (node != null) { writer.WriteStartElement("node"); writer.WriteAttributeString("id", node._id.ToString()); writer.WriteElementString("pos", "{" + node._bouding.X + "," + node._bouding.Y + "}"); writer.WriteElementString("size", "{" + node._bouding.Width + "," + node._bouding.Height + "}"); if (node._listNodeObject.Count != 0) { writer.WriteStartElement("list-object"); foreach (NodeObject item in node._listNodeObject) { writer.WriteElementString("id", item._objectID.ToString()); } writer.WriteEndElement(); } writer.WriteEndElement(); traverseTree4Writring(writer, node._topLeft); traverseTree4Writring(writer, node._topRight); traverseTree4Writring(writer, node._bottomLeft); traverseTree4Writring(writer, node._bottomRight); } }
private void traverseTree(QuadNode node, Rectangle r, List<NodeObject> result) { if (node == null) { return; } if (node._listNodeObject.Count != 0 && Rectangle.Intersect(node._bouding, r) != Rectangle.Empty) { result.AddRange(node._listNodeObject.ToList()); } else { if (Rectangle.Intersect(node._bouding, r) == Rectangle.Empty) { return; } } traverseTree(node._topLeft, r, result); traverseTree(node._topRight, r, result); traverseTree(node._bottomLeft, r, result); traverseTree(node._bottomRight, r, result); }
private void initTreeWithMinSize(QuadNode node) { if (node._bouding.Width <= _minSize || node._bouding.Height <= _minSize || node._listNodeObject.Count == 0) { return; } else { node._topLeft = new QuadNode(node._bouding.X, node._bouding.Y, node._bouding.Width / 2, node._bouding.Height / 2, node._id * 8 + 1); node._topRight = new QuadNode(node._bouding.X + node._bouding.Width / 2, node._bouding.Y, node._bouding.Width / 2, node._bouding.Height / 2, node._id * 8 + 2); node._bottomRight = new QuadNode(node._bouding.X + node._bouding.Width / 2, node._bouding.Y + node._bouding.Height / 2, node._bouding.Width / 2, node._bouding.Height / 2, node._id * 8 + 3); node._bottomLeft = new QuadNode(node._bouding.X, node._bouding.Y + node._bouding.Height / 2, node._bouding.Width / 2, node._bouding.Height / 2, node._id * 8 + 4); distributeObject(node._topLeft, node._listNodeObject); distributeObject(node._topRight, node._listNodeObject); distributeObject(node._bottomLeft, node._listNodeObject); distributeObject(node._bottomRight, node._listNodeObject); node._listNodeObject.Clear(); } initTreeWithMinSize(node._topLeft); initTreeWithMinSize(node._topRight); initTreeWithMinSize(node._bottomLeft); initTreeWithMinSize(node._bottomRight); }
private void distributeObject(QuadNode quadrant, List<NodeObject> listObject) { quadrant._listNodeObject = new List<NodeObject>(); foreach (NodeObject item in listObject) { if (Rectangle.Intersect((Rectangle)item._boxObject, quadrant._bouding) != Rectangle.Empty) { quadrant._listNodeObject.Add(item); } } }
public void set(QuadNode<Tile> tile, int x, int y) { if (tile == null || x < 0 || x >= size.x || y < 0 || y >= size.y) return; _data[x, y] = tile; }
public Chunk() { _data = new QuadNode<Tile>[size.x, size.y]; for (int i = 0; i < size.x; i++) { for (int j = 0; j < size.y; j++) { _data[i, j] = new QuadNode<Tile>(); if (j > 0) _data[i, j - 1].attach(_data[i, j], SIDE_4.TOP); if (i > 0) _data[i - 1, j].attach(_data[i, j], SIDE_4.RIGHT); } } }