示例#1
0
        private void AssertValidID(Entity.Id id)
        {
            int index = (int)id.Index;

            Debug.Assert(index < m_EntityComponentMasks.Count, "entity ID outside vector range");
            Debug.Assert(m_EntityVersions[index] == id.Version, "attempt to access Entity via a stale entity id");
        }
示例#2
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);
        }
示例#3
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));
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        public void Destroy(Entity.Id entity)
        {
            AssertValidID(entity);
            int           index = (int)entity.Index;
            ComponentMask mask  = m_EntityComponentMasks[index];

            for (int i = 0; i < m_ComponentHelpers.Count; i++)
            {
                BaseComponentHelper helper = m_ComponentHelpers[i];
                if (helper != null && mask[i])
                {
                    helper.RemoveComponent(new Entity(this, entity));
                }
            }
            m_EntityComponentMasks[index].Reset();
            m_EntityVersions[index]++;
            m_FreeList.Add((uint)index);
        }
示例#7
0
 private Entity Get(Entity.Id id)
 {
     AssertValidID(id);
     return(new Entity(this, id));
 }
示例#8
0
 internal bool Valid(Entity.Id id)
 {
     return((int)id.Index < m_EntityVersions.Count && m_EntityVersions[(int)id.Index] == id.Version);
 }
示例#9
0
 internal bool Matches(Entity.Id m_ID, ComponentMask mask)
 {
     return((m_EntityComponentMasks[(int)m_ID.Index] & mask) == mask);
 }
示例#10
0
 internal ComponentMask ComponentMask(Entity.Id id)
 {
     AssertValidID(id);
     return(m_EntityComponentMasks.ElementAt((int)id.Index));
 }