Exemple #1
0
        public Entity AddContainedInCell(Entitas.Entity newContainedInCell)
        {
            var component = CreateComponent <ContainedInCellComponent>(BoidsComponentIds.ContainedInCell);

            component.ContainedInCell = newContainedInCell;
            return(AddComponent(BoidsComponentIds.ContainedInCell, component));
        }
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());
            }
        }
        public void ExecuteSystemTest([NUnit.Framework.Range (1, 10, 1)] int totalSystemExecutions)
        {
            //  Setup
            Vector3 velocity = new Vector3(10, 20, 30);
            Vector3 position = new Vector3(1, 2, 3);
            Vector3 expectedPosition = position;
            _testEnity = Pools.pool.CreateEntity()
                    .AddPosition(position)
                    .AddVelocity(velocity);

            //Desired. Strong typing when CreateSystem<T> is called.
            VelocitySystem velocitySystem = Pools.pool.CreateSystem<VelocitySystem>() as VelocitySystem;

            //  This will run the system exacly once.
            for (var ex = 0; ex < totalSystemExecutions; ex++)
            {
                //for every execution
                velocitySystem.Execute();

                //we expect it to move by one velocity unit
                expectedPosition += velocity;
            }

            //  Assert
            Assert.AreEqual(expectedPosition, _testEnity.position.position, "The entity position will the original position plus one velocity.");
        }
 public void Init(Pool pool, Entity entity)
 {
     _pool = pool;
     _entity = entity;
     _entity.OnEntityReleased += onEntityReleased;
     Update();
 }
 void onComponentRemoved(Entity e, int index, IComponent component)
 {
     if (_pool.HasEntity(e)) {
         updateName();
     } else {
         DestroyBehaviour();
     }
 }
 void onEntityChanged(Entity e, int index, IComponent component)
 {
     if (!e.HasComponent(_debugIndex)) {
         DestroyBehaviour();
     } else {
         updateName();
     }
 }
 //Whenever a new ball is created, follow it
 protected virtual void BallCreatedGroup_OnEntityAdded(Group collection, Entity ballEntity, int index, IComponent component)
 {
     //Debug.Log ("created" + ballEntity);
     foreach (var entity in _aiGroup.GetEntities())
     {
         entity.ReplaceAI (ballEntity, entity.aI.deadZoneY, entity.aI.velocityY);
     }
 }
        public void AddComponentTest()
        {
            //  Setup
            _testEnity = Pools.pool.CreateEntity().AddVelocity(new Vector3(1, 2, 3));

            //  Assert
            Assert.AreEqual(new Vector3(1, 2, 3), _testEnity.velocity.velocity, "The entity velocity will be the same as previously 'added'.");
        }
        public Entity AddCollision(Entitas.Entity newSelf, Entitas.Entity newOther)
        {
            var component = CreateComponent <CollisionComponent>(InputComponentIds.Collision);

            component.self  = newSelf;
            component.other = newOther;
            return(AddComponent(InputComponentIds.Collision, component));
        }
        public void AddComponentTest()
        {
            //  Setup
            _testEnity = Pools.pool.CreateEntity().AddPosition(new Vector3(1, 2, 3), false);

            //  Assert
            Assert.AreEqual(new Vector3(1, 2, 3), _testEnity.position.position, "The entity position will be the same as previously 'added'.");
        }
