コード例 #1
0
        void IInitializable.Initialize()
        {
            m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent);
            m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this);

            Application.ApplicationExit += delegate
            {
                Util3D.Shutdown();
                GameEngine.Shutdown();
            };

            GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews();

            m_gameDocumentRegistry.DocumentAdded   += m_gameDocumentRegistry_DocumentAdded;
            m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved;

            string ns = m_schemaLoader.NameSpace;

            // register GridRenderer on grid child.
            DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType");

            gridType.Define(new ExtensionInfo <GridRenderer>());

            // register NativeGameWorldAdapter on game type.
            m_schemaLoader.GameType.Define(new ExtensionInfo <NativeDocumentAdapter>());

            // parse schema annotation.
            foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes())
            {
                var topLevelAnnotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (topLevelAnnotations == null)
                {
                    continue;
                }

                // First, go through and interpret the annotations that are not inherited
                List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>();
                foreach (XmlNode annot in topLevelAnnotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == NativeAnnotations.NativeType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeObjectAdapter>());
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeDocumentType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeDocumentType, GameEngine.GetDocumentTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeDocumentAdapter>());
                        }
                    }
                }

                if (domType.GetTag(NativeAnnotations.NativeType) == null)
                {
                    continue;
                }
                uint typeId          = (uint)domType.GetTag(NativeAnnotations.NativeType);
                bool isBoundableType = false;

                // Now, go through and interpret annotations that can be inheritted from base clases.
                // Sometimes a native property can be inheritted from a base class. In this model, we
                // will create a separate "property id" for each concrete class. When a property is
                // inheritted, the "property ids" for each type in the inheritance chain will be different
                // and unrelated.

                foreach (var inherittedType in domType.Lineage)
                {
                    var annotations = inherittedType.GetTagLocal <IEnumerable <XmlNode> >();
                    if (annotations == null)
                    {
                        continue;
                    }

                    foreach (XmlNode annot in annotations)
                    {
                        XmlElement elm = annot as XmlElement;
                        if (elm.LocalName == NativeAnnotations.NativeProperty)
                        {
                            // find a prop name and added to the attribute.
                            string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName);
                            string attribName     = elm.GetAttribute(NativeAnnotations.Name);
                            uint   propId         = GameEngine.GetObjectPropertyId(typeId, nativePropName);
                            if (!string.IsNullOrEmpty(attribName))
                            {
                                AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name));
                                attribInfo.SetTag(NativeAnnotations.NativeProperty, propId);
                            }
                            else
                            {
                                NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId);
                                nativeAttribs.Add(attribInfo);
                            }

                            if (nativePropName == "Bounds" || nativePropName == "LocalBounds")
                            {
                                isBoundableType = true;
                            }
                        }
                        else if (elm.LocalName == NativeAnnotations.NativeElement)
                        {
                            ChildInfo info = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name));
                            string    name = elm.GetAttribute(NativeAnnotations.NativeName);
                            info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name));
                        }
                        else if (elm.LocalName == NativeAnnotations.NativeVis)
                        {
                            using (var transfer = new NativeObjectAdapter.NativePropertyTransfer())
                            {
                                using (var stream = transfer.CreateStream())
                                    foreach (var a in elm.Attributes)
                                    {
                                        var attrib = a as XmlAttribute;
                                        if (attrib.Name == "geo")
                                        {
                                            NativeObjectAdapter.PushAttribute(
                                                0,
                                                typeof(string), 1,
                                                attrib.Value,
                                                transfer.Properties, stream);
                                        }
                                    }

                                GameEngine.SetTypeAnnotation(typeId, "vis", transfer.Properties);
                            }
                        }
                    }
                }

                if (nativeAttribs.Count > 0)
                {
                    domType.SetTag(nativeAttribs.ToArray());
                }

                if (isBoundableType && domType.IsAbstract == false)
                {
                    domType.Define(new ExtensionInfo <BoundableObject>());
                }
            }


            // register BoundableObject
            m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>());   // doesn't have a bound native attributes -- is this really intended?s

            #region code to handle gameObjectFolder

            {
                // This code is fragile and need to be updated whenever
                // any relevant part of the schema changes.
                // purpose:
                // gameObjectFolderType does not exist in C++
                // this code will map gameObjectFolderType to gameObjectGroupType.
                DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType;
                DomNodeType groupType     = m_schemaLoader.GameObjectGroupType;

                // map native bound attrib from gameObject to GobFolder
                NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>();
                foreach (var attrib in nativeAttribs)
                {
                    if (attrib.Name == "Bounds")
                    {
                        gobFolderType.SetTag(new NativeAttributeInfo[] { attrib });
                        break;
                    }
                }

                // map type.
                //      XLE --> Separate GameObjectFolder type from GameObjectGroup type
                // gobFolderType.Define(new ExtensionInfo<NativeObjectAdapter>());
                // gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType));

                // map all native attributes of gameObjectGroup to gameFolder
                foreach (AttributeInfo srcAttrib in groupType.Attributes)
                {
                    object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty);
                    if (nativeIdObject == null)
                    {
                        continue;
                    }
                    AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name);
                    if (destAttrib == null)
                    {
                        continue;
                    }
                    destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject);
                    destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib);
                }

                // map native element from gameObjectGroupType to gameObjectFolderType.
                object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement);
                foreach (ChildInfo srcChildInfo in gobFolderType.Children)
                {
                    if (srcChildInfo.IsList)
                    {
                        srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId);
                    }
                }

                m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId);
            }

            #endregion

            // set up scripting bindings
            if (m_scriptingService != null)
            {
                m_scriptingService.SetVariable("cv", new GUILayer.TweakableBridge());
            }
        }
