예제 #1
0
        /// <summary>
        /// Stops a scene.
        /// A stopped scene is not rendered nor updated.
        /// </summary>
        /// <param name="id">The ID of the scene.</param>
        public void StopScene(int id)
        {
            // Check if scene exists.
            if (scenes.ContainsKey(id))
            {
                // Get scene as state.
                ISceneState state = (ISceneState)scenes[id];

                // If scene is already stopped, return.
                if (state.State == SceneState.Stopped)
                {
                    return;
                }

                // If scene is paused, remove entities from render system.
                else if (state.State == SceneState.Paused)
                {
                    // Get renderable entities.
                    IReadOnlyList <IEntity> renderables = state.Stop().Where(entity => entity is IRenderable).ToList();

                    // Remove entities from render system.
                    foreach (IEntity entity in renderables)
                    {
                        renderSystem.RemoveEntity(entity.Id);
                    }
                }

                // Else, remove entities from all systems.
                else
                {
                    // Get entities.
                    IReadOnlyList <IEntity> entities = state.Stop();

                    // Remove entities from systems.
                    foreach (IEntity entity in entities)
                    {
                        collisionSystem.RemoveEntity(entity.Id);
                        inputSystem.RemoveEntity(entity.Id);
                        renderSystem.RemoveEntity(entity.Id);
                        updateSystem.RemoveEntity(entity.Id);
                    }
                }
            }
        }