Пример #1
0
        /// <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 };
        }
Пример #2
0
 public DelayedUpdate(Op type, int entity, IEcsComponentPool component, int componentId)
 {
     Type        = type;
     Entity      = entity;
     Pool        = component;
     ComponentId = componentId;
 }
Пример #3
0
 public DelayedUpdate(Op type, int entity, IEcsComponentPool pool, int componentId)
 {
     Type        = type;
     Pool        = pool;
     Entity      = entity;
     ComponentId = componentId;
 }
Пример #4
0
 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);
 }
Пример #5
0
 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);
 }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
 public ComponentLink(IEcsComponentPool pool, int itemId)
 {
     Pool   = pool;
     ItemId = itemId;
 }