Exemple #1
0
 internal void CreateComponentTypesFrom(List <TypeInfo> componentTypeInfos)
 {
     foreach (var componentTypeInfo in componentTypeInfos)
     {
         var type          = componentTypeInfo.AsType();
         var componentType = new EntityComponentType(type);
         _componentTypes.Add(type, componentType);
     }
 }
Exemple #2
0
        private void CreateComponentPool(EntityComponentType componentType, int initialSize, ObjectPoolIsFullPolicy isFullPolicy)
        {
            Debug.Assert(componentType != null);
            Debug.Assert(initialSize > 0);
            Debug.Assert(!_componentPoolsByComponentTypeIndex.ContainsKey(componentType.Index));

            var poolType      = typeof(ComponentPool <>).MakeGenericType(componentType.Type);
            var componentPool = (IComponentPool)_dependencyResolver.Resolve(poolType, initialSize, isFullPolicy);

            _componentPoolsByComponentTypeIndex.Add(componentType.Index, componentPool);
        }
Exemple #3
0
        internal void MarkComponentToBeRemoved(Entity entity, EntityComponentType componentType)
        {
            Debug.Assert(entity != null);
            Debug.Assert(componentType != null);

            var pair = new EntityComponentTypePair(entity, componentType);

            if (!_componentsToRemove.Contains(pair))
            {
                _componentsToRemove.Add(pair);
            }
        }
Exemple #4
0
        internal EntityComponent GetComponent(Entity entity, EntityComponentType componentType)
        {
            Debug.Assert(entity != null);
            Debug.Assert(componentType != null);

            var components = _componentTypeEntitiesToComponents[componentType.Index];


            EntityComponent component = null;

            components?.TryGetValue(entity, out component);
            return(component);
        }
Exemple #5
0
        internal EntityComponent AddComponent(Entity entity, EntityComponentType componentType)
        {
            Debug.Assert(entity != null);
            Debug.Assert(componentType != null);

            if (componentType.Index >= _componentTypeEntitiesToComponents.Capacity)
            {
                _componentTypeEntitiesToComponents[componentType.Index] = null;
            }
            var components = _componentTypeEntitiesToComponents[componentType.Index];

            if (components == null)
            {
                _componentTypeEntitiesToComponents[componentType.Index] = components = new Dictionary <Entity, EntityComponent>();
            }

            EntityComponent component;

            IComponentPool componentPool;

            if (_componentPoolsByComponentTypeIndex.TryGetValue(componentType.Index, out componentPool))
            {
                component = componentPool.New();
                if (component == null)
                {
                    return(null);
                }
            }
            else
            {
                component = _dependencyResolver.Resolve <EntityComponent>(componentType.Type);
            }

            component.Entity   = entity;
            components[entity] = component;

            entity.ComponentBits[componentType.Index] = true;

            MarkEntityToBeRefreshed(entity);

            return(component);
        }
Exemple #6
0
        internal EntityComponent GetComponent(Entity entity, EntityComponentType componentType)
        {
            Debug.Assert(entity != null);
            Debug.Assert(componentType != null);

            if (componentType.Index >= _componentTypeEntitiesToComponents.Count)
            {
                return(null);
            }

            var components = _componentTypeEntitiesToComponents[componentType.Index];

            if (components == null)
            {
                return(null);
            }

            EntityComponent component;

            components.TryGetValue(entity, out component);
            return(component);
        }
Exemple #7
0
 public EntityComponentTypePair(Entity entity, EntityComponentType componentType)
 {
     Entity        = entity;
     ComponentType = componentType;
 }