示例#1
0
        /// <summary>
        /// Runs a scene.
        /// </summary>
        /// <param name="id">The ID of the scene.</param>
        /// <param name="initialise">Whether to intialise the scene.</param>
        public void RunScene(int id, bool initialise)
        {
            // Check if the scene exists.
            if (scenes.ContainsKey(id))
            {
                // Get scene as scene state.
                ISceneState state = (ISceneState)scenes[id];

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

                // Else if scene is paused, then we want to remove the entities from the render system.
                else if (state.State == SceneState.Paused)
                {
                    // Get renderable entities from scene.
                    IReadOnlyList <IEntity> renderables = scenes[id].GetEntities().Where(entity => entity is IRenderable).ToList();

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

                // Run scene.
                IReadOnlyList <IEntity> entities = state.Run(initialise);

                // Add entities to systems.
                foreach (IEntity entity in entities)
                {
                    collisionSystem.AddEntity(entity);
                    inputSystem.AddEntity(entity);
                    if (entity is IRenderable)
                    {
                        renderSystem.AddEntity(entity);
                    }
                    if (entity is IUpdatable)
                    {
                        updateSystem.AddEntity(entity);
                    }
                }
            }
        }