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(); } }
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 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(); }
public void RollBack(EntityWorldFrameData data, PtKeyFrameCollection collection) { Reset(); foreach(Guid entityId in data.EntityIds) { Entity entity = AddEntity(entityId); foreach (IComponent com in data.Components) { if(com.EntityId == entityId) { foreach(FrameIdxInfo info in collection.KeyFrames) { if(info.EqualsInfo(com)) { IParamsUpdatable updatableCom = com as IParamsUpdatable; if (updatableCom != null) updatableCom.UpdateParams(info.Params); else throw new Exception("Component " + com.ToString() + " must be IParamsUpdatable"); break; } } entity.AddComponent(com); } } }; foreach(FrameIdxInfo info in collection.KeyFrames) { if(!ContainEntity(info.EntityId)) { if(info.Cmd == FrameCommand.SYNC_CREATE_ENTITY) { NotifyCreateEntity(info); } } else { if (info.Cmd == FrameCommand.SYNC_REMOVE_ENTITY) { NotifyRemoveEntity(info.EntityId); } } } }
/// 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); } } }
/// 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); } } }
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()); } }