示例#1
0
        public NativeDesignControl(DesignView designView) :
            base(designView)
        {
            ClientSize = new Size(10, 10);
            if (!GameEngine.IsInError)
            {
                swapChainId = GameEngine.GetObjectTypeId("SwapChain");
                SurfaceId   = GameEngine.CreateObject(swapChainId, this.Handle, IntPtr.Size);
                SizePropId  = GameEngine.GetObjectPropertyId(swapChainId, "Size");
                GameEngine.SetObjectProperty(swapChainId, SurfaceId, SizePropId, ClientSize);
                BkgColorPropId = GameEngine.GetObjectPropertyId(swapChainId, "BkgColor");
                GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, BackColor);
            }
            if (s_marqueePen == null)
            {
                s_marqueePen             = new Pen(Color.FromArgb(30, 30, 30), 2);
                s_marqueePen.DashPattern = new float[] { 3, 3 };
            }

            m_renderState                = new RenderState();
            m_renderState.RenderFlag     = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit | GlobalRenderFlags.Shadows;
            m_renderState.WireFrameColor = Color.DarkBlue;
            m_renderState.SelectionColor = Color.FromArgb(66, 255, 161);
            BackColor              = SystemColors.ControlDark;
            m_renderState.Changed += (sender, e) => Invalidate();
        }
示例#2
0
        private void m_gameDocumentRegistry_DocumentAdded(object sender, ItemInsertedEventArgs <IGameDocument> e)
        {
            IGameDocument document = e.Item;
            IGame         game     = document.Cast <IGame>();

            if (document == m_gameDocumentRegistry.MasterDocument)
            {
                NativeObjectAdapter gameLevel = document.Cast <NativeObjectAdapter>();
                GameEngine.CreateObject(gameLevel);
                GameEngine.SetGameLevel(gameLevel);
                gameLevel.UpdateNativeOjbect();

                //create vertex buffer for grid.
                IGrid        grid       = document.As <IGame>().Grid;
                GridRenderer gridRender = grid.Cast <GridRenderer>();
                gridRender.CreateVertices();

                m_designView.Context = document.Cast <IGameContext>();
            }
            DomNode masterNode    = m_gameDocumentRegistry.MasterDocument.As <DomNode>();
            DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>();

            NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>();

            gworld.Insert(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"), -1);
        }
示例#3
0
        public RenderState()
        {
            string typeName = typeof(RenderState).Name;

            m_typeId       = GameEngine.GetObjectTypeId(typeName);
            m_intanceId    = GameEngine.CreateObject(m_typeId, IntPtr.Zero, 0);
            m_renderFlagId = GameEngine.GetObjectPropertyId(m_typeId, "GlobalRenderFlags");
            m_wirecolorId  = GameEngine.GetObjectPropertyId(m_typeId, "WireframeColor");
            m_selColorId   = GameEngine.GetObjectPropertyId(m_typeId, "SelectionColor");
        }
示例#4
0
 public ImageData(ulong instanceId)
 {
     TypeId          = GameEngine.GetObjectTypeId("ImageData");
     LoadFromFileId  = GameEngine.GetObjectPropertyId(TypeId, "LoadFromFile");
     ConvertId       = GameEngine.GetObjectPropertyId(TypeId, "Convert");
     BufferPointerId = GameEngine.GetObjectPropertyId(TypeId, "BufferPointer");
     WidthId         = GameEngine.GetObjectPropertyId(TypeId, "Width");
     HeightId        = GameEngine.GetObjectPropertyId(TypeId, "Height");
     BytesPerPixelId = GameEngine.GetObjectPropertyId(TypeId, "BytesPerPixel");
     RowPitchId      = GameEngine.GetObjectPropertyId(TypeId, "RowPitch");
     FormatId        = GameEngine.GetObjectPropertyId(TypeId, "Format");
     m_instanceId    = instanceId;
     if (m_instanceId == 0)
     {
         m_manageLifetime = true;
         m_instanceId     = GameEngine.CreateObject(TypeId, IntPtr.Zero, 0);
     }
     RefreshCachedProperties();
 }
示例#5
0
        public void Insert(DomNode parent, DomNode child, ChildInfo chInfo, int index)
        {
            NativeObjectAdapter childObject  = child.As <NativeObjectAdapter>();
            NativeObjectAdapter parentObject = parent.As <NativeObjectAdapter>();

            object listIdObj = chInfo.GetTag(NativeAnnotations.NativeElement);

            if (childObject == null || parentObject == null || listIdObj == null)
            {
                return;
            }

            if (chInfo.IsList && index >= (parent.GetChildList(chInfo).Count - 1))
            {
                index = -1;
            }

            if (ManageNativeObjectLifeTime)
            {
                GameEngine.CreateObject(childObject);
                childObject.UpdateNativeOjbect();
            }
            System.Diagnostics.Debug.Assert(childObject.InstanceId != 0);

            uint  listId   = (uint)listIdObj;
            uint  typeId   = (uint)chInfo.DefiningType.GetTag(NativeAnnotations.NativeType);
            ulong parentId = parentObject.InstanceId;
            ulong childId  = childObject.InstanceId;

            if (index >= 0)
            {
                GameEngine.ObjectInsertChild(typeId, listId, parentId, childId, index);
            }
            else
            {
                GameEngine.ObjectAddChild(typeId, listId, parentId, childId);
            }

            foreach (var node in child.Children)
            {
                Insert(child, node, node.ChildInfo, -1); // use -1 for index to indicate an append operation.
            }
        }
示例#6
0
        public TextureRenderSurface(int width, int height)
        {
            Size   sz  = new Size(width, height);
            IntPtr ptr = IntPtr.Zero;

            unsafe
            {
                ptr = new IntPtr(&sz);
            };

            int sizeInBytes = System.Runtime.InteropServices.Marshal.SizeOf(sz);

            string typeName = this.GetType().Name;

            m_typeId       = GameEngine.GetObjectTypeId(typeName);
            BkgColorPropId = GameEngine.GetObjectPropertyId(m_typeId, "BkgColor");

            m_intanceId = GameEngine.CreateObject(0, 0, m_typeId, null);
        }
示例#7
0
        private void Init()
        {
            if (m_game != null)
            {
                return;
            }

            NativeObjectAdapter curLevel = GameEngine.GetGameLevel();

            try
            {
                // create new document by creating a Dom node of the root type defined by the schema
                DomNode   rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement);
                INameable nameable = rootNode.As <INameable>();
                nameable.Name = "Game";
                NativeObjectAdapter gameLevel = rootNode.Cast <NativeObjectAdapter>();
                GameEngine.CreateObject(gameLevel);
                GameEngine.SetGameLevel(gameLevel);
                gameLevel.UpdateNativeOjbect();
                NativeGameWorldAdapter gworld = rootNode.Cast <NativeGameWorldAdapter>();
                m_game = rootNode.Cast <IGame>();
                IGameObjectFolder rootFolder = m_game.RootGameObjectFolder;
                m_renderSurface.Game            = m_game;
                m_renderSurface.GameEngineProxy = m_gameEngine;
            }
            finally
            {
                GameEngine.SetGameLevel(curLevel);
            }


            m_mainWindow.Closed += delegate
            {
                GameEngine.DestroyObject(m_game.Cast <NativeObjectAdapter>());
                m_renderSurface.Dispose();
            };
        }
