Beispiel #1
0
        public void Create_ListPool_from_large_collection_it_uses_capacity_equal_or_bigger_than_collection()
        {
            ICollection <int> expectedValues = Enumerable.Range(0, 10).ToArray();

            using var sut = new ListPool <int>(expectedValues);

            Assert.Equal(expectedValues.Count, sut.Count);
            Assert.True(sut.Capacity >= expectedValues.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #2
0
        public void Create_ListPool_from_small_collection_it_uses_minimum_capacity()
        {
            ICollection <int> expectedValues = Enumerable.Range(0, 10).ToArray();

            using var sut = new ListPool <int>(expectedValues);

            Assert.Equal(expectedValues.Count, sut.Count);
            Assert.Equal(32, sut.Capacity);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #3
0
        public void Contains_empty_ListPool_without_indicating_capacity_returns_false()
        {
            int randomItem = s_fixture.Create <int>();

            using var sut = new ListPool <int>();

            bool actual = sut.Contains(randomItem);

            Assert.False(actual);
        }
Beispiel #4
0
        public void AddRange_from_array_adds_all_items()
        {
            int[] expectedValues = Enumerable.Range(0, 10).ToArray();
            using var sut = new ListPool <int>(10);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Length, sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #5
0
        public void AddRange_from_array_bigger_than_capacity_then_it_grows_and_add_items()
        {
            int[] expectedValues = Enumerable.Range(0, 1000).ToArray();
            using var sut = new ListPool <int>(128);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Length, sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #6
0
        public void Create_ListPool_from_enumerable()
        {
            IEnumerable <int> values = Enumerable.Range(0, 10);

            using var sut = new ListPool <int>(values);

            IEnumerable <int> expectedValues = values.ToArray();

            Assert.Equal(expectedValues.Count(), sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #7
0
        public void AddRange_from_enumerable_as_IEnumerable_bigger_than_capacity_then_it_grows_and_add_items()
        {
            IEnumerable <int> expectedValues = Enumerable.Range(0, 1000);

            using var sut = new ListPool <int>(128);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Count(), sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #8
0
        public void AddRange_from_enumerable_as_IEnumerable_adds_all_items()
        {
            IEnumerable <int> expectedValues = Enumerable.Range(0, 10);

            using var sut = new ListPool <int>(10);

            sut.AddRange(expectedValues);

            Assert.Equal(expectedValues.Count(), sut.Count);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
        }
Beispiel #9
0
        public override void Serialize_and_deserialize_ListPool_with_value_types()
        {
            using ListPool <int> expectedItems = new ListPool <int>
                  {
                      s_fixture.Create <int>(), s_fixture.Create <int>(), s_fixture.Create <int>()
                  };
            string serializedItems = JsonSerializer.ToJsonString(expectedItems);

            using ListPool <int> actualItems = JsonSerializer.Deserialize <ListPool <int> >(serializedItems);

            Assert.Equal(expectedItems.Count, actualItems.Count);
            Assert.All(expectedItems, expectedItem => actualItems.Contains(expectedItem));
        }
        public void Add_items_when_capacity_is_full_then_buffer_autogrow()
        {
            using var sut = new ListPool <int>(128);
            var expectedItems = s_fixture.CreateMany <int>(sut.Capacity * 2).ToList();

            foreach (int expectedItem in expectedItems)
            {
                sut.Add(expectedItem);
            }

            Assert.Equal(expectedItems.Count, sut.Count);
            Assert.True(expectedItems.All(expectedItem => sut.Contains(expectedItem)));
        }
Beispiel #11
0
        public void AddRange_adds_all_items()
        {
            int[] expectedValues       = Enumerable.Range(0, 10).ToArray();
            int   expectedItem0        = s_fixture.Create <int>();
            int   expectedItem1        = s_fixture.Create <int>();
            int   expectedItem2        = s_fixture.Create <int>();
            int   expectedItemAtTheEnd = s_fixture.Create <int>();
            int   expectedCount        = expectedValues.Length + 4;

            using var sut = new ListPool <int>(20)
                  {
                      expectedItem0, expectedItem1, expectedItem2
                  };

            sut.AddRange(expectedValues);
            sut.Add(expectedItemAtTheEnd);

            Assert.Equal(expectedCount, sut.Count);
            Assert.Equal(expectedItem0, sut[0]);
            Assert.Equal(expectedItem1, sut[1]);
            Assert.Equal(expectedItem2, sut[2]);
            Assert.All(expectedValues, expectedValue => sut.Contains(expectedValue));
            Assert.Equal(expectedItemAtTheEnd, sut[13]);
        }
Beispiel #12
0
    public void Render1000ms(float dt)
    {
        DictionaryPool <int, ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary = DictionaryPool <int, ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList, FetchListStatusItemUpdater> .Allocate();

        foreach (FetchList2 fetchList in fetchLists)
        {
            if (!((Object)fetchList.Destination == (Object)null))
            {
                ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList value = null;
                int instanceID = fetchList.Destination.GetInstanceID();
                if (!pooledDictionary.TryGetValue(instanceID, out value))
                {
                    value = (pooledDictionary[instanceID] = ListPool <FetchList2, FetchListStatusItemUpdater> .Allocate());
                }
                value.Add(fetchList);
            }
        }
        DictionaryPool <Tag, float, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary2 = DictionaryPool <Tag, float, FetchListStatusItemUpdater> .Allocate();

        DictionaryPool <Tag, float, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary3 = DictionaryPool <Tag, float, FetchListStatusItemUpdater> .Allocate();

        foreach (KeyValuePair <int, ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList> item in pooledDictionary)
        {
            ListPool <Tag, FetchListStatusItemUpdater> .PooledList pooledList2 = ListPool <Tag, FetchListStatusItemUpdater> .Allocate();

            Storage destination = item.Value[0].Destination;
            foreach (FetchList2 item2 in item.Value)
            {
                item2.UpdateRemaining();
                Dictionary <Tag, float> remaining = item2.GetRemaining();
                foreach (KeyValuePair <Tag, float> item3 in remaining)
                {
                    if (!pooledList2.Contains(item3.Key))
                    {
                        pooledList2.Add(item3.Key);
                    }
                }
            }
            ListPool <Pickupable, FetchListStatusItemUpdater> .PooledList pooledList3 = ListPool <Pickupable, FetchListStatusItemUpdater> .Allocate();

            foreach (GameObject item4 in destination.items)
            {
                if (!((Object)item4 == (Object)null))
                {
                    Pickupable component = item4.GetComponent <Pickupable>();
                    if (!((Object)component == (Object)null))
                    {
                        pooledList3.Add(component);
                    }
                }
            }
            DictionaryPool <Tag, float, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary4 = DictionaryPool <Tag, float, FetchListStatusItemUpdater> .Allocate();

            foreach (Tag item5 in pooledList2)
            {
                float num = 0f;
                foreach (Pickupable item6 in pooledList3)
                {
                    if (item6.KPrefabID.HasTag(item5))
                    {
                        num += item6.TotalAmount;
                    }
                }
                pooledDictionary4[item5] = num;
            }
            foreach (Tag item7 in pooledList2)
            {
                if (!pooledDictionary2.ContainsKey(item7))
                {
                    pooledDictionary2[item7] = WorldInventory.Instance.GetTotalAmount(item7);
                }
                if (!pooledDictionary3.ContainsKey(item7))
                {
                    pooledDictionary3[item7] = WorldInventory.Instance.GetAmount(item7);
                }
            }
            foreach (FetchList2 item8 in item.Value)
            {
                bool should_add  = false;
                bool should_add2 = true;
                bool should_add3 = false;
                Dictionary <Tag, float> remaining2 = item8.GetRemaining();
                foreach (KeyValuePair <Tag, float> item9 in remaining2)
                {
                    Tag   key           = item9.Key;
                    float value2        = item9.Value;
                    float num2          = pooledDictionary4[key];
                    float b             = pooledDictionary2[key];
                    float num3          = pooledDictionary3[key];
                    float num4          = Mathf.Min(value2, b);
                    float num5          = num3 + num4;
                    float minimumAmount = item8.GetMinimumAmount(key);
                    if (num2 + num5 < minimumAmount)
                    {
                        should_add = true;
                    }
                    if (num5 < value2)
                    {
                        should_add2 = false;
                    }
                    if (num2 + num5 > value2 && value2 > num5)
                    {
                        should_add3 = true;
                    }
                }
                item8.UpdateStatusItem(Db.Get().BuildingStatusItems.WaitingForMaterials, ref item8.waitingForMaterialsHandle, should_add2);
                item8.UpdateStatusItem(Db.Get().BuildingStatusItems.MaterialsUnavailable, ref item8.materialsUnavailableHandle, should_add);
                item8.UpdateStatusItem(Db.Get().BuildingStatusItems.MaterialsUnavailableForRefill, ref item8.materialsUnavailableForRefillHandle, should_add3);
            }
            pooledDictionary4.Recycle();
            pooledList3.Recycle();
            pooledList2.Recycle();
            item.Value.Recycle();
        }
        pooledDictionary3.Recycle();
        pooledDictionary2.Recycle();
        pooledDictionary.Recycle();
    }
Beispiel #13
0
    private void GetBuildableStates(bool force_update)
    {
        if (Assets.BuildingDefs != null && Assets.BuildingDefs.Count != 0)
        {
            if (timeSinceNotificationPing < specialNotificationEmbellishDelay)
            {
                timeSinceNotificationPing += Time.unscaledDeltaTime;
            }
            if (timeSinceNotificationPing >= notificationPingExpire)
            {
                notificationPingCount = 0;
            }
            int num = 10;
            if (force_update)
            {
                num = Assets.BuildingDefs.Count;
                buildable_state_update_idx = 0;
            }
            ListPool <HashedString, PlanScreen> .PooledList pooledList = ListPool <HashedString, PlanScreen> .Allocate();

            for (int i = 0; i < num; i++)
            {
                buildable_state_update_idx = (buildable_state_update_idx + 1) % Assets.BuildingDefs.Count;
                BuildingDef buildingDef = Assets.BuildingDefs[buildable_state_update_idx];
                if (!buildingDef.Deprecated && tagCategoryMap.TryGetValue(buildingDef.Tag, out HashedString value))
                {
                    RequirementsState requirementsState = RequirementsState.Complete;
                    if (!DebugHandler.InstantBuildMode && !Game.Instance.SandboxModeActive)
                    {
                        if (!Db.Get().TechItems.IsTechItemComplete(buildingDef.PrefabID))
                        {
                            requirementsState = RequirementsState.Tech;
                        }
                        else if (!ProductInfoScreen.MaterialsMet(buildingDef.CraftRecipe))
                        {
                            requirementsState = RequirementsState.Materials;
                        }
                    }
                    if (!buildableDefs.ContainsKey(buildingDef))
                    {
                        buildableDefs.Add(buildingDef, requirementsState);
                    }
                    else if (buildableDefs[buildingDef] != requirementsState)
                    {
                        buildableDefs[buildingDef] = requirementsState;
                        if ((UnityEngine.Object)productInfoScreen.currentDef == (UnityEngine.Object)buildingDef)
                        {
                            ignoreToolChangeMessages++;
                            productInfoScreen.ClearProduct(false);
                            productInfoScreen.Show(true);
                            productInfoScreen.ConfigureScreen(buildingDef);
                            ignoreToolChangeMessages--;
                        }
                        if (requirementsState == RequirementsState.Complete)
                        {
                            foreach (ToggleInfo item in toggleInfo)
                            {
                                HashedString x = (HashedString)item.userData;
                                if (x == value)
                                {
                                    string   text      = "NotificationPing";
                                    Animator component = item.toggle.GetComponent <Animator>();
                                    if (!component.GetCurrentAnimatorStateInfo(0).IsTag(text) && !pooledList.Contains(value))
                                    {
                                        pooledList.Add(value);
                                        item.toggle.gameObject.GetComponent <Animator>().Play(text);
                                        if (KTime.Instance.UnscaledGameTime - initTime > 1.5f)
                                        {
                                            if (timeSinceNotificationPing >= specialNotificationEmbellishDelay)
                                            {
                                                string sound = GlobalAssets.GetSound("NewBuildable_Embellishment", false);
                                                if (sound != null)
                                                {
                                                    EventInstance instance = SoundEvent.BeginOneShot(sound, SoundListenerController.Instance.transform.GetPosition());
                                                    SoundEvent.EndOneShot(instance);
                                                }
                                            }
                                            string sound2 = GlobalAssets.GetSound("NewBuildable", false);
                                            if (sound2 != null)
                                            {
                                                EventInstance instance2 = SoundEvent.BeginOneShot(sound2, SoundListenerController.Instance.transform.GetPosition());
                                                instance2.setParameterValue("playCount", (float)notificationPingCount);
                                                SoundEvent.EndOneShot(instance2);
                                            }
                                        }
                                        timeSinceNotificationPing = 0f;
                                        notificationPingCount++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            pooledList.Recycle();
        }
    }
 public bool ListPool()
 {
     return(_listPool.Contains(N / 2));
 }
Beispiel #15
0
 public void ListPool()
 {
     _listPool.Contains(N / 2);
 }