Example #1
0
 public void UpdatePosition(int x, int y, ScenePartitionerEntry entry)
 {
     Widthdraw(entry);
     entry.x = x;
     entry.y = y;
     Insert(entry);
 }
Example #2
0
    public void Remove(ScenePartitionerEntry entry)
    {
        Extents nodeExtents = GetNodeExtents(entry);

        if (nodeExtents.x + nodeExtents.width > nodes.GetLength(2))
        {
            Debug.LogError(" x/w " + nodeExtents.x + "/" + nodeExtents.width + " < " + nodes.GetLength(2));
        }
        if (nodeExtents.y + nodeExtents.height > nodes.GetLength(1))
        {
            Debug.LogError(" y/h " + nodeExtents.y + "/" + nodeExtents.height + " < " + nodes.GetLength(1));
        }
        int layer = entry.layer;

        for (int i = nodeExtents.y; i < nodeExtents.y + nodeExtents.height; i++)
        {
            for (int j = nodeExtents.x; j < nodeExtents.x + nodeExtents.width; j++)
            {
                if (!nodes[layer, i, j].dirty)
                {
                    nodes[layer, i, j].dirty = true;
                    dirtyNodes.Add(new DirtyNode
                    {
                        layer = layer,
                        x     = j,
                        y     = i
                    });
                }
            }
        }
        entry.obj = null;
    }
    public HandleVector <int> .Handle Add(string name, object obj, int x, int y, int width, int height, ScenePartitionerLayer layer, Action <object> event_callback)
    {
        ScenePartitionerEntry scenePartitionerEntry = new ScenePartitionerEntry(name, obj, x, y, width, height, layer, partitioner, event_callback);

        partitioner.Add(scenePartitionerEntry);
        return(scenePartitionerEntries.Allocate(scenePartitionerEntry));
    }
        public GameObject FindThreat()
        {
            threats.Clear();
            ListPool <ScenePartitionerEntry, ThreatMonitor> .PooledList pooledList = ListPool <ScenePartitionerEntry, ThreatMonitor> .Allocate();

            Extents extents = new Extents(Grid.PosToCell(eggToProtect), maxThreatDistance);

            GameScenePartitioner.Instance.GatherEntries(extents, GameScenePartitioner.Instance.attackableEntitiesLayer, pooledList);
            for (int i = 0; i < pooledList.Count; i++)
            {
                ScenePartitionerEntry scenePartitionerEntry = pooledList[i];
                FactionAlignment      factionAlignment      = scenePartitionerEntry.obj as FactionAlignment;
                if (!((UnityEngine.Object)factionAlignment.transform == (UnityEngine.Object)null) && !((UnityEngine.Object)factionAlignment == (UnityEngine.Object)alignment) && factionAlignment.IsAlignmentActive() && navigator.CanReach(factionAlignment.attackable))
                {
                    bool  flag     = false;
                    Tag[] allyTags = base.def.allyTags;
                    foreach (Tag tag in allyTags)
                    {
                        if (factionAlignment.HasTag(tag))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        threats.Add(factionAlignment);
                    }
                }
            }
            pooledList.Recycle();
            return(PickBestTarget(threats));
        }
Example #5
0
    public void GatherEntries(int x, int y, int width, int height, ScenePartitionerLayer layer, object event_data, List <ScenePartitionerEntry> gathered_entries, int query_id)
    {
        Extents nodeExtents = GetNodeExtents(x, y, width, height);
        int     num         = Math.Min(nodeExtents.y + nodeExtents.height, nodes.GetLength(1));
        int     num2        = Math.Max(nodeExtents.y, 0);
        int     num3        = Math.Max(nodeExtents.x, 0);
        int     num4        = Math.Min(nodeExtents.x + nodeExtents.width, nodes.GetLength(2));
        int     layer2      = layer.layer;

        for (int i = num2; i < num; i++)
        {
            for (int j = num3; j < num4; j++)
            {
                int count = nodes[layer2, i, j].entries.Count;
                for (int k = 0; k < count; k++)
                {
                    ScenePartitionerEntry scenePartitionerEntry = nodes[layer2, i, j].entries[k];
                    if (scenePartitionerEntry != null && scenePartitionerEntry.queryId != queryId)
                    {
                        if (scenePartitionerEntry.obj == null)
                        {
                            nodes[layer2, i, j].entries[k] = null;
                        }
                        else if (x + width - 1 >= scenePartitionerEntry.x && x <= scenePartitionerEntry.x + scenePartitionerEntry.width - 1 && y + height - 1 >= scenePartitionerEntry.y && y <= scenePartitionerEntry.y + scenePartitionerEntry.height - 1)
                        {
                            scenePartitionerEntry.queryId = queryId;
                            gathered_entries.Add(scenePartitionerEntry);
                        }
                    }
                }
            }
        }
    }
 public void UpdatePosition(HandleVector <int> .Handle handle, int x, int y)
 {
     if (handle.IsValid())
     {
         ScenePartitionerEntry data = scenePartitionerEntries.GetData(handle);
         data.UpdatePosition(x, y);
     }
 }
