/// <summary> /// Creates new ecs-world instance. /// </summary> /// <param name="config">Optional config for default cache sizes. On zero or negative value - default value will be used.</param> public EcsWorld(EcsWorldConfig config = default) { var finalConfig = new EcsWorldConfig { EntityComponentsCacheSize = config.EntityComponentsCacheSize <= 0 ? EcsWorldConfig.DefaultEntityComponentsCacheSize : config.EntityComponentsCacheSize, FilterEntitiesCacheSize = config.FilterEntitiesCacheSize <= 0 ? EcsWorldConfig.DefaultFilterEntitiesCacheSize : config.FilterEntitiesCacheSize, WorldEntitiesCacheSize = config.WorldEntitiesCacheSize <= 0 ? EcsWorldConfig.DefaultWorldEntitiesCacheSize : config.WorldEntitiesCacheSize, WorldFiltersCacheSize = config.WorldFiltersCacheSize <= 0 ? EcsWorldConfig.DefaultWorldFiltersCacheSize : config.WorldFiltersCacheSize, WorldComponentPoolsCacheSize = config.WorldComponentPoolsCacheSize <= 0 ? EcsWorldConfig.DefaultWorldComponentPoolsCacheSize : config.WorldComponentPoolsCacheSize }; Config = finalConfig; Entities = new EcsEntityData[Config.WorldEntitiesCacheSize]; FreeEntities = new EcsGrowList <int> (Config.WorldEntitiesCacheSize); Filters = new EcsGrowList <EcsFilter> (Config.WorldFiltersCacheSize); FilterByIncludedComponents = new Dictionary <int, EcsGrowList <EcsFilter> > (Config.WorldFiltersCacheSize); FilterByExcludedComponents = new Dictionary <int, EcsGrowList <EcsFilter> > (Config.WorldFiltersCacheSize); ComponentPools = new IEcsComponentPool[Config.WorldComponentPoolsCacheSize]; _filterCtor = new object[] { this }; }
public DelayedUpdate(Op type, int entity, IEcsComponentPool component, int componentId) { Type = type; Entity = entity; Pool = component; ComponentId = componentId; }
public DelayedUpdate(Op type, int entity, IEcsComponentPool pool, int componentId) { Type = type; Pool = pool; Entity = entity; ComponentId = componentId; }
protected void AddDelayedUpdate(DelayedUpdate.Op type, int entity, IEcsComponentPool component, int componentId) { if (_delayedUpdatesCount == _delayedUpdates.Length) { Array.Resize(ref _delayedUpdates, _delayedUpdatesCount << 1); } _delayedUpdates[_delayedUpdatesCount++] = new DelayedUpdate(type, entity, component, componentId); }
void AddDelayedUpdate(DelayedUpdate.Op type, int entity, IEcsComponentPool component, int componentId) { if (_delayedUpdatesCount == _delayedUpdates.Length) { var newDelayedUpdates = new DelayedUpdate[_delayedUpdatesCount << 1]; Array.Copy(_delayedUpdates, 0, newDelayedUpdates, 0, _delayedUpdatesCount); _delayedUpdates = newDelayedUpdates; } _delayedUpdates[_delayedUpdatesCount++] = new DelayedUpdate(type, entity, component, componentId); }
internal void AddComponent(byte index, IEcsComponent component) { EcsArchetype newArchetype = _archetypeManager.FindOrCreateNextArchetype(_archetype, index); foreach (byte curIndex in _archetype.Indices) { IEcsComponentPool componentPool = _archetype.GetComponentPool(curIndex); newArchetype.AddComponent(curIndex, componentPool.Get(ArchetypeIndex)); } newArchetype.AddComponent(index, component); _archetype.RemoveEntity(this); _archetype = newArchetype; _archetype.AddEntity(this); }
internal void RemoveComponent(byte index) { EcsArchetype newArchetype = _archetypeManager.FindOrCreatePriorArchetype(_archetype, index); foreach (byte curIndex in _archetype.Indices) { if (curIndex == index) { continue; } IEcsComponentPool componentPool = _archetype.GetComponentPool(curIndex); newArchetype.AddComponent(curIndex, componentPool.Get(ArchetypeIndex)); } _archetype.RemoveEntity(this); _archetype = newArchetype; _archetype.AddEntity(this); }
public ComponentLink(IEcsComponentPool pool, int itemId) { Pool = pool; ItemId = itemId; }