Exemple #11
0
        public Entity ReplaceContainedInCell(Entitas.Entity newContainedInCell)
        {
            var component = CreateComponent <ContainedInCellComponent>(BoidsComponentIds.ContainedInCell);

            component.ContainedInCell = newContainedInCell;
            ReplaceComponent(BoidsComponentIds.ContainedInCell, component);
            return(this);
        }
        public void ReplaceComponentTest()
        {
            //  Setup
            _testEnity = Pools.pool.CreateEntity().AddPosition(new Vector3(1, 2, 3), false);
            _testEnity = Pools.pool.CreateEntity().ReplacePosition(new Vector3(11, 22, 33), _testEnity.position.useTween);

            //  Assert
            Assert.AreEqual(new Vector3(11, 22, 33), _testEnity.position.position, "The entity position will be the same as previously 'replaced'.");
        }
        public void Init(Pool pool, Entity entity)
        {
            _pool = pool;
            _entity = entity;
            _unfoldedComponents = new bool[_pool.totalComponents];
            _entity.OnComponentRemoved += onComponentRemoved;

            UnfoldAllComponents();
        }
 private void OnEntityRemoved(Entity entity)
 {
     if (tableContents.ContainsKey(entity.creationIndex))
     {
         var entryToRemove = tableContents[entity.creationIndex];
         Destroy(entryToRemove.gameObject);
         tableContents.Remove(entity.creationIndex);
     }
 }
Exemple #15
0
        public void Setup()
        {
            EcsComponentType <MiniEcsComponentA> .Register();

            EcsComponentType <MiniEcsComponentB> .Register();

            EcsComponentType <MiniEcsComponentC> .Register();

            EcsComponentType <MiniEcsComponentD> .Register();

            _world = new EcsWorld();

            _entitasWorld = new Context <EntitasEntity>(4, () => new EntitasEntity());

            for (int i = 0; i < 15000; ++i)
            {
                EntitasEntity entity = _entitasWorld.CreateEntity();
                entity.AddComponent(0, new EntitasComponentA());
                entity.AddComponent(1, new EntitasComponentB());
                entity.AddComponent(3, new EntitasComponentD());

                entity = _entitasWorld.CreateEntity();
                entity.AddComponent(0, new EntitasComponentA());
                entity.AddComponent(2, new EntitasComponentC());

                entity = _entitasWorld.CreateEntity();
                entity.AddComponent(1, new EntitasComponentB());
                entity.AddComponent(3, new EntitasComponentD());

                entity = _entitasWorld.CreateEntity();
                entity.AddComponent(1, new EntitasComponentB());
                entity.AddComponent(3, new EntitasComponentD());

                entity = _entitasWorld.CreateEntity();
                entity.AddComponent(1, new EntitasComponentB());
                entity.AddComponent(2, new EntitasComponentC());

                entity = _entitasWorld.CreateEntity();
                entity.AddComponent(0, new EntitasComponentA());
                entity.AddComponent(1, new EntitasComponentB());

                entity = _entitasWorld.CreateEntity();
                entity.AddComponent(0, new EntitasComponentA());
                entity.AddComponent(3, new EntitasComponentD());

                _world.CreateEntity(new MiniEcsComponentA(), new MiniEcsComponentB(), new MiniEcsComponentD());
                _world.CreateEntity(new MiniEcsComponentA(), new MiniEcsComponentC());
                _world.CreateEntity(new MiniEcsComponentB(), new MiniEcsComponentD());
                _world.CreateEntity(new MiniEcsComponentB(), new MiniEcsComponentD());
                _world.CreateEntity(new MiniEcsComponentB(), new MiniEcsComponentC());
                _world.CreateEntity(new MiniEcsComponentA(), new MiniEcsComponentB());
                _world.CreateEntity(new MiniEcsComponentA(), new MiniEcsComponentD());
            }
        }
        public void Init(Pool pool, Entity entity, int debugIndex)
        {
            _pool = pool;
            _entity = entity;
            _debugIndex = debugIndex;
            _unfoldedComponents = new bool[_pool.totalComponents];
            _entity.OnComponentAdded += onEntityChanged;
            _entity.OnComponentRemoved += onEntityChanged;
            updateName();

            UnfoldAllComponents();
        }
		public override bool Matches(Entity entity)
		{
			for (int i = 0, indicesLength = indices.Length; i < indicesLength; i++)
			{
				if (entity.HasComponent(indices[i]))
				{
					return false;
				}
			}

			return true;
		}
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);
            _defaultGeneratorSystem            = new DefaultEcsGeneratorSystem(_defaultWorld);
            _defaultGeneratorMultiSystem       = new DefaultEcsGeneratorSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            _monoWorld = new WorldBuilder().AddSystem(new MonoSystem()).Build();
            _time      = new GameTime();

            _leoWorld   = new LeoWorld();
            _leoSystem  = new LeoSystem();
            _leoSystems = new LeoSystems(_leoWorld).Add(_leoSystem);
            _leoSystems.ProcessInjects().Init();

            SimpleEntitiesSubmissionScheduler sveltoScheduler = new SimpleEntitiesSubmissionScheduler();

            _sveltoWorld  = new EnginesRoot(sveltoScheduler);
            _sveltoSystem = new SveltoSystem();
            _sveltoWorld.AddEngine(_sveltoSystem);
            IEntityFactory sveltoFactory = _sveltoWorld.GenerateEntityFactory();

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());

                MonoEntity monoEntity = _monoWorld.CreateEntity();
                monoEntity.Attach(new MonoComponent());

                LeoEntity leoEntity = _leoWorld.NewEntity();
                leoEntity.Get <LeoComponent>();

                sveltoFactory.BuildEntity <SveltoEntity>((uint)i, _sveltoGroup);
            }

            sveltoScheduler.SubmitEntities();
        }
