Example #1
0
        public void Init(EcsSystems systems)
        {
            var world = systems.GetWorld(worldName);

            _filter = world.Filter <T> ().End();
            _pool   = world.GetPool <T> ();
        }
 internal static void BlockAllClick(EcsFilter <ClickEvent> events, int buttonNumer)
 {
     for (var i = 0; i < events.GetEntitiesCount(); i++)
     {
         events.Get1[i].IsBlocked = true;
     }
 }
Example #3
0
 /// <summary>
 /// Immediately removes all entities in given filter.
 /// Use it carefully!
 /// </summary>
 public static void Clear <T> (this EcsFilter <T> filter) where T : struct
 {
     foreach (var idx in filter)
     {
         filter.GetEntity(idx).Destroy();
     }
 }
Example #4
0
        public void Init(EcsSystems systems)
        {
            var worldConstraints = systems.GetWorld(PhysicsWorldNames.Constraints);

            springsBodyBody  = worldConstraints.Filter <SpringBodyBody>().End();
            springsBodySpace = worldConstraints.Filter <SpringBodySpace>().End();
        }
Example #5
0
 /// <summary>
 /// Mark all entities in a filter with RemoveEntityComponent.
 /// </summary>
 public static void MarkRemove(this EcsFilter filter)
 {
     foreach (var idx in filter)
     {
         filter.GetEntity(idx).Get <RemoveEntityComponent>();
     }
 }
Example #6
0
 public bool IsCompatible(EcsFilter filter)
 {
     if (BitsCount > 0 && filter.IncludeMask.BitsCount <= BitsCount)
     {
         int i    = filter.IncludeMask.BitsCount - 1;
         var maxJ = BitsCount - 1;
         for (; i >= 0; i--)
         {
             var j   = maxJ;
             var bit = filter.IncludeMask.Bits[i];
             for (; j >= 0; j--)
             {
                 if (Bits[j] == bit)
                 {
                     break;
                 }
             }
             if (j == -1)
             {
                 break;
             }
         }
         if (i == -1)
         {
             return(!IsIntersects(filter.ExcludeMask));
         }
     }
     return(false);
 }
Example #7
0
        void IEcsWorldDebugListener.OnFilterCreated(EcsFilter filter)
        {
            var go = new GameObject();

            go.transform.SetParent(_filtersRoot);
            go.hideFlags = HideFlags.NotEditable;
            var observer = go.AddComponent <EcsFilterObserver> ();

            observer.World  = this;
            observer.Filter = filter;

            // included components.
            var goName = $"Inc<{filter.IncludedTypes[0].Name}";

            for (var i = 1; i < filter.IncludedTypes.Length; i++)
            {
                goName += $",{filter.IncludedTypes[i].Name}";
            }
            goName += ">";
            // excluded components.
            if (filter.ExcludedTypes != null)
            {
                goName += $".Exc<{filter.ExcludedTypes[0].Name}";
                for (var i = 1; i < filter.ExcludedTypes.Length; i++)
                {
                    goName += $",{filter.ExcludedTypes[i].Name}";
                }
                goName += ">";
            }
            go.name = goName;
        }
