Пример #1
0
        public ComponentSet(World world)
        {
            entities   = new SparseSet();
            components = new PagedArray <T>();

            world.OnEntityRemoved += OnEntityRemoved;
        }
Пример #2
0
        /// <summary>
        /// constructs an instance of <see cref="SafeSystemSchedule"/>
        /// </summary>
        /// <param name="laneCount">the number of concurrent systems that can be run</param>
        /// <param name="type">the type of systems for this schedule</param>
        /// <param name="pagePower">the size of the storage pages as a power of 2, larger is closer to a flat array, but costs more memory</param>
        /// <param name="pageCount">the number of pages to initialize to start</param>
        public SafeSystemSchedule(SystemType type, int laneCount, int pagePower = 8, int pageCount = 1)
        {
            //initialize all fields
            _laneCount = laneCount;
            _lanes     = new SystemInfo[laneCount];
            _running   = new bool[laneCount];
            _type      = type;

            _systemCache = new PagedArray <SystemInfo>(pagePower, pageCount);
            _entries     = new PagedArray <Entry>(pagePower, pageCount);
        }
Пример #3
0
        /// <summary>
        /// copies an instance of <see cref="SafeSystemSchedule"/>
        /// </summary>
        /// <param name="copy">the schedule to copy</param>
        public SafeSystemSchedule(SafeSystemSchedule copy)
        {
            if (copy == null)
            {
                throw new ArgumentNullException(nameof(copy));
            }
            //copy int values
            _count     = copy._count;
            _next      = copy._next;
            _top       = copy._top;
            _start     = copy._start;
            _end       = copy._end;
            _rrStart   = copy._rrStart;
            _rrEnd     = copy._rrEnd;
            _laneCount = copy._laneCount;

            //initialize int arrays
            _lanes   = new SystemInfo[_laneCount];
            _running = new bool[_laneCount];

            //copy values in lane arrays
            for (int i = 0; i < _laneCount; i++)
            {
                _lanes[i]   = copy._lanes[i];
                _running[i] = copy._running[i];
            }

            //copy storage arrays
            _systemCache = new PagedArray <SystemInfo>(copy._entries.PagePower, copy._entries.PageCount);
            _entries     = new PagedArray <Entry>(copy._entries.PagePower, copy._entries.PageCount);

            for (int i = 0; i < _top; i++)
            {
                _systemCache[i] = copy._systemCache[i];
                _entries[i]     = copy._entries[i];
            }

            //copy run recurrences
            for (int i = 0; i < copy._runRecurrences.Count; i++)
            {
                _runRecurrences.Add(copy._runRecurrences[i]);
            }

            //copy free space queue
            for (int i = 0; i < copy.freeSpace.Count; i++)
            {
                int space = copy.freeSpace.Dequeue();
                freeSpace.Enqueue(space);
                copy.freeSpace.Enqueue(space);
            }
        }
Пример #4
0
 /// <summary>
 /// Constructs an entity buffer
 /// </summary>
 /// <param name="entityHash">the hash value for the entity hash table, larger means faster name searches but more memory</param>
 /// <param name="systemLinkHash">the hash value for system link hash table, larger means faster search but more memory</param>
 /// <param name="entityPagePower">the size of the entity pages in the form of a power of 2</param>
 /// <param name="entityPageCount">the initial number of entity pages, this has a small affect on early performance</param>
 /// <param name="entityComponentPagePower">the size of the entity component pages in the form of a power of 2</param>
 /// <param name="entityComponentPageCount">the initial number of entity pages, this has a small affect on early performance</param>
 /// <param name="entityListPagePower">the size of the entity list pages in the form of a power of 2</param>
 /// <param name="entityListPageCount">the initial number of entity pages, this has a small affect on early performance</param>
 /// <param name="systemLinkPagePower">the size of the systemlink pages in the form of a power of 2</param>
 /// <param name="systemLinkPageCount">the initial number of entity pages, this has a small affect on early performance</param>
 /// <param name="componentTypes">The registry for component types which is used to get type IDs if a system is registered before its type ids are filled out</param>
 public EntityBuffer(IComponentTypeRegistry componentTypes, int entityHash = 47, int systemLinkHash = 47, int entityPagePower = 8,
                     int entityComponentPagePower = 8, int entityListPagePower = 8, int systemLinkPagePower = 8, int entityPageCount = 1,
                     int entityComponentPageCount = 1, int entityListPageCount = 1, int systemLinkPageCount = 1)
 {
     _entities       = new NamedDataRegistry <BufferedBinarySearchTree <EntityLink> >(entityPagePower, entityPageCount, entityHash);
     _links          = new PagedArray <SystemLink>(systemLinkPagePower, systemLinkPageCount);
     _lists          = new PagedArray <EntityList>(systemLinkPagePower, systemLinkPageCount);
     _hashVal        = systemLinkHash;
     _starts         = new int[_hashVal];
     _ends           = new int[_hashVal];
     _listPower      = entityListPagePower;
     _listPages      = entityListPageCount;
     _entityPower    = entityComponentPagePower;
     _entityPages    = entityComponentPageCount;
     _componentTypes = componentTypes;
 }
Пример #5
0
        public static void Run()
        {
            PrecisionTimer timer = new PrecisionTimer();
            //CompleteBinarySearchTree<int> test = new CompleteBinarySearchTree<int>(10, 1);

            int count = 16384;

            //timer.Start();
            //for (int i = 0; i < count; i++)
            //        test.Add(i, i);
            //timer.Stop();



            double time = timer.ElapsedSeconds / count;

            int[]            testArray = new int[count];
            PagedArray <int> testPaged = new PagedArray <int>(14, 1);

            testPaged[int.MaxValue] = 1;
            int a = 0;
            IEnumerator <int> enumer = testPaged.GetEnumerator();

            timer.Reset();
            //Console.ReadLine();
            timer.Start();
            while (enumer.MoveNext())
            //foreach (int i in testArray)
            {
                //timer.Stop();
                //Console.WriteLine(i);
                //timer.Start();
                a = enumer.Current;
                //a = i;
            }
            timer.Stop();
            //Console.WriteLine(a);

            //Console.WriteLine(time);
            //Console.WriteLine(time * count);
            //Console.WriteLine(time / (1.0 / 60.0) * 100);
            Console.WriteLine(timer.ElapsedSeconds / count);
            Console.WriteLine(timer.ElapsedSeconds);
            Console.WriteLine(timer.ElapsedSeconds / (1.0 / 60.0) * 100);
            Console.WriteLine(1.0 / 60.0);
            Console.ReadLine();
        }
Пример #6
0
        public static void Run()
        {
            PrecisionTimer   timer = new PrecisionTimer();
            PagedArray <int> paged = new PagedArray <int>(2, 64);

            int[] normy = new int[2048];

            normy[0]  = 1;
            normy[15] = 1;
            paged[0]  = 1;
            paged[15] = 1;
            for (int i = 0; i < 1; i++)
            {
                timer.Reset();
                timer.Start();
                Array.Copy(normy, 0, normy, 34, 16);
                timer.Stop();
            }

            Console.WriteLine(timer.ElapsedSecondsF);

            paged[50] = 0;

            for (int i = 0; i < 1; i++)
            {
                timer.Reset();

                timer.Start();
                paged.CopyData(0, 16, 34);
                timer.Stop();
            }

            Console.WriteLine(timer.ElapsedSecondsF);

            Console.ReadLine();
        }