コード例 #2
0
        void IInitializable.Initialize()
        {
            m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent);
            m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this);

            Application.ApplicationExit += delegate
            {
                Util3D.Shutdown();
                GameEngine.Shutdown();
            };

            GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews();

            m_gameDocumentRegistry.DocumentAdded   += m_gameDocumentRegistry_DocumentAdded;
            m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved;

            string ns = m_schemaLoader.NameSpace;

            // register GridRenderer on grid child.
            DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType");

            gridType.Define(new ExtensionInfo <GridRenderer>());

            // register NativeGameWorldAdapter on game type.
            m_schemaLoader.GameType.Define(new ExtensionInfo <NativeGameWorldAdapter>());

            // parse schema annotation.
            foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes())
            {
                IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (annotations == null)
                {
                    continue;
                }


                // collect all the properties that only exist in native side.
                List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>();

                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == NativeAnnotations.NativeType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeObjectAdapter>());
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeProperty)
                    {
                        // find a prop name and added to the attribute.


                        string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName);
                        string attribName     = elm.GetAttribute(NativeAnnotations.Name);
                        uint   typeId         = (uint)domType.GetTag(NativeAnnotations.NativeType);
                        uint   propId         = GameEngine.GetObjectPropertyId(typeId, nativePropName);
                        if (!string.IsNullOrEmpty(attribName))
                        {
                            AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name));
                            attribInfo.SetTag(NativeAnnotations.NativeProperty, propId);
                        }
                        else
                        {
                            NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId);
                            nativeAttribs.Add(attribInfo);
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeElement)
                    {
                        ChildInfo info   = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name));
                        uint      typeId = (uint)domType.GetTag(NativeAnnotations.NativeType);
                        string    name   = elm.GetAttribute(NativeAnnotations.NativeName);
                        info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name));
                    }
                }

                if (nativeAttribs.Count > 0)
                {
                    domType.SetTag(nativeAttribs.ToArray());
                }
            }


            // register BoundableObject
            m_schemaLoader.GameObjectType.Define(new ExtensionInfo <BoundableObject>());
            m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>());

            #region code to handle gameObjectFolder

            {
                // This code is fragile and need to be updated whenever
                // any relevant part of the schema changes.
                // purpose:
                // gameObjectFolderType does not exist in C++
                // this code will map gameObjectFolderType to gameObjectGroupType.
                DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType;
                DomNodeType groupType     = m_schemaLoader.GameObjectGroupType;

                // map native bound attrib from gameObject to GobFolder
                NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>();
                foreach (var attrib in nativeAttribs)
                {
                    if (attrib.Name == "Bounds")
                    {
                        gobFolderType.SetTag(new NativeAttributeInfo[] { attrib });
                        break;
                    }
                }

                // map type.
                gobFolderType.Define(new ExtensionInfo <NativeObjectAdapter>());
                gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType));

                // map all native attributes of gameObjectGroup to gameFolder
                foreach (AttributeInfo srcAttrib in groupType.Attributes)
                {
                    object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty);
                    if (nativeIdObject == null)
                    {
                        continue;
                    }
                    AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name);
                    if (destAttrib == null)
                    {
                        continue;
                    }
                    destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject);
                    destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib);
                }

                // map native element from gameObjectGroupType to gameObjectFolderType.
                object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement);
                foreach (ChildInfo srcChildInfo in gobFolderType.Children)
                {
                    if (srcChildInfo.IsList)
                    {
                        srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId);
                    }
                }

                m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId);
            }

            #endregion
        }