Example #7
0
        /// <summary>
        /// A slightly more thread safe version of HashSet.Remove that at least avoids self
        /// races.
        /// </summary>
        /// <param name="set">The set to modify.</param>
        /// <param name="entry">The entry to remove.</param>
        /// <returns>true if the set was modified, or false otherwise.</returns>
        private static bool RemoveLocked(SceneEntryHash set, ScenePartitionerEntry entry)
        {
            bool result;

            lock (set) {
                result = set.Remove(entry);
            }
            return(result);
        }
 public void Free(ref HandleVector <int> .Handle handle)
 {
     if (handle.IsValid())
     {
         ScenePartitionerEntry data = scenePartitionerEntries.GetData(handle);
         data.Release();
         scenePartitionerEntries.Free(handle);
         handle.Clear();
     }
 }
Example #9
0
 private void RunEntries(List <ScenePartitionerEntry> gathered_entries, object event_data)
 {
     for (int i = 0; i < gathered_entries.Count; i++)
     {
         ScenePartitionerEntry scenePartitionerEntry = gathered_entries[i];
         if (scenePartitionerEntry.obj != null && scenePartitionerEntry.eventCallback != null)
         {
             scenePartitionerEntry.eventCallback(event_data);
         }
     }
 }
    public void Iterate <IteratorType>(int x, int y, int width, int height, ScenePartitionerLayer layer, ref IteratorType iterator) where IteratorType : Iterator
    {
        ListPool <ScenePartitionerEntry, GameScenePartitioner> .PooledList pooledList = ListPool <ScenePartitionerEntry, GameScenePartitioner> .Allocate();

        Instance.GatherEntries(x, y, width, height, layer, pooledList);
        for (int i = 0; i < ((List <ScenePartitionerEntry>)pooledList).Count; i++)
        {
            ScenePartitionerEntry scenePartitionerEntry = ((List <ScenePartitionerEntry>)pooledList)[i];
            iterator.Iterate(scenePartitionerEntry.obj);
        }
        pooledList.Recycle();
    }
    public static void GatherNearbyFetchChores(FetchChore root_chore, Precondition.Context context, int x, int y, int radius, List <Precondition.Context> succeeded_contexts, List <Precondition.Context> failed_contexts)
    {
        ListPool <ScenePartitionerEntry, FetchAreaChore> .PooledList pooledList = ListPool <ScenePartitionerEntry, FetchAreaChore> .Allocate();

        GameScenePartitioner.Instance.GatherEntries(x - radius, y - radius, radius * 2 + 1, radius * 2 + 1, GameScenePartitioner.Instance.fetchChoreLayer, pooledList);
        for (int i = 0; i < pooledList.Count; i++)
        {
            ScenePartitionerEntry scenePartitionerEntry = pooledList[i];
            FetchChore            fetchChore            = scenePartitionerEntry.obj as FetchChore;
            fetchChore.CollectChoresFromGlobalChoreProvider(context.consumerState, succeeded_contexts, failed_contexts, true);
        }
        pooledList.Recycle();
    }
Example #12
0
    public void ClearCell(int cell)
    {
        Vector2I vector2I = Grid.CellToXY(cell);

        ListPool <ScenePartitionerEntry, DebugTool> .PooledList pooledList = ListPool <ScenePartitionerEntry, DebugTool> .Allocate();

        GameScenePartitioner.Instance.GatherEntries(vector2I.x, vector2I.y, 1, 1, GameScenePartitioner.Instance.pickupablesLayer, pooledList);
        for (int i = 0; i < pooledList.Count; i++)
        {
            ScenePartitionerEntry scenePartitionerEntry = pooledList[i];
            Pickupable            pickupable            = scenePartitionerEntry.obj as Pickupable;
            if ((Object)pickupable != (Object)null && (Object)pickupable.GetComponent <MinionBrain>() == (Object)null)
            {
                Util.KDestroyGameObject(pickupable.gameObject);
            }
        }
        pooledList.Recycle();
    }
