示例#1
0
 public void DestroyEntity(EntityId entity)
 {
     index.RemoveEntity(entity);
     tracker.Destroy(entity);
 }
示例#2
0
        private void UpdateEntitiesWithStateChanges()
        {
            // update our list of added and removed entities
            _addedEntities.Clear();
            _removedEntities.Clear();
            _notifiedAddingEntities.IterateAndClear(entity => _addedEntities.Add(entity));
            _notifiedRemovedEntities.IterateAndClear(entity => _removedEntities.Add(entity));

            ++UpdateNumber;

            // Add entities
            for (int i = 0; i < _addedEntities.Count; ++i)
            {
                RuntimeEntity toAdd = _addedEntities[i];

                InternalAddEntity(toAdd);

                // apply initialization changes
                toAdd.ApplyModifications();
            }
            // can't clear b/c it is shared

            // copy our state change entities notice that we do this after adding entities, because
            // adding entities triggers the data state change notifier
            _notifiedStateChangeEntities.IterateAndClear(entity => _stateChangeEntities.Add(entity));

            // Remove entities
            for (int i = 0; i < _removedEntities.Count; ++i)
            {
                RuntimeEntity toRemove = _removedEntities[i];

                // remove listeners
                toRemove.ModificationNotifier.Listener    -= OnEntityModified;
                toRemove.DataStateChangeNotifier.Listener -= OnEntityDataStateChanged;

                // remove all data from the entity and then push said changes out
                foreach (DataAccessor accessor in toRemove.SelectData())
                {
                    toRemove.RemoveData(accessor);
                }
                toRemove.DataStateChangeUpdate();

                // remove the entity from the list of entities
                _entities.Remove(toRemove, GetEntitiesListFromMetadata(toRemove));
                EventNotifier.Submit(DestroyedEntityEvent.Create(toRemove));

                // notify listeners we removed an event
                EventNotifier.Submit(EntityRemovedEvent.Create(toRemove));

                // remove it from the index
                _entityIndex.RemoveEntity(toRemove);
            }
            // can't clear b/c it is shared

            // Do a data state change on the given items.
            {
                int i = 0;
                while (i < _stateChangeEntities.Count)
                {
                    if (_stateChangeEntities[i].NeedsMoreDataStateChangeUpdates() == false)
                    {
                        // reset the notifier so it can be added to the _stateChangeEntities again
                        _stateChangeEntities[i].DataStateChangeNotifier.Reset();
                        _stateChangeEntities.RemoveAt(i);
                    }
                    else
                    {
                        _stateChangeEntities[i].DataStateChangeUpdate();
                        ++i;
                    }
                }
            }

            // apply the modifications to the modified entities this data is not shared, so we can
            // clear it
            _notifiedModifiedEntities.IterateAndClear(modified => {
                modified.ApplyModifications();
            });

            // update the global entity
            _globalEntity.ApplyModifications();
            _globalEntity.DataStateChangeUpdate();
        }