// Destorys any pending entities in the Entity Destroy List. void DestroyEntities(GameTime gameTime) { // REMOVE ANY ENTITIES FOUND IN THE ENTITY TRASH OverallPerformance.RestartTiming("DestroyEntitiesTime"); for (int i = 0; i < _entityDestroy.Count; i++) { Entity entity = _entityDestroy[i]; if (entity.PreDestroy(gameTime, this)) { _entities.Remove(entity.Name); EntityRenderPerformance.RemoveTiming(entity.Name); EntityUpdatePerformance.RemoveTiming(entity.Name); Collider.Remove(entity); entity.Name = null; entity.PostDestroy(gameTime, this); } } _entityDestroy.Clear(); OverallPerformance.StopTiming("DestroyEntitiesTime"); }
public override void Update(GameTime gameTime) { LastUpdateTime = gameTime; // Allow Map to Perform Update Routine if (MapScript != null) { OverallPerformance.RestartTiming("MapScriptUpdateTime"); MapScript.Update(this, gameTime); OverallPerformance.StopTiming("MapScriptUpdateTime"); } OverallPerformance.ResetAll(); OverallPerformance.RestartTiming("TotalEntityUpdateTime"); foreach (string entityId in _entities.Keys) { Entity entity = _entities[entityId]; entity.PreviousBoundingBox = entity.CurrentBoundingBox; EntityUpdatePerformance.RestartTiming(entityId); { entity.Update(gameTime, this); } EntityUpdatePerformance.StopTiming(entityId); // Recalculate the Entities BoundingBox. entity.CurrentBoundingBox = entity.GetPxBoundingBox(gameTime); // Reset the IsOnScreen variable before the next drawing operation. entity.IsOnScreen = false; // If the entity has moved, then update his position in the QuadTree. OverallPerformance.StartTiming("ColliderUpdateTime"); { if (entity.CurrentBoundingBox != entity.PreviousBoundingBox) { Collider.Update(entity); } } OverallPerformance.StopTiming("ColliderUpdateTime"); } OverallPerformance.StopTiming("TotalEntityUpdateTime"); DestroyEntities(gameTime); CreateEntities(gameTime); // If the Map Loaded flag has beem set, we need to invoke the MapScripts MapLoaded event hook. if (_mapLoaded) { EntityRenderPerformance.Clear(); EntityUpdatePerformance.Clear(); if (MapScript != null) { MapScript.MapLoaded(this, Map, _mapLoadedEventArgs); } _mapLoadedEventArgs = null; _mapLoaded = false; DestroyEntities(gameTime); CreateEntities(gameTime); } }