/// <summary> /// Updates the status of the entity inside of the cache; ie, if the entity is now /// passing the filter but was not before, then it will be added to the cache. /// </summary> /// <returns>The change in cache status for the entity</returns> public CacheChangeResult UpdateCache(RuntimeEntity entity) { UnorderedListMetadata metadata = GetMetadata(entity); bool passed = _filter.Check(entity); bool contains = CachedEntities.Contains(entity, metadata); // The entity is not in the cache it now passes the filter, so add it to the cache if (contains == false && passed) { CachedEntities.Add(entity, metadata); return(CacheChangeResult.Added); } // The entity is in the cache but it no longer passes the filter, so remove it if (contains && passed == false) { CachedEntities.Remove(entity, metadata); return(CacheChangeResult.Removed); } // no change to the cache return(CacheChangeResult.NoChange); }
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(); }
/// <summary> /// Removes the given item from the list of items that receive visualization events. /// </summary> /// <param name="visualizable">The visualized item.</param> public void Remove(IVisualizable visualizable) { _visualizable.Remove(visualizable, visualizable.VisualizationMetadata); }
protected void RemoveAsInterruptor() { interruptors.Remove(this); }
/// <summary> /// Return controller collision with this collider /// </summary> /// <param name="collider">Collider to be ignroed</param> public void RemoveIgnoredCollider(Collider collider) { ignoredColliders.Remove(collider); }