예제 #1
0
        public T SetSystem <T>(T system, ExecutionType execType, int layer = 0) where T : EntitySystem
        {
            system.World = world;

            if (systems.ContainsKey(typeof(T)))
            {
                systems[typeof(T)].Add((EntitySystem)system);
            }
            else
            {
                systems[typeof(T)] = new List <EntitySystem>();
                systems[typeof(T)].Add((EntitySystem)system);
            }


            if (execType == ExecutionType.Draw)
            {
                if (!Drawlayers.ContainsKey(layer))
                {
                    Drawlayers[layer] = new Bag <EntitySystem>();
                }

                Bag <EntitySystem> drawBag = Drawlayers[layer];
                if (drawBag == null)
                {
                    drawBag = Drawlayers[layer] = new Bag <EntitySystem>();
                }
                if (!drawBag.Contains((EntitySystem)system))
                {
                    drawBag.Add((EntitySystem)system);
                }
                Drawlayers = (from d in Drawlayers orderby d.Key ascending select d).ToDictionary(pair => pair.Key, pair => pair.Value);
            }
            else if (execType == ExecutionType.Update)
            {
                if (!Updatelayers.ContainsKey(layer))
                {
                    Updatelayers[layer] = new Bag <EntitySystem>();
                }

                Bag <EntitySystem> updateBag = Updatelayers[layer];
                if (updateBag == null)
                {
                    updateBag = Updatelayers[layer] = new Bag <EntitySystem>();
                }
                if (!updateBag.Contains((EntitySystem)system))
                {
                    updateBag.Add((EntitySystem)system);
                }
                Updatelayers = (from d in Updatelayers orderby d.Key ascending select d).ToDictionary(pair => pair.Key, pair => pair.Value);
            }
            if (!mergedBag.Contains((EntitySystem)system))
            {
                mergedBag.Add((EntitySystem)system);
            }
            system.SystemBit = SystemBitManager.GetBitFor(system);

            return((T)system);
        }
예제 #2
0
 /**
  * Delete the provided entity from the world.
  * @param e entity
  */
 public void DeleteEntity(Entity e)
 {
     groupManager.Remove(e);
     if (!deleted.Contains(e))
     {
         deleted.Add(e);
     }
 }
예제 #3
0
        public T SetSystem <T>(T system, ExecutionType execType, int layer = 0) where T : EntitySystem
        {
            system.World = world;

            systems.Add(typeof(T), (EntitySystem)system);

            if (execType == ExecutionType.Draw)
            {
                if (!Drawlayers.ContainsKey(layer))
                {
                    Drawlayers[layer] = new Bag <EntitySystem>();
                }

                Bag <EntitySystem> drawBag = Drawlayers[layer];
                if (drawBag == null)
                {
                    drawBag = Drawlayers[layer] = new Bag <EntitySystem>();
                }
                if (!drawBag.Contains((EntitySystem)system))
                {
                    drawBag.Add((EntitySystem)system);
                }
            }
            else if (execType == ExecutionType.Update)
            {
                if (!Updatelayers.ContainsKey(layer))
                {
                    Updatelayers[layer] = new Bag <EntitySystem>();
                }

                Bag <EntitySystem> updateBag = Updatelayers[layer];
                if (updateBag == null)
                {
                    updateBag = Updatelayers[layer] = new Bag <EntitySystem>();
                }
                if (!updateBag.Contains((EntitySystem)system))
                {
                    updateBag.Add((EntitySystem)system);
                }
            }
            if (!mergedBag.Contains((EntitySystem)system))
            {
                mergedBag.Add((EntitySystem)system);
            }
            system.SystemBit = SystemBitManager.GetBitFor(system);

            return((T)system);
        }
        public void Remove(Entity e)
        {
            activeEntities.Set(e.GetId(), null);

            e.SetTypeBits(0);

            Refresh(e);

            RemoveComponentsOfEntity(e);

            count--;
            totalRemoved++;

            removedAndAvailable.Add(e);
            if (RemovedEntityEvent != null)
            {
                RemovedEntityEvent(e);
            }
        }
        public Bag <Component> GetComponents(Entity e)
        {
            entityComponents.Clear();
            int entityId = e.GetId();

            for (int a = 0, b = componentsByType.Size(); b > a; a++)
            {
                Bag <Component> components = componentsByType.Get(a);
                if (components != null && entityId < components.Size())
                {
                    Component component = components.Get(entityId);
                    if (component != null)
                    {
                        entityComponents.Add(component);
                    }
                }
            }
            return(entityComponents);
        }
예제 #6
0
        /// <summary>
        /// Remove an entity from the world
        /// </summary>
        /// <param name="e">Entity you want to remove</param>
        public void Remove(Entity e)
        {
            System.Diagnostics.Debug.Assert(e != null);
            activeEntities.Set(e.Id, null);

            e.TypeBits = 0;

            Refresh(e);

            RemoveComponentsOfEntity(e);

            count--;
            totalRemoved++;

            removedAndAvailable.Add(e);
            if (RemovedEntityEvent != null)
            {
                RemovedEntityEvent(e);
            }
        }
예제 #7
0
        /// <summary>
        /// Get all components assigned to an entity
        /// </summary>
        /// <param name="e">Entity for which you want the components</param>
        /// <returns>Bag of components</returns>
        public Bag <Component> GetComponents(Entity e)
        {
            System.Diagnostics.Debug.Assert(e != null);
            entityComponents.Clear();
            int entityId = e.Id;

            for (int a = 0, b = componentsByType.Size; b > a; a++)
            {
                Bag <Component> components = componentsByType.Get(a);
                if (components != null && entityId < components.Size)
                {
                    Component component = components.Get(entityId);
                    if (component != null)
                    {
                        entityComponents.Add(component);
                    }
                }
            }
            return(entityComponents);
        }
예제 #8
0
 /**
  * Ensure all systems are notified of changes to this entity.
  * @param e entity
  */
 internal void RefreshEntity(Entity e)
 {
     System.Diagnostics.Debug.Assert(e != null);
     refreshed.Add(e);
 }
예제 #9
0
 /**
  * Delete the provided entity from the world.
  * @param e entity
  */
 public void DeleteEntity(Entity e)
 {
     System.Diagnostics.Debug.Assert(e != null);
     deleted.Add(e);
 }
예제 #10
0
 /**
  * Ensure all systems are notified of changes to this entity.
  * @param e entity
  */
 public void RefreshEntity(Entity e)
 {
     refreshed.Add(e);
 }