Exemplo n.º 1
0
        // This shouldn't be public, since it doesn't do proper add/remove from systems.
        private Component GetOrAllocateComponentAndUpdateBitField(Entity e, int componentTypeId, out bool allocatedNew)
        {
            //int liveIndex = liveIdRoster[e.LiveId];
            int liveIndex = e.LiveId;

            Debug.Assert(e == entityPool[liveIndex], "Entity has wrong id");
            ComponentManagerBase componentManager = componentManagers[componentTypeId];

#if ALTERNATE_LAYOUT
            int index = liveIndex + componentTypeId * MaxEntities;
#else
            int index = liveIndex * EntityManager.MaxComponentTypes + componentTypeId;
#endif
            int componentTypeLookupId = componentLookupIdsPerEntity[index];
            if (componentTypeLookupId == -1)
            {
                // Allocate a new component for this entity
                short     componentLookupId;
                Component component = componentManager.AllocateComponentForEntity(e, out componentLookupId);
                componentLookupIdsPerEntity[index] = componentLookupId;
                allocatedNew = true;

                // Make sure the entity is tagged as having this component
                e.ComponentTypesBitField |= ComponentTypeIdHelper.GetBit(componentTypeId);

                return(component);
            }
            else
            {
                // Retrieve
                allocatedNew = false;
                return(componentManager.GetComponentAt(componentTypeLookupId));
            }
        }
Exemplo n.º 2
0
        public Component GetComponent(int entityLiveId, int componentTypeId)
        {
            ComponentManagerBase componentManager = componentManagers[componentTypeId];

#if ALTERNATE_LAYOUT
            int componentTypeLookupId = componentLookupIdsPerEntity[entityLiveId + componentTypeId * MaxEntities];
#else
            int componentTypeLookupId = componentLookupIdsPerEntity[liveIndex * EntityManager.MaxComponentTypes + componentTypeId];
#endif
            return((componentTypeLookupId != -1) ? componentManager.GetComponentAt(componentTypeLookupId) : null);
        }
Exemplo n.º 3
0
        // Returns null if no such component.
        public Component GetComponent(Entity e, int componentTypeId)
        {
            int liveIndex = e.LiveId;

            Debug.Assert(e == entityPool[liveIndex], "Entity has wrong id");

            ComponentManagerBase componentManager = componentManagers[componentTypeId];

#if ALTERNATE_LAYOUT
            int componentTypeLookupId = componentLookupIdsPerEntity[liveIndex + componentTypeId * MaxEntities];
#else
            int componentTypeLookupId = componentLookupIdsPerEntity[liveIndex * EntityManager.MaxComponentTypes + componentTypeId];
#endif
            return((componentTypeLookupId != -1) ? componentManager.GetComponentAt(componentTypeLookupId) : null);
        }