Esempio n. 1
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            IdToSystems.Clear();
            SystemsToId.Clear();
            foreach (var kvp in ArchetypeToSystems)
            {
                kvp.Value.Dispose();
            }

            ArchetypeToSystems.Clear();

            CustomSerializer?.Dispose();
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            var groupLength = m_Groups.Count;

            m_CachedDictionaryEventKeepIds.Clear();

            // Remove automatically groups with 0 entities in it
            // If none are found, we remove the group from the list.
            // If an entity is attached to the group with the same id, we use another version of this id (a là Entity class)
            for (int i = 0; i != m_EntityGroup.Length; i++)
            {
                var group = m_EntityGroup.EntityGroups[i];
                m_CachedDictionaryEventKeepIds[group.ReferenceId] = true;
            }
            for (int i = 0; i != m_MaxId; i++)
            {
                if (m_Groups.FastTryGet(i, out var _) &&
                    !m_CachedDictionaryEventKeepIds.FastTryGet(i, out var __))
                {
                    var group = m_Groups[i];

                    Debug.Log($"Group({i}, {group.Version}) was unused, so it was removed.");

                    group.IsCreated = false;
                    group.Version++;

                    m_PooledGroups.Enqueue(group);
                    m_Groups.Remove(i);
                }
            }
        }
Esempio n. 3
0
        public void TestFastDictionary()
        {
            var facit = new Dictionary <int, string>();
            var fast  = new FastDictionary <int, string>();

            for (int r = 0; r < 1000000; r++)
            {
                var rnd = PRNG.Next(0, 13);
                switch (rnd)
                {
                case 0:
                    facit.Clear();
                    fast.Clear();
                    break;

                case 1:
                case 2:
                {
                    // add/change using indexer
                    int key;
                    if (facit.Count > 2 && PRNG.Next(0, 100) < 20)
                    {
                        key = GetRandomKey(facit);
                    }
                    else
                    {
                        key = PRNG.Next(1, 1000);
                    }
                    facit[key] = key.ToString();
                    fast[key]  = key.ToString();
                    break;
                }

                case 3:
                case 4:
                    // add using Add()
                    int b = PRNG.Next(1, 1000);
                    if (facit.ContainsKey(b) == false)
                    {
                        facit.Add(b, b.ToString());
                        fast.Add(b, b.ToString());
                    }
                    break;

                case 5:
                case 6:
                {
                    // add using GetOrInit()
                    int     c      = PRNG.Next(0, 1000);
                    bool    exists = facit.ContainsKey(c);
                    ref var str    = ref fast.GetOrInit(c, out bool wasCreated);
                    Assert.AreEqual(exists, !wasCreated);
                    str = c.ToString();
                    if (!exists)
                    {
                        facit[c] = c.ToString();
                    }
                    break;
                }
Esempio n. 4
0
        protected override void OnDestroyManager()
        {
            m_ApplyGroupIdFromSceneGroupIds.Clear();
            m_Groups.Clear();
            m_PooledGroups.Clear();

            m_ApplyGroupIdFromSceneGroupIds = null;
            m_Groups = null;
        }