public override void Update(GameTime gameTime)
        {
            foreach (var entityId in _addedEntities)
            {
                _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
                ActiveCount++;
                EntityAdded?.Invoke(entityId);
            }

            foreach (var entityId in _changedEntities)
            {
                _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
                EntityChanged?.Invoke(entityId);
            }

            foreach (var entityId in _removedEntities)
            {
                // we must notify subscribers before removing it from the pool
                // otherwise an entity system could still be using the entity when the same id is obtained.
                EntityRemoved?.Invoke(entityId);

                var entity = _entityBag[entityId];
                _entityBag[entityId] = null;
                _componentManager.Destroy(entityId);
                _entityToComponentBits[entityId] = default(BitVector32);
                ActiveCount--;
                _entityPool.Free(entity);
            }

            _addedEntities.Clear();
            _removedEntities.Clear();
            _changedEntities.Clear();
        }
Esempio n. 2
0
 public void OnEntityRemoved(EntityRemoved message)
 {
     foreach (var shipSpawner in Components)
     {
         shipSpawner.Targets.Remove(message.Entity);
     }
 }
Esempio n. 3
0
 protected virtual void OnEntityRemoved(Entity e)
 {
     if (e.UsingPool != null)
     {
         e.UsingPool.myPool.ReturnToPool(e, ref e.UsingPool.active);
     }
     EntityRemoved?.Invoke(this, e);
 }
Esempio n. 4
0
 private void ClearEntities()
 {
     foreach (var entity in Entities)
     {
         EntityRemoved?.Invoke(this, new CharacterArgs(entity.Value));
     }
     Entities.Clear();
 }
Esempio n. 5
0
 public override bool Remove(Entity item)
 {
     EntityRemoved?.Invoke(this, item);
     if (item is EntityVisible visible)
     {
         drawablesMap.Remove(visible);
     }
     return(base.Remove(item));
 }
Esempio n. 6
0
        /// <summary>
        /// Raises the Entity Added event
        /// </summary>
        /// <param name="args">The event args</param>
        protected void OnEntityRemoved(CacheObjectEventArgs args)
        {
            var handler = EntityRemoved;

            if (handler != null)
            {
                EntityRemoved.Invoke(this, args);
            }
        }
Esempio n. 7
0
 private void RemoveOldEntitiesFromCache()
 {
     foreach (var current in Entities)
     {
         EntityRemoved?.Invoke(current);
         current.IsInList = false;
     }
     entityCache.Clear();
 }
Esempio n. 8
0
 public void OnEntityRemoved(EntityRemoved message)
 {
     // If an entity was removed from the system we want to make sure
     // that no AI is targeting it anymore. Otherwise the id may be
     // re-used before the AI is updated, leading to bad references.
     foreach (var ai in Components)
     {
         ai.OnEntityInvalidated(message.Entity);
     }
 }
Esempio n. 9
0
        public bool RemoveEntity(Character entity)
        {
            var success = Entities.TryRemove(entity.Id, out entity);

            if (success)
            {
                EntityRemoved?.Invoke(this, new CharacterArgs(entity));
            }
            return(success);
        }
Esempio n. 10
0
        protected virtual void OnEntityRemoved(Entity e)
        {
            if (e.UsingPool != null &&
                e.PreventReturnToPoolOnDetach == false)
            {
                e.UsingPool.myPool.ReturnToPool(e, ref e.UsingPool.active);
            }

            EntityRemoved?.Invoke(this, e);
        }
Esempio n. 11
0
        public Model()
        {
            _graph = new ModelGraph();

            _graph.VertexAdded   += i => EntityAdded?.Invoke(i);
            _graph.VertexRemoved += i => EntityRemoved?.Invoke(i);
            _graph.EdgeAdded     += i => RelationshipAdded?.Invoke(i);
            _graph.EdgeRemoved   += i => RelationshipRemoved?.Invoke(i);
            _graph.Cleared       += (i, j) => ModelCleared?.Invoke();
        }
Esempio n. 12
0
        public bool RemoveEntity(Character character)
        {
            var success = Entities.TryRemove(character.Id, out character);

            if (success)
            {
                EntityRemoved?.Invoke(this, new CharacterArgs(character));
            }
            return(success);
        }
Esempio n. 13
0
 public void OnEntityRemoved(EntityRemoved message)
 {
     // An item was removed, unequip it everywhere.
     foreach (var slot in Components)
     {
         if (slot.Item == message.Entity)
         {
             slot.Item = 0;
         }
     }
 }