Example #13
0
    private void Widthdraw(ScenePartitionerEntry entry)
    {
        Extents nodeExtents = GetNodeExtents(entry);

        if (nodeExtents.x + nodeExtents.width > nodes.GetLength(2))
        {
            Debug.LogError(" x/w " + nodeExtents.x + "/" + nodeExtents.width + " < " + nodes.GetLength(2));
        }
        if (nodeExtents.y + nodeExtents.height > nodes.GetLength(1))
        {
            Debug.LogError(" y/h " + nodeExtents.y + "/" + nodeExtents.height + " < " + nodes.GetLength(1));
        }
        int layer = entry.layer;

        for (int i = nodeExtents.y; i < nodeExtents.y + nodeExtents.height; i++)
        {
            for (int j = nodeExtents.x; j < nodeExtents.x + nodeExtents.width; j++)
            {
                int count = nodes[layer, i, j].entries.Count;
                for (int k = 0; k < count; k++)
                {
                    if (nodes[layer, i, j].entries[k] == entry)
                    {
                        if (!nodes[layer, i, j].dirty)
                        {
                            nodes[layer, i, j].dirty = true;
                            dirtyNodes.Add(new DirtyNode
                            {
                                layer = layer,
                                x     = j,
                                y     = i
                            });
                        }
                        nodes[layer, i, j].entries[k] = null;
                        break;
                    }
                }
            }
        }
    }
Example #14
0
 public void FreeResources()
 {
     for (int i = 0; i < nodes.GetLength(0); i++)
     {
         for (int j = 0; j < nodes.GetLength(1); j++)
         {
             for (int k = 0; k < nodes.GetLength(2); k++)
             {
                 for (int l = 0; l < nodes[i, j, k].entries.Count; l++)
                 {
                     ScenePartitionerEntry scenePartitionerEntry = nodes[i, j, k].entries[l];
                     if (scenePartitionerEntry != null)
                     {
                         scenePartitionerEntry.partitioner = null;
                         scenePartitionerEntry.obj         = null;
                     }
                 }
                 nodes[i, j, k].entries.Clear();
             }
         }
     }
     nodes = null;
 }
Example #15
0
 private void Insert(ScenePartitionerEntry entry)
 {
     if (entry.obj == null)
     {
         Debug.LogWarning("Trying to put null go into scene partitioner");
     }
     else
     {
         Extents nodeExtents = GetNodeExtents(entry);
         if (nodeExtents.x + nodeExtents.width > nodes.GetLength(2))
         {
             Debug.LogError(entry.obj.ToString() + " x/w " + nodeExtents.x + "/" + nodeExtents.width + " < " + nodes.GetLength(2));
         }
         if (nodeExtents.y + nodeExtents.height > nodes.GetLength(1))
         {
             Debug.LogError(entry.obj.ToString() + " y/h " + nodeExtents.y + "/" + nodeExtents.height + " < " + nodes.GetLength(1));
         }
         int layer = entry.layer;
         for (int i = nodeExtents.y; i < nodeExtents.y + nodeExtents.height; i++)
         {
             for (int j = nodeExtents.x; j < nodeExtents.x + nodeExtents.width; j++)
             {
                 if (!nodes[layer, i, j].dirty)
                 {
                     nodes[layer, i, j].dirty = true;
                     dirtyNodes.Add(new DirtyNode
                     {
                         layer = layer,
                         x     = j,
                         y     = i
                     });
                 }
                 nodes[layer, i, j].entries.Add(entry);
             }
         }
     }
 }
Example #16
0
 public ScenePartitionerEntry Add(ScenePartitionerEntry entry)
 {
     Insert(entry);
     return(entry);
 }
