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"); }
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); }
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)); }
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); }
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); }
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); }
private Entity Get(Entity.Id id) { AssertValidID(id); return(new Entity(this, id)); }
internal bool Valid(Entity.Id id) { return((int)id.Index < m_EntityVersions.Count && m_EntityVersions[(int)id.Index] == id.Version); }
internal bool Matches(Entity.Id m_ID, ComponentMask mask) { return((m_EntityComponentMasks[(int)m_ID.Index] & mask) == mask); }
internal ComponentMask ComponentMask(Entity.Id id) { AssertValidID(id); return(m_EntityComponentMasks.ElementAt((int)id.Index)); }