/// <summary> /// Loads the given filename into a scene and returns it. /// </summary> /// <param name="filename">The filename of the scene</param> /// <param name="loadMaterials">Should load materials</param> /// <remarks>If false is passed to load materials they are not loaded from the content manager into the texture object. This is for the editor</remarks> public static IceScene LoadScene(string filename, bool loadMaterials) { if (!filename.EndsWith(".icescene")) { filename += ".icescene"; } string _filename = Path.GetFullPath(filename); if (!File.Exists(_filename)) { throw new FileNotFoundException("File Not Found: " + filename); } IceScene scene = Serialization.SceneSerializer.DeSerializeScene(filename, GlobalDataHolder.ContentFolderPath); scene.WillRenderNotActive = false; Scenes.Add(scene); if (_activeScene == null) { _activeScene = scene; } if (loadMaterials == true) { InitializeScene(scene); } scene.Enabled = true; scene.WillRenderNotActive = true; return(scene); }
private static void InitializeScene(IceScene _scene) { _scene.InitializeContent(Game.Instance.Services); _scene.ContentManager.RootDirectory = GlobalDataHolder.ContentFolderPath; // Create a default full sized camera Camera camera = new Camera(); camera.Position = Vector2.Zero; camera.Update(1 / 60f); _scene.ActiveCameras.Add(camera); // Load Materials foreach (Material _material in _scene.Materials) { _material.Texture = _scene._content.Load <Texture2D>(_material.Filename.Substring(0, _material.Filename.Length - 4)); _material.Scope = AssetScope.Local; } // Load Fonts foreach (IceFont _font in _scene.Fonts) { _font.Font = _scene._content.Load <SpriteFont>(_font.Filename.Replace(".spritefont", "")); } #if !XNATOUCH foreach (IceEffect _effect in _scene.Effects) { if (_effect.Effects != null) { continue; } // removing ".fx" from the name string name = _effect.Filename.Substring(0, _effect.Filename.Length - 3); _effect.Load(GlobalDataHolder.ContentManager, new string[] { name }); } #endif //Load Scene Components foreach (IceSceneComponent _comp in _scene.SceneComponents) { _comp.SetOwner(_scene); _comp.OnRegister(); } //Register Scene Items for (int i = 0; i < _scene.SceneItems.Count; i++) { SceneItem item = _scene.SceneItems[i]; item.SceneParent = _scene; if (item.IsRegistered == false) { item.OnRegister(); } } }
/// <summary> /// Queues Up The Drawable Items to Draw to the screen /// </summary> /// <param name="device">The GraphicsDevice to use</param> /// <param name="elapsed">The elapsed gametime since the last draw</param> /// <param name="scene">The IceScene to draw</param> public static void DrawIceCreamScene(GraphicsDevice device, float elapsed, IceScene scene) { IceProfiler.StartProfiling(IceProfilerNames.ICE_CORE_DRAW); foreach (SceneItem _item in scene.SceneItems) { if (_item.IsTemplate == true) { continue; } _item.Draw(elapsed); } IceProfiler.StopProfiling(IceProfilerNames.ICE_CORE_DRAW); }
protected override void Draw(GameTime gameTime) { _elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (DrawingManager.IgnoreClearBeforeRendering == false) { this.GraphicsDevice.Clear(this.DefaultClearColor); } if (SceneManager.ActiveScene != null) { if (SceneManager.Scenes.Count > 1) { for (int i = 0; i < SceneManager.Scenes.Count; i++) { IceScene item = SceneManager.Scenes[i]; if (item != SceneManager.ActiveScene && item.WillRenderNotActive) { IceCore.DrawIceCreamScene(graphics.GraphicsDevice, _elapsed, item); } } } if (SceneManager.ActiveScene._hasBeenUpdatedOnce == true) { IceCore.DrawIceCreamScene(graphics.GraphicsDevice, _elapsed, SceneManager.ActiveScene); } IceCore.RenderIceCream(); } //for (int y = 0; y < SceneManager.ActiveScene._spatialGrid.Rows; y++) //{ // for (int x = 0; x < SceneManager.ActiveScene._spatialGrid.Cols; x++) // { // Drawing.DebugShapes.DrawLine( // new Vector2(x * SceneManager.ActiveScene._spatialGrid.CellSize, // 0), // new Vector2(x * SceneManager.ActiveScene._spatialGrid.CellSize, // SceneManager.ActiveScene._spatialGrid.SceneHeight), // Color.White); // } // Drawing.DebugShapes.DrawLine( // new Vector2(0, // y * SceneManager.ActiveScene._spatialGrid.CellSize), // new Vector2(SceneManager.ActiveScene._spatialGrid.SceneWidth, // y * SceneManager.ActiveScene._spatialGrid.CellSize), // Color.White); //} base.Draw(gameTime); }
public static IceScene AddBlankScene() { IceScene _newScene = new IceScene(); Camera _camera = new Camera(); _newScene.ActiveCameras.Add(_camera); Scenes.Add(_newScene); _newScene._content = new ContentManager(Game.Instance.Services); if (_activeScene == null) { _activeScene = _newScene; } return(_newScene); }
public static void UnLoadScene(IceScene oldScene) { oldScene.Unload(); oldScene.ContentManager.Unload(); oldScene.ContentManager.Dispose(); Scenes.Remove(oldScene); if (oldScene == ActiveScene) { ActiveScene = null; } if (ActiveScene == null && Scenes.Count > 0) //Pick the top scene { ActiveScene = Scenes[Scenes.Count - 1]; } }
protected override void Draw(GameTime gameTime) { _elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (DrawingManager.IgnoreClearBeforeRendering == false) { this.GraphicsDevice.Clear(this.DefaultClearColor); } if (SceneManager.ActiveScene != null) { if (SceneManager.Scenes.Count > 1) { for (int i = 0; i < SceneManager.Scenes.Count; i++) { IceScene item = SceneManager.Scenes[i]; if (item != SceneManager.ActiveScene && item.WillRenderNotActive) { IceCore.DrawIceCreamScene(graphics.GraphicsDevice, _elapsed, item); } } } if (SceneManager.ActiveScene._hasBeenUpdatedOnce == true) { IceCore.DrawIceCreamScene(graphics.GraphicsDevice, _elapsed, SceneManager.ActiveScene); } IceCore.RenderIceCream(); IceCream.Debug.OnScreenStats.Draw(); DrawingManager.GraphicsDevice.RasterizerState = RasterizerState.CullNone; DrawingManager.GraphicsDevice.DepthStencilState = DepthStencilState.Default; //DrawingManager.SpriteBatch.Begin(); IceFarseerManager.Instance.DrawDebug(DrawingManager.SpriteBatch, SceneManager.ActiveScene.ActiveCameras[0]); //DrawingManager.SpriteBatch.End(); //PrimitiveBatch _primitiveBatch = new PrimitiveBatch(DrawingManager.GraphicsDevice); //_primitiveBatch.SetViewPortSize(DrawingManager.ViewPortSize.X, DrawingManager.ViewPortSize.Y); //_primitiveBatch.Begin(PrimitiveType.TriangleList, SceneManager.ActiveScene.ActiveCameras[0].GetMatrix(DebugShapes.Parallax)); //Color colorFill = Color.Black; //List<Vector2> vertices = new List<Vector2>(); //vertices.Add(new Vector2(0, 0)); //vertices.Add(new Vector2(300, 0)); //vertices.Add(new Vector2(100, 200)); //vertices.Add(new Vector2(10, 20)); //DebugShapes.DrawPolygon(vertices.ToArray(), colorFill); ////_primitiveBatch.AddVertex(vertices[0], colorFill); ////_primitiveBatch.AddVertex(vertices[1], colorFill); ////_primitiveBatch.AddVertex(vertices[2], colorFill); //Vector2[] _tempVertices = new Vector2[Settings.MaxPolygonVertices]; //SceneItem testItem = SceneManager.ActiveScene.SceneItems[4]; //foreach (Fixture fixture in testItem.IceFarseerEntity.Body.FixtureList) //{ // PolygonShape poly = (PolygonShape)fixture.Shape; // int vertexCount = poly.Vertices.Count; // System.Diagnostics.Debug.Assert(vertexCount <= Settings.MaxPolygonVertices); // Transform xf; // fixture.Body.GetTransform(out xf); // for (int i = 0; i < vertexCount; ++i) { // _tempVertices[i] = MathUtils.Multiply(ref xf, poly.Vertices[i]); // } // DebugShapes.DrawSolidPolygon(_tempVertices, vertexCount, colorFill); //} ////foreach (DebugLine line in DebugShapes.LinesList) { //// _primitiveBatch.AddVertex(line.vertex, line.color); ////} //_primitiveBatch.End(); } //for (int y = 0; y < SceneManager.ActiveScene._spatialGrid.Rows; y++) //{ // for (int x = 0; x < SceneManager.ActiveScene._spatialGrid.Cols; x++) // { // Drawing.DebugShapes.DrawLine( // new Vector2(x * SceneManager.ActiveScene._spatialGrid.CellSize, // 0), // new Vector2(x * SceneManager.ActiveScene._spatialGrid.CellSize, // SceneManager.ActiveScene._spatialGrid.SceneHeight), // Color.White); // } // Drawing.DebugShapes.DrawLine( // new Vector2(0, // y * SceneManager.ActiveScene._spatialGrid.CellSize), // new Vector2(SceneManager.ActiveScene._spatialGrid.SceneWidth, // y * SceneManager.ActiveScene._spatialGrid.CellSize), // Color.White); //} base.Draw(gameTime); }