public static ComponentMask Get <C1>()
        {
            ComponentMask mask = new ComponentMask();

            mask[1 << ComponentIndexer.GetFamily <C1>()] = true;
            return(mask);
        }
Exemple #2
0
        private ComponentPool <C> AccommodateComponent <C>() where C : class, IComponent, new()
        {
            int family = ComponentIndexer.GetFamily <C>();

            if (m_ComponentPools.Count <= family)
            {
                m_ComponentPools.Resize(family + 1, null);
            }
            if (m_ComponentPools[family] == null)
            {
                ComponentPool <C> pool = new ComponentPool <C>();
                pool.Expand((int)m_IndexCounter);
                m_ComponentPools[family] = pool;
            }
            if (m_ComponentHelpers.Count <= family)
            {
                m_ComponentHelpers.Resize(family + 1, null);
            }
            if (m_ComponentHelpers[family] == null)
            {
                ComponentHelper <C> helper = new ComponentHelper <C>();
                m_ComponentHelpers[family] = helper;
            }
            return((ComponentPool <C>)m_ComponentPools[family]);
        }
        public static ComponentMask Get <C1, C2, C3, C4, C5>()
        {
            ComponentMask mask = new ComponentMask();

            mask[1 << ComponentIndexer.GetFamily <C1>()] = true;
            mask[1 << ComponentIndexer.GetFamily <C2>()] = true;
            mask[1 << ComponentIndexer.GetFamily <C3>()] = true;
            mask[1 << ComponentIndexer.GetFamily <C4>()] = true;
            mask[1 << ComponentIndexer.GetFamily <C5>()] = true;
            return(mask);
        }
Exemple #4
0
        public EntityContext()
        {
            if (!SystemIndexer.Indexed)
            {
                SystemIndexer.Index();
            }
            if (!ComponentIndexer.Indexed)
            {
                ComponentIndexer.Index();
            }

            m_CachedEntityChanged = UpdateGroupsComponentAddedOrRemoved;
        }
Exemple #5
0
        internal int Remove <C>(Entity.Id id) where C : class, IComponent, new()
        {
            int entityId = (int)id.Index;
            int family   = ComponentIndexer.GetFamily <C>();

            ComponentMask mask = m_EntityComponentMasks[entityId];

            mask[1 << family] = false;
            m_EntityComponentMasks[entityId] = mask;

            ComponentPool <C> pool = (ComponentPool <C>)m_ComponentPools[family];

            pool.Destroy(entityId);

            return(entityId);
        }
Exemple #6
0
        internal C Component <C>(Entity.Id id) where C : class, IComponent, new()
        {
            AssertValidID(id);
            int family = ComponentIndexer.GetFamily <C>();

            if (family >= m_ComponentPools.Count)
            {
                return(default(C));
            }
            BaseComponentPool pool = m_ComponentPools[family];

            if (pool == null || !m_EntityComponentMasks[(int)id.Index][1 << family])
            {
                return(default(C));
            }
            return(((ComponentPool <C>)pool).Get((int)id.Index));
        }
Exemple #7
0
        internal int Assign <C>(Entity.Id id, C c) where C : class, IComponent, new()
        {
            AssertValidID(id);
            int           family   = ComponentIndexer.GetFamily <C>();
            int           entityId = (int)id.Index;
            ComponentMask mask     = m_EntityComponentMasks[entityId];

            Debug.Assert(!mask[1 << family]);

            ComponentPool <C> pool = AccommodateComponent <C>();

            pool.Put(c, entityId);

            mask[1 << family] = true;
            m_EntityComponentMasks[entityId] = mask;

            return(entityId);
        }
Exemple #8
0
        internal bool HasComponent <C>(Entity.Id id)
        {
            AssertValidID(id);
            int family = ComponentIndexer.GetFamily <C>();

            // We don't bother checking the component mask, as we return a nullptr anyway.
            if (family >= m_ComponentPools.Count)
            {
                return(false);
            }
            BaseComponentPool pool = m_ComponentPools[family];

            if (pool == null || !m_EntityComponentMasks[(int)id.Index][family])
            {
                return(false);
            }
            return(true);
        }