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(); }
void ReserveEntity(int entity, EcsEntity entityData) { entityData.IsReserved = true; if (_reservedEntitiesCount == _reservedEntities.Length) { Array.Resize(ref _reservedEntities, _reservedEntitiesCount << 1); } _reservedEntities[_reservedEntitiesCount++] = entity; #if DEBUG for (var ii = 0; ii < _debugListeners.Count; ii++) { _debugListeners[ii].OnEntityRemoved(entity); } #endif }
/// <summary> /// Destroyes world and exist entities. /// </summary> public void Destroy() { #if DEBUG if (_isDestroyed || _inDestroying) { throw new Exception("EcsWorld already destroyed."); } _inDestroying = true; CheckForLeakedEntities("Destroy"); #endif var entity = new EcsEntity(); entity.Owner = this; var maxCount = _entitiesCount; for (var i = _entitiesCount - 1; i >= 0; i--) { ref var entityData = ref _entities[i]; if (entityData.ComponentsCountX2 > 0) { entity.Id = i; entity.Gen = entityData.Gen; entity.Destroy(); } }