Esempio n. 14
0
        private void RemoveEntity(IEntity entity)
        {
            if (!_entities.Remove(entity))
            {
                return;
            }

            entity.WorldChanged -= OnEntityWorldChanged;
            entity.Removed      -= OnEntityRemoved;

            EntityRemoved?.Invoke(this, new EntityEventArgs(entity));
        }
Esempio n. 15
0
 public void OnEntityRemoved(EntityRemoved message)
 {
     // Unset owner for all components where the removed entity
     // was the owner.
     foreach (var component in Components)
     {
         if (component.Value == message.Entity)
         {
             component.Value = 0;
         }
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Destroy the entity with the given ID. Notifies all systems that the entity has been removed.
        /// </summary>
        /// <param name="entityId">The ID of the entity to destroy.</param>
        public void DestroyEntity(uint entityId)
        {
            int entityBitmask = GetEntityBitmask(entityId);
            int componentIndex;

            for (componentIndex = 0; componentIndex < entityTable.GetLength(ComponentRows); componentIndex++)
            {
                entityTable[componentIndex, entityId] = null;
            }

            entityInWorld[entityId] = false;
            EntityRemoved?.Invoke(this, new EntityEventArgs(entityId, entityBitmask));
        }
Esempio n. 17
0
        protected void RemoveEntity(RailEntityBase entity)
        {
            if (entities.ContainsKey(entity.Id))
            {
                entities.Remove(entity.Id);
                entity.RoomBase = null;
                entity.Removed();
                // TODO: Pooling entities?

                HandleRemovedEntity(entity.Id);
                EntityRemoved?.Invoke(entity);
            }
        }
Esempio n. 18
0
        public void Remove(IEntity entity)
        {
            if (!Entities.ContainsKey(entity.ID))
            {
                return;
            }

            entity = Entities[entity.ID];
            entity.ComponentAdded   -= ComponentAdded;
            entity.ComponentRemoved -= ComponentRemoved;

            Entities.Remove(entity.ID);

            EntityRemoved?.Invoke(this, new EntityRemovedEventArgs(entity));
        }
Esempio n. 19
0
        private void PostSaveChanges()
        {
            foreach (var databaseEntityAddedEventArgs in addedEntites)
            {
                EntityAdded?.Invoke(this, databaseEntityAddedEventArgs);
            }

            foreach (var databaseEntityModifiedEventArgs in modifiedEntites)
            {
                EntityModified?.Invoke(this, databaseEntityModifiedEventArgs);
            }

            foreach (var databaseEntityRemovedEventArgs in removedEntites)
            {
                EntityRemoved?.Invoke(this, databaseEntityRemovedEventArgs);
            }

            addedEntites.Clear();
            modifiedEntites.Clear();
            removedEntites.Clear();
        }
Esempio n. 20
0
        public void RemoveFromMap(Entity entity)
        {
            if (m_EntityIdToCoordinate.ContainsKey(entity.Id))
            {
                entity.EntityKilled -= RemoveFromMap;
                Coordinate current = m_EntityIdToCoordinate[entity.Id];

                if (m_CoordinateToMapTile.ContainsKey(current))
                {
                    m_CoordinateToMapTile[current].entities.Remove(entity);
                }

                m_EntityIdToCoordinate.Remove(entity.Id);

                EntityRemoved?.Invoke(this, new EntityArgs()
                {
                    entity     = entity,
                    coordinate = current
                });
            }
        }
Esempio n. 21
0
        private void UpdateEntityCollections()
        {
            OnlyValidEntities.Clear();
            NotOnlyValidEntities.Clear();
            NotValidDict.Clear();

            foreach (var e in ValidEntitiesByType)
            {
                e.Value.Clear();
            }

            while (keysForDelete.Count > 0)
            {
                var key = keysForDelete.Dequeue();

                if (entityCache.TryGetValue(key, out var entity))
                {
                    EntityRemoved?.Invoke(entity);
                    entityCache.Remove(key);
                }
            }

            foreach (var entity in entityCache)
            {
                var entityValue = entity.Value;

                if (entityValue.IsValid)
                {
                    OnlyValidEntities.Add(entityValue);
                    ValidEntitiesByType[entityValue.Type].Add(entityValue);
                }
                else
                {
                    NotOnlyValidEntities.Add(entityValue);
                    NotValidDict[entityValue.Id] = entityValue;
                }
            }
        }
Esempio n. 22
0
        public override void Update(GameTime gameTime)
        {
            foreach (var entity in _addedEntities)
            {
                _entities[entity.Id] = entity;
                entity.Initialize(_world);
                ActiveCount++;
                EntityAdded?.Invoke(entity);
            }

            foreach (var entity in _removedEntities)
            {
                if (_entities.ContainsKey(entity.Id))
                {
                    _entities[entity.Id] = null;
                    _entities.Remove(entity.Id);
                    ActiveCount--;
                    EntityRemoved?.Invoke(entity);
                }
            }

            _addedEntities.Clear();
            _removedEntities.Clear();

            foreach (var entity in _entities)
            {
                if (!entity.Value.IsExpired)
                {
                    entity.Value.Update(gameTime);
                }
                else
                {
                    _removedEntities.Add(entity.Value);
                }
            }
        }
Esempio n. 23
0
 public virtual void OnEntityRemoved(T entity)
 {
     EntityRemoved?.Invoke(entity);
 }
Esempio n. 24
0
 protected internal void OnEntityRemoved(EntityEventArgs args)
 {
     args.Entity.ComponentAdded   -= HandleComponentAdded;
     args.Entity.ComponentRemoved -= HandleComponentRemoved;
     EntityRemoved?.Invoke(this, args);
 }
Esempio n. 25
0
 private void OnEntityRemoved(Entity entity)
 {
     EntityRemoved?.Invoke(entity);
 }
Esempio n. 26
0
 protected virtual void OnEntityRemoved(Entity e)
 {
     EntityRemoved?.Invoke(this, e);
 }
Esempio n. 27
0
 /// <summary>
 /// Removes a child entity from this container
 /// </summary>
 /// <param name="child"></param>
 internal void RemoveChild(Entity child)
 {
     children.Remove(child);
     EntityRemoved?.Invoke(child);
 }
Esempio n. 28
0
 public static void RegisterRemovedCallback <T>(this EntityRef <T> entityRef, EntityRemoved <T> funcs) where T : class
 {
     entityRef.ParentPool.RegisterRemovedEvent(entityRef, funcs);
 }
Esempio n. 29
0
 private void OnEntityRemoved(object sender, EntityCollectionChangedEventArgs <TLinkTable> e)
 {
     EntityRemoved?.Invoke(this, new EntityCollectionChangedEventArgs <TEntity>(_getEntity(e.Entity)));
 }
        private static void RemoveEdge(long removerEntityId, long entityIdToRemove)
        {
            MyEntity holderEntity;

            MyEntities.TryGetEntityById(removerEntityId, out holderEntity);
            var holderPlayer = holderEntity != null
                ? MyAPIGateway.Players.GetPlayerControllingEntity(holderEntity)
                : null;

            MyEntity removeEntity = null;

            MyEntities.TryGetEntityById(entityIdToRemove, out removeEntity);

            if (removeEntity == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }

            #region Validation

            if (!MyEventContext.Current.IsLocallyInvoked)
            {
                if (holderEntity == null || holderPlayer == null ||
                    MyEventContext.Current.Sender.Value != holderPlayer.SteamUserId)
                {
                    MyEventContext.ValidationFailed();
                    return;
                }

                if (MyAreaPermissionSystem.Static != null && !MyAreaPermissionSystem.Static.HasPermission(
                        holderPlayer.IdentityId, removeEntity.GetPosition(), MyPermissionsConstants.QuickDeconstruct))
                {
                    holderPlayer.ShowNotification("You cannot quick deconstruct here", 2000, null,
                                                  new Vector4(1, 0, 0, 1));
                    return;
                }

                string err;
                if (!ValidateQuickRemove(holderPlayer, removeEntity, out err))
                {
                    MyEventContext.ValidationFailed();
                    if (!string.IsNullOrEmpty(err))
                    {
                        holderPlayer.ShowNotification(err, 2000, null, new Vector4(1, 0, 0, 1));
                    }
                    return;
                }
            }

            #endregion

            var block = removeEntity?.Get <MyBlockComponent>();
            if (block != null)
            {
                block.GridData.RemoveBlock(block.Block);
            }
            else
            {
                removeEntity.Close();
            }

            EntityRemoved?.Invoke(holderEntity, holderPlayer, removeEntity);
        }