Ejemplo n.º 1
0
        private void m_gameDocumentRegistry_DocumentRemoved(object sender, ItemRemovedEventArgs <IGameDocument> e)
        {
            IGameDocument document = e.Item;
            IGame         game     = document.Cast <IGame>();

            if (document == m_designView.Context.Cast <IGameDocument>())
            {// master document.
                IGrid        grid       = document.As <IGame>().Grid;
                GridRenderer gridRender = grid.Cast <GridRenderer>();
                gridRender.DeleteVertexBuffer();
                m_designView.Context = null;
                GameEngine.DestroyObject(game.Cast <NativeObjectAdapter>());
                GameEngine.Clear();
            }
            else
            {// sub document.
                DomNode masterNode            = m_gameDocumentRegistry.MasterDocument.As <DomNode>();
                DomNode rooFolderNode         = game.RootGameObjectFolder.Cast <DomNode>();
                NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>();
                gworld.Remove(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"));
            }
        }
Ejemplo n.º 2
0
        // render the scene.
        public override void Render()
        {
            bool skipRender =
                SurfaceId == 0 ||
                GameEngine.IsInError ||
                Width == 0 ||
                Height == 0 ||
                DesignView.Context == null;

            if (skipRender)
            {
                return;
            }

            m_clk.Start();
            GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, DesignView.BackColor);
            GameEngine.SetRenderState(RenderState);
            GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);

            IGame        game       = DesignView.Context.As <IGame>();
            GridRenderer gridRender = game.Grid.Cast <GridRenderer>();

            gridRender.Render(Camera);

            GameEngine.RenderGame();

            bool renderSelected = RenderState.DisplayBound == DisplayFlagModes.Selection ||
                                  RenderState.DisplayCaption == DisplayFlagModes.Selection ||
                                  RenderState.DisplayPivot == DisplayFlagModes.Selection;

            if (renderSelected)
            {
                var selection = DesignView.Context.As <ISelectionContext>().Selection;
                IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());
                RenderProperties(rootDomNodes,
                                 RenderState.DisplayCaption == DisplayFlagModes.Selection,
                                 RenderState.DisplayBound == DisplayFlagModes.Selection,
                                 RenderState.DisplayPivot == DisplayFlagModes.Selection);
            }

            RenderProperties(Items,
                             RenderState.DisplayCaption == DisplayFlagModes.Always,
                             RenderState.DisplayBound == DisplayFlagModes.Always,
                             RenderState.DisplayPivot == DisplayFlagModes.Always);

            GameEngine.SetRendererFlag(BasicRendererFlags.Foreground | BasicRendererFlags.Lit);
            if (DesignView.Manipulator != null)
            {
                DesignView.Manipulator.Render(this);
            }

            string str = string.Format("View Type: {0}   time per frame-render call: {1:0.00} ms", ViewType, m_clk.Milliseconds);

            GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
            GameEngine.End();

            if (IsPicking)
            {// todo: use Directx to draw marque.
                using (Graphics g = CreateGraphics())
                {
                    Rectangle rect = MakeRect(FirstMousePoint, CurrentMousePoint);
                    if (rect.Width > 0 && rect.Height > 0)
                    {
                        g.DrawRectangle(s_marqueePen, rect);
                    }
                }
            }
        }