Exemple #19
0
        public void EntitasStressTest()
        {
            List <EntitasEntity> entities = new List <EntitasEntity>();

            for (int i = 0; i < 1000; i++)
            {
                EntitasEntity entityABD = _entitasWorld.CreateEntity();
                entityABD.AddComponent(0, new EntitasComponentA());
                entityABD.AddComponent(1, new EntitasComponentB());
                entityABD.AddComponent(3, new EntitasComponentD());

                EntitasEntity entityAC = _entitasWorld.CreateEntity();
                entityAC.AddComponent(0, new EntitasComponentA());
                entityAC.AddComponent(2, new EntitasComponentC());

                EntitasEntity entityBD0 = _entitasWorld.CreateEntity();
                entityBD0.AddComponent(1, new EntitasComponentB());
                entityBD0.AddComponent(3, new EntitasComponentD());

                EntitasEntity entityBD1 = _entitasWorld.CreateEntity();
                entityBD1.AddComponent(1, new EntitasComponentB());
                entityBD1.AddComponent(3, new EntitasComponentD());

                EntitasEntity entityBC = _entitasWorld.CreateEntity();
                entityBC.AddComponent(1, new EntitasComponentB());
                entityBC.AddComponent(2, new EntitasComponentC());

                EntitasEntity entityAB = _entitasWorld.CreateEntity();
                entityAB.AddComponent(0, new EntitasComponentA());
                entityAB.AddComponent(1, new EntitasComponentB());

                EntitasEntity entityAD = _entitasWorld.CreateEntity();
                entityAD.AddComponent(0, new EntitasComponentA());
                entityAD.AddComponent(3, new EntitasComponentD());

                entities.Add(entityABD);
                entities.Add(entityAC);
                entities.Add(entityBD0);
                entities.Add(entityBD1);
                entities.Add(entityBC);
                entities.Add(entityAB);
                entities.Add(entityAD);
            }

            EntitasForEachOneComp();
            EntitasForEachTwoComp();

            foreach (Entity entity in entities)
            {
                entity.Destroy();
            }
        }
        /*
         * 
         * Wiki
         * 
         * 
         */

        static void entityExample(Entity entity) {
            entity.AddPosition(3, 7);
            entity.AddHealth(100);
            entity.isMovable = true;

            entity.ReplacePosition(10, 100);
            entity.ReplaceHealth(entity.health.health - 1);
            entity.isMovable = false;

            entity.RemovePosition();

            var hasPos = entity.hasPosition;
            var movable = entity.isMovable;
        }
 private void OnEntityAdded(Entity entity)
 {
     if (tableContents.ContainsKey(entity.creationIndex))
     {
         tableContents[entity.creationIndex].GetComponent<IEntityVisualizer>().EntityUpdated(entity);
     }
     else
     {
         var tableEntryObject = Instantiate(TableEntryGameObject);
         tableEntryObject.transform.SetParent(TableGridTransform.transform);
         tableEntryObject.GetComponent<IEntityVisualizer>().EntityUpdated(entity);
         tableContents.Add(entity.creationIndex, tableEntryObject);
     }
 }
