Ejemplo n.º 1
0
        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);
            }
        }