Example #1
0
        public static void RegisterAll()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            IEnumerable <Type> classTypes     = asm.GetTypes().Where(type => type.Namespace.EndsWith(ClassNamespace));
            IEnumerable <Type> componentTypes = asm.GetTypes().Where(type => type.Namespace.EndsWith(ComponentsNamespace));

            using (var enumerator = componentTypes.GetEnumerator()) {
                while (enumerator.MoveNext())
                {
                    var value = new AbstractComponent(enumerator.Current);
                    Components.Add(enumerator.Current, value);
                    HashSets.Add(value.HashCode, enumerator.Current);
                    Console.WriteLine($"Registry::Components\t::Add({value.ComponentType.Name}:{value.HashCode})");
                }
            }

            using (var enumerator = classTypes.GetEnumerator()) {
                while (enumerator.MoveNext())
                {
                    var value = new AbstractClass(enumerator.Current);
                    Classes.Add(enumerator.Current, value);
                    HashSets.Add(value.HashCode, enumerator.Current);
                    Console.WriteLine($"Registry::Classes\t::Add({value.ClassType.Name}({string.Join(", ", value.Components)}):{value.HashCode})");
                }
            }
        }
Example #2
0
        public void DebugClass <T>()
        {
            AbstractClass abstractClass = Registry.DirectClassSearch <T>();
            var           wrappers      = _containers[abstractClass.HashCode];

            for (int i = 0; i < wrappers.Length; i++)
            {
                Console.WriteLine(wrappers[i]);
            }
        }
Example #3
0
        /// <summary>
        /// Adds a new instance of a class and pushes it onto the end of
        /// the stack
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void CreateEntity <T>()
        {
            AbstractClass abstractClass = Registry.DirectClassSearch <T>();
            var           wrappers      = _containers[abstractClass.HashCode];

            for (int i = 0; i < wrappers.Length; i++)
            {
                wrappers[i].Add();
            }

            Console.WriteLine($"EcsTable::Created\t::{abstractClass.ClassType.Name} from {typeof(T).Name}");
        }
Example #4
0
        public EcsTable()
        {
            _containers = new Dictionary <uint, ValueWrapper[]>();

            var classes = Registry.GetAllClasses();

            for (int i = 0; i < classes.Length; i++)
            {
                AbstractClass  abstractClass = classes[i];
                ValueWrapper[] wrappers      = new ValueWrapper[abstractClass.Components.Length];

                for (int j = 0; j < wrappers.Length; j++)
                {
                    wrappers[j] = new ValueWrapper(Registry.GetComponent(abstractClass.Components[j]).ComponentType, abstractClass.ClassType);
                }

                _containers.Add(abstractClass.HashCode, wrappers);
            }
        }
Example #5
0
        public ContainerIterator GetIterator()
        {
            AbstractClass[]   classes = Registry.LazyClassesSearch(_components);
            List <RefArray[]> arrays  = new List <RefArray[]>();

            for (int i = 0; i < classes.Length; i++)
            {
                AbstractClass c    = classes[i];
                bool          done = false;

                for (int j = 0; j < _SOAs.Length; j++)
                {
                    TypeQueryResultValue result = _SOAs[j];
                    for (int k = 0; k < _components.Length; k++)
                    {
                        if (_SOAs[i].HashCode == c.HashCode)
                        {
                            RefArray[] classArgs = _SOAs[i].ComponentArrays;

                            if (classArgs.Length == 0)
                            {
                                continue;
                            }

                            arrays.Add(classArgs);
                            done = true;
                            Console.WriteLine("Added: " + c.ClassType.FullName);
                            break;
                        }
                    }

                    if (done)
                    {
                        break;
                    }
                }
            }

            return(new ContainerIterator(arrays.ToArray()));
        }