示例#8
0
        private void Init()
        {
            NativeObjectAdapter curLevel = GameEngine.GetGameLevel();

            try
            {
                // create new document by creating a Dom node of the root type defined by the schema
                DomNode   rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement);
                INameable nameable = rootNode.Cast <INameable>();
                nameable.Name = "ThumbnailGenerator";

                NativeObjectAdapter gameLevel = rootNode.Cast <NativeObjectAdapter>();
                GameEngine.CreateObject(gameLevel);
                GameEngine.SetGameLevel(gameLevel);
                gameLevel.UpdateNativeOjbect();
                NativeGameWorldAdapter gworld = rootNode.Cast <NativeGameWorldAdapter>();

                m_game = rootNode.Cast <IGame>();
                IGameObjectFolder rootFolder = m_game.RootGameObjectFolder;
                m_renderSurface          = new TextureRenderSurface(96, 96);
                m_renderState            = new RenderState();
                m_renderState.RenderFlag = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit | GlobalRenderFlags.Shadows;
            }
            finally
            {
                GameEngine.SetGameLevel(curLevel);
            }


            m_mainWindow.Closed += delegate
            {
                GameEngine.DestroyObject(m_game.Cast <NativeObjectAdapter>());
                m_renderSurface.Dispose();
                m_renderState.Dispose();
            };
        }
