コード例 #1
0
ファイル: GridLookup.cs プロジェクト: looki666/Green-Hell
        public void Move(T item, IntRect bounds)
        {
            GridLookup <T> .Root root;
            if (!this.rootLookup.TryGetValue(item, out root))
            {
                throw new ArgumentException("The item has not been added to this object");
            }
            IntRect previousBounds = root.previousBounds;

            if (previousBounds == bounds)
            {
                return;
            }
            for (int i = 0; i < root.items.Count; i++)
            {
                GridLookup <T> .Item item2 = root.items[i];
                item2.prev.next = item2.next;
                if (item2.next != null)
                {
                    item2.next.prev = item2.prev;
                }
            }
            root.previousBounds = bounds;
            int num = 0;

            for (int j = bounds.ymin; j <= bounds.ymax; j++)
            {
                for (int k = bounds.xmin; k <= bounds.xmax; k++)
                {
                    GridLookup <T> .Item item3;
                    if (num < root.items.Count)
                    {
                        item3 = root.items[num];
                    }
                    else
                    {
                        item3      = ((this.itemPool.Count <= 0) ? new GridLookup <T> .Item() : this.itemPool.Pop());
                        item3.root = root;
                        root.items.Add(item3);
                    }
                    num++;
                    item3.prev      = this.cells[k + j * this.size.x];
                    item3.next      = item3.prev.next;
                    item3.prev.next = item3;
                    if (item3.next != null)
                    {
                        item3.next.prev = item3;
                    }
                }
            }
            for (int l = root.items.Count - 1; l >= num; l--)
            {
                GridLookup <T> .Item item4 = root.items[l];
                item4.root = null;
                item4.next = null;
                item4.prev = null;
                root.items.RemoveAt(l);
                this.itemPool.Push(item4);
            }
        }
コード例 #2
0
 // Token: 0x060029A0 RID: 10656 RVA: 0x001C2368 File Offset: 0x001C0568
 public GridLookup <T> .Root Add(T item, IntRect bounds)
 {
     GridLookup <T> .Root root = new GridLookup <T> .Root
     {
         obj  = item,
         prev = this.all,
         next = this.all.next
     };
     this.all.next = root;
     if (root.next != null)
     {
         root.next.prev = root;
     }
     this.rootLookup.Add(item, root);
     this.Move(item, bounds);
     return(root);
 }
コード例 #3
0
        // Token: 0x060029A3 RID: 10659 RVA: 0x001C261C File Offset: 0x001C081C
        public List <U> QueryRect <U>(IntRect r) where U : class, T
        {
            List <U> list = ListPool <U> .Claim();

            for (int i = r.ymin; i <= r.ymax; i++)
            {
                int num = i * this.size.x;
                for (int j = r.xmin; j <= r.xmax; j++)
                {
                    GridLookup <T> .Item item = this.cells[j + num];
                    while (item.next != null)
                    {
                        item = item.next;
                        U u = item.root.obj as U;
                        if (!item.root.flag && u != null)
                        {
                            item.root.flag = true;
                            list.Add(u);
                        }
                    }
                }
            }
            for (int k = r.ymin; k <= r.ymax; k++)
            {
                int num2 = k * this.size.x;
                for (int l = r.xmin; l <= r.xmax; l++)
                {
                    GridLookup <T> .Item item2 = this.cells[l + num2];
                    while (item2.next != null)
                    {
                        item2           = item2.next;
                        item2.root.flag = false;
                    }
                }
            }
            return(list);
        }