public void process(int width, int height) { if (size == 1) { zone = getZone(x, y); } else { QuadTreeNode tl = new QuadTreeNode(getZone, size / 2, x, y); QuadTreeNode tr = new QuadTreeNode(getZone, size / 2, x + size / 2, y); QuadTreeNode bl = new QuadTreeNode(getZone, size / 2, x, y + size / 2); QuadTreeNode br = new QuadTreeNode(getZone, size / 2, x + size / 2, y + size / 2); tl.process(width, height); tr.process(width, height); bl.process(width, height); br.process(width, height); /* if (tr.x >= width) { tr.children = null; br.children = null; tr.zone = tl.zone; br.zone = bl.zone; } if (bl.y >= height) { bl.children = null; br.children = null; bl.zone = tl.zone; br.zone = tr.zone; } */ if (tl.children == null && tr.children == null && bl.children == null && br.children == null && tl.zone == tr.zone && tr.zone == bl.zone && bl.zone == br.zone) { zone = tl.zone; } else { children = new QuadTreeNode[] { tl, tr, bl, br }; } } }
public Dictionary<int, bool> WriteRoomMaskJson(JsonWriter output, string key, AGS.Types.RoomAreaMaskType maskType) { Dictionary<int,bool> usedZones = new Dictionary<int,bool>(); using (output.BeginArray(key)) { QuadTreeTools.ZoneGetter getZone = delegate(int x, int y) { int zone; if (x < 0 || y < 0 || y >= editor.RoomController.CurrentRoom.Height || x >= editor.RoomController.CurrentRoom.Width) { zone = 0; } else { zone = editor.RoomController.GetAreaMaskPixel(maskType, x, y); } usedZones[zone] = true; return zone; }; int rootSize = QuadTreeTools.GetRootSize( editor.RoomController.CurrentRoom.Width, editor.RoomController.CurrentRoom.Height); QuadTreeNode rootNode = new QuadTreeNode(getZone, QuadTreeTools.RootSizeToPixels(rootSize), 0, 0); rootNode.process(editor.RoomController.CurrentRoom.Width, editor.RoomController.CurrentRoom.Height); WriteQuadTreeNode(output, rootNode); } return usedZones; }