示例#9
0
        private void CreateNativeObject()
        {
            var node = DomNode;

            if (DomNode == null || m_instanceId != 0)
            {
                return;
            }

            var doc = node.GetRoot().As <NativeDocumentAdapter>();

            if (doc != null && doc.ManageNativeObjectLifeTime)
            {
                // The object might have a pre-assigned instance id.
                // If so, we should attempt to use that same id.
                // This is important if we want the id to persist between sessions
                //      --  For example, we must reference placement objects through
                //          a GUID value that remains constant. We don't want to create
                //          new temporary ids for placements every time we create them,
                //          when the GUID value is more reliable

                ulong existingId = 0;
                var   idField    = DomNode.Type.GetAttributeInfo("ID");
                if (idField != null)
                {
                    var id = DomNode.GetAttribute(idField);
                    if (id is UInt64)
                    {
                        existingId = (UInt64)id;
                    }
                    else
                    {
                        string stringId = id as string;
                        if (stringId != null && stringId.Length > 0)
                        {
                            if (!UInt64.TryParse(stringId, out existingId))
                            {
                                existingId = GUILayer.Utils.HashID(stringId);
                            }
                        }
                    }
                }

                using (var transfer = new NativePropertyTransfer())
                {
                    using (var stream = transfer.CreateStream())
                    {
                        foreach (AttributeInfo attribInfo in this.DomNode.Type.Attributes)
                        {
                            UpdateNativeProperty(DomNode, attribInfo, transfer.Properties, stream);
                        }
                        UpdateSecondaryNativeProperties(transfer.Properties, stream);
                        m_instanceId = GameEngine.CreateObject(doc.NativeDocumentId, existingId, TypeId, transfer.Properties);
                    }
                }

                if (m_instanceId != 0)
                {
                    m_documentId = doc.NativeDocumentId;
                    GameEngine.RegisterGob(m_documentId, m_instanceId, this);
                }
            }
        }
示例#10
0
            public NativeViewControl()
            {
                ClientSize = new Size(16, 16);
                if (!GameEngine.IsInError)
                {
                    swapChainId = GameEngine.GetObjectTypeId("SwapChain");
                    SurfaceId   = GameEngine.CreateObject(swapChainId, this.Handle, IntPtr.Size);
                    SizePropId  = GameEngine.GetObjectPropertyId(swapChainId, "Size");
                    GameEngine.SetObjectProperty(swapChainId, SurfaceId, SizePropId, ClientSize);
                    BkgColorPropId = GameEngine.GetObjectPropertyId(swapChainId, "BkgColor");
                    GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, BackColor);
                }

                m_renderState                = new RenderState();
                m_renderState.RenderFlag     = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit;
                m_renderState.WireFrameColor = Color.DarkBlue;
                m_renderState.SelectionColor = Color.FromArgb(66, 255, 161);
                BackColor = SystemColors.ControlDark;


                #region Context menu
                GlobalRenderFlags[] flags = new GlobalRenderFlags[]
                {
                    GlobalRenderFlags.Solid,
                    GlobalRenderFlags.WireFrame,
                    GlobalRenderFlags.Textured,
                    GlobalRenderFlags.RenderBackFace,
                    GlobalRenderFlags.Lit
                };
                ContextMenuStrip cntx = new ContextMenuStrip();
                foreach (var flag in flags)
                {
                    ToolStripMenuItem item =
                        new ToolStripMenuItem(flag.ToString());
                    item.Tag    = flag;
                    item.Click += delegate(object sender, EventArgs e)
                    {
                        ToolStripMenuItem menu = (ToolStripMenuItem)sender;
                        RenderState.RenderFlag = RenderState.RenderFlag ^ (GlobalRenderFlags)menu.Tag;
                        this.Invalidate();
                    };

                    cntx.Items.Add(item);
                }



                cntx.Items.Add(new ToolStripSeparator());
                ToolStripMenuItem views = new ToolStripMenuItem("View");
                cntx.Items.Add(views);
                views.DropDownOpening += delegate
                {
                    foreach (ToolStripMenuItem item in views.DropDownItems)
                    {
                        item.Checked = (ViewType == (ViewTypes)item.Tag);
                    }
                };

                foreach (var val in Enum.GetValues(typeof(ViewTypes)))
                {
                    ViewTypes         viewtype = (ViewTypes)val;
                    ToolStripMenuItem item     = new ToolStripMenuItem(viewtype.ToString());
                    item.Tag    = viewtype;
                    item.Click += delegate(object sender, EventArgs e)
                    {
                        ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
                        this.ViewType = (ViewTypes)menuItem.Tag;
                    };

                    views.DropDownItems.Add(item);
                }


                cntx.Opening += delegate
                {
                    GlobalRenderFlags renderflags = RenderState.RenderFlag;
                    foreach (ToolStripItem item in cntx.Items)
                    {
                        if (item is ToolStripSeparator)
                        {
                            break;
                        }
                        ((ToolStripMenuItem)item).Checked = (renderflags & (GlobalRenderFlags)item.Tag) != 0;
                    }
                };

                this.ContextMenuStrip = cntx;
                #endregion
            }