/* * Updates the internal quadtree to make it identical to the given terrain * quadtree. Collects the tasks necessary to create the missing texture * tiles, corresponding to newly created quads. */ protected virtual void GetTiles(QuadTree parent, ref QuadTree tree, TerrainQuad quad) { //if tree not created, create a new tree and check if its tile is needed if (tree == null) { tree = new QuadTree(parent); tree.needTile = NeedTile(quad); } //If this trees tile is needed get a tile and add its task to the schedular if the task is not already done if (tree.needTile && tree.tile == null) { tree.tile = m_producer.GetTile(quad.GetLevel(), quad.GetTX(), quad.GetTY()); if (!tree.tile.GetTask().IsDone()) { //if task not done schedule task m_manager.GetSchedular().Add(tree.tile.GetTask()); } } if (!quad.IsLeaf() && m_producer.HasChildren(quad.GetLevel(), quad.GetTX(), quad.GetTY())) { for (int i = 0; i < 4; ++i) { GetTiles(tree, ref tree.children[i], quad.GetChild(i)); } } }
/* * Updates the internal quadtree to make it identical to the given terrain * quadtree. This method releases the texture tiles corresponding to * deleted quads. */ protected virtual void PutTiles(QuadTree tree, TerrainQuad quad) { if (tree == null) { return; } //Check if this tile is needed, if not put tile. tree.needTile = NeedTile(quad); if (!tree.needTile && tree.tile != null) { m_producer.PutTile(tree.tile); tree.tile = null; } //If this qiad is a leaf then all children of the tree are not needed if (quad.IsLeaf()) { if (!tree.IsLeaf()) { tree.RecursiveDeleteChildren(this); } } else if (m_producer.HasChildren(quad.GetLevel(), quad.GetTX(), quad.GetTY())) { for (int i = 0; i < 4; ++i) { PutTiles(tree.children[i], quad.GetChild(i)); } } }