Ejemplo n.º 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");
        }
Ejemplo n.º 2
0
        internal void 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        internal C 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(c);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 private Entity Get(Entity.Id id)
 {
     AssertValidID(id);
     return(new Entity(this, id));
 }
Ejemplo n.º 8
0
 internal bool Valid(Entity.Id id)
 {
     return((int)id.Index < m_EntityVersions.Count && m_EntityVersions[(int)id.Index] == id.Version);
 }
Ejemplo n.º 9
0
 internal bool Matches(Entity.Id m_ID, ComponentMask mask)
 {
     return((m_EntityComponentMasks[(int)m_ID.Index] & mask) == mask);
 }
Ejemplo n.º 10
0
 internal ComponentMask ComponentMask(Entity.Id id)
 {
     AssertValidID(id);
     return(m_EntityComponentMasks.ElementAt((int)id.Index));
 }