Exemplo n.º 1
0
        /// <summary>
        /// Adds the component.
        /// </summary>
        /// <param name="component">The component.</param>
        public void AddComponent(IComponent component)
        {
            Components.Add(component);

            var u = component as IUpdatable;

            if (u != null)
            {
                _updatables.Add(u);
            }

            var d = component as IDrawable;

            if (d != null)
            {
                _drawables.Add(d);
            }

            var c = component as ICollidable;

            if (c != null)
            {
                PhysicSystem.AddCollidable(c);
            }
        }
Exemplo n.º 2
0
        private void OpenSceneIfPending(DateTime now)
        {
            if (_pendingSceneToOpen != null)
            {
                LogSystem.Debug("WORLD: opening scene {0}", _pendingSceneToOpen.GetType().Name);

                // Time.
                if (_time.SinceGameStart <= float.Epsilon)
                {
                    _time.MarkAsGameStarted(now);
                }

                _time.MarkAsSceneStarted(now);
                _time.Update(now);

                // Call new scene initialization, in this moment the scene decide which components will be kept
                // on world and wich objects will be removed.
                _pendingSceneToOpen.Initialize();

                // Remove the scene survivors from components to remove.
                var sceneSurvivables = _componentsToRemove
                                       .Where(c => (c is ISceneSurvivable) && ((ISceneSurvivable)c).CanSurvive(CurrentScene, _pendingSceneToOpen));
                sceneSurvivables.EnableAll();
                _componentsToRemove = _componentsToRemove.Except(sceneSurvivables).ToList();

                // Remove the components selected by the scene to be removed from world.
                foreach (var c in _componentsToRemove)
                {
                    Components.Remove(c);
                    _updatables.Remove(c as IUpdatable);
                    _drawables.Remove(c as IDrawable);
                    PhysicSystem.RemoveCollidable(c as ICollidable);
                }

                _componentsToRemove.Clear();

                // Change the current world scene.
                CurrentScene = _pendingSceneToOpen;

                _pendingSceneToOpen = null;

                LogSystem.Debug("WORLD: scene opened");
            }
            else
            {
                _time.Update(now);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update the instance.
        /// </summary>
        /// <param name="now">The current real world time.</param>
        public void Update(DateTime now)
        {
            OpenSceneIfPending(now);
            CurrentScene.Update();

            var updatablesCount = _updatables.Count;

            _drawablesCount = _drawables.Count;

            IUpdatable current;

            for (int i = 0; i < updatablesCount; i++)
            {
                current = _updatables[i];

                if (current.Enabled)
                {
                    current.Update();
                }
            }

            PhysicSystem.Update();
            InputSystem.Update();
        }