Example #17
0
 private Extents GetNodeExtents(ScenePartitionerEntry entry)
 {
     return(GetNodeExtents(entry.x, entry.y, entry.width, entry.height));
 }
        public void Begin(Precondition.Context context)
        {
            base.sm.fetcher.Set(context.consumerState.gameObject, base.smi);
            chores.Clear();
            chores.Add(rootChore);
            Grid.CellToXY(Grid.PosToCell(rootChore.destination.transform.GetPosition()), out int x, out int y);
            ListPool <Precondition.Context, FetchAreaChore> .PooledList pooledList = ListPool <Precondition.Context, FetchAreaChore> .Allocate();

            ListPool <Precondition.Context, FetchAreaChore> .PooledList pooledList2 = ListPool <Precondition.Context, FetchAreaChore> .Allocate();

            if (rootChore.allowMultifetch)
            {
                GatherNearbyFetchChores(rootChore, context, x, y, 3, pooledList, pooledList2);
            }
            float      num        = Mathf.Max(1f, Db.Get().Attributes.CarryAmount.Lookup(context.consumerState.consumer).GetTotalValue());
            Pickupable pickupable = context.data as Pickupable;

            if ((UnityEngine.Object)pickupable == (UnityEngine.Object)null)
            {
                Debug.Assert(pooledList.Count > 0, "succeeded_contexts was empty");
                Precondition.Context context2   = pooledList[0];
                FetchChore           fetchChore = (FetchChore)context2.chore;
                Debug.Assert(fetchChore != null, "fetch_chore was null");
                DebugUtil.LogWarningArgs("Missing root_fetchable for FetchAreaChore", fetchChore.destination, fetchChore.tags[0]);
                pickupable = fetchChore.FindFetchTarget(context.consumerState);
            }
            Debug.Assert((UnityEngine.Object)pickupable != (UnityEngine.Object)null, "root_fetchable was null");
            List <Pickupable> list = new List <Pickupable>();

            list.Add(pickupable);
            float num2          = pickupable.UnreservedAmount;
            float minTakeAmount = pickupable.MinTakeAmount;
            int   x2            = 0;
            int   y2            = 0;

            Grid.CellToXY(Grid.PosToCell(pickupable.transform.GetPosition()), out x2, out y2);
            int num3 = 6;

            x2 -= num3 / 2;
            y2 -= num3 / 2;
            ListPool <ScenePartitionerEntry, FetchAreaChore> .PooledList pooledList3 = ListPool <ScenePartitionerEntry, FetchAreaChore> .Allocate();

            GameScenePartitioner.Instance.GatherEntries(x2, y2, num3, num3, GameScenePartitioner.Instance.pickupablesLayer, pooledList3);
            Tag prefabTag = pickupable.GetComponent <KPrefabID>().PrefabTag;

            for (int i = 0; i < pooledList3.Count; i++)
            {
                ScenePartitionerEntry scenePartitionerEntry = pooledList3[i];
                if (num2 > num)
                {
                    break;
                }
                Pickupable pickupable2 = scenePartitionerEntry.obj as Pickupable;
                KPrefabID  component   = pickupable2.GetComponent <KPrefabID>();
                if (!(component.PrefabTag != prefabTag) && !(pickupable2.UnreservedAmount <= 0f))
                {
                    component.UpdateTagBits();
                    if (component.HasAllTags_AssumeLaundered(ref rootChore.requiredTagBits) && !component.HasAnyTags_AssumeLaundered(ref rootChore.forbiddenTagBits) && !list.Contains(pickupable2) && rootContext.consumerState.consumer.CanReach(pickupable2))
                    {
                        float unreservedAmount = pickupable2.UnreservedAmount;
                        list.Add(pickupable2);
                        num2 += unreservedAmount;
                        if (list.Count >= 10)
                        {
                            break;
                        }
                    }
                }
            }
            pooledList3.Recycle();
            num2 = Mathf.Min(num, num2);
            if (minTakeAmount > 0f)
            {
                num2 -= num2 % minTakeAmount;
            }
            deliveries.Clear();
            float num4 = Mathf.Min(rootChore.originalAmount, num2);

            if (minTakeAmount > 0f)
            {
                num4 -= num4 % minTakeAmount;
            }
            deliveries.Add(new Delivery(rootContext, num4, OnFetchChoreCancelled));
            float num5 = num4;

            for (int j = 0; j < pooledList.Count; j++)
            {
                if (num5 >= num2)
                {
                    break;
                }
                Precondition.Context context3    = pooledList[j];
                FetchChore           fetchChore2 = context3.chore as FetchChore;
                if (fetchChore2 != rootChore && context3.IsSuccess() && (UnityEngine.Object)fetchChore2.overrideTarget == (UnityEngine.Object)null && (UnityEngine.Object)fetchChore2.driver == (UnityEngine.Object)null && fetchChore2.tagBits.AreEqual(ref rootChore.tagBits))
                {
                    num4 = Mathf.Min(fetchChore2.originalAmount, num2 - num5);
                    if (minTakeAmount > 0f)
                    {
                        num4 -= num4 % minTakeAmount;
                    }
                    chores.Add(fetchChore2);
                    deliveries.Add(new Delivery(context3, num4, OnFetchChoreCancelled));
                    num5 += num4;
                    if (deliveries.Count >= 10)
                    {
                        break;
                    }
                }
            }
            num5 = Mathf.Min(num5, num2);
            float num6 = num5;

            fetchables.Clear();
            for (int k = 0; k < list.Count; k++)
            {
                if (num6 <= 0f)
                {
                    break;
                }
                Pickupable pickupable3 = list[k];
                num6 -= pickupable3.UnreservedAmount;
                fetchables.Add(pickupable3);
            }
            fetchAmountRequested = num5;
            reservations.Clear();
            pooledList.Recycle();
            pooledList2.Recycle();
        }