Ejemplo n.º 1
0
        public ComponentSet(World world)
        {
            entities   = new SparseSet();
            components = new PagedArray <T>();

            world.OnEntityRemoved += OnEntityRemoved;
        }
        public void SparseSet_Stress_Test()
        {
            var set = new SparseSet(1000, 1000);

            var random         = new Random();
            var testCollection = Enumerable.Range(0, 1000)
                                 .OrderBy(x => random.Next())
                                 .ToList();

            foreach (var element in testCollection)
            {
                set.Add(element);
            }

            foreach (var element in testCollection)
            {
                Assert.IsTrue(set.HasItem(element));
            }

            foreach (var element in testCollection)
            {
                Assert.IsTrue(set.HasItem(element));
                set.Remove(element);
                Assert.IsFalse(set.HasItem(element));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a factory that provides ECS funcitonality.
        /// </summary>
        /// <param name="entityCapacity">The total of amount of entities supported by this factory.</param>
        /// <param name="componentCapacity">The total of amount of unique <see cref="IComponent"/> types supported by this factory.</param>
        /// <param name="systemCapacity">The total of amount of unique <see cref="MorroSystem"/> types supported by this factory.</param>
        public MorroFactory(uint entityCapacity, uint componentCapacity, uint systemCapacity)
        {
            EntityCapacity    = entityCapacity;
            ComponentCapacity = componentCapacity;
            SystemCapacity    = systemCapacity;

            componentAddition    = new Queue <Tuple <uint, IComponent[]> >((int)EntityCapacity);
            componentSubtraction = new Queue <Tuple <uint, Type[]> >((int)EntityCapacity);
            entityRemovalQueue   = new SparseSet(EntityCapacity);

            // System Setup
            systems      = new MorroSystem[SystemCapacity];
            systemLookup = new Dictionary <Type, uint>((int)SystemCapacity);

            // Component Setup
            componentData   = new IComponent[ComponentCapacity][];
            componentLookup = new Dictionary <Type, uint>((int)ComponentCapacity);

            for (int i = 0; i < ComponentCapacity; i++)
            {
                componentData[i] = new IComponent[EntityCapacity];
            }

            // Entity Setup
            attachedComponents = new SparseSet[EntityCapacity];
            attachedSystems    = new SparseSet[EntityCapacity];
            vacancies          = new Queue <uint>((int)EntityCapacity);

            for (int i = 0; i < EntityCapacity; i++)
            {
                attachedComponents[i] = new SparseSet(ComponentCapacity);
                attachedSystems[i]    = new SparseSet(SystemCapacity);
            }
        }
Ejemplo n.º 4
0
        // Constructors
        ///////////////////////////

        public Archetype(EntityType type)
        {
            this.type = type;
            entities  = new SparseSet <int, EntityId>(i => i, this.MoveDataRow);
            data      = SparseEntitySet <ComponentArray>();
            free      = new Queue <int>();
            edges     = SparseEntitySet <Archetype>();
        }
Ejemplo n.º 5
0
        // Constructors
        ///////////////////////////

        public EntityIndex()
        {
            root       = new Archetype(new EntityType());
            archetypes = new List <Archetype>();
            index      = SparseEntitySet <Record>();
            dataTypes  = SparseEntitySet <Type>();
            archetypes.Add(root);
        }
Ejemplo n.º 6
0
        public Factory(uint capacity)
        {
            Capacity = capacity;
            workers  = new Worker[Capacity];

            behaviorAddition    = new Queue <Tuple <uint, Trade[]> >((int)capacity);
            behaviorSubtraction = new Queue <Tuple <uint, Type[]> >((int)capacity);
            vacancies           = new Queue <uint>((int)capacity);
            entityRemoval       = new SparseSet(capacity);
        }
        public void SparseSet_Smoke_Test()
        {
            var set = new SparseSet(15, 10);

            set.Add(6);
            set.Add(15);
            set.Add(0);

            set.Remove(15);

            Assert.IsTrue(set.HasItem(6));
            Assert.AreEqual(2, set.Length);
        }
Ejemplo n.º 8
0
        public void SparseSet_Smoke_Test()
        {
            var set = new SparseSet(15, 10);

            set.Add(6);
            set.Add(15);
            set.Add(0);

            //IEnumerable test
            Assert.AreEqual(set.Count, set.Count());

            set.Remove(15);

            Assert.IsTrue(set.HasItem(6));
            Assert.AreEqual(2, set.Count);

            //IEnumerable test
            Assert.AreEqual(set.Count, set.Count());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Does the actual solving.
        /// </summary>
        /// <param name="problem"></param>
        /// <returns></returns>
        protected override IRoute DoSolve(IProblem problem)
        {
            // convert to a symetric problem if needed.
            IProblem _problem = problem;

            if (!_problem.Symmetric)
            {
                _problem  = Convertor.ConvertToSymmetric(_problem);
                _was_asym = true;
            }

            // create the list of customers.
            _customers = new List <int>();
            for (int customer = 0; customer < _problem.Size; customer++)
            {
                _customers.Add(customer);
            }
            _sparse_set = SparseSetHelper.CreateNearestNeighourSet(_problem, _customers, _customers.Count / 10);
            //_sparse_set = SparseSetHelper.CreateNonSparseSet(_problem, _customers);
            // construct a route from the customers.
            //FixedSymmetricRoute init_route = new FixedSymmetricRoute(_customers);

            // construct a random route using best-placement.
            ArbitraryInsertionSolver bp_solver = new ArbitraryInsertionSolver();
            IRoute bp_route = bp_solver.Solve(_problem);
            FixedSymmetricRoute init_route = new FixedSymmetricRoute(bp_route);

            double     init_route_weight = LinKernighanSolver.Weight(_problem, init_route);
            RouteFound route             = new RouteFound()
            {
                Route       = init_route,
                RouteWeight = init_route_weight
            };

            Console.WriteLine("Route {0}:{1}",
                              route.Route.ToString(),
                              route.RouteWeight);

            // step 2.
            EdgeSet     X           = new EdgeSet();
            EdgeSet     Y           = new EdgeSet();
            IList <int> untried_t_1 = new List <int>(route.Route);

            while (untried_t_1.Count > 0)
            {
                // select t1.
                int t_1 = untried_t_1[0];
                untried_t_1.RemoveAt(0);

                // search route with t_1.
                RouteFound t_1_route = this.AfterSelectt1(_problem, route, X, Y, t_1);

                // select the better route.
                if (t_1_route.RouteWeight < route.RouteWeight)
                {
                    untried_t_1 = new List <int>(route.Route);
                    route       = RouteFound.SelectBest(route, t_1_route);
                    X           = new EdgeSet();
                    Y           = new EdgeSet();
                }
            } // step 2 and step 12.

            // convert back to asym solution if needed.
            //result.RemoveAt(result.Count - 1);
            if (_was_asym)
            {
                return(this.ConvertToASymRoute(new List <int>(route.Route)));
            }
            return(route.Route);
        }
Ejemplo n.º 10
0
 public ComponentStore(uint maxComponents)
 {
     Set       = new SparseSet(maxComponents);
     instances = new T[maxComponents];
 }
Ejemplo n.º 11
0
 public SparseSetResolver()
 {
     indices  = new SparseSet(10);
     handlers = new List <IHandler <IMessage> >();
 }