Exemple #22
0
        public void Update()
        {
            LogicFrameBehaviour logic = Sim.GetBehaviour <LogicFrameBehaviour>();

            Entitas.Entity entity = Sim.GetEntityWorld().GetEntity(GameClientData.SelfControlEntityId);
            if (entity != null)
            {
                MoveComponent comp = entity.GetComponent <MoveComponent>();
                if (comp != null)
                {
                    Vector2 dir = comp.GetDirVector2();
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.A))
                    {
                        dir.x = -1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.S))
                    {
                        dir.y = -1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.W))
                    {
                        dir.y = 1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.D))
                    {
                        dir.x = 1;
                    }
                    if (!InputManager.Instance.IsAnyKeyCodeActive())
                    {
                        dir.x = 0;
                        dir.y = 0;
                    }
                    if (dir != comp.GetDirVector2())
                    {
                        Debug.Log(string.Format("keyframeIdx:{0} roleid:{1}", logic.CurrentFrameIdx, comp.EntityId));

                        //KeyFrameSender.AddFrameCommand(new FrameIdxInfo(logic.CurrentFrameIdx,FrameCommand.SYNC_MOVE,comp.EntityId,new string[] { dir.x + "", dir.y + "", "0" }));

                        KeyFrameSender.AddCurrentFrameCommand(FrameCommand.SYNC_MOVE, comp.EntityId, new string[] { dir.x + "", dir.y + "", "0" });
                    }

                    //bullet
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.Space))
                    {
                        KeyFrameSender.AddCurrentFrameCommand(FrameCommand.SYNC_CREATE_ENTITY, Common.Utils.GuidToString(), new string[] { ((int)EntityWorld.EntityOperationEvent.CreateBullet) + "", comp.EntityId });
                    }
                }
            }
        }
        private void Wrap(Entity entity, UnityEngine.Bounds bounds)
        {
            var position = entity.position;

            if (position.x < bounds.min.x)
                entity.ReplacePosition(position.x + bounds.size.x, position.y);

            if (position.x > bounds.max.x)
                entity.ReplacePosition(position.x - bounds.size.x, position.y);

            if (position.y < bounds.min.y)
                entity.ReplacePosition(position.x, position.y + bounds.size.y);

            if (position.y > bounds.max.y)
                entity.ReplacePosition(position.x, position.y - bounds.size.y);
        }
        private void OnEventAdded(Entity eventEntity)
        {
            var eventEntities = Pools.pool.GetGroup(Matcher.AllOf(Matcher.GameEvent, Matcher.GameEventState)).GetEntities();
            var possibleEventToDisplay = eventEntities.FirstOrDefault(entity => entity.gameEventState.EventState == EventState.Presented);

            if (possibleEventToDisplay != null && possibleEventToDisplay.gameEvent != CurrentGameEvent)
            {
                CurrentGameEvent = possibleEventToDisplay.gameEvent;
                UpdateEvent(possibleEventToDisplay.gameEvent);
                UiView.SetActive(true);
            }
            else if (possibleEventToDisplay == null)
            {
                CurrentGameEvent = null;
                UiView.SetActive(false);
            }
        }
