Beispiel #1
0
        void updateGroupsComponentAddedOrRemoved(IEntity entity, int index, IComponent component)
        {
            var groups = _groupsForIndex[index];

            if (groups != null)
            {
                var events = EntitasCache.GetGroupChangedList <TEntity>();

                var tEntity = (TEntity)entity;

                for (int i = 0; i < groups.Count; i++)
                {
                    events.Add(groups[i].HandleEntity(tEntity));
                }

                for (int i = 0; i < events.Count; i++)
                {
                    var groupChangedEvent = events[i];
                    if (groupChangedEvent != null)
                    {
                        groupChangedEvent(
                            groups[i], tEntity, index, component
                            );
                    }
                }

                EntitasCache.PushGroupChangedList <TEntity>(events);
            }
        }
Beispiel #2
0
        static int[] distinctIndices(IList <int> indices)
        {
            var indicesSet = EntitasCache.GetIntHashSet();

            foreach (var index in indices)
            {
                indicesSet.Add(index);
            }
            var uniqueIndices = new int[indicesSet.Count];

            indicesSet.CopyTo(uniqueIndices);
            Array.Sort(uniqueIndices);

            EntitasCache.PushIntHashSet(indicesSet);

            return(uniqueIndices);
        }
Beispiel #3
0
        /// Returns all indices of added components.
        public int[] GetComponentIndices()
        {
            if (_componentIndicesCache == null)
            {
                var indices = EntitasCache.GetIntList();

                for (int i = 0; i < _components.Length; i++)
                {
                    if (_components[i] != null)
                    {
                        indices.Add(i);
                    }
                }

                _componentIndicesCache = indices.ToArray();

                EntitasCache.PushIntList(indices);
            }

            return(_componentIndicesCache);
        }
Beispiel #4
0
        /// Returns all added components.
        public IComponent[] GetComponents()
        {
            if (_componentsCache == null)
            {
                var components = EntitasCache.GetIComponentList();

                for (int i = 0; i < _components.Length; i++)
                {
                    var component = _components[i];
                    if (component != null)
                    {
                        components.Add(component);
                    }
                }

                _componentsCache = components.ToArray();

                EntitasCache.PushIComponentList(components);
            }

            return(_componentsCache);
        }
Beispiel #5
0
        static int[] mergeIndices(int[] allOfIndices, int[] anyOfIndices, int[] noneOfIndices)
        {
            var indicesList = EntitasCache.GetIntList();

            if (allOfIndices != null)
            {
                indicesList.AddRange(allOfIndices);
            }
            if (anyOfIndices != null)
            {
                indicesList.AddRange(anyOfIndices);
            }
            if (noneOfIndices != null)
            {
                indicesList.AddRange(noneOfIndices);
            }

            var mergedIndices = distinctIndices(indicesList);

            EntitasCache.PushIntList(indicesList);

            return(mergedIndices);
        }