Example #1
0
        public NodeFamily()
        {
            type      = typeof(T);
            activator = ObjectActivatorHelpers.GetActivator <T>();

            var fields = type.GetFields();

            foreach (var field in fields)
            {
                if (field.IsInitOnly || field.IsLiteral || field.IsStatic || !field.IsPublic)
                {
                    continue;
                }

                fieldTypes.Add(field);
                fieldSet.Add(field);
            }

            ConstituentTypes = new ConstituentTypes(fieldSet.Select(f => f.FieldType));
            isTuple          = type.Name.StartsWith(TUPLE_NAME);
            if (isTuple)
            {
                genericTypeArguments = type.GenericTypeArguments;
            }
        }
Example #2
0
        public void OnComponentAdded(Entity entity, object component)
        {
            if (!ConstituentTypes.Contains(component.GetType()))
            {
                return;
            }

            AddIfMatch(entity);
        }
Example #3
0
        public void OnComponentRemoved(Entity entity, object component)
        {
            //If the component isn't important, ignore it
            if (!ConstituentTypes.Contains(component.GetType()))
            {
                return;
            }

            //If it was, remove it
            Remove(entity);
        }
        internal void Register(ConstituentTypes types)
        {
            if (types.Count == 0)
            {
                return;
            }

            if (familyTypes.ContainsKey(types))
            {
                return;
            }

            var instance = defaultFamilyActivator(types);

            familyTypes.Add(types, instance);
            families.AddLast(instance);
        }
Example #5
0
 public SophisticatedFamily(ConstituentTypes constituentTypes)
 {
     ConstituentTypes = constituentTypes;
 }
 public IFamily Get(ConstituentTypes constituentTypes)
 {
     //TODO Sets don't hash to the same value
     return(familyTypes[constituentTypes]);
 }