Exemple #25
0
        //Tweener tweener;
        protected override void OnRender(Entitas.Entity entity)
        {
            base.OnRender(entity);

            TransformComponent com_Pos  = entity.GetComponent <TransformComponent>();
            MoveComponent      com_Move = entity.GetComponent <MoveComponent>();

            if (com_Pos != null)
            {
                double lerp    = SimulationManager.Instance.GetFrameLerp() * SimulationManager.Instance.GetFrameMsLength() / 1000;/// Time.deltaTime;
                var    pos1    = com_Pos.GetPositionVector2();
                var    nextPos = pos1 + com_Move.GetDirVector2() * (com_Move.GetSpeed() * (float)(Time.deltaTime / SimulationManager.Instance.GetFrameMsLength() / 1000));

                //if (tweener != null)
                //    tweener.Kill();
                //tweener = null;

                transform.DOLocalMove(Vector2.Lerp(pos1, nextPos, (float)lerp), .5f, false);

                //transform.localPosition = Vector2.Lerp(transform.position, nextPos, (float)lerp);
            }
        }
        /// Adds copies of all specified components to the target entity.
        /// If replaceExisting is true it will replace exisintg components.
        public static void CopyTo(this Entity entity,
                                  Entity target,
                                  bool replaceExisting = false,
                                  params int[] indices)
        {
            var componentIndices = indices.Length == 0
                                        ? entity.GetComponentIndices()
                                        : indices;
            for(int i = 0; i < componentIndices.Length; i++) {
                var index = componentIndices[i];
                var component = entity.GetComponent(index);
                var clonedComponent = target.CreateComponent(
                    index, component.GetType()
                );
                component.CopyPublicMemberValues(clonedComponent);

                if(replaceExisting) {
                    target.ReplaceComponent(index, clonedComponent);
                } else {
                    target.AddComponent(index, clonedComponent);
                }
            }
        }
 static void movableComponent(Entity e)
 {
     var movable = e.isMovable;
     e.isMovable = true;
     e.isMovable = false;
 }
        static void positionComponent(Entity e, PositionComponent component, int x, int y)
        {
            var pos = e.position;
            var has = e.hasPosition;

            e.AddPosition(x, y);
            e.AddPosition(component);

            e.ReplacePosition(x, y);

            e.RemovePosition();
        }
 /// This will exclude all entities which don't pass the filter.
 protected abstract bool Filter(Entity entity);
 public override bool Matches(Entity entity)
 {
     return entity.HasComponents(indices);
 }
 void onEntityReleased(Entity e)
 {
     DestroyBehaviour();
 }
 void addEntity(Group group, Entity entity)
 {
     _collectedEntities.Add(entity);
 }
 public void TearDown()
 {
     Pools.pool.DestroyEntity(_testEnity);
     _testEnity = null;
     Pools.pool.Reset();
 }
 void onComponentRemoved(Entity e, int index, IComponent component)
 {
     if (!_pool.HasEntity(e)) {
         DestroyBehaviour();
     }
 }
 //whenever a ball is destroyed, stop following it.
 protected virtual void BallDestroyGroup_OnEntityAdded(Group collection, Entity ballEntity, int index, IComponent component)
 {
     //Debug.Log ("destroy" + ballEntity);
     foreach (var entity in _aiGroup.GetEntities())
     {
         entity.ReplaceAI (null, entity.aI.deadZoneY, entity.aI.velocityY);
         entity.ReplaceVelocity ( new RMC.Common.UnityEngineReplacement.Vector3 (0,0,0));
     }
 }
Exemple #36
0
 void addEntity(Group group,
                Entity entity,
                int index,
                IComponent component)
 {
     var added = _collectedEntities.Add(entity);
     if(added) {
         entity.Retain(this);
     }
 }
 private void OnGameEntityAdded(Group group, Entity entity, int index, IComponent component)
 {
     _gameEntity = group.GetSingleEntity();
 }
 public void EntityUpdated(Entity entity)
 {
     Name.text = entity.name.Name;
     Airspeed.text = entity.airframe.MaxAirSpeed.ToString();
     Condition.text = entity.health.Health.ToString(CultureInfo.InvariantCulture);
 }
 void onEntityReleased(Entity e)
 {
     Destroy(gameObject);
 }