Ejemplo n.º 1
0
        /// <summary>
        /// возвращаем первую ентити у которой есть необходимые нам компоненты
        /// </summary>
        /// <param name="outEntity"></param>
        /// <param name="componentIDs"></param>
        public bool TryGetEntityByComponents(out IEntity outEntity, ref HECSMask mask)
        {
            if (cacheTryGet.TryGetValue(mask, out outEntity))
            {
                if (outEntity.IsAlive)
                {
                    return(true);
                }
                else
                {
                    cacheTryGet.Remove(mask);
                }
            }

            var count = EntitiesCount;

            for (int i = 0; i < count; i++)
            {
                var currentEntity = Entities[i];

                if (currentEntity.ContainsMask(ref mask))
                {
                    outEntity = currentEntity;
                    cacheTryGet.Add(mask, currentEntity);
                    return(true);
                }
            }

            outEntity = null;
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Если нам нужно убедиться что такая ентити существует, или дождаться когда она появиться,
        /// то мы отправляем команду ожидать появления нужной сущности
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command"></param>
        /// <param name="waitForComponent"></param>
        public void Command <T>(T command, ref HECSMask waitForComponent) where T : ICommand, IGlobalCommand
        {
            if (TryGetEntityByComponents(out var entity, ref waitForComponent))
            {
                commandService.Invoke(command);
            }

            waitingCommandsSystems.AddWaitingCommand(command, waitForComponent);
        }
Ejemplo n.º 3
0
 public Filter(World world, HECSMask includeComponents, HECSMask excludeComponents)
 {
     this.world  = world;
     mask        = includeComponents;
     excludeMask = excludeComponents;
     world.AddGlobalReactComponent(this);
     world.AddEntityListener(this, true);
     GatherEntities(world);
 }
Ejemplo n.º 4
0
        public bool TryGetHecsComponent <T>(HECSMask mask, out T component) where T : IComponent
        {
            var needed = components[mask.Index];

            if (needed != null && needed is T cast)
            {
                component = cast;
                return(true);
            }

            component = default;
            return(false);
        }
Ejemplo n.º 5
0
        public List <IEntity> GetFilter(HECSMask include, HECSMask exclude)
        {
            int sumMask = include.GetHashCode();

            sumMask += exclude.GetHashCode();

            if (filters.TryGetValue(sumMask, out var filter))
            {
                return(filter.Entities);
            }

            var nf = new Filter(world, include, exclude);

            filters.Add(sumMask, nf);
            return(nf.Entities);
        }
Ejemplo n.º 6
0
 public List <IEntity> Filter(HECSMask include) => entityFilter.GetFilter(include);
Ejemplo n.º 7
0
 public bool ContainsMask(ref HECSMask mask)
 {
     return(componentsMask.Contain(ref mask));
 }
Ejemplo n.º 8
0
        public void RemoveHecsComponent(HECSMask component)
        {
            var needed = components[component.Index];

            RemoveHecsComponent(needed);
        }
Ejemplo n.º 9
0
 public bool TryGetComponentFromEntity <T>(out T component, ref HECSMask owner, ref HECSMask neededComponent, int worldIndex) where T : IComponent
 => worlds[worldIndex].TryGetComponentFromEntity(out component, ref owner, ref neededComponent);
Ejemplo n.º 10
0
 public List <IEntity> GetFilter(HECSMask include)
 {
     return(GetFilter(include, HECSMask.Empty));
 }
Ejemplo n.º 11
0
 public T GetHECSComponent <T>(ref HECSMask owner, int worldIndex = 0) => worlds[worldIndex].GetHECSComponent <T>(ref owner);
Ejemplo n.º 12
0
        public bool TryGetSystemFromEntity <T>(ref HECSMask mask, out T system, int worldIndex = 0) where T : ISystem
        {
            var world = Instance.worlds[worldIndex];

            return(world.TryGetSystemFromEntity(ref mask, out system));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// возвращаем первую ентити у которой есть необходимые нам компоненты
        /// </summary>
        /// <param name="outEntity"></param>
        /// <param name="componentIDs"></param>
        public static bool TryGetEntityByComponents(out IEntity outEntity, ref HECSMask mask, int worldIndex = 0)
        {
            var world = Instance.worlds[worldIndex];

            return(world.TryGetEntityByComponents(out outEntity, ref mask));
        }
Ejemplo n.º 14
0
 public static List <IEntity> Filter(HECSMask include, int worldIndex = 0) => Instance.worlds[worldIndex].Filter(include);
Ejemplo n.º 15
0
 /// <summary>
 /// Если нам нужно убедиться что такая ентити существует, или дождаться когда она появиться,
 /// то мы отправляем команду ожидать появления нужной сущности
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="command"></param>
 /// <param name="waitForComponent"></param>
 public static void Command <T>(T command, ref HECSMask waitForComponent, int worldIndex = 0) where T : ICommand, IGlobalCommand
 => Worlds[worldIndex].Command(command, ref waitForComponent);