コード例 #1
0
 /** Return the next column that should be removed from the scene */
 public ColumnDestroyTask GetNextDestroyColumn()
 {
     lock (unloadQueue)
     {
         if (unloadQueue.Count > 0)
         {
             ColumnDestroyTask result = unloadQueue[0];
             unloadQueue.RemoveAt(0);
             return(result);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #2
0
    /** Given a rectangle with corners 'min' and 'max', unload all the chunks not within the rectangle */
    public void UnloadInRange(Vector2i min, Vector2i max)
    {
        // helper variables
        int             xMin    = min.x;
        int             zMin    = min.z;
        int             xMax    = max.x;
        int             zMax    = max.z;
        List <Vector2i> removal = new List <Vector2i>();

        // mark positions for removal
        lock (this)
        {
            foreach (Vector2i pos in loadedData.Keys)
            {
                if (pos.x < xMin || pos.z < zMin || pos.x > xMax || pos.z > zMax)
                {
                    removal.Add(pos);
                }
            }
        }

        // remove columns outside of range
        foreach (Vector2i pos in removal)
        {
            lock (this)
            {
                loadedData.Remove(pos);
            }
        }

        // call removal events
        foreach (Vector2i pos in removal)
        {
            ColumnDestroyTask task = new ColumnDestroyTask(pos);
            bool contains;
            lock (this) contains = renderedData.Remove(pos);
            if (contains)
            {
                lock (unloadQueue) unloadQueue.Add(task);
            }
        }
    }