Example #8
0
 private void ForEachTrigger <T>(EcsFilter <T> filter) where T : struct, ITriggerEvent
 {
     foreach (var index in filter)
     {
         ref var hannpend = ref filter.Get1(index);
         Log($"Trigger event {typeof(T).Name}", hannpend.colliderOwner, hannpend.collisionWith);
     }
    private static void CreateOrDestroyEntities(EcsWorld world, EcsFilter filter, int count, Action <EcsWorld> createEntity)
    {
        IEcsGroup group = world.Filter(filter);

        if (group.CalculateCount() == count)
        {
            return;
        }

        IEcsEntity[] entities = group.ToEntityArray();
        for (int i = entities.Length; i < count; i++)
        {
            createEntity(world);
        }

        for (int i = count; i < entities.Length; i++)
        {
            IEcsEntity             entity    = entities[i];
            BroadphaseRefComponent brRef     = entity.GetComponent <BroadphaseRefComponent>();
            CharacterComponent     character = entity.GetComponent <CharacterComponent>();

            Object.Destroy(character.Ref.gameObject);

            foreach (SAPChunk chunk in brRef.Chunks)
            {
                BroadphaseHelper.RemoveFormChunk(chunk, entity.Id);
            }

            entity.Destroy();
        }
    }
    /// <summary>
    /// You better don't use this extensions in real projects, 'cause it can strike on performance
    /// </summary>
    public static T2 GetSecondComponent <T1, T2>(
        this EcsFilter <T1, T2> filter,
        Func <T1, bool> limits1 = null,
        Func <T2, bool> limits2 = null)
        where T1 : class, new()
        where T2 : class, new()
    {
        if (limits1 == null)
        {
            limits1 = x => true;
        }
        if (limits2 == null)
        {
            limits2 = x => true;
        }

        for (int i = 0; i < filter.EntitiesCount; i++)
        {
            var component1 = filter.Components1 != null
                ? filter.Components1[i]
                : null;
            var component2 = filter.Components2 != null
                ? filter.Components2[i]
                : null;
            if (!limits1(component1) || !limits2(component2))
            {
                continue;
            }

            return(component2);
        }

        return(null);
    }
Example #11
0
        public void Init(EcsSystems systems)
        {
            var world = systems.GetWorld();

            boundingCircles = world.Filter <BoundingCircle>().End();
            meshes          = world.Filter <Mesh>().Inc <Pose>().End();
        }
 public static bool AllEntitiesEquals <T>(this EcsFilter filter)
     where T : struct
 {
     for (int i = 0; i < filter.GetEntitiesCount() - 1; i++)
     {
         ref var currentEntity = ref filter.GetEntity(i).Get <T>();
         ref var nextEntity    = ref filter.GetEntity(i + 1).Get <T>();
Example #13
0
 /// <summary>
 /// simple clear filter
 /// </summary>
 /// <param name="filter"></param>
 public static void ClearSimple(this EcsFilter filter)
 {
     foreach (int i in filter)
     {
         ref EcsEntity entity = ref filter.GetEntity(i);
         entity.Destroy();
     }
Example #14
0
 public static EcsFilter <T1, T2> Out <T1, T2>(this EcsFilter <T1, T2> filter, out T1[] get1, out T2[] get2, out EcsEntity[] entities)
     where T1 : class where T2 : class
 {
     get1     = filter.Get1;
     get2     = filter.Get2;
     entities = filter.Entities;
     return(filter);
 }
Example #15
0
        public void Init(EcsSystems systems)
        {
            var world = systems.GetWorld();

            shapes        = world.Filter <Shape>().Inc <BoundingBox>().End();
            shapesPool    = world.GetPool <Shape>();
            boundingBoxes = world.GetPool <BoundingBox>();
        }
Example #16
0
        public void Init(EcsSystems systems)
        {
            var world = systems.GetWorld();

            circles = world.Filter <RigidBody>().Inc <Circle>().Inc <BoundingBox>().End();
            meshes  = world.Filter <RigidBody>().Inc <Mesh>().Inc <BoundingBox>().End();
            grabberElasticityCoefficient = 40f;
        }
Example #17
0
 void IEcsSystem.Initialize(EcsWorld world)
 {
     _world = world;
     Debug.LogFormat("{0} => initialize", GetType().Name);
     _world.SubscribeToEvent <ControlEvent> (OnControlEntity);
     _controlObjects     = _world.GetFilter <ControlComponent> ();
     _controlComponentId = _world.GetComponentIndex <ControlComponent> ();
 }
Example #18
0
 public static void HandleEvents <T>(this EcsFilter <T> filter, EcsWorld _world, Action <T> action) where T : class, new()
 {
     foreach (var idx in filter)
     {
         action(filter.Components1[idx]);
         _world.RemoveEntity(filter.Entities[idx]);
     }
 }
Example #19
0
 void IEcsSystem.Initialize(EcsWorld world)
 {
     _world = world;
     Debug.LogFormat("{0} => initialize", GetType().Name);
     _destroyObjects           = _world.GetFilter <DestroyComponent> ();
     _destroyComponentId       = _world.GetComponentIndex <DestroyComponent> ();
     _world.OnComponentDetach += OnComponentDetach;
     _world.SubscribeToEvent <DestroyEvent> (OnDestroyEntity);
 }
Example #20
0
        public void Init(EcsSystems systems)
        {
            var worldEvents = systems.GetWorld(PhysicsWorldNames.Events);
            var physicsData = systems.GetShared <PhysicsData>();

            contacts     = worldEvents.Filter <Contact <TagA, TagB> >().End();
            contactsPool = worldEvents.GetPool <Contact <TagA, TagB> >();
            RegisterSolver(worldEvents, physicsData.ContactSolversMatrix);
        }
Example #21
0
 void IEcsSystem.Initialize(EcsWorld world)
 {
     _world = world;
     Debug.LogFormat("{0} => initialize", GetType().Name);
     _goObjects          = _world.GetFilter <GameObjectComponent, SnakeComponent> ();
     _controlComponentId = _world.GetComponentIndex <ControlComponent> ();
     _goComponentId      = _world.GetComponentIndex <GameObjectComponent> ();
     _snakeComponentId   = _world.GetComponentIndex <SnakeComponent> ();
 }
Example #22
0
        public static void AllDestroy(this EcsFilter f)
        {
            var ecsEntities = f.Entities;

            foreach (var i in f)
            {
                ecsEntities[i].Destroy();
            }
        }
Example #23
0
        public static void CleanFilter(this EcsFilter filter)
        {
            var world = filter.GetWorld();

            for (var i = 0; i < filter.EntitiesCount; i++)
            {
                world.RemoveEntity(filter.Entities[i]);
            }
        }
Example #24
0
 void IEcsSystem.Initialize(EcsWorld world)
 {
     _world = world;
     Debug.LogFormat("{0} => initialize", GetType().Name);
     _colliderComponentId = _world.GetComponentIndex <ColliderComponent> ();
     _snakeComponentId    = _world.GetComponentIndex <SnakeComponent> ();
     _collisionObjects    = _world.GetFilter <ColliderComponent, DestroyComponent> ();
     _snakeObjects        = _world.GetFilter <ColliderComponent, SnakeComponent> ();
 }
Example #25
0
        public static void AllUnset <T>(this EcsFilter f) where T : class
        {
            var e = f.Entities;

            foreach (var i in f)
            {
                e[i].Unset <T>();
            }
        }
Example #26
0
        public void Init(EcsSystems systems)
        {
            var worldEvents = systems.GetWorld(PhysicsWorldNames.Events);
            var physicsData = systems.GetShared <PhysicsData>();

            possibleContacts     = worldEvents.Filter <PossibleContact <ShapeA, ShapeB> >().End();
            possibleContactsPool = worldEvents.GetPool <PossibleContact <ShapeA, ShapeB> >();
            contactSolversMatrix = physicsData.ContactSolversMatrix;
            RegisterTester(worldEvents, physicsData.ContactTestersMatrix);
        }
Example #27
0
        public static List <EcsEntity> ToEntitieNumbersList <T>(this EcsFilter <T> filter) where T : class, new()
        {
            var result = new List <EcsEntity>();

            foreach (var idx in filter)
            {
                result.Add(filter.Entities[idx]);
            }

            return(result);
        }
Example #28
0
        public static List <T> ToEntitiesList <T>(this EcsFilter <T> filter) where T : class, new()
        {
            var result = new List <T>();

            foreach (var idx in filter)
            {
                result.Add(filter.Components1[idx]);
            }

            return(result);
        }
        internal static bool IsBlockedClick(EcsFilter <ClickEvent> events, int buttonNumer)
        {
            var isBlock = false;

            for (var i = 0; i < events.GetEntitiesCount(); i++)
            {
                isBlock = isBlock || (events.Get1[i].ButtonNumber == buttonNumer && events.Get1[i].IsBlocked);
            }

            return(isBlock);
        }
        internal static bool IsPressClick(EcsFilter <ClickEvent> events, int buttonNumer)
        {
            var isPress = false;

            for (var i = 0; i < events.GetEntitiesCount(); i++)
            {
                isPress = isPress || events.Get1[i].ButtonNumber == buttonNumer;
            }

            return(isPress);
        }